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
;
58 "account-type": "juju",
77 "account-type": "odl",
81 defaultType
: 'openstack',
90 label
: "Availability Zone",
91 ref
: 'availability-zone'
93 label
: "Default Subnet ID",
94 ref
: 'default-subnet-id'
116 label
: "Authentication URL",
122 label
: 'Management Network',
125 label
: 'Floating IP Pool',
126 ref
: 'floating-ip-pool',
129 label
: "User Domain",
133 label
: "Project Domain",
134 ref
: 'project-domain',
145 label
: "Tenant Name",
148 label
: 'Management Network',
158 "container-name": "image-management",
159 "label": "Image Management",
167 label
: 'Image Directory Path',
168 ref
: 'image-directory-path',
175 "account-type": "openstack"
178 "account-type": "cloudsim_proxy"
181 "account-type": "aws"
184 "account-type": "openvim"
190 "aws": require("../../images/aws.png"),
191 "openvim": require("../../images/openmano.png"),
192 "openstack": require("../../images/openstack.png"),
193 "cloudsim_proxy": require("../../images/riftio.png"),
194 "odl": require("../../images/OpenDaylight_logo.png"),
195 "juju": require("../../images/juju.svg")
200 "openvim": "Open VIM",
201 "openstack": "OpenStack",
202 "cloudsim_proxy": "Cloudsim"
206 export default class AccountStore
{
209 this['config-agent'] = [];
213 this.refreshingAll
= false;
214 this.sdnOptions
= [];
215 this.AccountMeta
= AccountMeta
;
217 this.bindActions(AccountActions(this.alt
));
218 this.registerAsync(AccountSource
);
219 this.exportPublicMethods({
220 closeSocket
:this.closeSocket
,
221 setAccountTemplate
: this.setAccountTemplate
,
222 handleParamChange
: this.handleParamChange
,
223 handleNameChange
: this.handleNameChange
,
224 handleAccountTypeChange
: this.handleAccountTypeChange
,
225 updateAccount
: this.updateAccount
,
226 viewAccount
: this.viewAccount
,
227 handleNestedParamChange
: this.handleNestedParamChange
,
228 getImage
: this.getImage
231 refreshAllAccountsSuccess
= () => {
236 refreshAllAccountsLoading
= () => {
241 refreshAllAccountsError
= () => {
244 refreshCloudAccountFail
= () => {
247 refreshCloudAccountSuccess
= () => {
250 getResourceOrchestratorSuccess
= (data
) => {
251 this.alt
.actions
.global
.hideScreenLoader
.defer();
252 if(data
['rw-launchpad:resource-orchestrator'] && (data
['rw-launchpad:resource-orchestrator']['account-type'] == 'openmano')) {
258 deleteAccountSuccess
= (response
) => {
260 currentAccount
: false,
264 openAccountSocketSuccess
= (connection
) => {
266 let ws
= window
.multiplexer
.channel(connection
);
267 if (!connection
) return;
270 channelId
: connection
272 ws
.onmessage
= (socket
) => {
274 var data
= JSON
.parse(socket
.data
);
275 Utils
.checkAuthentication(data
.statusCode
, function() {
279 label
: 'Select an SDN Account',
282 SdnOptions
= SdnOptions
.concat(this.generateOptionsByName(data
.sdn
.data
))
284 cloud
: data
.cloud
.data
,
285 'config-agent': data
['config-agent'].data
,
287 sdnOptions
: SdnOptions
290 //If account is selected, updated connection status only
291 if(self
.currentAccount
) {
292 let Account
= self
.getAccountFromStream(data
[self
.currentAccount
.type
].data
, self
.currentAccount
.name
);
293 newState
.account
= self
.account
;
294 newState
.account
['connection-status'] = Account
['connection-status']
296 self
.setState(newState
)
298 console
.log('Hit at exception in openAccountSocketSuccess', error
)
306 closeSocket
= () => {
308 window
.multiplexer
.channel(this.channelId
).close();
314 setAccountTemplate
= (AccountType
, type
) => {
317 'account-type': type
|| AccountMeta
[AccountType
].defaultType
,
318 params
: AccountMeta
[AccountType
].params
[AccountMeta
[AccountType
].defaultType
],
319 nestedParams
: AccountMeta
[AccountType
].nestedParams
? AccountMeta
[AccountType
].nestedParams
[AccountMeta
[AccountType
].defaultType
]:null,
320 'connection-status': {
325 account
[type
|| AccountMeta
[AccountType
].defaultType
] = {}
328 accountType
: AccountType
,
329 types
: AccountMeta
[AccountType
].types
,
333 getAccountFromStream(data
, name
) {
335 data
.map(function(a
) {
342 viewAccount
= ({type
, name
}) => {
345 if(this && this[type
].length
) {
346 accounts
= this[type
];
347 data
= this.getAccountFromStream(accounts
, name
);
349 let accountParams
= {
350 params
: AccountMeta
[type
].params
[data
['account-type']]
353 let accountNestedParams
= {
354 nestedParams
: AccountMeta
[type
].nestedParams
?AccountMeta
[type
].nestedParams
[data
['account-type']]:null
358 currentAccount
: {type
, name
},
359 account
: Object
.assign(data
, accountParams
, accountNestedParams
),
365 generateOptionsByName(data
) {
367 if (data
&& data
.constructor.name
== "Array") {
368 data
.map(function(d
) {
377 updateAccount
= (account
) => {
378 this.setState({account
:account
})
380 handleNameChange
= (event
) => {
381 var account
= this.account
;
382 account
.name
= event
.target
.value
;
389 handleAccountTypeChange
= (node
, event
) => {
391 temp
.name
= this.account
.name
;
392 temp
['account-type'] = event
.target
.value
;
393 temp
.params
= AccountMeta
[this.accountType
].params
[event
.target
.value
];
394 temp
.nestedParams
= AccountMeta
[this.accountType
]?AccountMeta
[this.accountType
].nestedParams
[event
.target
.value
]:null;
395 temp
[event
.target
.value
] = {};
400 handleParamChange(node
, event
) {
401 return function(event
) {
402 var account
= this.state
.account
;
403 account
[account
['account-type']][node
.ref
] = event
.target
.value
;
404 account
.params
[node
.ref
] = event
.target
.value
;
405 this.updateAccount(account
);
408 handleNestedParamChange(containerName
, node
, event
) {
409 return function(event
) {
410 var account
= this.state
.account
;
411 account
[account
['account-type']][containerName
] = account
[account
['account-type']][containerName
] || {};
412 account
[account
['account-type']][containerName
][node
.ref
] = event
.target
.value
;
413 account
[containerName
] = account
[containerName
] || {};
414 account
[containerName
].params
= account
[containerName
].params
|| {};
415 account
[containerName
].params
[node
.ref
] = event
.target
.value
;
416 this.updateAccount(account
);
419 getImage
= (type
) => {
420 return AccountMeta
.image
[type
];