});
});
};
+// Composer.update = function(req) {
+// var api_server = req.query['api_server'];
+// var catalogType = req.params.catalogType;
+// var id = req.params.id;
+// var data = req.body;
+// console.log('Updating', catalogType, 'id', id, 'on', api_server);
+// var jsonData = {};
+// jsonData[catalogType] = {};
+// jsonData[catalogType] = data;
+// return new Promise(function(resolve, reject) {
+// var requestHeaders = {};
+// _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, {
+// 'Authorization': req.get('Authorization')
+// });
+// request({
+// uri: utils.confdPort(api_server) + APIVersion + '/api/config/' + catalogType + '-catalog' + '/' + catalogType + '/' + id,
+// method: 'PUT',
+// headers: requestHeaders,
+// forever: constants.FOREVER_ON,
+// rejectUnauthorized: false,
+// json: jsonData
+// }, function(error, response, body) {
+// if (utils.validateResponse('Composer.update', error, response, body, resolve, reject)) {
+// resolve({
+// statusCode: response.statusCode
+// });
+// }
+// });
+// });
+//
+
Composer.update = function(req) {
+ console.log(' Updating file', req.file.originalname, 'as', req.file.filename);
var api_server = req.query['api_server'];
- var catalogType = req.params.catalogType;
- var id = req.params.id;
- var data = req.body;
- console.log('Updating', catalogType, 'id', id, 'on', api_server);
- var jsonData = {};
- jsonData[catalogType] = {};
- jsonData[catalogType] = data;
+ // dev_download_server is for testing purposes.
+ // It is the direct IP address of the Node server where the
+ // package will be hosted.
+ var download_host = req.query['dev_download_server'];
+
+ if (!download_host) {
+ download_host = req.protocol + '://' + req.headers.host;
+ }
+ var input = {
+ 'external-url': download_host + '/composer/update/' + req.file.filename,
+ 'package-type': 'VNFD',
+ 'package-id': uuid()
+ }
return new Promise(function(resolve, reject) {
- var requestHeaders = {};
- _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, {
- 'Authorization': req.get('Authorization')
- });
- request({
- uri: utils.confdPort(api_server) + APIVersion + '/api/config/' + catalogType + '-catalog' + '/' + catalogType + '/' + id,
- method: 'PUT',
- headers: requestHeaders,
- forever: constants.FOREVER_ON,
- rejectUnauthorized: false,
- json: jsonData
- }, function(error, response, body) {
- if (utils.validateResponse('Composer.update', error, response, body, resolve, reject)) {
- resolve({
- statusCode: response.statusCode
- });
- }
+ Promise.all([
+ rp({
+ uri: utils.confdPort(api_server) + '/api/operations/package-update',
+ method: 'POST',
+ headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, {
+ 'Authorization': req.get('Authorization')
+ }),
+ forever: constants.FOREVER_ON,
+ rejectUnauthorized: false,
+ resolveWithFullResponse: true,
+ json: true,
+ body: {
+ input: input
+ }
+ })
+ ]).then(function(result) {
+ var data = {};
+ data['transaction_id'] = result[0].body['output']['transaction-id'];
+
+ // Add a status checker on the transaction and then to delete the file later
+ PackageFileHandler.checkCreatePackageStatusAndHandleFile(req, data['transaction_id'], true);
+
+ // Return status to composer UI to update the status.
+ resolve({
+ statusCode: constants.HTTP_RESPONSE_CODES.SUCCESS.OK,
+ data: data
+ });
+ }).catch(function(error) {
+ var res = {};
+ console.log('Problem with Composer.upload', error);
+ res.statusCode = error.statusCode || 500;
+ res.errorMessage = {
+ error: 'Failed to upload package ' + req.file.originalname + '. Error: ' + error
+ };
+ reject(res);
});
});
};
// Add a status checker on the transaction and then to delete the file later
PackageFileHandler.checkCreatePackageStatusAndHandleFile(req, data['transaction_id']);
-
+
// Return status to composer UI to update the status.
resolve({
statusCode: constants.HTTP_RESPONSE_CODES.SUCCESS.OK,
});
});
};
+
+
+
Composer.addFile = function(req) {
console.log(' Uploading file', req.file.originalname, 'as', req.file.filename);
var api_server = req.query['api_server'];
})
]).then(function(result) {
var data = {};
- data['transaction_id'] = result[0].body['output']['transaction-id'];
+ data['transaction_id'] = result[0].body['output']['task-id'];
resolve({
statusCode: constants.HTTP_RESPONSE_CODES.SUCCESS.OK,
data: data
}, constants.PACKAGE_FILE_DELETE_DELAY_MILLISECONDS);
};
-function checkStatus(req, transactionId) {
+function checkStatus(req, transactionId, isUpdate) {
var upload_server = req.query['upload_server'];
var headers = _.extend({},
{
'Authorization': req.get('Authorization')
}
);
+ var type = isUpdate ? 'update' : 'upload';
request({
- url: upload_server + ':' + constants.PACKAGE_MANAGER_SERVER_PORT + '/api/upload/' + transactionId + '/state',
+ url: upload_server + ':' + constants.PACKAGE_MANAGER_SERVER_PORT + '/api/' + type + '/' + transactionId + '/state',
type: 'GET',
headers: headers,
forever: constants.FOREVER_ON,
deleteFile(req.file.filename);
} else {
setTimeout(function() {
- checkStatus(req, transactionId);
+ checkStatus(req, transactionId, isUpdate);
}, constants.PACKAGE_FILE_ONBOARD_TRANSACTION_STATUS_CHECK_DELAY_MILLISECONDS);
}
}
});
};
-PackageFileHandler.checkCreatePackageStatusAndHandleFile = function(req, transactionId) {
- checkStatus(req, transactionId);
+PackageFileHandler.checkCreatePackageStatusAndHandleFile = function(req, transactionId, isUpdate) {
+ checkStatus(req, transactionId, isUpdate);
};
-module.exports = PackageFileHandler;
\ No newline at end of file
+module.exports = PackageFileHandler;
/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
onUploadCatalogPackageStatusUpdated(response) {
const upload = updateStatusInfo(response);
this.updatePackage(upload);
+ console.log('updating package upload')
// if pending with no transaction id - do nothing
// bc DropZone.js will notify upload progress
if (upload.pending && upload.transactionId) {
+ console.log('checking status')
delayStatusCheck(this.getInstance().requestCatalogPackageUploadStatus, upload);
} else if (upload.success) {
this.getInstance().loadCatalogs();
+ console.log('finished uploading to node, requesting status from rest')
}
}
statusInfo.pending = true;
statusInfo.progress = 100;
statusInfo.message = 'Upload completed.';
- statusInfo.transactionId = responseData['transaction-id'] || catalogPackage.transactionId;
+ statusInfo.transactionId = responseData['transaction_id'] || responseData['transaction-id'] || catalogPackage.transactionId;
break;
case 'upload-error':
statusInfo.error = true;
case 'download-requested':
statusInfo.pending = true;
statusInfo.progress = 25;
- statusInfo.transactionId = responseData['transaction-id'] || catalogPackage.transactionId;
+ statusInfo.transactionId = responseData['transaction_id'] || responseData['transaction-id'] || catalogPackage.transactionId;
break;
case 'pending':
statusInfo.pending = true;