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');
59 "account-type": "juju",
78 "account-type": "odl",
82 defaultType
: 'openstack',
91 label
: "Availability Zone",
92 ref
: 'availability-zone'
94 label
: "Default Subnet ID",
95 ref
: 'default-subnet-id'
117 label
: "Authentication URL",
123 label
: 'Management Network',
126 label
: 'Floating IP Pool',
127 ref
: 'floating-ip-pool',
130 label
: "User Domain",
134 label
: "Project Domain",
135 ref
: 'project-domain',
146 label
: "Tenant Name",
149 label
: 'Management Network',
159 "container-name": "image-management",
160 "label": "Image Management",
168 label
: 'Image Directory Path',
169 ref
: 'image-directory-path',
176 "account-type": "openstack"
179 "account-type": "cloudsim_proxy"
182 "account-type": "aws"
185 "account-type": "openvim"
191 "aws": require("../../images/aws.png"),
192 "openvim": require("../../images/openmano.png"),
193 "openstack": require("../../images/openstack.png"),
194 "cloudsim_proxy": require("../../images/riftio.png"),
195 "odl": require("../../images/OpenDaylight_logo.png"),
196 "juju": require("../../images/juju.svg")
201 "openvim": "Open VIM",
202 "openstack": "OpenStack",
203 "cloudsim_proxy": "Cloudsim"
207 export default class AccountStore
{
210 this['config-agent'] = [];
214 this.refreshingAll
= false;
215 this.sdnOptions
= [];
216 this.AccountMeta
= AccountMeta
;
218 this.bindActions(AccountActions(this.alt
));
219 this.registerAsync(AccountSource
);
220 this.exportPublicMethods({
221 closeSocket
:this.closeSocket
,
222 setAccountTemplate
: this.setAccountTemplate
,
223 handleParamChange
: this.handleParamChange
,
224 handleNameChange
: this.handleNameChange
,
225 handleAccountTypeChange
: this.handleAccountTypeChange
,
226 updateAccount
: this.updateAccount
,
227 viewAccount
: this.viewAccount
,
228 handleNestedParamChange
: this.handleNestedParamChange
,
229 getImage
: this.getImage
232 refreshAllAccountsSuccess
= () => {
237 refreshAllAccountsLoading
= () => {
242 refreshAllAccountsError
= () => {
245 refreshCloudAccountFail
= () => {
248 refreshCloudAccountSuccess
= () => {
251 getResourceOrchestratorSuccess
= (data
) => {
252 this.alt
.actions
.global
.hideScreenLoader
.defer();
253 if(data
['rw-launchpad:resource-orchestrator'] && (data
['rw-launchpad:resource-orchestrator']['account-type'] == 'openmano')) {
259 deleteAccountSuccess
= (response
) => {
261 currentAccount
: false,
265 openAccountSocketSuccess
= (connection
) => {
267 let ws
= window
.multiplexer
.channel(connection
);
268 if (!connection
) return;
271 channelId
: connection
273 ws
.onmessage
= (socket
) => {
275 var data
= JSON
.parse(socket
.data
);
276 Utils
.checkAuthentication(data
.statusCode
, function() {
280 label
: 'Select an SDN Account',
283 SdnOptions
= SdnOptions
.concat(this.generateOptionsByName(data
.sdn
.data
))
285 cloud
: data
.cloud
.data
,
286 'config-agent': data
['config-agent'].data
,
288 sdnOptions
: SdnOptions
291 //If account is selected, updated connection status only
292 if(self
.currentAccount
) {
293 let Account
= self
.getAccountFromStream(data
[self
.currentAccount
.type
].data
, self
.currentAccount
.name
);
294 newState
.account
= self
.account
;
295 newState
.account
['connection-status'] = Account
&& Account
['connection-status']
297 self
.setState(newState
)
299 console
.log('Hit at exception in openAccountSocketSuccess', error
)
307 closeSocket
= () => {
309 window
.multiplexer
.channel(this.channelId
).close();
315 setAccountTemplate
= (AccountType
, type
) => {
318 'account-type': type
|| AccountMeta
[AccountType
].defaultType
,
319 params
: AccountMeta
[AccountType
].params
[AccountMeta
[AccountType
].defaultType
],
320 nestedParams
: AccountMeta
[AccountType
].nestedParams
? AccountMeta
[AccountType
].nestedParams
[AccountMeta
[AccountType
].defaultType
]:null,
321 'connection-status': {
326 account
[type
|| AccountMeta
[AccountType
].defaultType
] = {}
329 accountType
: AccountType
,
330 types
: AccountMeta
[AccountType
].types
,
334 getAccountFromStream(data
, name
) {
336 data
&& _
.isArray(data
) && data
.map(function(a
) {
343 viewAccount
= ({type
, name
}) => {
346 if(this && this[type
] && this[type
].length
) {
347 accounts
= this[type
];
348 data
= this.getAccountFromStream(accounts
, name
);
350 let accountParams
= {
351 params
: AccountMeta
[type
].params
[data
['account-type']]
354 let accountNestedParams
= {
355 nestedParams
: AccountMeta
[type
].nestedParams
?AccountMeta
[type
].nestedParams
[data
['account-type']]:null
359 currentAccount
: {type
, name
},
360 account
: Object
.assign(data
, accountParams
, accountNestedParams
),
366 generateOptionsByName(data
) {
368 if (data
&& _
.isArray(data
)) {
369 data
.map(function(d
) {
378 updateAccount
= (account
) => {
379 this.setState({account
:account
})
381 handleNameChange
= (event
) => {
382 var account
= this.account
;
383 account
.name
= event
.target
.value
;
390 handleAccountTypeChange
= (node
, event
) => {
392 temp
.name
= this.account
.name
;
393 temp
['account-type'] = event
.target
.value
;
394 temp
.params
= AccountMeta
[this.accountType
].params
[event
.target
.value
];
395 temp
.nestedParams
= AccountMeta
[this.accountType
]?AccountMeta
[this.accountType
].nestedParams
[event
.target
.value
]:null;
396 temp
[event
.target
.value
] = {};
401 handleParamChange(node
, event
) {
402 return function(event
) {
403 var account
= this.state
.account
;
404 account
[account
['account-type']][node
.ref
] = event
.target
.value
;
405 account
.params
[node
.ref
] = event
.target
.value
;
406 this.updateAccount(account
);
409 handleNestedParamChange(containerName
, node
, event
) {
410 return function(event
) {
411 var account
= this.state
.account
;
412 account
[account
['account-type']][containerName
] = account
[account
['account-type']][containerName
] || {};
413 account
[account
['account-type']][containerName
][node
.ref
] = event
.target
.value
;
414 account
[containerName
] = account
[containerName
] || {};
415 account
[containerName
].params
= account
[containerName
].params
|| {};
416 account
[containerName
].params
[node
.ref
] = event
.target
.value
;
417 this.updateAccount(account
);
420 getImage
= (type
) => {
421 return AccountMeta
.image
[type
];