Update package copy operation
authorBob Gallagher <bob.gallagher@riftio.com>
Fri, 14 Apr 2017 11:00:46 +0000 (07:00 -0400)
committerBob Gallagher <bob.gallagher@riftio.com>
Fri, 14 Apr 2017 11:00:46 +0000 (07:00 -0400)
- fix passing wrong id
- reformat progress message
- fix handling of error condition
- support backend only requesting a single id

Change-Id: I4d5671107c7016586c3413af8523f55e879c2973
Signed-off-by: Bob Gallagher <bob.gallagher@riftio.com>
skyquake/plugins/composer/api/composer.js
skyquake/plugins/composer/src/src/sources/CatalogPackageManagerSource.js
skyquake/plugins/composer/src/src/stores/CatalogPackageManagerStore.js

index f9f0591..5ff92c8 100644 (file)
@@ -486,29 +486,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
index 290d715..e059f94 100644 (file)
@@ -158,9 +158,9 @@ const CatalogPackageManagerSource = {
                                                reject(operation);
                                        };
                                        const data = {
-                                               "package-type": operationInfo.packageType,
-                                               "package-id": operationInfo.id,
-                                               "package-name": operationInfo.name
+                                               "package-type": operationInfo.args.packageType,
+                                               "package-id": operationInfo.args.id,
+                                               "package-name": operationInfo.args.name
                                        }
                                        const path = getComposerApiPath('package-copy');
                                        ajaxFetch(path, operationInfo, successHandler, failHandler, 'POST', data, true);
@@ -176,15 +176,14 @@ const CatalogPackageManagerSource = {
                        remote: function(state, operation) {
                                return new Promise(function(resolve, reject) {
                                        const successHandler = (response) => {
-                                               const status = response.data[0].status;
+                                               const status = response.data.status;
                                                const state = status === "COMPLETED" ? SUCCESS : status === "FAILED" ? FAILED : PENDING;
                                                state.progress = state.pending ? operation.progress + ((100 - operation.progress) / 2) : 100;
                                                let newOp = Object.assign({}, operation, state);
                                                resolve(newOp);
                                        };
                                        const failHandler = (response) => {
-                                               let operation = Object.assign({}, this, FAILED);
-                                               reject(operation);
+                                               reject(Object.assign({}, operation, FAILED));
                                        };
                                        const path = getComposerApiPath('package-manager/jobs/' + operation.transactionId);
                                        ajaxFetch(path, operation, successHandler, failHandler);
index c964c67..9d23042 100644 (file)
@@ -124,15 +124,17 @@ class CatalogPackageManagerStore {
 
        copyCatalogPackage(sourcePackage) {
                let operationInfo = Object.assign({}, defaults.operation);
-               operationInfo.name =  "Duplication of " + sourcePackage.name;
-               operationInfo.id = guid();
-               operationInfo.icon = imgCopy;
-               operationInfo.type = 'copy';
-               operationInfo.message = 'Requesting package duplication.';
+
                operationInfo.args.packageType = sourcePackage['uiState']['type'].toUpperCase();
                operationInfo.args.id =  sourcePackage.id;
                operationInfo.args.name =  sourcePackage.name + ' copy';
 
+               operationInfo.id = guid();
+               operationInfo.icon = imgCopy;
+               operationInfo.type = 'copy';
+               operationInfo.name =  "Creating " + operationInfo.args.name;
+               operationInfo.message = "Requesting duplication";
+
                this.addOperation(operationInfo);
                this.getInstance().requestCatalogPackageCopy(operationInfo, sourcePackage);
        }