Changes to generate console link when required 96/296/1
authorKIRAN KASHALKAR <kiran.kashalkar@riftio.com>
Thu, 8 Sep 2016 15:40:38 +0000 (11:40 -0400)
committerKIRAN KASHALKAR <kiran.kashalkar@riftio.com>
Thu, 8 Sep 2016 15:40:38 +0000 (11:40 -0400)
Signed-off-by: KIRAN KASHALKAR <kiran.kashalkar@riftio.com>
12 files changed:
skyquake/plugins/launchpad/api/launchpad.js
skyquake/plugins/launchpad/routes.js
skyquake/plugins/launchpad/src/launchpadFleetActions.js
skyquake/plugins/launchpad/src/launchpadFleetSource.js
skyquake/plugins/launchpad/src/launchpadFleetStore.js
skyquake/plugins/launchpad/src/launchpad_card/launchpadCardMgmtInterfaces.jsx
skyquake/plugins/launchpad/src/launchpad_card/launchpad_card.scss
skyquake/plugins/launchpad/src/recordViewer/recordCard.jsx
skyquake/plugins/launchpad/src/recordViewer/recordViewActions.js
skyquake/plugins/launchpad/src/recordViewer/recordViewSource.js
skyquake/plugins/launchpad/src/recordViewer/recordViewStore.js
skyquake/plugins/launchpad/src/recordViewer/recordViewer.scss

index 02c28eb..3972289 100644 (file)
@@ -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;
index d8f6493..f9d6ce7 100644 (file)
@@ -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);
index 2863c7a..4052ebb 100644 (file)
@@ -39,4 +39,6 @@ module.exports = Alt.generateActions(
                                        'closeNsrCard',
                                        'instantiateNetworkService',
                                        'setNsListPanelVisible',
+                                       'getVDUConsoleLinkSuccess',
+                                       'getVDUConsoleLinkError'
                                        );
index 71e3d7d..dac8a82 100644 (file)
@@ -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)
index 54c45e4..520eebe 100644 (file)
@@ -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;
index 782e99f..35f9caa 100644 (file)
@@ -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 (
-            <li key={index}><h3>{i["name"] + '-' + i.id.substr(0,4)}</h3><a href={i["console-url"]} target="_blank">{consoleLink}</a></li>
+            <li key={index}><h3>{i["name"] + '-' + i.id.substr(0,4)}</h3><span className='consoleLink' onClick={self.openConsole.bind(self, i["console-url"])}>{consoleLink} *</span></li>
           )
         });
+      notice = <li className='notice'>* If a separate browser window does not open, please check if the popup was blocked and allow it.</li>
     } else {
       status = <li>No VDU Console Links have been specified.</li>
     }
     console_html = (
         <ul>
           {status}
+          {notice}
         </ul>
     );
 
index 1c77c61..01a798a 100644 (file)
         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;
index e3c3dad..dc092bc 100644 (file)
@@ -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(
               <li key={index}>
                 <h3>
                   {vdur['name'] + '-' + vdur.id.substr(0,4)}
                 </h3>
-                <a href={vdur['console-url']} target='_blank'>
-                  {consoleLink}
-                </a>
+                <span className='consoleLink' onClick={self.openConsole.bind(self, vdur["console-url"])}>
+                  {consoleLink} *
+                </span>
               </li>
             )
+            notice = <li className='notice'>* If a separate browser window does not open, please check if the popup was blocked and allow it.</li>
           });
           consoleUrlsComponent = (
             <div className="consoleUrlsComponent">
               <ul className="consoleUrlsList">
                 {consoleUrlsList}
+                {notice}
               </ul>
             </div>
           );
index a9d5250..8197b5b 100644 (file)
@@ -33,5 +33,5 @@ export default Alt.generateActions(
                                    'getConfigSocketJobError',
                                    'createVirtualLinkLoading', 'createVirtualLinkSuccess', 'createVirtualLinkError',
                                    'editVirtualLinkLoading', 'editVirtualLinkSuccess', 'editVirtualLinkError',
-                                   'deleteVirtualLinkLoading', 'deleteVirtualLinkSuccess', 'deleteVirtualLinkError',
+                                   'deleteVirtualLinkLoading', 'deleteVirtualLinkSuccess', 'deleteVirtualLinkError'
                                    );
index 97c7bc1..49c3122 100644 (file)
@@ -272,5 +272,4 @@ export default {
             error: RecordViewActions.editVirtualLinkError
         }
     }
-
 }
index fbdae39..589af02 100644 (file)
@@ -328,7 +328,6 @@ class RecordViewStore {
     triggerEditVirtualLink(params) {
         this.editVirtualLink(params);
     }
-
 }
 
 
index 2f3fa75..c19d76b 100644 (file)
       .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;