});
}
+/**
+ * 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
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);
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);
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);
}