NOTICKET: Project prefixes on NSD/VNFD
authorKIRAN KASHALKAR <kiran.kashalkar@riftio.com>
Thu, 30 Mar 2017 22:20:58 +0000 (18:20 -0400)
committerKIRAN KASHALKAR <kiran.kashalkar@riftio.com>
Thu, 30 Mar 2017 22:20:58 +0000 (18:20 -0400)
Signed-off-by: KIRAN KASHALKAR <kiran.kashalkar@riftio.com>
skyquake/framework/core/modules/routes/navigation.js
skyquake/plugins/composer/api/composer.js
skyquake/plugins/composer/src/src/libraries/utils.js
skyquake/plugins/launchpad/api/launchpad.js

index 7a6d99c..bf9c47b 100644 (file)
@@ -44,7 +44,7 @@ Router.get('/login.html', cors(), function(req, res) {
 
 Router.get('/', cors(), function(req, res) {
        var api_server = req.query['api_server'] || (req.protocol + '://' + configurationAPI.globalConfiguration.get().api_server);
-       if (req.session.loggedIn) {
+       if (req.session && req.session.loggedIn) {
                console.log('Logged in. Redirect to launchpad')
                res.redirect('/launchpad/?api_server=' + api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname));
        } else {
index 447e1d9..f98020c 100644 (file)
@@ -34,6 +34,7 @@ var DataCenters = {};
 Composer.get = function(req) {
     var api_server = req.query['api_server'];
     var results = {}
+    var projectPrefix = req.session.projectId ? "project-" : "";
     return new Promise(function(resolve, reject) {
         Promise.all([
             rp({
@@ -121,7 +122,7 @@ Composer.get = function(req) {
                 "descriptors": []
             }];
             if (result[0].body) {
-                response[0].descriptors = JSON.parse(result[0].body).collection['nsd:nsd'];
+                response[0].descriptors = JSON.parse(result[0].body).collection[projectPrefix + 'nsd:nsd'];
                 if (result[2].body) {
                     var data = JSON.parse(result[2].body);
                     if (data && data["nsr:ns-instance-opdata"] && data["nsr:ns-instance-opdata"]["rw-nsr:nsd-ref-count"]) {
@@ -141,10 +142,10 @@ Composer.get = function(req) {
                 }
             };
             if (result[1].body) {
-                response[1].descriptors = JSON.parse(result[1].body).collection['vnfd:vnfd'];
+                response[1].descriptors = JSON.parse(result[1].body).collection[projectPrefix + 'vnfd:vnfd'];
             };
             // if (result[2].body) {
-            //   response[2].descriptors = JSON.parse(result[2].body).collection['pnfd:pnfd'];
+            //   response[2].descriptors = JSON.parse(result[2].body).collection[projectPrefix + 'pnfd:pnfd'];
             // };
             resolve({
                 statusCode: response.statusCode || 200,
index ee4163c..ff2adc0 100644 (file)
@@ -180,6 +180,9 @@ export default {
                                                console.log('Something went wrong while resolving a leafref. Reached a leaf with predicate.');
                                        } else {
                                                // contains no predicate
+                                               if (!objectCopy) {
+                                                       break;
+                                               }
                                                results.push(objectCopy[fragment]);
                                        }
                                }
@@ -236,6 +239,9 @@ export default {
                                                }
                                        } else {
                                                // contains no predicate
+                                               if (!objectCopy) {
+                                                       break;
+                                               }
                                                objectCopy = objectCopy[fragment];
                                        }
                                }
index 6fe48f4..2febc3c 100644 (file)
@@ -168,6 +168,7 @@ var DataCenters = {};
 Catalog.get = function(req) {
     var api_server = req.query['api_server'];
     var results = {}
+    var projectPrefix = req.session.projectId ? "project-" : "";
     return new Promise(function(resolve, reject) {
         Promise.all([
             rp({
@@ -258,12 +259,12 @@ Catalog.get = function(req) {
             var vnfdCatalog = null;
             var vnfdDict = {};
             if (result[1].body) {
-                vnfdCatalog = JSON.parse(result[1].body).collection['vnfd:vnfd'].map(function(v, i) {
+                vnfdCatalog = JSON.parse(result[1].body).collection[projectPrefix + 'vnfd:vnfd'].map(function(v, i) {
                     vnfdDict[v.id] = v['short-name'] || v.name;
                 })
             }
             if (result[0].body) {
-                response[0].descriptors = JSON.parse(result[0].body).collection['nsd:nsd'];
+                response[0].descriptors = JSON.parse(result[0].body).collection[projectPrefix + 'nsd:nsd'];
                 if (result[2].body) {
                     var data = JSON.parse(result[2].body);
                     if (data && data["nsr:ns-instance-opdata"] && data["nsr:ns-instance-opdata"]["rw-nsr:nsd-ref-count"]) {
@@ -286,10 +287,10 @@ Catalog.get = function(req) {
                 }
             };
             if (result[1].body) {
-                response[1].descriptors = JSON.parse(result[1].body).collection['vnfd:vnfd'];
+                response[1].descriptors = JSON.parse(result[1].body).collection[projectPrefix + 'vnfd:vnfd'];
             };
             // if (result[2].body) {
-            //   response[2].descriptors = JSON.parse(result[2].body).collection['pnfd:pnfd'];
+            //   response[2].descriptors = JSON.parse(result[2].body).collection[projectPrefix + 'pnfd:pnfd'];
             // };
             resolve({
                 statusCode: response.statusCode || 200,
@@ -508,6 +509,7 @@ NSR.get = function(req) {
     var nsrPromises = [];
     var api_server = req.query["api_server"];
     var id = req.params.id;
+    var projectPrefix = req.session.projectId ? "project-" : "";
     var nsdInfo = new Promise(function(resolve, reject) {
         request({
             uri: utils.projectContextUrl(req, utils.confdPort(api_server) + APIVersion + '/api/config/nsd-catalog/nsd?deep'),
@@ -523,7 +525,7 @@ NSR.get = function(req) {
                 var isString = typeof(response.body) == "string";
                 if (isString && response.body == '') return resolve('empty');
                 data = isString ? JSON.parse(response.body) : response.body;
-                var nsdData = data.collection["nsd:nsd"];
+                var nsdData = data.collection[projectPrefix + "nsd:nsd"];
                 if (nsdData.constructor.name == "Object") {
                     nsdData = [nsdData];
                 }