summaryrefslogtreecommitdiffstats
path: root/lib/deploy.js
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-12-06 10:16:43 -0500
committerAlex Shatov <alexs@att.com>2018-12-06 10:16:43 -0500
commitca00a932eae5e706f01519612fce1015c9ff9d58 (patch)
tree796210ad1dfb8e4e717c06264f01fb64faa0fda6 /lib/deploy.js
parent84d5646b3f0250079c386ed2e1eb9fd7d551004e (diff)
3.1.0/5.1.0 - check for finished deployment
- external version 3.1.0 - internal version 5.1.0 for code change - no API change - check for finished deployment creation - success or failure - stop querying cloudify manager on failed deployment creation - use optional $CONSUL_URL to get url of consul - improved info used for audit and logging and responses - added more unit tests unit test coverage summary Statements : 80.99% ( 946/1168 ) Branches : 58.22% ( 294/505 ) Functions : 81.28% ( 165/203 ) Lines : 81.53% ( 936/1148 ) Change-Id: I831cd0db0d2e148e6da4c9190495aacf72e2d39c Signed-off-by: Alex Shatov <alexs@att.com> Issue-ID: DCAEGEN2-929
Diffstat (limited to 'lib/deploy.js')
-rw-r--r--lib/deploy.js88
1 files changed, 40 insertions, 48 deletions
diff --git a/lib/deploy.js b/lib/deploy.js
index 2d75b52..4829040 100644
--- a/lib/deploy.js
+++ b/lib/deploy.js
@@ -21,7 +21,6 @@ See the License for the specific language governing permissions and limitations
const config = process.mainModule.exports.config;
/* Set delays between steps */
-const DELAY_INSTALL_WORKFLOW = 30000;
const DELAY_RETRIEVE_OUTPUTS = 5000;
const DELAY_DELETE_DEPLOYMENT = 30000;
const DELAY_DELETE_BLUEPRINT = 10000;
@@ -43,9 +42,9 @@ cfy.setLogger(logger);
// Try to parse a string as JSON
var parseContent = function(input) {
- var res = {json: false, content: input};
+ const res = {json: false, content: input};
try {
- var parsed = JSON.parse(input);
+ const parsed = JSON.parse(input);
res.json = true;
res.content = parsed;
}
@@ -96,8 +95,7 @@ var normalizeError = function (err) {
// Augment the raw outputs from a deployment with the descriptions from the blueprint
var annotateOutputs = function (req, id, rawOutputs) {
return new Promise(function(resolve, reject) {
-
- var outItems = Object.keys(rawOutputs);
+ const outItems = Object.keys(rawOutputs);
if (outItems.length < 1) {
// No output items, so obviously no descriptions, just return empty object
@@ -137,37 +135,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(req, id, blueprint, inputs) {
- logger.info(req.dcaeReqId, "deploymentId: " + id + " starting blueprint upload");
- // Upload blueprint
+exports.launchBlueprint = function(req, id, blueprint, inputs) {
+ const log_deployment_id = "deploymentId(" + id + "): ";
+ var step_log = log_deployment_id + "uploading blueprint";
+ logger.info(req.dcaeReqId, step_log);
return cfy.uploadBlueprint(req, id, blueprint)
- // Create deployment
.then (function(result) {
- logger.info(req.dcaeReqId, "deploymentId: " + id + " blueprint uploaded");
- // Create deployment
- return cfy.createDeployment(req, id, id, inputs);
+ step_log = log_deployment_id + "creating deployment";
+ logger.info(req.dcaeReqId, step_log);
+ // Create deployment
+ return cfy.createDeployment(req, id, id, inputs);
})
// create the deployment and keep checking, for up to 5 minutes, until creation is complete
- .then(function(result){
- return cfy.getDeploymentCreationResult(req, id);
- })
- .then(function(){
- logger.info(req.dcaeReqId, "deploymentId: " + id + " deployment created");
- return cfy.initiateWorkflowExecution(req, id, 'install');
- })
- .catch(function(error) {
- logger.info(req.dcaeReqId, "Error: " + JSON.stringify(error) + " for launch blueprint/deployment creation for deploymentId " + id);
- throw normalizeError(error);
- });
+ .then(function(result) {
+ step_log = log_deployment_id + "waiting for deployment creation";
+ logger.info(req.dcaeReqId, step_log);
+ return cfy.waitForDeploymentCreation(req, id);
+ })
+ .then(function() {
+ step_log = log_deployment_id + "install";
+ logger.info(req.dcaeReqId, step_log);
+ return cfy.initiateWorkflowExecution(req, id, 'install');
+ })
+ .catch(function(error) {
+ step_log = " while " + step_log;
+ logger.info(req.dcaeReqId, "Error: " + JSON.stringify(error) + step_log);
+ error.message = (error.message && (step_log + ": " + error.message))
+ || ("failed: " + step_log);
+ throw normalizeError(error);
+ });
};
-exports.launchBlueprint = launchBlueprint;
// Finish installation launched with launchBlueprint
-const finishInstallation = function(req, deploymentId, executionId) {
+exports.finishInstallation = function(req, deploymentId, executionId) {
logger.info(req.dcaeReqId, "finishInstallation: " + deploymentId + " -- executionId: " + executionId);
- return cfy.getWorkflowResult(req, executionId)
+ return cfy.waitForWorkflowExecution(req, executionId)
.then (function(result){
logger.info(req.dcaeReqId, "deploymentId: " + deploymentId + " install workflow successfully executed");
// Retrieve the outputs from the deployment, as specified in the blueprint
@@ -194,10 +198,9 @@ const finishInstallation = function(req, deploymentId, executionId) {
throw normalizeError(err);
});
};
-exports.finishInstallation = finishInstallation;
// Initiate uninstall workflow against a deployment, but don't wait for workflow to finish
-const launchUninstall = function(req, deploymentId) {
+exports.launchUninstall = function(req, deploymentId) {
logger.info(req.dcaeReqId, "deploymentId: " + deploymentId + " starting uninstall workflow");
// Run uninstall workflow
return cfy.initiateWorkflowExecution(req, deploymentId, 'uninstall')
@@ -209,11 +212,10 @@ const launchUninstall = function(req, deploymentId) {
throw normalizeError(err);
});
};
-exports.launchUninstall = launchUninstall;
-const finishUninstall = function(req, deploymentId, executionId) {
+exports.finishUninstall = function(req, deploymentId, executionId) {
logger.info(req.dcaeReqId, "finishUninstall: " + deploymentId + " -- executionId: " + executionId);
- return cfy.getWorkflowResult(req, executionId)
+ return cfy.waitForWorkflowExecution(req, executionId)
.then (function(result){
logger.info(req.dcaeReqId, "deploymentId: " + deploymentId + " uninstall workflow successfully executed");
// Delete the deployment
@@ -236,11 +238,10 @@ const finishUninstall = function(req, deploymentId, executionId) {
});
};
-exports.finishUninstall = finishUninstall;
// Get the status of a workflow execution
-exports.getExecutionStatus = function (req, exid) {
- return cfy.getWorkflowExecutionStatus(req, exid)
+exports.getExecutionStatus = function (req, execution_id) {
+ return cfy.getExecutionStatus(req, execution_id)
.then(function(res){
var result = {
@@ -276,17 +277,12 @@ exports.getExecutionStatus = function (req, exid) {
exports.deployBlueprint = function(req, id, blueprint, inputs) {
// Upload blueprint, create deployment, and initiate install workflow
- return launchBlueprint(req, id, blueprint, inputs)
+ return exports.launchBlueprint(req, id, blueprint, inputs)
// Wait for the workflow to complete
- .then(
-
- // launchBlueprint promise fulfilled -- finish installation
- function(result){
- return finishInstallation(req, result.deploymentId, result.executionId); // Will throw normalized error if it fails
+ .then(function(result){
+ return exports.finishInstallation(req, result.deploymentId, result.executionId); // Will throw normalized error if it fails
},
-
- // launchBlueprint promise rejected -- report error
function(err) {
throw normalizeError(err);
});
@@ -297,14 +293,10 @@ exports.undeployDeployment = function(req, id) {
logger.info(req.dcaeReqId, "deploymentId: " + id + " starting uninstall workflow");
// Run launch uninstall workflow
- return launchUninstall(req, id)
-
- // launchUninstall promise fulfilled -- finish uninstall
+ return exports.launchUninstall(req, id)
.then (function(result){
- return finishUninstall(req, result.deploymentId, result.executionId); // Will throw normalized error if it fails
+ return exports.finishUninstall(req, result.deploymentId, result.executionId); // Will throw normalized error if it fails
},
-
- // launchUninstall promise rejected -- report error
function(err){
throw normalizeError(err);
});