diff options
Diffstat (limited to 'lib/deploy.js')
-rw-r--r-- | lib/deploy.js | 54 |
1 files changed, 44 insertions, 10 deletions
diff --git a/lib/deploy.js b/lib/deploy.js index cb78f6f..d4ce1d4 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -1,5 +1,5 @@ /* -Copyright(c) 2017-2018 AT&T Intellectual Property. All rights reserved. +Copyright(c) 2017-2020 AT&T Intellectual Property. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -130,19 +130,32 @@ 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) -exports.launchBlueprint = function(req, id, blueprint, inputs) { +exports.launchBlueprint = function(req, id, blueprint, bpid, inputs) { + const log_blueprint_id = "blueprintId(" + bpid + "): "; const log_deployment_id = "deploymentId(" + id + "): "; - var step_log = log_deployment_id + "uploading blueprint"; + var step_log = log_blueprint_id + "uploading blueprint"; logger.info(req.dcaeReqId, step_log); - return cfy.uploadBlueprint(req, id, blueprint) + + return cfy.checkBlueprintExits(req, bpid) + + .then (function (result) { + logger.info(req.dcaeReqId, " checkBlueprintExits result " + result); + // Upload blueprint + if ( result === false ) { + logger.info(req.dcaeReqId, " blueprint with id: " + log_blueprint_id + " does not exist. Uploading"); + return cfy.uploadBlueprint(req, bpid, blueprint) + } + else { + logger.info(req.dcaeReqId, " blueprint with id: " + log_blueprint_id + " already exits. No need to upload"); + } + }) .then (function(result) { step_log = log_deployment_id + "creating deployment"; logger.info(req.dcaeReqId, step_log); // Create deployment - return cfy.createDeployment(req, id, id, inputs); + return cfy.createDeployment(req, id, bpid, inputs); }) - // create the deployment and keep checking, for up to 5 minutes, until creation is complete .then(function(result) { step_log = log_deployment_id + "waiting for deployment creation"; @@ -210,22 +223,43 @@ exports.launchUninstall = function(req, deploymentId) { exports.finishUninstall = function(req, deploymentId, executionId) { logger.info(req.dcaeReqId, "finishUninstall: " + deploymentId + " -- executionId: " + executionId); + var bid = ""; return cfy.waitForWorkflowExecution(req, executionId) .then (function(result){ logger.info(req.dcaeReqId, "deploymentId: " + deploymentId + " uninstall workflow successfully executed"); + logger.info(req.dcaeReqId, "deploymentId: " + deploymentId + " getting associated blueprint_id"); + return cfy.getBlueprintIdFromDeployment(req, deploymentId); + }) + .then (function(result){ + bid = result.json.blueprint_id; + logger.info(req.dcaeReqId, "deploymentId: " + deploymentId + " associated blueprint_id: " + bid); // Delete the deployment return delay(DELAY_DELETE_DEPLOYMENT).then(function() { return cfy.deleteDeployment(req, deploymentId); - }); + }); }) .then (function(result){ logger.info(req.dcaeReqId, "deploymentId: " + deploymentId + " deployment deleted"); - // Delete the blueprint - return delay(DELAY_DELETE_BLUEPRINT).then(function() { - return cfy.deleteBlueprint(req, deploymentId); + return delay(DELAY_DELETE_DEPLOYMENT).then(function() { + return cfy.shouldBlueprintGetDeleted(req, bid); }); }) + .then (function (result) { + logger.info(req.dcaeReqId, "deploymentId: " + deploymentId + " shouldBlueprintGetDeleted: " + result); + if ( result === true ) { + return cfy.getBlueprintTenantName(req, bid) + .then (function(result){ + const tenant = result.json.items[0].tenant_name; + logger.info(req.dcaeReqId, "deploymentId: " + deploymentId + " deleting bluerpint with id: " + + bid + " and tenant_name: " + tenant); + // Delete the blueprint + req.query.cfy_tenant_name = tenant; + return cfy.deleteBlueprint(req, bid); + }); + } + }) .then (function(result){ + logger.info(req.dcaeReqId, "deploymentId: " + deploymentId + " done with uninstall"); return result; }) .catch (function(err){ |