vCO Workflow Script to Get A List of Successful Deployment IDs from vFabric Application Director v5.2

The following script enables produces a list of successful deployment IDs from vFabric Application Director v5.2

 

 

 

var strPhysicalDataCenter;
	strPhysicalDataCenter = "DataCenter01";

var strVirtualDataCenter;
	strVirtualDataCenter = "Production";

var intPage;
	intPage = 0;

var intPageSize;
	intPageSize = 1000;

var arrDeploymentIDs;
	arrDeploymentIDs = new Array();

var objRESTOperation;
	objRESTOperation = new RESTOperation("RESTOperation");
	objRESTOperation.defaultContentType = "application/json";
	objRESTOperation.method = "GET";
	objRESTOperation.urlTemplate = "/darwin/api/1.0/deployments/all-groups/page/" + intPage + "/page-size/" + intPageSize;
	if ( strPhysicalDataCenter == "DataCenter01" )
	{
		objRESTOperation.host = objRESTHostDataCenter01;
	}
	else if ( strPhysicalDataCenter == "DataCenter02" )
	{
		objRESTOperation.host = objRESTHostDataCenter02;
	}

var objRESTRequest;
	objRESTRequest = objRESTOperation.createRequest([], null);
	objRESTRequest.contentType = "application/json";
	objRESTRequest.setHeader("Accept","application/json");
	if ( strVirtualDataCenter == "Specific" )
	{
		objRESTRequest.setHeader("Authorization", "Basic " + strPassWordSpecific);
	}
	else
	{
		objRESTRequest.setHeader("Authorization", "Basic " + strPassWordDefault);
	}

var objRESTResponse;
	objRESTResponse = objRESTRequest.execute();

if ( objRESTResponse.statusCode == 200 )
{
	var strContentAsString;
		strContentAsString = objRESTResponse.contentAsString;

	var objJSON;
		objJSON = JSON.parse(strContentAsString);

	if ( objJSON.errors == false )
	{
		var arrJSONResults;
			arrJSONResults = objJSON.results;

		for (var i = 0; i<arrJSONResults.length; i++)
		{
			var objJSONResult;
				objJSONResult = arrJSONResults[i];

			var	strResultsId;
				strResultsId = objJSONResult.id;

			if ( ( objJSONResult.deploymentState == "DEPLOYMENT_SUCCESS" ) )
			{
				arrDeploymentIDs.push(strResultsId);
			}
		}
	}
	else
	{
		var arrMessageList;
			arrMessageList = objJSON.messageList;

		var strErrorMessages;
			strErrorMessages = "";

		for ( var vii = 0; vii < arrMessageList.length; vii++ )
		{
			var objMessage;
				objMessage = arrMessageList[vii];

			strErrorMessages += vii + ") " + objMessage.message + "<br />";
		}

		System.error("===== JSON Error: " + objJSON.errors);
		throw "JSON Error: " + objJSON.errors;
	}
}
else
{
	System.error("===== HTTP Error: " + objRESTResponse.statusCode);
	throw "HTTP Error: " + objRESTResponse.statusCode;
}

Leave a Reply