4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import Alt
from './alt';
21 var FleetSource
= require('./launchpadFleetSource.js');
22 var FleetActions
= require('./launchpadFleetActions.js');
23 import CardActions
from './launchpad_card/launchpadCardActions.js';
24 var Utils
= require('utils/utils.js');
25 import LaunchNetworkServiceSource
from './instantiate/launchNetworkServiceSource.js';
26 import LaunchNetworkServiceActions
from './instantiate/launchNetworkServiceActions.js';
28 import {LaunchpadSettings
} from './settings.js';
32 var _
= require('underscore');
33 // _.debounce(function(){});
34 function FleetStoreConstructor() {
37 this.descriptorCount
= 0;
39 this.selectedSlaParam
= '';
42 this.exportAsync(FleetSource
);
43 this.exportAsync(LaunchNetworkServiceSource
);
45 this.dropdownSlide
= ['', 0];
46 this.slideChange
= -1;
47 this.validateErrorEvent
= 0;
48 this.launchpadSettings
= new LaunchpadSettings();
49 this.openedNsrIDs
= this.launchpadSettings
.openedNSRs();
50 this.isNsListPanelVisible
= true;
54 openNSRSocketLoading
: FleetActions
.openNSRSocketLoading
,
55 openNSRSocketSuccess
: FleetActions
.openNSRSocketSuccess
,
57 handleUpdateControlInput
: CardActions
.updateControlInput
,
59 handleNsrControlSuccess
: FleetActions
.nsrControlSuccess
,
60 handleNsrControlError
: FleetActions
.nsrControlError
,
61 handleSlideNoStateChange
: FleetActions
.slideNoStateChange
,
62 handleSlideNoStateChangeSuccess
: FleetActions
.slideNoStateChangeSuccess
,
63 getNsrInstancesSuccess
: FleetActions
.getNsrInstancesSuccess
,
64 getNsrInstancesError
: FleetActions
.getNsrInstancesError
,
65 deleteNsrInstanceSuccess
: FleetActions
.deleteNsrInstanceSuccess
,
66 deletingNSR
: FleetActions
.deletingNSR
,
67 deleteNsrInstanceError
: FleetActions
.deleteNsrInstanceError
,
68 setNSRStatusSuccess
: FleetActions
.setNSRStatusSuccess
,
69 setNSRStatusError
: FleetActions
.setNSRStatusError
,
70 validateReset
: FleetActions
.validateReset
,
71 validateError
: FleetActions
.validateError
,
72 //Launch Network Service Source Actions
73 getCatalogSuccess
: LaunchNetworkServiceActions
.getCatalogSuccess
,
74 // Card management actions
75 openNsrCard
: FleetActions
.openNsrCard
,
76 closeNsrCard
: FleetActions
.closeNsrCard
,
77 instantiateNetworkService
: FleetActions
.instantiateNetworkService
,
78 setNsListPanelVisible
: FleetActions
.setNsListPanelVisible
,
81 this.bindAction(LaunchNetworkServiceActions
.launchNSRSuccess
, responseData
=> {
83 this.openNsrCard(responseData
.data
.nsr_id
);
85 console
.log("Unable to open NS Card for response data: ", responseData
);
88 this.exportPublicMethods({
89 getFleets: function() {
90 return this.getState().fleets
;
92 closeSocket
: this.closeSocket
.bind(self
)
96 FleetStoreConstructor
.prototype.handleLogout = function() {
100 FleetStoreConstructor
.prototype.closeSocket = function() {
102 window
.multiplexer
.channel(this.channelId
).close();
110 FleetStoreConstructor
.prototype.openNSRSocketLoading = function(connection
) {
111 console
.log('open socketloading')
112 Alt
.actions
.global
.showScreenLoader
.defer();
114 FleetStoreConstructor
.prototype.openNSRSocketSuccess = function(connection
) {
116 var isLoading
= true;
117 var ws
= window
.multiplexer
.channel(connection
);
118 if (!connection
) return;
121 channelId
: connection
123 ws
.onmessage = function(socket
) {
125 var data
= JSON
.parse(socket
.data
);
127 console
.warn('NSRS property not present on the payload, check that the api server is functioning correct and that the LP is fully launched. Received: ', data
);
130 Utils
.checkAuthentication(data
.statusCode
, function() {
133 let deletingNSRs
= [];
136 deletingNSRs
= _
.filter(self
.nsrs
, function(nsr
) {
137 return nsr
.deleting
== true;
141 deletingNSRs
.forEach(function(deletingNSR
) {
142 data
.nsrs
.map(nsr
=> {
143 if (nsr
.id
== deletingNSR
.id
) {
144 _
.extend(nsr
, deletingNSR
);
150 Alt
.actions
.global
.hideScreenLoader
.defer();
156 console
.log('HIT an exception in openNSRSocketSuccess', e
);
160 FleetStoreConstructor
.prototype.getNsrInstancesSuccess = function(data
) {
165 FleetStoreConstructor
.prototype.deleteNsrInstanceSuccess = function(data
) {
166 console
.log('deleted', data
)
169 FleetStoreConstructor
.prototype.deletingNSR = function(id
) {
170 console
.log('deleting NSR', id
);
174 nsrs
= this.nsrs
.map(nsr
=> {
177 self
.closedNsrCard(id
);
185 console
.log('No NSR\'s found. Should never get here');
189 FleetStoreConstructor
.prototype.deleteNsrInstanceError = function(data
) {};
190 FleetStoreConstructor
.prototype.getNsrInstancesError = function(data
) {
191 console
.log('ERROR', data
)
193 FleetStoreConstructor
.prototype.handleUpdateControlInput
= _
.debounce(function(data
) {
195 FleetStore
.nsrControl(opt
.operation
, opt
.url
, data
[1])
197 FleetStoreConstructor
.prototype.handleNsrControlSuccess = function(data
) {
200 FleetStoreConstructor
.prototype.handleNsrControlError = function() {};
201 FleetStoreConstructor
.prototype.handleSlideNoStateChange = function(data
) {
203 dropdownSlide
: data
.pane
,
205 slideChange
: data
.slideChange
208 FleetStoreConstructor
.prototype.handleSlideNoStateChangeSuccess = function() {
210 slideChange
: this.slideChange
- 1
213 FleetStoreConstructor
.prototype.setNSRStatusSuccess = function() {};
214 FleetStoreConstructor
.prototype.setNSRStatusError = function(data
) {
215 console
.log('Error changing NSR State', data
)
218 FleetStoreConstructor
.prototype.getCatalogSuccess = function(data
) {
220 var descriptorCount
= 0;
221 data
.forEach(function(catalog
) {
222 descriptorCount
+= catalog
.descriptors
.length
;
226 descriptorCount
: descriptorCount
230 FleetStoreConstructor
.prototype.validateError = function(msg
) {
232 validateErrorEvent
: true,
233 validateErrorMsg
: msg
236 FleetStoreConstructor
.prototype.validateReset = function() {
238 validateErrorEvent
: false
243 FleetStoreConstructor
.prototype.openNsrCard = function(id
) {
244 //console.log("*** *** FleetStore.openNsrCard with nsr id:", id);
245 const openedNsrIDs
= this.openedNsrIDs
.slice(0);
246 // Only add if card is not there
248 if (!openedNsrIDs
.includes(id
)) {
249 openedNsrIDs
.unshift(id
);
250 this.launchpadSettings
.addOpenNSR(id
);
252 openedNsrIDs
: openedNsrIDs
255 console
.log("NSR already open, id:%s", id
);
258 console
.log("null nsr id.");
261 FleetStoreConstructor
.prototype.closeNsrCard = function(id
) {
262 this.launchpadSettings
.removeOpenNSR(id
);
264 openedNsrIDs
: this.openedNsrIDs
.filter(nsr_id
=> nsr_id
!== id
)
267 FleetStoreConstructor
.prototype.instantiateNetworkService = function(id
) {
268 window
.location
.hash
= window
.location
.hash
+ '/launch';
271 FleetStoreConstructor
.prototype.setNsListPanelVisible = function(isVisible
) {
273 isNsListPanelVisible
: isVisible
277 FleetStore
= Alt
.createStore(FleetStoreConstructor
);
278 module
.exports
= FleetStore
;