X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FUI.git;a=blobdiff_plain;f=skyquake%2Fplugins%2Fcomposer%2Fapi%2Fcomposer.js;h=eaf5059663bbcccb475f53c11af2e655373091f8;hp=b0684bf21ecde4a6e2ff9399833c26df8cfb0142;hb=6620bca06b9874e68e8bc11ce28b7a6eeda5cc03;hpb=75a161743ecd8dd234e458fa24e10f0e301be926 diff --git a/skyquake/plugins/composer/api/composer.js b/skyquake/plugins/composer/api/composer.js index b0684bf21..eaf505966 100644 --- a/skyquake/plugins/composer/api/composer.js +++ b/skyquake/plugins/composer/api/composer.js @@ -272,7 +272,7 @@ Composer.create = function(req) { }); }); }; -Composer.update = function(req) { +Composer.updateSave = function(req) { var api_server = req.query['api_server']; var catalogType = req.params.catalogType; var id = req.params.id; @@ -301,6 +301,62 @@ Composer.update = function(req) { } }); }); +} + +Composer.update = function(req) { + console.log(' Updating file', req.file.originalname, 'as', req.file.filename); + var api_server = req.query['api_server']; + // 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.get('host');//api_server + ':' + utils.getPortForProtocol(req.protocol); + } + var input = { + 'external-url': download_host + '/composer/update/' + req.file.filename, + 'package-type': 'VNFD', + 'package-id': uuid() + } + return new Promise(function(resolve, reject) { + 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); + }); + }); }; Composer.upload = function(req) { @@ -312,7 +368,7 @@ Composer.upload = function(req) { var download_host = req.query['dev_download_server']; if (!download_host) { - download_host = req.protocol + '://' + req.headers.host; + download_host = req.protocol + '://' + req.get('host');//req.api_server + ':' + utils.getPortForProtocol(req.protocol); } return new Promise(function(resolve, reject) { @@ -358,6 +414,9 @@ Composer.upload = function(req) { }); }); }; + + + Composer.addFile = function(req) { console.log(' Uploading file', req.file.originalname, 'as', req.file.filename); var api_server = req.query['api_server']; @@ -366,9 +425,14 @@ Composer.addFile = function(req) { var package_type = req.query['package_type'].toUpperCase(); var package_path = req.query['package_path']; if (!download_host) { - download_host = req.protocol + '://' + req.headers.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 } - return new Promise(function(resolve, reject) { Promise.all([ rp({ @@ -382,17 +446,12 @@ Composer.addFile = function(req) { resolveWithFullResponse: true, json: true, body: { - 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 - } + input: input } }) ]).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 @@ -553,6 +612,9 @@ FileManager.get = function(req) { data: data.body }); } + }).catch(function(err) { + console.log('Failed to retrieve FileManager.list') + resolve(err); }) } })