Delete Failed vRO Workflow Runs
If you have worked with vRealize Orchestrator 7 you'll probably have a love/hate relationship to the long-lived Java client.
vRO 8 deprecated the Java client and we're left with the HTML5 interface (yes, I know that you might be able to use the old client for some operations still..). The switch has been a bit of the struggle for some of us, but now I've gotten used to the HTML client now and started to enjoy it.
Still, there is some features missing in the HTML UI, one of those are the "Delete all finished workflow runs"
I like to keep the Workflow Runs screen free of Failed runs as this will give me an easy way of seeing if some workflows are failing when logging in to the dashboard.
When doing a lot of testing it's quite handy to re-run workflows to keep the input parameters, but it's a pain to always remember to delete those failed runs. This could quickly leave you with a screen like this
And a list of ever growing failed runs
As far as I've seen there's no built-in action or workflow for deleting a lot of runs, we're left with clicking through each and every failed run.
To rectify this I decided to look into creating something that could help me delete multiple runs. Let's take a look at how we can accomplish this
vRO workflow object
vRO has an object type for it's Workflows.
A workflow run generates a Workflow token
Unfortunately none of these have a method for deleting workflow runs. We can however get the state of a Workflow token which we can use for filtering the failed runs
But how can we delete those failed runs?
vRO API to the rescue
vRO has an API which has a lot of possibilities not built into the Objects available to us.
To check out the API documentation for your specific vRO instance you can use the Swagger documentation found at https://<fqdn>/vco/api/docs
In the Swagger doc I found a Delete workflow run method which seems to fit my use-case.
The API method takes two parameters, the Workflow Id and the Execution Id, both of which we can fetch with the built-in Workflow and Workflow Token object.
Rest client in vRO
There's multiple ways of working with the HTTP REST plugin in vRO. If we're using vRO with vRA the vRA Host object actually has the possibility to create a REST client directly from the vRA Host object which also takes care of authentication
The REST client has methods for creating and exectuing requests which we'll make use of.
If you're running vRO standalone you'll have to take care of creating the REST client and handle the authentication yourself.
Delete Failed Runs Workflow
Let's take a look at the final workflow.
The workflow takes one input parameter, the Workflow object. In addition there's a variable for holding the vRA Host object.
The actual code for deleting failed runs of a specific workflow fits in a Scriptable task
1var executions = workflow.executions;
2var client = vraHost.createRestClient();
3
4for each (var run in executions){
5 if(run.state === "failed"){
6 System.debug("id: " + run.id)
7
8 //Build REST request
9 var path = "/vco/api/workflows/" + workflow.id + "/executions/" + run.id;
10 var request = client.createRequest("DELETE", path);
11
12 var response = client.execute(request);
13 System.debug("statusCode: " + response.statusCode);
14 if(response.statusCode !== 204){
15 System.error("Couldn't delete workflow run " + run.id + ", status message: " + response.statusMessage);
16 }
17 }
18}
If we run this workflow we get to choose the Workflow we want to delete runs from, both name and Workflow Id works
The code in the Scriptable task should probably be moved to an Action, but for the sake of simplicity I've left it as is for now.
The workflow works with one Workflow and it's runs/executions, if you'd want to delete all failed runs for all workflows you'll have to iterate through all of the workflows, but this should be doable.
Summary
This post has shown how we can make use of the vRO Api, and the vRA Host object, for handling those Failed workflow runs.
Note that you should be careful with deleting stuff, and of course do not delete workflow runs that contains useful troubleshooting information.
Thanks for reading!