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 AccountActions
from './accountActions.js';
19 import AccountSource
from './accountSource.js';
21 var Utils
= require('utils/utils.js');
22 var rw
= require('utils/rw.js');
23 var altImage
= rw
.getSearchParams(window
.location
).alt_image
;
24 var _
= require('lodash');
35 'resource-orchestrator': {
36 defaultType
: 'openmano',
40 'ro-account-type': 'openmano'
78 "account-type": "juju",
102 label
: "Authentication URL",
108 label
: "User domain",
112 label
: "Project domain",
113 ref
: 'project-domain',
127 // label: "Management Network",
128 // ref: 'mgmt-network'
131 // label: "Plugin Name",
132 // ref: 'plugin-name',
135 // label: "Security Groups",
136 // ref: 'security-groups',
140 // label: "Dynamic Flavor Support ",
141 // ref: 'dynamic-flavor-support',
146 // label: "Floating IP Pool",
147 // ref: 'floating-ip-pool',
151 // label: "Certificate Validation",
152 // ref: 'cert-validate',
161 "account-type": "odl",
164 "account-type": "openstack",
168 defaultType
: 'openstack',
177 label
: "Availability Zone",
178 ref
: 'availability-zone'
180 label
: "Default Subnet ID",
181 ref
: 'default-subnet-id'
203 label
: "Authentication URL",
209 label
: 'Default Management Network',
213 label
: 'Default Floating IP Pool Network Name',
214 ref
: 'floating-ip-pool',
217 label
: "User Domain",
221 label
: "Project Domain",
222 ref
: 'project-domain',
233 label
: "Tenant Name",
236 label
: 'Management Network',
253 label
: "Management Network",
256 label
: "Public IP pool",
257 ref
: "public-ip-pool"
259 label
: "WAN Interface",
269 "container-name": "image-management",
270 "label": "Image Management",
278 label
: 'Image Directory Path',
279 ref
: 'image-directory-path',
286 "account-type": "openstack"
289 "account-type": "cloudsim_proxy"
292 "account-type": "aws"
295 "account-type": "openvim"
298 "account-type": "prop_cloud1"
304 "aws": require("../../images/aws.png"),
305 "openvim": require("../../images/openmano.png"),
306 "openstack": require("../../images/openstack.png"),
307 "cloudsim_proxy": require("../../images/riftio.png"),
308 "odl": require("../../images/OpenDaylight_logo.png"),
309 "juju": require("../../images/juju.svg"),
310 "prop_cloud1": require("../../images/brocade.png"),
311 "openmano": require("../../images/openmano.png")
316 "openvim": "Open VIM",
317 "openstack": "OpenStack",
318 "cloudsim_proxy": "Cloudsim",
319 "prop_cloud1": "Brocade",
320 "openmano": "OpenStack"
324 export default class AccountStore
{
326 // const savedData = JSON.parse(window.sessionStorage.getItem('account'));
327 const savedData
= null;
328 this.saveAccountToSessionStorage(null, true)
330 this['config-agent'] = [];
331 this['resource-orchestrator'] = [];
333 this.savedData
= savedData
;
335 // this.account = savedData.account;
336 // this.accountType = savedData.accountType;
337 this.types
= this.accountType
? AccountMeta
[this.accountType
].types
: [];
338 this.refreshingAll
= false;
339 this.sdnOptions
= [];
340 this.AccountMeta
= AccountMeta
;
342 this.vduInstanceTimeout
= '';
343 this.bindActions(AccountActions(this.alt
));
344 this.registerAsync(AccountSource
);
345 this.exportPublicMethods({
346 closeSocket
:this.closeSocket
,
347 setAccountTemplate
: this.setAccountTemplate
,
348 handleParamChange
: this.handleParamChange
,
349 handleNameChange
: this.handleNameChange
,
350 handleAccountTypeChange
: this.handleAccountTypeChange
,
351 updateAccount
: this.updateAccount
,
352 viewAccount
: this.viewAccount
,
353 handleNestedParamChange
: this.handleNestedParamChange
,
354 getImage
: this.getImage
,
355 saveAccountToSessionStorage
: this.saveAccountToSessionStorage
,
356 updateVduTimeout
: this.updateVduTimeout
,
357 getTransientAccountForUser
: this.getTransientAccountForUser
360 refreshAllAccountsSuccess
= () => {
365 refreshAllAccountsLoading
= () => {
370 refreshAllAccountsError
= () => {
373 refreshCloudAccountFail
= () => {
376 refreshCloudAccountSuccess
= () => {
379 deleteAccountSuccess
= (response
) => {
380 this.saveAccountToSessionStorage(null, true);
382 currentAccount
: false,
386 openAccountSocketSuccess
= (connection
) => {
388 let ws
= window
.multiplexer
.channel(connection
);
389 if (!connection
) return;
392 channelId
: connection
394 ws
.onmessage
= (socket
) => {
396 var data
= JSON
.parse(socket
.data
);
397 Utils
.checkAuthentication(data
.statusCode
, function() {
401 label
: 'Select an SDN Account',
404 SdnOptions
= SdnOptions
.concat(this.generateOptionsByName(data
.sdn
.data
))
406 cloud
: data
.cloud
.data
,
407 'config-agent': data
['config-agent'].data
,
409 'resource-orchestrator': data
['resource-orchestrator'].data
,
410 sdnOptions
: SdnOptions
413 //If account is selected, updated connection status only
414 if(self
.currentAccount
&& (self
.account
|| self
.savedData
)) {
415 let Account
= self
.getAccountFromStream(data
[self
.currentAccount
.type
].data
, self
.currentAccount
.name
);
416 newState
.account
= self
.changedData
? self
.account
: self
.savedData
|| self
.account
;
418 newState
.account
['connection-status'] = Account
&& Account
['connection-status'];
419 newState
.savedData
= null;
421 self
.setState(newState
);
423 console
.log('Hit at exception in openAccountSocketSuccess', error
)
431 closeSocket
= () => {
433 window
.multiplexer
.channel(this.channelId
).close();
439 setAccountTemplate
= (AccountType
, type
, savedData
) => {
440 console
.log('Setting Account Template')
443 'account-type': type
|| AccountMeta
[AccountType
].defaultType
,
444 params
: AccountMeta
[AccountType
].params
[AccountMeta
[AccountType
].defaultType
],
445 nestedParams
: AccountMeta
[AccountType
].nestedParams
? AccountMeta
[AccountType
].nestedParams
[AccountMeta
[AccountType
].defaultType
]:null,
446 'connection-status': {
451 account
[type
|| AccountMeta
[AccountType
].defaultType
] = {}
453 account
: savedData
|| account
,
454 accountType
: AccountType
,
455 types
: AccountMeta
[AccountType
].types
,
456 currentAccount
: null,
461 getAccountFromStream(data
, name
) {
463 data
&& _
.isArray(data
) && data
.map(function(a
) {
470 viewAccount
= ({type
, name
}, savedData
) => {
471 console
.log('Viewing account')
474 let vduInstanceTimeout
= '';
475 if(this && this[type
] && this[type
].length
) {
476 accounts
= this[type
];
477 data
= this.getAccountFromStream(accounts
, name
);
478 const isRo
= data
.hasOwnProperty('ro-account-type');
480 let accountParams
= {
481 params
: AccountMeta
[type
].params
[
482 isRo
? data
['ro-account-type'] : data
['account-type']
486 let accountNestedParams
= {
487 nestedParams
: AccountMeta
[type
].nestedParams
?AccountMeta
[type
].nestedParams
[
488 isRo
? data
['ro-account-type'] : data
['account-type']
491 if (data
.hasOwnProperty('vdu-instance-timeout')) {
492 vduInstanceTimeout
= data
['vdu-instance-timeout'];
495 currentAccount
: {type
, name
},
496 account
: (savedData
? savedData
: Object
.assign(data
, accountParams
, accountNestedParams
)) || null,
498 types
: AccountMeta
[type
].types
,
499 vduInstanceTimeout
: vduInstanceTimeout
,
505 currentAccount
: {type
, name
},
508 types
: AccountMeta
[type
].types
,
512 generateOptionsByName(data
) {
514 if (data
&& _
.isArray(data
)) {
515 data
.map(function(d
) {
524 updateAccount
= (account
) => {
525 this.saveAccountToSessionStorage(account
);
526 this.setState({account
:account
,
529 handleNameChange
= (event
) => {
530 var account
= this.account
;
531 account
.name
= event
.target
.value
;
532 this.saveAccountToSessionStorage(account
)
540 updateVduTimeout
= (event
) => {
541 var vduInstanceTimeout
= event
.target
.value
;
544 vduInstanceTimeout
:vduInstanceTimeout
548 handleAccountTypeChange
= (node
, isRo
, event
) => {
550 temp
.name
= this.account
.name
;
552 temp
['ro-account-type'] = event
.target
.value
;
554 temp
['account-type'] = event
.target
.value
;
556 temp
.params
= AccountMeta
[this.accountType
].params
[event
.target
.value
];
557 temp
.nestedParams
= (AccountMeta
[this.accountType
] && AccountMeta
[this.accountType
].nestedParams
)?AccountMeta
[this.accountType
].nestedParams
[event
.target
.value
]:null;
558 temp
[event
.target
.value
] = {};
559 this.saveAccountToSessionStorage(temp
)
565 handleParamChange(node
, isRo
, event
) {
566 return function(event
) {
567 var account
= this.state
.account
;
569 account
[account
['ro-account-type']][node
.ref
] = event
.target
.value
;
572 account
[account
['account-type']][node
.ref
] = event
.target
.value
;
575 account
.params
[node
.ref
] = event
.target
.value
;
576 this.updateAccount(account
);
579 handleNestedParamChange(containerName
, node
, event
) {
580 return function(event
) {
581 var account
= this.state
.account
;
582 account
[account
['account-type']][containerName
] = account
[account
['account-type']][containerName
] || {};
583 account
[account
['account-type']][containerName
][node
.ref
] = event
.target
.value
;
584 account
[containerName
] = account
[containerName
] || {};
585 account
[containerName
].params
= account
[containerName
].params
|| {};
586 account
[containerName
].params
[node
.ref
] = event
.target
.value
;
587 this.updateAccount(account
);
590 getImage
= (type
) => {
591 return AccountMeta
.image
[type
];
593 createAccountSuccess
= () => {
594 this.setState({account
: {}})
595 this.saveAccountToSessionStorage(null, true)
597 handleCancelAccount
= () => {
598 this.setState({account
: {}, currentAccount
: null, savedData
: null, accountType
: null, types
: []})
599 this.saveAccountToSessionStorage(null, true)
601 saveAccountToSessionStorage
= (account
, clear
) => {
602 const userProfile
= this.userProfile
;
606 window
.sessionStorage
.removeItem(userProfile
.userId
+ '@' + userProfile
.domain
+ ':account');
612 const state
= account
|| this.account
;
613 window
.sessionStorage
.setItem(userProfile
.userId
+ '@' + userProfile
.domain
+ ':account', JSON
.stringify(state
));
618 getTransientAccountForUser
= (userProfile
) => {
619 let userProfileTransientAccount
= window
.sessionStorage
.getItem(userProfile
.userId
+ '@' + userProfile
.domain
+ ':account') || null;
620 var transientAccount
= null;
621 if (userProfileTransientAccount
) {
622 transientAccount
= JSON
.parse(userProfileTransientAccount
);
624 this.saveAccountToSessionStorage(null, true);
625 if(!this.userProfile
) {
627 savedData
: transientAccount
,
628 userProfile
: userProfile