From 5887e136dc63a909acba0e529dacf383df9061d7 Mon Sep 17 00:00:00 2001 From: KIRAN KASHALKAR Date: Thu, 8 Sep 2016 11:40:38 -0400 Subject: [PATCH] Changes to generate console link when required Signed-off-by: KIRAN KASHALKAR --- skyquake/plugins/launchpad/api/launchpad.js | 41 ++++++++++++++++++- skyquake/plugins/launchpad/routes.js | 7 ++++ .../launchpad/src/launchpadFleetActions.js | 2 + .../launchpad/src/launchpadFleetSource.js | 20 +++++++++ .../launchpad/src/launchpadFleetStore.js | 5 +++ .../launchpadCardMgmtInterfaces.jsx | 15 ++++++- .../src/launchpad_card/launchpad_card.scss | 12 ++++++ .../launchpad/src/recordViewer/recordCard.jsx | 20 +++++++-- .../src/recordViewer/recordViewActions.js | 2 +- .../src/recordViewer/recordViewSource.js | 1 - .../src/recordViewer/recordViewStore.js | 1 - .../src/recordViewer/recordViewer.scss | 10 +++++ 12 files changed, 125 insertions(+), 11 deletions(-) diff --git a/skyquake/plugins/launchpad/api/launchpad.js b/skyquake/plugins/launchpad/api/launchpad.js index 02c28eb4f..397228942 100644 --- a/skyquake/plugins/launchpad/api/launchpad.js +++ b/skyquake/plugins/launchpad/api/launchpad.js @@ -809,7 +809,9 @@ NSR.addVnfrDataPromise = function(req, nsrs) { nsr['console-urls'] = nsr['console-urls'] ? nsr['console-urls'] : []; vnfr && vnfr['vdur'] && vnfr['vdur'].map(function(vdur) { - vdur['console-url'] && nsr['console-urls'].push({ + // This console-url is what front-end will hit to generate a real console-url + vdur['console-url'] = 'api/vnfr/' + vnfr.id + '/vdur/' + vdur.id + '/console-url'; + nsr['console-urls'].push({ id: vdur.id, name: vdur.name, 'console-url': vdur['console-url'] @@ -1275,7 +1277,11 @@ VNFR.get = function(req) { vnfr['nfvi-metrics'] = buildNfviGraphs(vnfr.vdur); vnfr['epa-params'] = epa_aggregator(vnfr.vdur); vnfr['service-primitives-present'] = (vnfr['vnf-configuration'] && vnfr['vnf-configuration']['service-primitive'] && vnfr['vnf-configuration']['service-primitive'].length > 0) ? true : false; - }) + vnfr['vdur'] && vnfr['vdur'].map(function(vdur, vdurIndex) { + // This console-url is what front-end will hit to generate a real console-url + vdur['console-url'] = 'api/vnfr/' + vnfr.id + '/vdur/' + vdur.id + '/console-url'; + }); + }); return resolve(returnData); }; }); @@ -1625,6 +1631,36 @@ VDUR.get = function(req) { }) } +VDUR.consoleUrl = {}; +VDUR.consoleUrl.get = function(req) { + var api_server = req.query["api_server"]; + var vnfrID = req.params.vnfr_id; + var vdurID = req.params.vdur_id; + var uri = utils.confdPort(api_server); + uri += APIVersion + '/api/operational/vnfr-console/vnfr/' + vnfrID + '/vdur/' + vdurID + '/console-url' + '?deep'; + var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, { + 'Authorization': req.get('Authorization') + }); + return new Promise(function(resolve, reject) { + request({ + url: uri, + method: 'GET', + headers: headers, + forever: constants.FOREVER_ON, + rejectUnauthorized: false, + }, function(error, response, body) { + if (utils.validateResponse('VDUR.consoleUrl.get', error, response, body, resolve, reject)) { + var data = JSON.parse(response.body); + var returnData = data; + return resolve({ + data: returnData, + statusCode: response.statusCode + }); + }; + }); + }) +} + CloudAccount.get = function(req) { var api_server = req.query["api_server"]; var uri = utils.confdPort(api_server); @@ -2015,6 +2051,7 @@ module.exports.catalog = Catalog; module.exports.nsr = NSR; module.exports.vnfr = VNFR; module.exports.vlr = VLR; +module.exports.vdur = VDUR; module.exports.rift = RIFT; module.exports.computeTopology = ComputeTopology; module.exports.networkTopology = NetworkTopology; diff --git a/skyquake/plugins/launchpad/routes.js b/skyquake/plugins/launchpad/routes.js index d8f6493bf..f9d6ce733 100644 --- a/skyquake/plugins/launchpad/routes.js +++ b/skyquake/plugins/launchpad/routes.js @@ -160,6 +160,13 @@ app.get('/api/nsr', cors(), function(req, res) { utils.sendErrorResponse(error, res); }) }); + app.get('/api/vnfr/:vnfr_id/vdur/:vdur_id/console-url', function(req, res) { + launchpadAPI['vdur']['consoleUrl'].get(req).then(function(data) { + utils.sendSuccessResponse(data, res); + }, function(error) { + utils.sendErrorResponse(error, res); + }); + }) app.get('/api/catalog', cors(), function(req, res) { launchpadAPI['catalog'].get(req).then(function(data) { utils.sendSuccessResponse(data, res); diff --git a/skyquake/plugins/launchpad/src/launchpadFleetActions.js b/skyquake/plugins/launchpad/src/launchpadFleetActions.js index 2863c7ad2..4052ebb78 100644 --- a/skyquake/plugins/launchpad/src/launchpadFleetActions.js +++ b/skyquake/plugins/launchpad/src/launchpadFleetActions.js @@ -39,4 +39,6 @@ module.exports = Alt.generateActions( 'closeNsrCard', 'instantiateNetworkService', 'setNsListPanelVisible', + 'getVDUConsoleLinkSuccess', + 'getVDUConsoleLinkError' ); diff --git a/skyquake/plugins/launchpad/src/launchpadFleetSource.js b/skyquake/plugins/launchpad/src/launchpadFleetSource.js index 71e3d7d5d..dac8a826f 100644 --- a/skyquake/plugins/launchpad/src/launchpadFleetSource.js +++ b/skyquake/plugins/launchpad/src/launchpadFleetSource.js @@ -61,6 +61,26 @@ module.exports = function(Alt) { success: FleetActions.getNsrInstancesSuccess, error: FleetActions.getNsrInstancesError }, + getVDUConsoleLink: { + remote: function(state, url) { + return new Promise(function(resolve, reject) { + $.ajax({ + url: url + '?api_server=' + API_SERVER, + type: 'GET', + beforeSend: Utils.addAuthorizationStub, + success: function(data) { + resolve(data); + }, + error: function(error) { + console.log('There was an error getting the VDU link', error); + return reject(error); + } + }); + }); + }, + success: FleetActions.getVDUConsoleLinkSuccess, + error: FleetActions.getVDUConsoleLinkError + }, deleteNsrInstance: { remote: function(d, id) { console.log(id) diff --git a/skyquake/plugins/launchpad/src/launchpadFleetStore.js b/skyquake/plugins/launchpad/src/launchpadFleetStore.js index 54c45e4a9..520eebecd 100644 --- a/skyquake/plugins/launchpad/src/launchpadFleetStore.js +++ b/skyquake/plugins/launchpad/src/launchpadFleetStore.js @@ -76,6 +76,7 @@ function FleetStoreConstructor() { closeNsrCard: FleetActions.closeNsrCard, instantiateNetworkService: FleetActions.instantiateNetworkService, setNsListPanelVisible: FleetActions.setNsListPanelVisible, + getVDUConsoleLinkSuccess: FleetActions.getVDUConsoleLinkSuccess }); this.bindAction(LaunchNetworkServiceActions.launchNSRSuccess, responseData => { @@ -274,5 +275,9 @@ FleetStoreConstructor.prototype.setNsListPanelVisible = function(isVisible) { }) } +FleetStoreConstructor.prototype.getVDUConsoleLinkSuccess = function(data) { + data['console-url'] && window.open(data['console-url']); +} + FleetStore = Alt.createStore(FleetStoreConstructor); module.exports = FleetStore; diff --git a/skyquake/plugins/launchpad/src/launchpad_card/launchpadCardMgmtInterfaces.jsx b/skyquake/plugins/launchpad/src/launchpad_card/launchpadCardMgmtInterfaces.jsx index 782e99f4b..35f9caa3b 100644 --- a/skyquake/plugins/launchpad/src/launchpad_card/launchpadCardMgmtInterfaces.jsx +++ b/skyquake/plugins/launchpad/src/launchpad_card/launchpadCardMgmtInterfaces.jsx @@ -19,6 +19,8 @@ import React from 'react'; import Loader from 'widgets/loading-indicator/loadingIndicator.jsx'; +import LaunchpadFleetStore from '../launchpadFleetStore.js'; + export default class managementInterfaces extends React.Component { constructor(props) { @@ -27,11 +29,18 @@ export default class managementInterfaces extends React.Component { componentWillReceiveProps(nextProps) { } + + openConsole = (url, event) => { + event.preventDefault(); + LaunchpadFleetStore.getVDUConsoleLink(url); + } render() { + let self = this; let dashboard_html; let console_html; let isDisplayed = this.props.display; let status; + let notice; let applicationDashboards = this.props.interfaces.sort(function(a,b) { try { if ((a["short-name"] + '-' + a.id.substr(0,4)) > (b["short-name"] + '-' + b.id.substr(0,4))) { @@ -72,17 +81,19 @@ export default class managementInterfaces extends React.Component { if(consoleLinks && consoleLinks.length > 0){ status = consoleLinks.map(function(i, index) { - let consoleLink = i["console-url"] ? 'Open VM Console' : 'None'; + let consoleLink = i["console-url"] ? 'Obtain Token And Open VM Console' : 'None'; return ( -
  • {i["name"] + '-' + i.id.substr(0,4)}

    {consoleLink}
  • +
  • {i["name"] + '-' + i.id.substr(0,4)}

    {consoleLink} *
  • ) }); + notice =
  • * If a separate browser window does not open, please check if the popup was blocked and allow it.
  • } else { status =
  • No VDU Console Links have been specified.
  • } console_html = ( ); diff --git a/skyquake/plugins/launchpad/src/launchpad_card/launchpad_card.scss b/skyquake/plugins/launchpad/src/launchpad_card/launchpad_card.scss index 1c77c612f..01a798ab5 100644 --- a/skyquake/plugins/launchpad/src/launchpad_card/launchpad_card.scss +++ b/skyquake/plugins/launchpad/src/launchpad_card/launchpad_card.scss @@ -195,6 +195,18 @@ justify-content: center; align-content: center; color:black; + + .notice { + padding-top: 0.5rem; + font-size: 0.75rem; + color: $gray-darker; + } + + span { + cursor: pointer; + text-decoration: underline; + } + a { cursor: pointer; margin-left: 0.5rem; diff --git a/skyquake/plugins/launchpad/src/recordViewer/recordCard.jsx b/skyquake/plugins/launchpad/src/recordViewer/recordCard.jsx index e3c3dadce..dc092bc9d 100644 --- a/skyquake/plugins/launchpad/src/recordViewer/recordCard.jsx +++ b/skyquake/plugins/launchpad/src/recordViewer/recordCard.jsx @@ -31,6 +31,8 @@ import ParseMP from '../monitoring_params/monitoringParamComponents.js'; import PlacementGroupsInfo from './placementGroupsInfo.jsx'; import JobListCard from '../launchpad_card/jobListCard.jsx'; import NSVirtualLinks from '../virtual_links/nsVirtualLinks.jsx'; +import LaunchpadFleetStore from '../launchpadFleetStore.js'; + export default class RecordCard extends React.Component { constructor(props) { super(props) @@ -40,7 +42,13 @@ export default class RecordCard extends React.Component { // console.log('Selected tab is', index, 'last index is', last); } + openConsole = (url, event) => { + event.preventDefault(); + LaunchpadFleetStore.getVDUConsoleLink(url); + } + render(){ + let self = this; let html; let content; let card; @@ -62,6 +70,8 @@ export default class RecordCard extends React.Component { let tabList = []; let tabPanels = []; + let notice = null; + switch(this.props.type) { case 'vnfr' : cardData = this.props.data[0]; @@ -103,22 +113,24 @@ export default class RecordCard extends React.Component { if (cardData['vdur']) { cardData['vdur'].map((vdur, index) => { - let consoleLink = vdur['console-url'] ? 'Open VM Console' : 'None'; + let consoleLink = vdur['console-url'] ? 'Obtain Token And Open VM Console' : 'None'; consoleUrlsList.push(
  • {vdur['name'] + '-' + vdur.id.substr(0,4)}

    - - {consoleLink} - + + {consoleLink} * +
  • ) + notice =
  • * If a separate browser window does not open, please check if the popup was blocked and allow it.
  • }); consoleUrlsComponent = (
      {consoleUrlsList} + {notice}
    ); diff --git a/skyquake/plugins/launchpad/src/recordViewer/recordViewActions.js b/skyquake/plugins/launchpad/src/recordViewer/recordViewActions.js index a9d5250a9..8197b5b63 100644 --- a/skyquake/plugins/launchpad/src/recordViewer/recordViewActions.js +++ b/skyquake/plugins/launchpad/src/recordViewer/recordViewActions.js @@ -33,5 +33,5 @@ export default Alt.generateActions( 'getConfigSocketJobError', 'createVirtualLinkLoading', 'createVirtualLinkSuccess', 'createVirtualLinkError', 'editVirtualLinkLoading', 'editVirtualLinkSuccess', 'editVirtualLinkError', - 'deleteVirtualLinkLoading', 'deleteVirtualLinkSuccess', 'deleteVirtualLinkError', + 'deleteVirtualLinkLoading', 'deleteVirtualLinkSuccess', 'deleteVirtualLinkError' ); diff --git a/skyquake/plugins/launchpad/src/recordViewer/recordViewSource.js b/skyquake/plugins/launchpad/src/recordViewer/recordViewSource.js index 97c7bc1b0..49c312288 100644 --- a/skyquake/plugins/launchpad/src/recordViewer/recordViewSource.js +++ b/skyquake/plugins/launchpad/src/recordViewer/recordViewSource.js @@ -272,5 +272,4 @@ export default { error: RecordViewActions.editVirtualLinkError } } - } diff --git a/skyquake/plugins/launchpad/src/recordViewer/recordViewStore.js b/skyquake/plugins/launchpad/src/recordViewer/recordViewStore.js index fbdae39e0..589af02ca 100644 --- a/skyquake/plugins/launchpad/src/recordViewer/recordViewStore.js +++ b/skyquake/plugins/launchpad/src/recordViewer/recordViewStore.js @@ -328,7 +328,6 @@ class RecordViewStore { triggerEditVirtualLink(params) { this.editVirtualLink(params); } - } diff --git a/skyquake/plugins/launchpad/src/recordViewer/recordViewer.scss b/skyquake/plugins/launchpad/src/recordViewer/recordViewer.scss index 2f3fa755a..c19d76bd6 100644 --- a/skyquake/plugins/launchpad/src/recordViewer/recordViewer.scss +++ b/skyquake/plugins/launchpad/src/recordViewer/recordViewer.scss @@ -275,9 +275,19 @@ .consoleUrlsList { display: flex; flex: 1 1 auto; + flex-direction: column; li { display: flex; flex: 1 1 auto; + &.notice { + padding-top: 0.5rem; + font-size: 0.75rem; + color: $gray-darker; + } + .consoleLink { + cursor: pointer; + text-decoration: underline; + } h3 { align-self: flex-start; flex: 1 1 auto; -- 2.25.1