User Tools

Site Tools


vrealize:eventbroker:testscript

TestScript for vCACProperties

This is the workflow used to test how vRA EventBroker handles the transfer of properties between vRA and vRO. (The result is described in the Clone Template Event List )

You will need to run this script in ALL Events fired, and it MUST be blocking!

IMPORTANT: WHEN PASSING VALUES TO vRA (from VRO) through these properties, make sure they are not NULL, vRO can handle NULL values, vRA will crash!!!

Input, must be payload (properties)

Output must be: virtualMachineDeleteProperties (Properties),virtualMachineAddOrUpdateProperties (Properties) and virtualMachineEvent (String)

virtualMachineDeleteProperties = new Properties();
virtualMachineAddOrUpdateProperties = new Properties();
 
function GetVRAProp(PropName)
{
	var PropValue = null;
	try
	{
		PropValue = vCACVmProperties.get (PropName)
	}
	catch (exception)
	{
		PropValue = null;
		System.log ("VRA Property: "+PropName+" is missing");
	}	
	return PropValue;
}
 
function DeleteTest()
{
	var deletelist = new Array();
	deletelist.push("Delete1")
	deletelist.push("Delete2")
	deletelist.push("Delete3")
	deletelist.push("Delete4")
	deletelist.push("Delete5")
	deletelist.push("Delete6")
	deletelist.push("Delete7")
	deletelist.push("Delete8")
	deletelist.push("Delete9")
	deletelist.push("Delete10")
	deletelist.push("Delete11")
	deletelist.push("Delete12")
	deletelist.push("Delete13")
	deletelist.push("Delete14")
	deletelist.push("Delete15")
	deletelist.push("Delete16")
	deletelist.push("Delete17")
	deletelist.push("Delete18")
	deletelist.push("Delete19")
	deletelist.push("Delete20")
 
	for each (el in deletelist)
	{
		var Prop = GetVRAProp(el);
		if (Prop != null)
		{
			System.warn("Removing (deletetestentry): "+el);
			virtualMachineDeleteProperties.put(el,Prop)
			return el;
			break;
		}
	}
	System.log("-------Nothing more to delete in deletetest--------");
	return null;
}
 
function PutTest()
{
	var createlist = new Array();
	createlist.push("aaa_PutValue1")
	createlist.push("aaa_PutValue2")
	createlist.push("aaa_PutValue3")
	createlist.push("aaa_PutValue4")
	createlist.push("aaa_PutValue5")
	createlist.push("aaa_PutValue6")
	createlist.push("aaa_PutValue7")
	createlist.push("aaa_PutValue8")
	createlist.push("aaa_PutValue9")
	createlist.push("aaa_PutValue10")
	createlist.push("aaa_PutValue11")
	createlist.push("aaa_PutValue12")
	createlist.push("aaa_PutValue13")
	createlist.push("aaa_PutValue14")
	createlist.push("aaa_PutValue15")
	createlist.push("aaa_PutValue16")
	createlist.push("aaa_PutValue17")
	createlist.push("aaa_PutValue18")
	createlist.push("aaa_PutValue19")
	createlist.push("aaa_PutValue20")
	createlist.push("aaa_PutValue21")
 
	var i = 1;
	for each (el in createlist)
	{
		var Prop = GetVRAProp(el);
		if (Prop == null)
		{
			System.warn("Adding (puttestentry): "+el);
			virtualMachineAddOrUpdateProperties.put (el,i)
			break;
		}
		i++;
	}
	System.log("-------Nothing more to put in puttest--------");
}
 
var executionContext = System.getContext();
 
System.log("BlueprintName: " + payload.get("blueprintName")) ;
System.log("ComponentId: " + payload.get("componentId")) ;
System.log("ComponentTypeId: " + payload.get("componentTypeId")) ;
System.log("EndpointId: " + payload.get("endpointId")) ;
System.log("RequestId: " + payload.get("requestId")) ;
System.log("VirtualMachineEvent: " + payload.get("virtualMachineEvent")) ;
System.log("WorkflowNextState: " + payload.get("workflowNextState")) ;
 
RequestID = payload.get("requestId");
 
 
 
var lifecycleState = payload.get("lifecycleState") ;
System.log("State: " + lifecycleState.get("state")) ;
System.log("Phase: " + lifecycleState.get("phase")) ;
System.log("Event: " + lifecycleState.get("event")) ;
 
var machine = payload.get("machine") ;
System.log("ID: " + machine.get("id")) ;
System.log("Name: " + machine.get("name")) ;
System.log("ExternalReference: " + machine.get("externalReference")) ;
System.log("Owner: " + machine.get("owner")) ;
System.log("Type: " + machine.get("type")) ;
System.log("Properties: " + machine.get("properties")) ;
 
 
var vCACVmProperties = machine.get("properties") ;
if (vCACVmProperties != null) {
	var log = "";
	log += "vCAC VM properties :\n";
	var array = new Array();
	for each (var key in vCACVmProperties.keys) {
		array.push(key + " : " + vCACVmProperties.get(key));	
	}
	array.sort();
 
	for each (var line in array) {
		log += "\t" + line + "\n";
	}	
	System.log(log);	
 
}
 
var xx = GetVRAProp("SopraSteriaCounter");
if (xx == null)
{
	// First Entry
	virtualMachineAddOrUpdateProperties.put("SopraSteriaCounter",1);
	System.log ("**** INIT COUNTER ****");
}
else
{
	var NewVal = parseInt(xx);
 
	virtualMachineAddOrUpdateProperties.put("SopraSteriaCounter",++NewVal);
	System.log ("**** COUNTER == "+NewVal+" ****");
 
}
 
 
var tt = GetVRAProp("Testing1");
var tx = GetVRAProp("Testing2");
 
if (tt != null)
{
	virtualMachineDeleteProperties.put("Testing1",tt)
}
else
{
	virtualMachineAddOrUpdateProperties.put ("Testing1","true")
}
 
if (tx != null)
{
	virtualMachineDeleteProperties.put("Testing2",tx)
}
else
{
	virtualMachineAddOrUpdateProperties.put ("Testing2","true")
}
var StopAt = DeleteTest()
 
PutTest()
 
var xy = GetVRAProp("SopraSteriaCounterStop");
 
System.log ("COmpare: !"+StopAt+ "! vs !"+xy+"!");
if (xy != null)
{
	if (xy ==  StopAt)
	{
		System.log ("#### REACHED END OF COUNTER -- SETTING BUILD FAIL");
		virtualMachineEvent = "BuildFailure";
	}
}
 
//BuildFailure – Stops the provisioning workflow in a failed state.
//BuildSuccess – Stops the provisioning workflow in a success state.
vrealize/eventbroker/testscript.txt · Last modified: 2018/11/30 01:03 by admin