summaryrefslogtreecommitdiffstats
path: root/lib/deploy.js
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-01-24 13:35:28 -0500
committerAlex Shatov <alexs@att.com>2018-01-24 13:35:28 -0500
commit4e30c82b172cf422ab5179e3c566ef01ca14cb3a (patch)
tree0efa3043daeb8001516d671df5d8e1b81ca4b798 /lib/deploy.js
parent70253f7088be04125d9fac8f9bddfaa63778608e (diff)
unit tests coverage 68% and more info in audit
* refactored the unit test - simpler dh server initialization * new unit tests for the dcae-deployments * new unit tests for healthcheck - info * new server_instance_uuid - unique per deployment-handler instance for logging and info * dragging req object over the stack to show req data in logging and audit and metrics * new feature variable collection of policies per component in DCAE Change-Id: I8388d7e5e11e3a6c871cf3d507bd8a07b09add29 Issue-ID: DCAEGEN2-249 Signed-off-by: Alex Shatov <alexs@att.com>
Diffstat (limited to 'lib/deploy.js')
-rw-r--r--lib/deploy.js144
1 files changed, 75 insertions, 69 deletions
diff --git a/lib/deploy.js b/lib/deploy.js
index 7f83620..e651773 100644
--- a/lib/deploy.js
+++ b/lib/deploy.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.
*/
@@ -58,7 +58,7 @@ var parseContent = function(input) {
// create a normalized representation of errors, whether they're a node.js Error or a Cloudify API error
var normalizeError = function (err) {
var e;
-
+
if (err instanceof Error) {
/* node.js system error */
e = createError("Error communicating with CM: " + err.message, 504, "system", 202, 'cloudify-manager');
@@ -71,7 +71,7 @@ var normalizeError = function (err) {
var status = err.status || 502;
var cfyCode = "UNKNOWN";
var cfyMessage;
-
+
if (err.body) {
var p = parseContent(err.body);
if (p.json) {
@@ -84,28 +84,28 @@ var normalizeError = function (err) {
}
message = "Status " + status + " from CM API -- error code: " + cfyCode + " -- message: " + cfyMessage;
}
-
+
/* Pass through 400-level status, recast 500-level */
var returnStatus = (err.status > 499) ? 502 : err.status;
e = createError(message, returnStatus, "api", 502, 'cloudify-manager');
}
-
+
return e;
};
// Augment the raw outputs from a deployment with the descriptions from the blueprint
-var annotateOutputs = function (id, rawOutputs) {
+var annotateOutputs = function (req, id, rawOutputs) {
return new Promise(function(resolve, reject) {
-
+
var outItems = Object.keys(rawOutputs);
-
+
if (outItems.length < 1) {
// No output items, so obviously no descriptions, just return empty object
resolve({});
}
else {
// Call Cloudify to get the descriptions
- cfy.getOutputDescriptions(id)
+ cfy.getOutputDescriptions(req, id)
.then(function(res) {
// Assemble an outputs object with values from raw output and descriptions just obtained
var p = parseContent(res.body);
@@ -115,16 +115,16 @@ var annotateOutputs = function (id, rawOutputs) {
outs[i] = {value: rawOutputs[i]};
if (p.content.outputs[i] && p.content.outputs[i].description) {
outs[i].description = p.content.outputs[i].description;
- }
+ }
});
resolve(outs);
}
else {
reject({code: "API_INVALID_RESPONSE", message: "Invalid response for output descriptions query"});
- }
+ }
});
}
-
+
});
};
@@ -137,41 +137,43 @@ var delay = function(dtime) {
// Go through the Cloudify API call sequence to upload blueprint, create deployment, and launch install workflow
// (but don't wait for the workflow to finish)
-const launchBlueprint = function(id, blueprint, inputs) {
- logger.debug(null, "deploymentId: " + id + " starting blueprint upload");
+const launchBlueprint = function(req, id, blueprint, inputs) {
+ logger.debug(req.dcaeReqId, "deploymentId: " + id + " starting blueprint upload");
// Upload blueprint
- return cfy.uploadBlueprint(id, blueprint)
-
+ return cfy.uploadBlueprint(req, id, blueprint)
+
// Create deployment
.then (function(result) {
- logger.debug(null, "deploymentId: " + id + " blueprint uploaded");
+ logger.debug(req.dcaeReqId, "deploymentId: " + id + " blueprint uploaded");
// Create deployment
- return cfy.createDeployment(id, id, inputs);
+ return cfy.createDeployment(req, id, id, inputs);
})
-
+
// Launch the workflow, but don't wait for it to complete
.then(function(result){
- logger.debug(null, "deploymentId: " + id + " deployment created");
+ logger.debug(req.dcaeReqId, "deploymentId: " + id + " deployment created");
return delay(DELAY_INSTALL_WORKFLOW)
- .then(function(){
- return cfy.initiateWorkflowExecution(id, 'install');
+ .then(function(){
+ return cfy.initiateWorkflowExecution(req, id, 'install');
});
})
.catch(function(error) {
- logger.debug(null, "Error: " + error + " for launch blueprint for deploymentId " + id);
+ logger.debug(req.dcaeReqId, "Error: " + error + " for launch blueprint for deploymentId " + id);
throw normalizeError(error);
});
};
exports.launchBlueprint = launchBlueprint;
// Finish installation launched with launchBlueprint
-const finishInstallation = function(deploymentId, executionId) {
- logger.debug(null, "finishInstallation: " + deploymentId + " -- executionId: " + executionId);
- return cfy.getWorkflowResult(executionId)
+const finishInstallation = function(req, deploymentId, executionId) {
+ logger.debug(req.dcaeReqId, "finishInstallation: " + deploymentId + " -- executionId: " + executionId);
+ return cfy.getWorkflowResult(req, executionId)
.then (function(result){
- logger.debug(null, "deploymentId: " + deploymentId + " install workflow successfully executed");
+ logger.debug(req.dcaeReqId, "deploymentId: " + deploymentId + " install workflow successfully executed");
// Retrieve the outputs from the deployment, as specified in the blueprint
- return delay(DELAY_RETRIEVE_OUTPUTS).then(function() { return cfy.getOutputs(deploymentId); });
+ return delay(DELAY_RETRIEVE_OUTPUTS).then(function() {
+ return cfy.getOutputs(req, deploymentId);
+ });
})
.then(function(result) {
// We have the raw outputs from the deployment but not annotated with the descriptions
@@ -182,45 +184,49 @@ const finishInstallation = function(deploymentId, executionId) {
if (p.content.outputs) {
rawOutputs = p.content.outputs;
}
- }
+ }
}
- logger.debug(null, "output retrieval result for " + deploymentId + ": " + JSON.stringify(result));
- return annotateOutputs(deploymentId, rawOutputs);
+ logger.debug(req.dcaeReqId, "output retrieval result for " + deploymentId + ": " + JSON.stringify(result));
+ return annotateOutputs(req, deploymentId, rawOutputs);
})
.catch(function(err) {
- logger.debug(null, "Error finishing install workflow: " + err + " -- " + JSON.stringify(err));
+ logger.debug(req.dcaeReqId, "Error finishing install workflow: " + err + " -- " + JSON.stringify(err));
throw normalizeError(err);
});
};
exports.finishInstallation = finishInstallation;
// Initiate uninstall workflow against a deployment, but don't wait for workflow to finish
-const launchUninstall = function(deploymentId) {
- logger.debug(null, "deploymentId: " + deploymentId + " starting uninstall workflow");
+const launchUninstall = function(req, deploymentId) {
+ logger.debug(req.dcaeReqId, "deploymentId: " + deploymentId + " starting uninstall workflow");
// Run uninstall workflow
- return cfy.initiateWorkflowExecution(deploymentId, 'uninstall')
+ return cfy.initiateWorkflowExecution(req, deploymentId, 'uninstall')
.then(function(result) {
return result;
})
.catch(function(err) {
- logger.debug(null, "Error initiating uninstall workflow: " + err + " -- " + JSON.stringify(err));
+ logger.debug(req.dcaeReqId, "Error initiating uninstall workflow: " + err + " -- " + JSON.stringify(err));
throw normalizeError(err);
- });
+ });
};
exports.launchUninstall = launchUninstall;
-const finishUninstall = function(deploymentId, executionId) {
- logger.debug(null, "finishUninstall: " + deploymentId + " -- executionId: " + executionId);
- return cfy.getWorkflowResult(executionId)
+const finishUninstall = function(req, deploymentId, executionId) {
+ logger.debug(req.dcaeReqId, "finishUninstall: " + deploymentId + " -- executionId: " + executionId);
+ return cfy.getWorkflowResult(req, executionId)
.then (function(result){
- logger.debug(null, "deploymentId: " + deploymentId + " uninstall workflow successfully executed");
+ logger.debug(req.dcaeReqId, "deploymentId: " + deploymentId + " uninstall workflow successfully executed");
// Delete the deployment
- return delay(DELAY_DELETE_DEPLOYMENT).then(function() {return cfy.deleteDeployment(deploymentId);});
+ return delay(DELAY_DELETE_DEPLOYMENT).then(function() {
+ return cfy.deleteDeployment(req, deploymentId);
+ });
})
.then (function(result){
- logger.debug(null, "deploymentId: " + deploymentId + " deployment deleted");
+ logger.debug(req.dcaeReqId, "deploymentId: " + deploymentId + " deployment deleted");
// Delete the blueprint
- return delay(DELAY_DELETE_BLUEPRINT).then(function() {return cfy.deleteBlueprint(deploymentId);});
+ return delay(DELAY_DELETE_BLUEPRINT).then(function() {
+ return cfy.deleteBlueprint(req, deploymentId);
+ });
})
.then (function(result){
return result;
@@ -228,19 +234,19 @@ const finishUninstall = function(deploymentId, executionId) {
.catch (function(err){
throw normalizeError(err);
});
-
+
};
exports.finishUninstall = finishUninstall;
// Get the status of a workflow execution
-exports.getExecutionStatus = function (exid) {
- return cfy.getWorkflowExecutionStatus(exid)
+exports.getExecutionStatus = function (req, exid) {
+ return cfy.getWorkflowExecutionStatus(req, exid)
.then(function(res){
-
+
var result = {
operationType: res.json.workflow_id
};
-
+
// Map execution status
if (res.json.status === "terminated") {
result.status = "succeeded";
@@ -254,11 +260,11 @@ exports.getExecutionStatus = function (exid) {
else {
result.status = "processing";
}
-
+
if (res.json.error) {
result.error = res.json.error;
}
- logger.debug(null, "getExecutionStatus result: " + JSON.stringify(result));
+ logger.debug(req.dcaeReqId, "getExecutionStatus result: " + JSON.stringify(result));
return result;
})
.catch(function(error) {
@@ -267,37 +273,37 @@ exports.getExecutionStatus = function (exid) {
};
// Go through the Cloudify API call sequence to do a deployment
-exports.deployBlueprint = function(id, blueprint, inputs) {
+exports.deployBlueprint = function(req, id, blueprint, inputs) {
+
+ // Upload blueprint, create deployment, and initiate install workflow
+ return launchBlueprint(req, id, blueprint, inputs)
- // Upload blueprint, create deployment, and initiate install workflow
- return launchBlueprint(id, blueprint, inputs)
-
// Wait for the workflow to complete
.then(
-
+
// launchBlueprint promise fulfilled -- finish installation
function(result){
- return finishInstallation(result.deploymentId, result.executionId); // Will throw normalized error if it fails
+ return finishInstallation(req, result.deploymentId, result.executionId); // Will throw normalized error if it fails
},
-
+
// launchBlueprint promise rejected -- report error
function(err) {
- throw normalizeError(err);
+ throw normalizeError(err);
});
};
// Go through the Cloudify API call sequence to do an undeployment of a previously deployed blueprint
-exports.undeployDeployment = function(id) {
- logger.debug(null, "deploymentId: " + id + " starting uninstall workflow");
-
+exports.undeployDeployment = function(req, id) {
+ logger.debug(req.dcaeReqId, "deploymentId: " + id + " starting uninstall workflow");
+
// Run launch uninstall workflow
- return launchUninstall(id)
-
+ return launchUninstall(req, id)
+
// launchUninstall promise fulfilled -- finish uninstall
.then (function(result){
- return finishUninstall(result.deploymentId, result.executionId); // Will throw normalized error if it fails
+ return finishUninstall(req, result.deploymentId, result.executionId); // Will throw normalized error if it fails
},
-
+
// launchUninstall promise rejected -- report error
function(err){
throw normalizeError(err);