2 * Copyright 2016 RIFT.IO Inc
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * STANDARD_RIFT_IO_COPYRIGHT
20 import NetworkServiceActions from './launchNetworkServiceActions.js';
21 import NetworkServiceSource from './launchNetworkServiceSource.js';
22 import GUID from 'utils/guid.js';
23 import AppHeaderActions from 'widgets/header/headerActions.js';
24 import Alt from '../alt';
27 class LaunchNetworkServiceStore {
33 this.sla_parameters = [];
35 this.selectedCloudAccount = {};
36 this.dataCenters = {};
37 this.cloudAccounts = [];
38 this.isLoading = false;
39 this.isStandAlone = false;
40 this.hasConfigureNSD = false;
41 this['input-parameters'] = [];
42 this.registerAsync(NetworkServiceSource);
43 this.exportPublicMethods({
44 getMockData: getMockData.bind(this),
45 getMockSLA: getMockSLA.bind(this),
46 saveNetworkServiceRecord: this.saveNetworkServiceRecord,
47 updateSelectedCloudAccount: this.updateSelectedCloudAccount,
48 updateSelectedDataCenter: this.updateSelectedDataCenter,
49 updateInputParam: this.updateInputParam,
50 resetView: this.resetView,
51 nameUpdated: this.nameUpdated
53 this.bindActions(NetworkServiceActions);
54 this.descriptorSelected = this.descriptorSelected.bind(this);
55 this.nameUpdated = this.nameUpdated.bind(this);
57 nameUpdated = (name) => {
62 updateSelectedCloudAccount = (cloudAccount) => {
64 selectedCloudAccount: cloudAccount
66 if (cloudAccount['account-type'] == 'openmano') {
67 let datacenter = this.dataCenters[cloudAccount['name']][0];
68 // newState.selectedDataCenter = datacenter;
69 newState.dataCenterID = datacenter.uuid;
72 this.setState(newState);
74 updateSelectedDataCenter = (dataCenter) => {
75 console.log('updateed', dataCenter)
77 dataCenterID: dataCenter
81 console.log('reseting state')
86 descriptorSelected(data) {
93 //['input-parameter-xpath']
94 if (NSD['input-parameter-xpath']) {
95 newState.hasConfigureNSD = true;
96 newState['input-parameters'] = NSD['input-parameter-xpath'];
98 newState.hasConfigureNSD = false;
99 newState['input-parameters'] = null;
101 NSD["constituent-vnfd"].map((v) => {
102 VNFIDs.push(v["vnfd-id-ref"]);
104 this.getInstance().getVDU(VNFIDs);
105 this.setState(newState);
109 getCatalogSuccess(catalogs) {
114 catalogs.forEach(function(catalog) {
115 switch (catalog.type) {
119 self.descriptorSelected(catalog.descriptors)
134 getCloudAccountSuccess(cloudAccounts) {
136 newState.cloudAccounts = cloudAccounts || [];
137 if(cloudAccounts && cloudAccounts.length > 0) {
138 newState.selectedCloudAccount = cloudAccounts[0]
140 newState.selectedCloudAccount = {};
142 this.setState(newState);
144 getDataCentersSuccess(dataCenters) {
146 dataCenters: dataCenters
148 if (this.selectedCloudAccount['account-type'] == 'openmano') {
149 newState.dataCenterID = dataCenters[this.selectedCloudAccount.name][0].uuid
151 this.setState(newState)
153 getLaunchpadConfigSuccess = (config) => {
154 let isStandAlone = ((!config) || config["operational-mode"] == "STANDALONE");
156 isStandAlone: isStandAlone
159 getVDUSuccess(VNFD) {
164 saveNetworkServiceRecord(name, launch) {
165 //input-parameter: [{uuid: < some_unique_name>, xpath: <same as you got from nsd>, value: <user_entered_value>}]
167 'input-parameter-xpath':[{
174 "nsd-ref": this.state.selectedNSDid,
177 "description": "a description for " + guuid,
178 "admin-status": launch ? "ENABLED" : "DISABLED"
180 if (this.state.isStandAlone) {
181 payload["cloud-account"] = this.state.selectedCloudAccount.name;
183 if (this.state.selectedCloudAccount['account-type'] == "openmano") {
184 payload['om-datacenter'] = this.state.dataCenterID;
186 if (this.state.hasConfigureNSD) {
187 let ips = this.state['input-parameters'];
188 let ipsToSend = ips.filter(function(ip) {
189 if (ip.value && ip.value != "") {
196 if (ipsToSend.length > 0) {
197 payload['input-parameter'] = ipsToSend;
208 console.log('is Loading', this)
210 launchNSRSuccess(data) {
211 let tokenizedHash = window.location.hash.split('/');
215 return window.location.hash = 'launchpad/' + tokenizedHash[2];
217 launchNSRError(error) {
218 AppHeaderActions.validateError.defer('Something went wrong while trying to instantiate. Check the error logs for more information');
223 updateInputParam = (i, value) => {
224 let ip = this['input-parameters'];
227 'input-parameters': ip
232 function getMockSLA(id) {
233 console.log('Getting mock SLA Data for id: ' + id);
235 sla_parameters: slaData
239 function getMockData() {
240 console.log('Getting mock Descriptor Data');
247 export default Alt.createStore(LaunchNetworkServiceStore);