From: Bob Gallagher Date: Fri, 14 Apr 2017 11:00:46 +0000 (-0400) Subject: Update package copy operation X-Git-Tag: v2.0.0~8 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=d66bc2c37221a3e4d35d6188f6ab011526bebbf5;p=osm%2FUI.git Update package copy operation - 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 --- diff --git a/skyquake/plugins/composer/api/composer.js b/skyquake/plugins/composer/api/composer.js index f9f059164..5ff92c80e 100644 --- a/skyquake/plugins/composer/api/composer.js +++ b/skyquake/plugins/composer/api/composer.js @@ -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 diff --git a/skyquake/plugins/composer/src/src/sources/CatalogPackageManagerSource.js b/skyquake/plugins/composer/src/src/sources/CatalogPackageManagerSource.js index 290d71518..e059f9441 100644 --- a/skyquake/plugins/composer/src/src/sources/CatalogPackageManagerSource.js +++ b/skyquake/plugins/composer/src/src/sources/CatalogPackageManagerSource.js @@ -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); diff --git a/skyquake/plugins/composer/src/src/stores/CatalogPackageManagerStore.js b/skyquake/plugins/composer/src/src/stores/CatalogPackageManagerStore.js index c964c6796..9d23042e7 100644 --- a/skyquake/plugins/composer/src/src/stores/CatalogPackageManagerStore.js +++ b/skyquake/plugins/composer/src/src/stores/CatalogPackageManagerStore.js @@ -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); }