aboutsummaryrefslogtreecommitdiffstats
path: root/lib/cloudify.js
diff options
context:
space:
mode:
authorShadi Haidar <sh1986@att.com>2020-01-14 13:31:20 -0500
committerShadi Haidar <sh1986@att.com>2020-08-19 17:51:07 -0400
commit3d364e4ffa2bfdbffa75679ad67fbaa93ce0b8bf (patch)
tree6dfefbd3a80f38b567f06f37621cda1f524572c2 /lib/cloudify.js
parentd6a5b946f05f43a9942d3d564d66a0a3396933a5 (diff)
DH install/uninstall improvements
Install workflow changes: -Use inventory blueprint (BP) typeId when uploading BP to Cloudify/CFY -Set global visibility when uploading BP to CFY for multi-tenant access -Re-use BP if it exists in CFY rather than alawys uploading a new BP -Do not add a new service in inventory anymore Un-Install workflow changes: -Retreive associated BP against the deployment -Check if any other deployments still exist against the BP -If no associated deployments, get the associated tenant for the BP -Only delete BP if there are no more associated BPs -Do not remove associated service from inventory (it won't exist) Coverage summary Statements : 78.01% ( 997/1278 ) Branches : 56.45% ( 302/535 ) Functions : 74.89% ( 164/219 ) Lines : 78.54% ( 988/1258 ) Issue-ID: DCAEGEN2-2022 Signed-off-by: Shadi Haidar <sh1986@att.com> Change-Id: I9cb197edc3a0276c5ca95f9c936fc7300d849f56 Signed-off-by: Shadi Haidar <sh1986@att.com> Signed-off-by: Shadi Haidar (sh1986) <sh1986@att.com> Signed-off-by: Shadi Haidar <sh1986@att.com>
Diffstat (limited to 'lib/cloudify.js')
-rw-r--r--lib/cloudify.js93
1 files changed, 92 insertions, 1 deletions
diff --git a/lib/cloudify.js b/lib/cloudify.js
index 77e6d72..2c7af6e 100644
--- a/lib/cloudify.js
+++ b/lib/cloudify.js
@@ -92,6 +92,17 @@ const getDeploymentCreationStatus = function(req, deployment_id) {
return doRequest(req, reqOptions, null, CLOUDIFY);
};
+// Get blueprint_id for a particular deployment
+exports.getBlueprintIdFromDeployment = function(req, deployment_id) {
+ const reqOptions = {
+ method : "GET",
+ uri : cfyAPI + "/deployments/" + deployment_id + "?_include=blueprint_id"
+ };
+ addAuthToOptions(reqOptions, req);
+
+ return doRequest(req, reqOptions, null, CLOUDIFY);
+};
+
// Poll for the result of a workflow execution until it's done
// Return a promise for the final result of a workflow execution
exports.waitForWorkflowExecution = function(mainReq, execution_id) {
@@ -243,7 +254,7 @@ exports.uploadBlueprint = function(req, bpid, blueprint) {
// Set up the HTTP PUT request
const reqOptions = {
method : "PUT",
- uri : cfyAPI + "/blueprints/" + bpid,
+ uri : cfyAPI + "/blueprints/" + bpid + "?visibility=global",
headers : {
"Content-Type" : "application/octet-stream",
"Accept" : "*/*"
@@ -255,6 +266,86 @@ exports.uploadBlueprint = function(req, bpid, blueprint) {
return doRequest(req, reqOptions, zip_buffer, CLOUDIFY);
};
+// Checks if a blueprint exists in cloudify
+exports.checkBlueprintExits = function(req, bpid) {
+
+ // Set up the HTTP GET request
+ var reqOptions = {
+ method : "GET",
+ uri : cfyAPI + "/blueprints?id=" + bpid,
+ headers : {
+ "Content-Type" : "application/json",
+ "Accept" : "*/*"
+ }
+ };
+ addAuthToOptions(reqOptions, req);
+
+ return doRequest(req, reqOptions, null, CLOUDIFY)
+
+ .then (function(result) {
+ if (result.json.metadata.pagination.total > 0 ) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ })
+ .catch(function(error) {
+ logger.debug(req.dcaeReqId, "Error getting BP from Cloudify for deployment id: " + req.params['deploymentId'] + " and blueprint id: " + bpid );
+ throw(error);
+ });
+};
+
+// Get the tenant_name associated with a blueprint
+exports.getBlueprintTenantName = function(req, bpid) {
+
+ // Set up the HTTP GET request
+ var reqOptions = {
+ method : "GET",
+ uri : cfyAPI + "/blueprints?id=" + bpid + "&_include=tenant_name",
+ headers : {
+ "Content-Type" : "application/json",
+ "Accept" : "*/*"
+ }
+ };
+ addAuthToOptions(reqOptions, req);
+
+ return doRequest(req, reqOptions, null, CLOUDIFY);
+};
+
+// Checks if a blueprint should be deleted from cloudify due to no associated deployments
+exports.shouldBlueprintGetDeleted = function(req, bpid) {
+
+ // Set up the HTTP GET request
+ var reqOptions = {
+ method : "GET",
+ uri : cfyAPI + "/deployments?blueprint_id=" + bpid + "&_all_tenants=true&_include=id",
+ headers : {
+ "Content-Type" : "application/json",
+ "Accept" : "*/*"
+ }
+ };
+ const tenant = req.query.cfy_tenant_name;
+ req.query.cfy_tenant_name = DEFAULT_TENANT;
+ addAuthToOptions(reqOptions, req);
+ req.query.cfy_tenant_name = tenant;
+
+ return doRequest(req, reqOptions, null, CLOUDIFY)
+
+ .then (function(result) {
+ if (result.json.metadata.pagination.total > 0 ) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ })
+ .catch(function(error) {
+ logger.debug(req.dcaeReqId, "Error getting deployments info from Cloudify for deployment id: " + req.params['deploymentId'] + " and blueprint id: " + bpid );
+ throw(error);
+ });
+};
+
// Creates a deployment from a blueprint
exports.createDeployment = function(req, dpid, bpid, inputs) {