aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dcae-deployments.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dcae-deployments.js')
-rw-r--r--lib/dcae-deployments.js107
1 files changed, 55 insertions, 52 deletions
diff --git a/lib/dcae-deployments.js b/lib/dcae-deployments.js
index 38dc3c4..9c1d918 100644
--- a/lib/dcae-deployments.js
+++ b/lib/dcae-deployments.js
@@ -1,16 +1,16 @@
/*
-Copyright(c) 2017 AT&T Intellectual Property. All rights reserved.
+Copyright(c) 2018 AT&T Intellectual Property. All rights reserved.
-Licensed under the Apache License, Version 2.0 (the "License");
+Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing,
+Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-CONDITIONS OF ANY KIND, either express or implied.
+CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
*/
@@ -36,11 +36,18 @@ const inventory = inv({url: config.inventory.url});
/* Set up middleware stack for initial processing of request */
app.use(middleware.checkType('application/json')); // Validate type
app.use(bodyParser.json({strict: true})); // Parse body as JSON
+app.use(function(req, res, next) {
+ log.debug(req.dcaeReqId,
+ "new req: " + req.method + " " + req.originalUrl +
+ " from: " + req.ip + " body: " + JSON.stringify(req.body)
+ );
+ next();
+});
/* Return a promise for a blueprint for the given service type ID */
-const getBlueprint = function(serviceTypeId) {
- return inventory.getBlueprintByType(serviceTypeId)
+const getBlueprint = function(req, serviceTypeId) {
+ return inventory.getBlueprintByType(req, serviceTypeId)
.then(function (blueprintInfo) {
if (!blueprintInfo.blueprint) {
var e = new Error("No service type with ID " + serviceTypeId);
@@ -48,7 +55,7 @@ const getBlueprint = function(serviceTypeId) {
throw e;
}
return blueprintInfo;
- })
+ })
};
/* Generate self and status links object for responses */
@@ -57,7 +64,7 @@ const createLinks = function(req, deploymentId, executionId) {
return {
self: baseURL,
status: baseURL + '/operation/' + executionId
- };
+ };
};
/* Generate a success response body for PUT and DELETE operations */
@@ -71,13 +78,11 @@ const createResponse = function(req, result) {
/* Look up running (or in process of deploying) instances of the given service type */
app.get('/', function (req, res, next) {
var services = []
-
-
- var searchTerm = {};
+ var searchTerm;
req.query['serviceTypeId'] && (searchTerm = {typeId: req.query['serviceTypeId']});
-
- inventory.getServicesByType(searchTerm)
+
+ inventory.getServicesByType(req, searchTerm)
.then(function (result) {
var deployments = result.map(function(service){
return {
@@ -92,70 +97,68 @@ app.get('/', function (req, res, next) {
/* Accept an incoming deployment request */
app.put('/:deploymentId', function(req, res, next) {
-
- log.debug(req.dcaeReqId, "body: " + JSON.stringify(req.body));
-
+
/* Make sure there's a serviceTypeId in the body */
if (!req.body['serviceTypeId']) {
var e = new Error ('Missing required parameter serviceTypeId');
e.status = 400;
throw e;
}
-
+
/* Make sure the deploymentId doesn't already exist */
- inventory.verifyUniqueDeploymentId(req.params['deploymentId'])
+ inventory.verifyUniqueDeploymentId(req, req.params['deploymentId'])
/* Get the blueprint for this service type */
.then(function(res) {
- return getBlueprint(req.body['serviceTypeId']);
+ return getBlueprint(req, req.body['serviceTypeId']);
})
-
- /* Add this new service instance to inventory
- * Easier to remove from inventory if deployment fails than vice versa
+
+ /* Add this new service instance to inventory
+ * Easier to remove from inventory if deployment fails than vice versa
* Also lets client check for deployed/deploying instances if client wants to limit number of instances
*/
.then(function (blueprintInfo) {
req.dcaeBlueprint = blueprintInfo.blueprint;
- return inventory.addService(req.params['deploymentId'], blueprintInfo.typeId, "dummyVnfId", "dummyVnfType", "dummyLocation");
+ return inventory.addService(req, req.params['deploymentId'], blueprintInfo.typeId, "dummyVnfId", "dummyVnfType", "dummyLocation");
})
-
+
/* Upload blueprint, create deployment and start install workflow (but don't wait for completion */
.then (function() {
req.dcaeAddedToInventory = true;
- return deploy.launchBlueprint(req.params['deploymentId'], req.dcaeBlueprint, req.body['inputs']);
+ return deploy.launchBlueprint(req, req.params['deploymentId'], req.dcaeBlueprint, req.body['inputs']);
})
-
+
/* Send the HTTP response indicating workflow has started */
.then(function(result) {
res.status(202).json(createResponse(req, result));
log.audit(req, 202, "Execution ID: " + result.executionId);
return result;
})
-
+
/* Finish deployment--wait for the install workflow to complete, retrieve and annotate outputs */
.then(function(result) {
- return deploy.finishInstallation(result.deploymentId, result.executionId);
+ return deploy.finishInstallation(req, result.deploymentId, result.executionId);
})
-
+
/* Log completion in audit log */
.then (function(result) {
log.audit(req, 200, "Deployed id: " + req.params['deploymentId']);
})
-
+
/* All errors show up here */
- .catch(function(error) {
-
+ .catch(function(error) {
+
/* If we haven't already sent a response, let the error handler send response and log the error */
if (!res.headersSent) {
-
+
/* If we made an inventory entry, remove it */
if (req.dcaeAddedToInventory) {
- inventory.deleteService(req.params['deploymentId'])
+ inventory.deleteService(req, req.params['deploymentId'])
.catch(function(error) {
log.error(error, req);
});
}
-
+
next(error);
}
else {
@@ -164,46 +167,46 @@ app.put('/:deploymentId', function(req, res, next) {
error.message = "Error deploying deploymentId " + req.params['deploymentId'] + ": " + error.message
log.error(error, req);
log.audit(req, 500, error.message);
- }
+ }
});
});
/* Delete a running service instance */
app.delete('/:deploymentId', function(req, res, next) {
-
+
/* Launch the uninstall workflow */
- deploy.launchUninstall(req.params['deploymentId'])
-
+ deploy.launchUninstall(req, req.params['deploymentId'])
+
/* Delete the service from inventory */
.then(function(result) {
- return inventory.deleteService(req.params['deploymentId'])
+ return inventory.deleteService(req, req.params['deploymentId'])
.then (function() {
return result;
});
})
-
+
/* Send the HTTP response indicating workflow has started */
.then(function(result) {
res.status(202).send(createResponse(req, result));
log.audit(req, 202, "ExecutionId: " + result.executionId);
return result;
})
-
+
/* Finish the delete processing--wait for the uninstall to complete, delete deployment, delete blueprint */
.then(function(result) {
- return deploy.finishUninstall(result.deploymentId, result.executionId);
+ return deploy.finishUninstall(req, result.deploymentId, result.executionId);
})
-
+
/* Log completion in audit log */
.then(function(result) {
- log.audit(req, 200, "Undeployed id: " + req.params['deploymentId']);
+ log.audit(req, 200, "Undeployed id: " + req.params['deploymentId']);
})
-
+
/* All errors show up here */
.catch(function(error) {
/* If we haven't already sent a response, give it to the error handler to send response */
- if (!res.headersSent) {
+ if (!res.headersSent) {
next(error);
}
else {
@@ -217,8 +220,8 @@ app.delete('/:deploymentId', function(req, res, next) {
/* Get the status of a workflow execution */
app.get('/:deploymentId/operation/:executionId', function(req, res, next){
- deploy.getExecutionStatus(req.params['executionId'])
-
+ deploy.getExecutionStatus(req, req.params['executionId'])
+
/* Send success response */
.then(function(result) {
result.requestId = req.dcaeReqId;
@@ -226,9 +229,9 @@ app.get('/:deploymentId/operation/:executionId', function(req, res, next){
res.status(200).json(result);
log.audit(req, 200, "Workflow type: " + result.operationType + " -- execution status: " + result.status);
})
-
+
.catch(next); /* Let the error handler send the response and log the error */
-
+
});
-module.exports = app; \ No newline at end of file
+module.exports = app;