From 9c013ddf2d997053c1c8d8bd732275a932ff6b0a Mon Sep 17 00:00:00 2001 From: Rajesh Velandy Date: Fri, 28 Oct 2016 00:00:57 +0000 Subject: [PATCH] Bug 94 - SDN and Cloud/Config-Agent account data inconsistent Signed-off-by: Rajesh Velandy --- skyquake/plugins/accounts/api/accounts.js | 41 ++++--------------- .../accounts/api/sdn_account/sdnAccount.js | 18 ++++---- .../plugins/accounts/src/account/account.jsx | 4 +- .../accounts/src/account/accountStore.js | 2 +- .../src/instantiate/instantiateStore.js | 2 +- 5 files changed, 21 insertions(+), 46 deletions(-) diff --git a/skyquake/plugins/accounts/api/accounts.js b/skyquake/plugins/accounts/api/accounts.js index 1b51c7bfe..215032b1f 100644 --- a/skyquake/plugins/accounts/api/accounts.js +++ b/skyquake/plugins/accounts/api/accounts.js @@ -1,5 +1,5 @@ /* - * + * * Copyright 2016 RIFT.IO Inc * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,7 +28,7 @@ var ConfigAgent = require('./config_agent/configAgent') var Accounts = {}; var nameSpace = { cloud: 'cloud', - sdn: 'sdn-account', + sdn: 'sdn', 'config-agent': 'config-agent' }; Accounts.get = function(req) { @@ -81,11 +81,7 @@ function getAccount(req) { var id = req.params.id || req.params.name; var requestHeaders = {}; var type = nameSpace[req.params.type]; - var url = utils.confdPort(api_server) + '/api/operational/' + type; - //SDN model doesn't follow convention - if (type != 'sdn-account') { - url += '/account'; - } + var url = utils.confdPort(api_server) + '/api/operational/' + type + '/account'; if (id) { url += '/' + id; } @@ -108,16 +104,12 @@ function getAccount(req) { var data; var objKey = 'rw-' + type + ':account'; //SDN model doesn't follow convention - if (type == 'sdn-account') { - objKey = 'rw-sdn:sdn-account'; - } if (utils.validateResponse(type.toUpperCase() + '.get', error, response, body, resolve, reject)) { try { data = JSON.parse(response.body); if (!id) { data = data.collection; } - data = data[objKey] } catch (e) { console.log('Problem with "' + type.toUpperCase() + '.get"', e); @@ -148,27 +140,14 @@ function updateAccount(req) { var url = utils.confdPort(api_server) + '/api/config/' + type; var method = 'POST' if (!id) { - if (type == 'sdn-account') { - createData = { - 'sdn-account': Array.isArray(data) ? data : [data] - } - } else { - createData = { - 'account': Array.isArray(data) ? data : [data] - } + createData = { + 'account': Array.isArray(data) ? data : [data] } console.log('Creating ' + type + ' account: ', createData); } else { method = 'PUT'; - if (type == 'sdn-account') { - url += '/' + id; - createData['rw-sdn:sdn-account'] = Array.isArray(data) ? data : [data]; - - } else { - url += '/account/' + id; - createData['rw-' + type + ':account'] = Array.isArray(data) ? data : [data]; - } - //createData = createData[0]; + url += '/account/' + id; + createData['rw-' + type + ':account'] = Array.isArray(data) ? data : [data]; } @@ -206,11 +185,7 @@ function deleteAccount(req) { var requestHeaders = {}; var createData = {}; var url = utils.confdPort(api_server) + '/api/config/' + type; - if (type == 'sdn-account') { - url += '/' + id; - } else { - url += '/account/' + id; - } + url += '/account/' + id; return new Promise(function(resolve, reject) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, diff --git a/skyquake/plugins/accounts/api/sdn_account/sdnAccount.js b/skyquake/plugins/accounts/api/sdn_account/sdnAccount.js index c2b592dde..6757c2891 100644 --- a/skyquake/plugins/accounts/api/sdn_account/sdnAccount.js +++ b/skyquake/plugins/accounts/api/sdn_account/sdnAccount.js @@ -1,5 +1,5 @@ /* - * + * * Copyright 2016 RIFT.IO Inc * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,7 +41,7 @@ Sdn.get = function(req) { 'Authorization': req.get('Authorization') }); request({ - url: utils.confdPort(api_server) + '/api/operational/sdn-account?deep', + url: utils.confdPort(api_server) + '/api/operational/sdn/account?deep', type: 'GET', headers: requestHeaders, forever: constants.FOREVER_ON, @@ -51,7 +51,7 @@ Sdn.get = function(req) { var data; if (utils.validateResponse('Sdn.get', error, response, body, resolve, reject)) { try { - data = JSON.parse(response.body).collection['rw-sdn:sdn-account'] + data = JSON.parse(response.body).collection['rw-sdn:account'] } catch (e) { console.log('Problem with "Sdn.get"', e); @@ -81,7 +81,7 @@ Sdn.get = function(req) { }); request({ - url: utils.confdPort(api_server) + '/api/operational/sdn-account/' + id + '?deep', + url: utils.confdPort(api_server) + '/api/operational/sdn/account/' + id + '?deep', type: 'GET', headers: requestHeaders, forever: constants.FOREVER_ON, @@ -91,7 +91,7 @@ Sdn.get = function(req) { var data; if (utils.validateResponse('Sdn.get', error, response, body, resolve, reject)) { try { - data = JSON.parse(response.body)['rw-sdn:sdn-account']; + data = JSON.parse(response.body)['rw-sdn:sdn']; } catch (e) { console.log('Problem with "Sdn.get"', e); @@ -134,7 +134,7 @@ Sdn.create = function(req) { }); request({ - url: utils.confdPort(api_server) + '/api/config/sdn-account', + url: utils.confdPort(api_server) + '/api/config/sdn/account', method: 'POST', headers: requestHeaders, forever: constants.FOREVER_ON, @@ -159,7 +159,7 @@ Sdn.update = function(req) { return new Promise(function(resolve, reject) { var jsonData = { - "rw-sdn:sdn-account": data + "rw-sdn:sdn": data }; console.log('Updating SDN account ', id, ' with', JSON.stringify(jsonData)); @@ -172,7 +172,7 @@ Sdn.update = function(req) { }); request({ - url: utils.confdPort(api_server) + '/api/config/sdn-account/' + id, + url: utils.confdPort(api_server) + '/api/config/sdn/account/' + id, method: 'PUT', headers: requestHeaders, forever: constants.FOREVER_ON, @@ -215,7 +215,7 @@ Sdn.delete = function(req) { }); request({ - url: utils.confdPort(api_server) + '/api/config/sdn-account/' + id, + url: utils.confdPort(api_server) + '/api/config/sdn/account/' + id, method: 'DELETE', headers: requestHeaders, forever: constants.FOREVER_ON, diff --git a/skyquake/plugins/accounts/src/account/account.jsx b/skyquake/plugins/accounts/src/account/account.jsx index c40e62737..a3b0bf12e 100644 --- a/skyquake/plugins/accounts/src/account/account.jsx +++ b/skyquake/plugins/accounts/src/account/account.jsx @@ -328,12 +328,12 @@ class Account extends React.Component {
- {Account['connection-status'].status.toUpperCase()} + {Account['connection-status'] && Account['connection-status'].status && Account['connection-status'].status.toUpperCase()}
{ - Account['connection-status'].status.toUpperCase() === 'FAILURE' ? + (Account['connection-status'] && Account['connection-status'].status && Account['connection-status'].status.toUpperCase()) === 'FAILURE' ? displayFailureMessage(Account['connection-status'].details) : null } diff --git a/skyquake/plugins/accounts/src/account/accountStore.js b/skyquake/plugins/accounts/src/account/accountStore.js index 002a9e10c..29a15e2af 100644 --- a/skyquake/plugins/accounts/src/account/accountStore.js +++ b/skyquake/plugins/accounts/src/account/accountStore.js @@ -350,7 +350,7 @@ export default class AccountStore { } generateOptionsByName(data) { let results = []; - if (data.constructor.name == "Array") { + if (data && data.constructor.name == "Array") { data.map(function(d) { results.push({ label: d.name, diff --git a/skyquake/plugins/launchpad/src/instantiate/instantiateStore.js b/skyquake/plugins/launchpad/src/instantiate/instantiateStore.js index 480781685..5cf0807be 100644 --- a/skyquake/plugins/launchpad/src/instantiate/instantiateStore.js +++ b/skyquake/plugins/launchpad/src/instantiate/instantiateStore.js @@ -156,7 +156,7 @@ class LaunchNetworkServiceStore { let newState = { dataCenters: dataCenters || [] }; - if (this.ro['account-type'] == 'openmano') { + if (this.state.ro && this.state.ro['account-type'] == 'openmano') { newState.dataCenterID = dataCenters[this.ro.name][0].uuid } this.setState(newState) -- 2.25.1