3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 import NetworkServiceActions
from './launchNetworkServiceActions.js';
19 import NetworkServiceSource
from './launchNetworkServiceSource.js';
20 import GUID
from 'utils/guid.js';
21 import AppHeaderActions
from 'widgets/header/headerActions.js';
22 import Alt
from '../alt';
23 import _cloneDeep
from 'lodash/cloneDeep';
24 import _find
from 'lodash/find';
27 class LaunchNetworkServiceStore
{
37 this.sshKeysList
= [];
39 this.sla_parameters
= [];
41 this.selectedNSD
= {};
42 this.selectedCloudAccount
= {};
43 this.dataCenters
= [];
44 this.cloudAccounts
= [];
45 this.isLoading
= false;
46 this.hasConfigureNSD
= false;
47 this['input-parameters'] = [];
48 this.displayPlacementGroups
= false;
50 this.bindActions(NetworkServiceActions
);
51 this.nsdConfiguration
= {
53 selectedCloudAccount
: {},
56 /*Collection of vnf state containting cloud account and datacenter info.
59 this.vnfdCloudAccounts
= {};
61 this.configAgentAccounts
= [];
63 this.isPreviewing
= false;
64 this.isOpenMano
= false;
65 this.registerAsync(NetworkServiceSource
);
66 this.exportPublicMethods({
67 getMockData
: getMockData
.bind(this),
68 getMockSLA
: getMockSLA
.bind(this),
69 saveNetworkServiceRecord
: this.saveNetworkServiceRecord
,
72 updateInputParam
: this.updateInputParam
,
73 resetView
: this.resetView
,
74 nameUpdated
: this.nameUpdated
,
76 descriptorSelected
: this.descriptorSelected
.bind(this),
77 deselectDescriptor
: this.deselectDescriptor
,
78 previewDescriptor
: this.previewDescriptor
,
80 ipProfileFn
: this.ipProfileFn
,
82 usersFn
: this.usersFn
,
89 console
.log('reseting state');
92 'input-parameter-xpath': null,
93 'ns-placement-groups': null,
94 'vnf-placement-groups':null,
101 getCatalogSuccess(catalogs
) {
107 catalogs
.forEach(function(catalog
) {
108 switch (catalog
.type
) {
112 self
.descriptorSelected(catalog
.descriptors
[0])
114 console
.log('unable to select catalog')
125 nsd
[0].descriptors
.map(function(n
) {
129 nsd
, vnfd
, pnfd
, nsdDict
,
133 getLaunchCloudAccountSuccess(cloudAccounts
) {
135 newState
.cloudAccounts
= cloudAccounts
.filter(function(v
) {
137 return v
['connection-status'].status
== 'success';
139 if(cloudAccounts
.length
!= newState
.cloudAccounts
.length
) {
140 Alt
.actions
.global
.showNotification
.defer({type
: 'warning', msg
: 'One or more VIM accounts have failed to connect'});
142 if(cloudAccounts
&& cloudAccounts
.length
> 0) {
143 newState
.selectedCloudAccount
= newState
.cloudAccounts
[0];
144 if (cloudAccounts
[0]['account-type'] == 'openstack') {
145 newState
.displayPlacementGroups
= true;
147 newState
.displayPlacementGroups
= false;
150 newState
.selectedCloudAccount
= {};
153 this.setState(newState
);
155 getConfigAgentSuccess(configAgentAccounts
) {
157 configAgentAccounts
: configAgentAccounts
160 getDataCentersSuccess(data
) {
161 let dataCenters
= data
;
164 dataCenters
: dataCenters
|| []
166 if (this.ro
&& this.ro
['account-type'] == 'openmano') {
167 newState
.dataCenterID
= dataCenters
[this.ro
.name
][0].uuid
169 this.setState(newState
)
171 getVDUSuccess(VNFD
) {
177 Alt
.actions
.global
.showScreenLoader
.defer();
181 console
.log('is Loading', this)
183 launchNSRSuccess(data
) {
184 console
.log('Launching Network Service')
185 let tokenizedHash
= window
.location
.hash
.split('/');
186 Alt
.actions
.global
.hideScreenLoader
.defer();
190 return window
.location
.hash
= 'launchpad/' + tokenizedHash
[2];
192 launchNSRError(data
) {
193 var msg
= 'Something went wrong while trying to instantiate. Check the error logs for more information';
200 Alt
.actions
.global
.showNotification
.defer(msg
);
201 Alt
.actions
.global
.hideScreenLoader
.defer();
206 getInstantiateSshKeySuccess
= (data
) => {
212 getResourceOrchestratorSuccess
= (data
) => {
213 Alt
.actions
.global
.hideScreenLoader
.defer();
218 getResourceOrchestratorError
= (data
) => {
219 console
.log('getResourceOrchestrator Error: ', data
)
222 nameUpdated
= (e
) => {
227 deselectDescriptor
= () => {
228 console
.log('deselecting')
235 descriptorSelected
= (data
) => {
240 selectedNSDid
: NSD
.id
,
241 vld
: NSD
&& NSD
.vld
&& NSD
.vld
.map(function(v
) {
242 //Adding a type for UI state management
243 //This is deleted before launch
244 if(v
['ip-profile-ref']) {
245 v
.type
= 'ip-profile-ref';
247 if(v
['vim-network-name']) {
248 v
.type
= 'vim-network-name';
255 ipProfiles
: NSD
['ip-profiles']
257 newState
.selectedNSD
= data
;
258 newState
['input-parameters'] = [];
259 if (NSD
['input-parameter-xpath']) {
260 newState
.hasConfigureNSD
= true;
261 NSD
['input-parameter-xpath'].map(function(p
) {
262 newState
.hasConfigureNSD
= true;
263 newState
['input-parameters'].push(_cloneDeep(p
));
266 newState
.hasConfigureNSD
= false;
267 newState
['input-parameters'] = null;
269 if(NSD
['ns-placement-groups'] && NSD
['ns-placement-groups'].length
> 0 ) {
270 newState
['ns-placement-groups'] = NSD
['ns-placement-groups'];
272 if(NSD
['vnf-placement-groups'] && NSD
['vnf-placement-groups'].length
> 0 ) {
273 newState
['vnf-placement-groups'] = NSD
['vnf-placement-groups'];
275 NSD
["constituent-vnfd"].map((v
) => {
276 VNFIDs
.push(v
["vnfd-id-ref"]);
278 this.getInstance().getVDU(VNFIDs
);
279 this.setState(newState
);
281 previewDescriptor
= (data
) => {
290 updateInputParam
= (i
, value
) => {
291 let ip
= this['input-parameters'];
294 'input-parameters': ip
300 updateSelectedCloudAccount
: (cloudAccount
) => {
301 let nsd
= self
.nsd
[0];
303 selectedCloudAccount
: JSON
.parse(cloudAccount
.target
.value
)
305 if (cloudAccount
['account-type'] == 'openstack') {
306 newState
.displayPlacementGroups
= true;
308 newState
.displayPlacementGroups
= false;
310 self
.setState(newState
);
312 updateSelectedDataCenter
: (dataCenter
) => {
314 dataCenterID
: JSON
.parse(dataCenter
.target
.value
)
317 placementGroupUpdate
: (i
, k
, event
) => {
318 let value
= event
.target
.value
;
319 let pg
= self
['ns-placement-groups'];
322 'ns-placement-groups': pg
325 hostAggregateUpdate
: (pgi
, hai
, k
, event
) => {
326 let value
= event
.target
.value
;
327 let pg
= self
['ns-placement-groups'];
328 let ha
= pg
[pgi
]['host-aggregate'][hai
];
331 'ns-placement-groups': pg
334 addHostAggregate
: (pgi
) => {
335 let pg
= self
['ns-placement-groups'];
336 let ha
= pg
[pgi
]['host-aggregate'];
339 'ns-placement-groups': pg
342 removeHostAggregate
: (pgi
, hai
) => {
343 let pg
= self
['ns-placement-groups'];
344 let ha
= pg
[pgi
]['host-aggregate'];
347 'ns-placement-groups': pg
350 getNSDByID
: (id
) => {
358 placementGroupUpdate
: (i
, k
, event
) => {
359 let value
= event
.target
.value
;
360 let pg
= self
['vnf-placement-groups'];
363 'vnf-placement-groups': pg
366 hostAggregateUpdate
: (pgi
, hai
, k
, event
) => {
367 let value
= event
.target
.value
;
368 let pg
= self
['vnf-placement-groups'];
369 let ha
= pg
[pgi
]['host-aggregate'][hai
];
372 'vnf-placement-groups': pg
375 addHostAggregate
: (pgi
) => {
376 let pg
= self
['vnf-placement-groups'];
377 let ha
= pg
[pgi
]['host-aggregate'];
380 'vnf-placement-groups': pg
383 removeHostAggregate
: (pgi
, hai
) => {
384 let pg
= self
['vnf-placement-groups'];
385 let ha
= pg
[pgi
]['host-aggregate'];
388 'vnf-placement-groups': pg
391 updateSelectedCloudAccount
: (id
, cloudAccount
) => {
392 let vnfCA
= self
.vnfdCloudAccounts
;
394 if(!vnfCA
.hasOwnProperty(id
)) {
397 vnfCA
[id
].account
= JSON
.parse(cloudAccount
.target
.value
);
399 if (cloudAccount
['account-type'] == 'openmano' && this.dataCenters
&& self
.dataCenters
[cloudAccount
['name']]) {
400 let datacenter
= self
.dataCenters
[cloudAccount
['name']][0];
401 vnfCA
[id
].datacenter
= datacenter
.uuid
;
403 if (vnfCA
[id
].datacenter
) {
404 delete vnfCA
[id
].datacenter
;
408 if(vnfCA
.hasOwnProperty(id
)) {
409 if(vnfCA
[id
].hasOwnProperty('config-agent-account')) {
410 delete vnfCA
[id
].account
;
417 vnfdCloudAccounts
: vnfCA
420 updateSelectedConfigAgent
: (id
) => {
422 let configAgentRef
= JSON
.parse(e
.target
.value
);
423 let vnfCA
= self
.vnfdCloudAccounts
;
425 if(!vnfCA
.hasOwnProperty(id
)) {
428 vnfCA
[id
]['config-agent-account'] = configAgentRef
;
430 if(vnfCA
[id
].hasOwnProperty('account')) {
431 delete vnfCA
[id
]['config-agent-account'];
437 vnfdCloudAccounts
: vnfCA
441 updateSelectedDataCenter
: (id
, dataCenter
) => {
442 let vnfCA
= self
.vnfdCloudAccounts
;
446 vnfCA
[id
].datacenter
= JSON
.parse(dataCenter
.target
.value
);
448 vnfdCloudAccounts
: vnfCA
458 let type
= e
.target
.value
;
460 if (vld
[i
].hasOwnProperty('type')) {
461 delete vld
[i
][vld
[i
].type
]
465 if(type
== 'ip-profile-ref') {
466 let IPProfile
= self
.ipProfiles
;
467 vld
[i
][type
] = IPProfile
[0] && IPProfile
[0].name
;
468 delete vld
[i
]['vim-network-name'];
470 delete vld
[i
]['dns-server'];
473 delete vld
[i
]['ip-profile-ref'];
474 delete vld
[i
]['vim-network-name'];
476 self
.setState({vld
:vld
});
479 updateValue
: (i
, type
) => {
481 // Select Option returns JSON values.
482 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
484 vld
[i
][type
] = value
;
485 self
.setState({vld
:vld
});
490 ipProfileFn
= () => {
493 updateProfile
: (i
, key
) => {
495 // Select Option returns JSON values.
496 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
497 self
.ipProfiles
[i
]['ip-profile-params'][key
] = value
;
500 // Don't send this key
501 delete self
.ipProfiles
[i
]['ip-profile-params'][key
];
504 self
.setState({ipProfiles
:self
.ipProfiles
});
507 updateVersion
: (i
) => {
509 // Select Option returns JSON values.
510 let value
= e
.target
.value
;
511 self
.ipProfiles
[i
]['ip-profile-params']['ip-version'] = value
;
512 self
.setState({ipProfiles
:self
.ipProfiles
});
515 updateDNS
: (i
, dnsIndex
) => {
517 // Select Option returns JSON values.
518 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
519 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'][dnsIndex
] = value
;
520 self
.setState({ipProfiles
:self
.ipProfiles
});
523 updateDHCP
: (i
, property
) => {
525 let value
= e
.target
.value
;
526 //If value is meant to be boolean, convert it
527 if(value
== "true" || value
== "false") {
528 value
= JSON
.parse(value
);
530 if(!self
.ipProfiles
[i
]['ip-profile-params'].hasOwnProperty('dhcp-params')) {
531 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'] = {
537 //Removing DCHP property on disable to allow instantiation
539 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'] = {
543 self
.ipProfiles
[i
]['ip-profile-params']['dhcp-params'][property
] = value
;
545 self
.setState({ipProfiles
:self
.ipProfiles
});
556 if(self
.ipProfiles
[i
]['ip-profile-params']['dns-server']) {
557 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'].unshift({})
559 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'] = [{}];
562 self
.setState({ipProfiles
:self
.ipProfiles
});
565 removeDNS
: (i
, k
) => {
568 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'].splice(k
, 1);
569 if(self
.ipProfiles
[i
]['ip-profile-params']['dns-server'].length
== 0) {
570 delete self
.ipProfiles
[i
]['ip-profile-params']['dns-server'];
572 self
.setState({ipProfiles
:self
.ipProfiles
});
575 updateDNS
: (i
, k
) => {
578 let value
= e
.target
.value
;
579 self
.ipProfiles
[i
]['ip-profile-params']['dns-server'][k
].address
= value
;
580 self
.setState({ipProfiles
:self
.ipProfiles
});
588 updateNewKeyRefSelection
: (e
) => {
590 newRefSelection
: e
.target
.value
593 updateKeyRef
: (refIndex
, remove
) => {
596 let sshKeysRef
= self
.sshKeysRef
;
598 // if(!e.target.value) {
599 // return Alt.actions.global.showError.defer('Please select a key pair');
601 if(!isNaN(refIndex
)){
602 sshKeysRef
.splice(refIndex
, 1);
603 sshKeysRef
.push(e
.target
.value
);
605 sshKeysRef
.push(e
.target
.value
);
609 sshKeysRef
.splice(refIndex
, 1);
612 sshKeysRef
: sshKeysRef
,
613 newRefSelection
: null
622 add: function(sshKeysList
) {
627 'ssh-authorized-key': [sshKeysList
[0].name
]
629 let usersList
= self
.usersList
;
630 usersList
.push(newUser
);
636 remove: function(i
) {
638 self
.usersList
.splice(i
, 1);
640 usersList
: self
.usersList
644 update: function(i
, key
) {
646 let value
= e
.target
.value
;
647 self
.usersList
[i
][key
] = value
;
649 usersList
: self
.usersList
653 updateSSHkeyRef: function(i
, j
, remove
){
655 let usersList
= _cloneDeep(self
.usersList
)
656 let keys
= usersList
[i
]['ssh-authorized-key'];
658 let keyRef
= JSON
.parse(e
.target
.value
).name
;
666 usersList
[i
]['ssh-authorized-key'] = keys
;
674 saveNetworkServiceRecord(name
, launch
) {
675 //input-parameter: [{uuid: < some_unique_name>, xpath: <same as you got from nsd>, value: <user_entered_value>}]
677 'input-parameter-xpath':[{
685 // Create a filtered NSD payload from the decorated one as RW.REST cannot handle extra parameters now
687 nsdPayload
= _cloneDeep(_find(this.state
.nsd
[0].descriptors
, {id
: this.state
.selectedNSDid
}));
689 if (nsdPayload
!= {}) {
690 nsdPayload
['meta'] && delete nsdPayload
['meta'];
691 nsdPayload
['constituent-vnfd'] && nsdPayload
['constituent-vnfd'].map((constituentVnfd
) => {
692 constituentVnfd
['vnf-name'] && delete constituentVnfd
['vnf-name'];
693 constituentVnfd
['name'] && delete constituentVnfd
['name'];
695 nsdPayload
['placement-groups'] && nsdPayload
['placement-groups'].map((placementGroup
) => {
696 placementGroup
['member-vnfd'] && placementGroup
['member-vnfd'].map((memberVnfd
) => {
697 memberVnfd
['name'] && delete memberVnfd
['name'];
700 nsdPayload
['ns-placement-groups'] && delete nsdPayload
['ns-placement-groups'];
701 nsdPayload
['vnf-placement-groups'] && delete nsdPayload
['vnf-placement-groups'];
702 nsdPayload
.vld
= this.state
.vld
;
703 nsdPayload
.vld
&& nsdPayload
.vld
.map(function(v
){
708 let vnfdCloudAccounts
= this.state
.vnfdCloudAccounts
;
713 "description": "a description for " + guuid
,
714 "admin-status": launch
? "ENABLED" : "DISABLED",
718 if (this.state
.ro
&& this.state
.ro
['account-type'] == 'openmano') {
719 payload
['om-datacenter'] = this.state
.dataCenterID
;
721 if(!this.state
.selectedCloudAccount
) {
722 Alt
.actions
.global
.showNotification
.defer("No VIM Account Selected");
725 payload
["cloud-account"] = this.state
.selectedCloudAccount
.name
;
727 //Clean Input Parameters
728 if (this.state
.hasConfigureNSD
) {
729 let ips
= _cloneDeep(this.state
['input-parameters']);
731 let ipsToSend
= ips
.filter(function(ip
) {
732 if (ip
.value
&& ip
.value
!= "") {
735 delete ip
['default-value'];
741 if (ipsToSend
.length
> 0) {
742 payload
['input-parameter'] = ipsToSend
;
745 // These placement groups need to be refactored. Too much boilerplate.
746 if (this.state
.displayPlacementGroups
) {
747 nsPg
= this.state
['ns-placement-groups'];
748 vnfPg
= this.state
['vnf-placement-groups'];
749 if(nsPg
&& (nsPg
.length
> 0)) {
750 payload
['nsd-placement-group-maps'] = nsPg
.map(function(n
, i
) {
751 if(n
['availability-zone'] || n
['server-group'] || (n
['host-aggregate'].length
> 0)) {
753 'cloud-type': 'openstack'
755 if(n
['host-aggregate'].length
> 0) {
756 obj
['host-aggregate'] = n
['host-aggregate'].map(function(h
, j
) {
758 'metadata-key': h
.key
,
759 'metadata-value': h
.value
763 if(n
['availability-zone'] && (n
['availability-zone'] != '')) {
764 obj
['availability-zone'] = {name
: n
['availability-zone']};
766 if(n
['server-group'] && (n
['server-group'] != '')) {
767 obj
['server-group'] = {name
: n
['server-group']};
769 obj
['placement-group-ref'] = n
.name
;
772 }).filter(function(o
){
780 if(vnfPg
&& (vnfPg
.length
> 0)) {
781 payload
['vnfd-placement-group-maps'] = vnfPg
.map(function(n
, i
) {
782 if(n
['availability-zone'] || n
['server-group'] || (n
['host-aggregate'].length
> 0)) {
784 'cloud-type': 'openstack'
786 if(n
['host-aggregate'].length
> 0) {
787 obj
['host-aggregate'] = n
['host-aggregate'].map(function(h
, j
) {
789 'metadata-key': h
.key
,
790 'metadata-value': h
.value
794 if(n
['server-group'] && (n
['server-group'] != '')) {
795 obj
['server-group'] = {name
: n
['server-group']};
797 if(n
['availability-zone'] && (n
['availability-zone'] != '')) {
798 obj
['availability-zone'] = {name
: n
['availability-zone']};
800 obj
['placement-group-ref'] = n
.name
;
801 obj
['vnfd-id-ref'] = n
['vnfd-id-ref'];
804 }).filter(function(o
){
813 //Construct VNF cloud accounts
814 payload
['vnf-cloud-account-map'] = [];
815 for(let k
in vnfdCloudAccounts
) {
817 vnf
['member-vnf-index-ref'] = k
;
818 if(vnfdCloudAccounts
[k
].hasOwnProperty('account') && (vnfdCloudAccounts
[k
]['account'] && vnfdCloudAccounts
[k
]['account'].name
)) {
819 vnf
['cloud-account'] = vnfdCloudAccounts
[k
].account
.name
;
821 if(vnfdCloudAccounts
[k
].hasOwnProperty('config-agent-account') && vnfdCloudAccounts
[k
]['config-agent-account']) {
822 vnf
['config-agent-account'] = vnfdCloudAccounts
[k
]['config-agent-account'];
824 if(vnfdCloudAccounts
[k
].hasOwnProperty('datacenter')) {
825 vnf
['om-datacenter'] = vnfdCloudAccounts
[k
].datacenter
;
827 if(vnf
['om-datacenter'] || vnf
['cloud-account'] || vnf
['config-agent-account']) {
828 payload
['vnf-cloud-account-map'].push(vnf
);
832 payload
['ssh-authorized-key'] = this.state
.sshKeysRef
.map(function(k
) {
833 return {'key-pair-ref': JSON
.parse(k
).name
};
836 payload
['user'] = addKeyPairRefToUsers(this.state
.usersList
);
837 // console.log(payload)
845 function addKeyPairRefToUsers(list
) {
846 return list
.map(function(u
) {
849 'user-info': u
['user-info'],
850 'ssh-authorized-key': u
['ssh-authorized-key'].map(function(k
) {
859 function getMockSLA(id
) {
860 console
.log('Getting mock SLA Data for id: ' + id
);
862 sla_parameters
: slaData
866 function getMockData() {
867 console
.log('Getting mock Descriptor Data');
874 export default LaunchNetworkServiceStore
;