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';
20 import _filter
from 'lodash/filter';
21 import _extend
from 'lodash/extend';
22 import _debounce
from 'lodash/debounce';
23 var FleetSource
= require('./launchpadFleetSource.js');
24 var FleetActions
= require('./launchpadFleetActions.js');
25 import CardActions
from './launchpad_card/launchpadCardActions.js';
26 var Utils
= require('utils/utils.js');
27 import LaunchNetworkServiceSource
from './instantiate/launchNetworkServiceSource.js';
28 import LaunchNetworkServiceActions
from './instantiate/launchNetworkServiceActions.js';
30 import {LaunchpadSettings
} from './settings.js';
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
,
79 getVDUConsoleLinkSuccess
: FleetActions
.getVDUConsoleLinkSuccess
82 this.bindAction(LaunchNetworkServiceActions
.launchNSRSuccess
, responseData
=> {
84 this.openNsrCard(responseData
.data
.nsr_id
);
86 console
.log("Unable to open NS Card for response data: ", responseData
);
89 this.exportPublicMethods({
90 getFleets: function() {
91 return this.getState().fleets
;
93 closeSocket
: this.closeSocket
.bind(self
)
97 FleetStoreConstructor
.prototype.handleLogout = function() {
101 FleetStoreConstructor
.prototype.closeSocket = function() {
103 window
.multiplexer
.channel(this.channelId
).close();
111 FleetStoreConstructor
.prototype.openNSRSocketLoading = function(connection
) {
112 console
.log('open socketloading')
113 Alt
.actions
.global
.showScreenLoader
.defer();
115 FleetStoreConstructor
.prototype.openNSRSocketSuccess = function(connection
) {
117 var isLoading
= true;
118 var ws
= window
.multiplexer
.channel(connection
);
119 if (!connection
) return;
122 channelId
: connection
124 ws
.onmessage = function(socket
) {
126 var data
= JSON
.parse(socket
.data
);
128 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
);
131 Utils
.checkAuthentication(data
.statusCode
, function() {
134 let deletingNSRs
= [];
137 deletingNSRs
= _filter(self
.nsrs
, function(nsr
) {
138 return nsr
.deleting
== true;
142 deletingNSRs
.forEach(function(deletingNSR
) {
143 data
.nsrs
.map(nsr
=> {
144 if (nsr
.id
== deletingNSR
.id
) {
145 _extend(nsr
, deletingNSR
);
151 Alt
.actions
.global
.hideScreenLoader
.defer();
157 console
.log('HIT an exception in openNSRSocketSuccess', e
);
161 FleetStoreConstructor
.prototype.getNsrInstancesSuccess = function(data
) {
166 FleetStoreConstructor
.prototype.deleteNsrInstanceSuccess = function(data
) {
167 console
.log('deleted', data
)
170 FleetStoreConstructor
.prototype.deletingNSR = function(id
) {
171 console
.log('deleting NSR', id
);
175 nsrs
= this.nsrs
.map(nsr
=> {
178 self
.closedNsrCard(id
);
186 console
.log('No NSR\'s found. Should never get here');
190 FleetStoreConstructor
.prototype.deleteNsrInstanceError = function(data
) {};
191 FleetStoreConstructor
.prototype.getNsrInstancesError = function(data
) {
192 console
.log('ERROR', data
)
194 FleetStoreConstructor
.prototype.handleUpdateControlInput
= _debounce(function(data
) {
196 FleetStore
.nsrControl(opt
.operation
, opt
.url
, data
[1])
198 FleetStoreConstructor
.prototype.handleNsrControlSuccess = function(data
) {
201 FleetStoreConstructor
.prototype.handleNsrControlError = function() {};
202 FleetStoreConstructor
.prototype.handleSlideNoStateChange = function(data
) {
204 dropdownSlide
: data
.pane
,
206 slideChange
: data
.slideChange
209 FleetStoreConstructor
.prototype.handleSlideNoStateChangeSuccess = function() {
211 slideChange
: this.slideChange
- 1
214 FleetStoreConstructor
.prototype.setNSRStatusSuccess = function() {};
215 FleetStoreConstructor
.prototype.setNSRStatusError = function(data
) {
216 console
.log('Error changing NSR State', data
)
219 FleetStoreConstructor
.prototype.getCatalogSuccess = function(data
) {
221 var descriptorCount
= 0;
222 data
.forEach(function(catalog
) {
223 descriptorCount
+= catalog
.descriptors
.length
;
227 descriptorCount
: descriptorCount
231 FleetStoreConstructor
.prototype.validateError = function(msg
) {
233 validateErrorEvent
: true,
234 validateErrorMsg
: msg
237 FleetStoreConstructor
.prototype.validateReset = function() {
239 validateErrorEvent
: false
244 FleetStoreConstructor
.prototype.openNsrCard = function(id
) {
245 //console.log("*** *** FleetStore.openNsrCard with nsr id:", id);
246 const openedNsrIDs
= this.openedNsrIDs
.slice(0);
247 // Only add if card is not there
249 if (!openedNsrIDs
.includes(id
)) {
250 openedNsrIDs
.unshift(id
);
251 this.launchpadSettings
.addOpenNSR(id
);
253 openedNsrIDs
: openedNsrIDs
256 console
.log("NSR already open, id:%s", id
);
259 console
.log("null nsr id.");
262 FleetStoreConstructor
.prototype.closeNsrCard = function(id
) {
263 this.launchpadSettings
.removeOpenNSR(id
);
265 openedNsrIDs
: this.openedNsrIDs
.filter(nsr_id
=> nsr_id
!== id
)
268 FleetStoreConstructor
.prototype.instantiateNetworkService = function(id
) {
269 window
.location
.hash
= window
.location
.hash
+ '/launch';
272 FleetStoreConstructor
.prototype.setNsListPanelVisible = function(isVisible
) {
274 isNsListPanelVisible
: isVisible
278 FleetStoreConstructor
.prototype.getVDUConsoleLinkSuccess = function(data
) {
279 data
['console-url'] && window
.open(data
['console-url']);
282 FleetStore
= Alt
.createStore(FleetStoreConstructor
, 'FleetStore');
283 module
.exports
= FleetStore
;