Bug 278 - Allow updating of NSD when there are instantiated network services
[osm/UI.git] / skyquake / plugins / composer / api / composer.js
index f9f0591..93cc553 100644 (file)
@@ -125,8 +125,7 @@ Composer.get = function(req) {
                 response[0].descriptors = JSON.parse(result[0].body).collection['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"]) {
-                        var nsdRefCountCollection = data["nsr:ns-instance-opdata"]["rw-nsr:nsd-ref-count"];
+                    if (data && data["nsr:ns-instance-opdata"]) {
                         response[0].descriptors.map(function(nsd) {
                             if (!nsd["meta"]) {
                                 nsd["meta"] = {};
@@ -134,9 +133,6 @@ Composer.get = function(req) {
                             if (typeof nsd['meta'] == 'string') {
                                 nsd['meta'] = JSON.parse(nsd['meta']);
                             }
-                            nsd["meta"]["instance-ref-count"] = _.findWhere(nsdRefCountCollection, {
-                                "nsd-id-ref": nsd.id
-                            })["instance-ref-count"];
                         });
                     }
                 }
@@ -486,29 +482,34 @@ PackageManager.copy = function(req) {
     });
 }
 
+/**
+ * This methods retrieves the status of package operations. It takes an optional
+ * transaction id (id) this if present will return only that status otherwise
+ * an array of status' will be response.
+ */
 PackageManager.getJobStatus = function(req) {
     var api_server = req.query["api_server"];
     var uri = utils.confdPort(api_server);
-    var url = '/api/operational/copy-jobs';
     var id = req.params['id'];
+    var url = uri + '/api/operational/copy-jobs' + (id ? '/job/' + id : '');
     return new Promise(function(resolve, reject) {
         request({
-            url: uri + url + '?deep',
+            url: url,
             method: 'GET',
             headers: _.extend({}, constants.HTTP_HEADERS.accept.data, {
                 'Authorization': req.get('Authorization')
             }),
             forever: constants.FOREVER_ON,
-            rejectUnauthorized: false,
+            rejectUnauthorized: false
         }, function(error, response, body) {
             if (utils.validateResponse('restconfAPI.streams', error, response, body, resolve, reject)) {
-                var data = JSON.parse(response.body)['rw-pkg-mgmt:copy-jobs'];
-                var returnData = [];
-                data && data.job.map(function(d) {
-                    if(d['transaction-id'] == id) {
-                        returnData.push(d)
-                    }
-                })
+                var returnData;
+                if (id) {
+                    returnData = JSON.parse(response.body)['rw-pkg-mgmt:job'];
+                } else {
+                    var data = JSON.parse(response.body)['rw-pkg-mgmt:copy-jobs'];
+                    returnData = (data && data.job) || [];
+                }
                 resolve({
                     statusCode: response.statusCode,
                     data: returnData
@@ -518,6 +519,9 @@ PackageManager.getJobStatus = function(req) {
     })
 }
 
+function makeAssetTypeParamName (type) {
+    return type.toLowerCase() + '-file-type';
+}
 FileManager.addFile = function(req) {
     console.log(' Uploading file', req.file.originalname, 'as', req.file.filename);
     var api_server = req.query['api_server'];
@@ -525,15 +529,17 @@ FileManager.addFile = function(req) {
     var package_id = req.query['package_id'];
     var package_type = req.query['package_type'].toUpperCase();
     var package_path = req.query['package_path'];
-    if (!download_host) {
+     if (!download_host) {
         download_host = req.protocol + '://' + req.get('host');//api_server + ':' + utils.getPortForProtocol(req.protocol);
     }
     var input = {
         'external-url': download_host + '/composer/upload/' + req.query['package_id'] + '/' + req.file.filename,
         'package-type': package_type,
         'package-id': package_id,
-        'package-path': package_path + '/' + req.file.filename
+        'package-path': package_path ? package_path + '/' + req.file.filename : req.file.filename
     }
+    var assetType = req.query['asset_type'].toUpperCase();
+    input[makeAssetTypeParamName(package_type)] = assetType;
     return new Promise(function(resolve, reject) {
         Promise.all([
             rp({
@@ -575,16 +581,17 @@ FileManager.get = function(req) {
     var id = req.query['package_id'];
     var downloadUrl = req.query['url'];
     var path = req.query['package_path'];
-    var payload = {
-        "input": {
-            "package-type": type,
-            "package-id": id
-        }
+    var assetType = req.query['asset_type'];
+    var input = {
+        "package-type": type,
+        "package-id": id
     }
+    var payload = {input: input};
     if(req.method == 'GET') {
         if(downloadUrl && path) {
             payload.input['external-url'] = downloadUrl;
             payload.input['package-path'] = path;
+            payload.input[makeAssetTypeParamName(type)] = assetType;
             return download(payload);
         } else {
             return list(payload);
@@ -592,6 +599,7 @@ FileManager.get = function(req) {
     }
     if(req.method == 'DELETE') {
         payload.input['package-path'] = path;
+        payload.input[makeAssetTypeParamName(type)] = assetType;
         return deleteFile(payload)
     }