Skip to content

Resuming and debugging failed runs

Recipe 3.4 made workflows fail well. This recipe is about what you do after a run has failed. Orchestrator gives you three tools. Resume from failed keeps a failed run alive, so you can fix the cause, correct an input, and carry on from the step that broke, without redoing the steps that worked. The debugger pauses a run at the elements and script lines you choose, so you can see the values each slot holds and step through it. Run replay records each step of a run, so you can see afterwards what every element received and changed.

You practise all three on List VMs by name from recipe 3.2. It only reads from vCenter, so you can fail it, resume it, and step through it as often as you like.

Getting ready

  • The workflow List VMs by name and the action com.vcfguide.chapter3/findVmsByName from recipe 3.2.
  • A login with a role that can edit workflows. To switch on run replay you also need an administrator login.
  • A lab where you can afford to experiment. Broadcom’s own guidance is to do script debugging outside production.

How to do it

Let the workflow resume after a failure

  1. Open List VMs by name and stay on the Summary tab.
  2. Set Resume workflow from failed behavior to Enabled, then click Save.
Workflow editor for List VMs by name, Summary tab. Below Server restart behavior (Resume workflow run), the drop-down Resume workflow from failed behavior is set to Enabled. Its other choices are System default and Disabled.
Figure 3.13. Resume from failed, switched on for one workflow.

Make it fail, then resume it

  1. Click Run and enter (testvm as namePattern. The parenthesis is never closed, so this isn’t a valid regular expression, and new RegExp in the action throws SyntaxError: Unterminated parenthetical. (Don’t test with an unclosed [: Rhino accepts [testvm without complaint and quietly matches almost every VM.)
  2. Watch the run. Instead of ending as Failed, it stops in the Waiting state, and a banner reads Waiting for input: “List VMs by name : Workflow Error System Handler”.
  3. Click Answer in the banner. The Input Request dialog opens on its Error in workflow tab. Set Choose action to continue to Resume.
  4. Open the Parameters tab, headed Modify the parameters for resume. It lists the input namePattern and the variables vms and vmNames, so you can correct either. Change namePattern to ^testvm and click Answer.
  5. The run carries on from the action element and ends as Completed. Its Logs tab shows the error from the first attempt, then the match count and the VM lines from the second.
A run of List VMs by name in the Waiting state, with the banner Waiting for input. The Input Request dialog is open on its Parameters tab, headed Modify the parameters for resume: an empty vms array, namePattern corrected to ^testvm, and vmNames. Behind it, the log shows SyntaxError: Unterminated parenthetical.
Figure 3.14. Resuming a failed run with a corrected input.
  1. To give up on a waiting run instead, click Answer and choose Cancel, or click Cancel Run at the top. The run then ends as Canceled.

Pause the workflow at a breakpoint

  1. Open the Schema tab of List VMs by name. Select the scriptable task Describe each VM and, in the element’s properties pane, click the breakpoint button beside the close button (its tooltip reads Enable breakpoint on element). A red square appears at the element’s top-left corner.
  2. Click Debug instead of Run, enter ^testvm as namePattern, and click Run.
  3. The run executes the action element, then pauses before Describe each VM. The run’s status reads Debugging and Suspended, a pause sign appears on the element, and the run details gain the controls Continue, Step into, Step over, and Step return.
  4. Open the Variables tab. It shows the vms array the action returned, namePattern, and vmNames, still Not set.
Debug run of List VMs by name, status Debugging and Suspended. Describe each VM carries a red breakpoint square and a green pause sign; its script is open on the right. The Variables tab shows vms Array[3], namePattern ^testvm and vmNames Not set, beside the Continue, Step into, Step over and Step return controls.
Figure 3.15. A debug run paused at a schema breakpoint.

Step through the script

  1. Still in the debug run, select Describe each VM and open its Scripting tab. Click the line number of vmNames.push(line); to add a script breakpoint. A red circle marks it.
  2. Click Step into. The debugger enters the script and stops on its first line, marked with a green triangle. The Debugger tab is now available.
  3. Click Continue. The run stops at your breakpoint, in the first pass of the loop. Open the Debugger tab: Item Variables on the right lists every variable the script can see (i, line, vms, vmNames, and the run’s workflow token) with its current value. On the left, click Click to add an expression and enter an expression of your own, such as vms.length - i; its value is worked out at each stop. Click Step over a few times, or Continue to reach the breakpoint again on the next pass, and watch the values change.
  4. Click the red circle again to remove the breakpoint, then click Continue. The run goes on to the end and completes.
The same debug run stopped inside the script of Describe each VM: line 4, vmNames.push(line), is highlighted with the breakpoint marker. The Debugger tab shows the watch expression vms.length - i with value 3, and Item Variables i 0, line testvm03 (poweredOff), vms Array[3], vmNames Array[0] and workflow [object WorkflowToken].
Figure 3.16. A script breakpoint, with watch expressions in the Debugger tab.

Record runs for replay

  1. As an administrator, go to System Settings > Performance and Features. Under Run Replay, switch on Enable run replay. Two more switches appear: Record replay for all runs (on) and Record scripting API calls (off). Click Save. Saving restarts the Orchestrator server about a minute later, so don’t do it while important runs are in progress.
  2. Run List VMs by name normally, with ^testvm.
  3. Go to Activity > Workflow Runs and open the run. On the left, switch on Show replay and expand the run’s start time: it lists each element that ran, in order. Select findVmsByName, then Describe each VM. The schema highlights the element, the panel on the right shows its properties, and the Variables tab shows the values as they were when that element finished. Runs from before you switched replay on are listed too, but have nothing to replay.
A completed run of List VMs by name with Show replay on. The left list expands the run into start, findVmsByName, Describe each VM and end; Describe each VM is selected and highlighted in the schema. The Variables tab shows namePattern ^testvm, vms Array[3] and vmNames Array[3].
Figure 3.17. Replaying a finished run, one element at a time.

How it works

Resume from failed changes what happens when an error reaches the top of the workflow, after any exception path and default error handler have had their chance (recipe 3.4). Without it, the run ends as Failed and its token is closed. With it, Orchestrator keeps the token open, keeps every slot’s value, and puts the run in the Waiting state, as if it were waiting for an answer from a person. Answering Resume runs the failed element again, with the values from the Parameters tab, and the run carries on from there. Everything before the failed element isn’t repeated.

Needs a lab check. Confirm that resuming runs the failed element again from its start, rather than the element after it. Broadcom’s documentation says the run resumes “from the last failed activity” but doesn’t say so in as many words.

Each workflow has its own setting. Enabled and Disabled apply to that workflow only. System default follows the server’s default, which is off, and that’s the setting the library workflows ship with. A waiting failed run doesn’t stay open for ever: if nobody answers it within the resume timeout, it times out and can’t be resumed any more. The timeout is the system property com.vmware.vco.engine.execute.resume-from-failed.timeout-sec, 86400 seconds (24 hours) by default. On the standalone appliance you change it with vracli vro properties set, as in recipe 2.8.

Needs a lab check. Confirm on 9.1.1 that vracli vro properties set -k com.vmware.vco.engine.execute.resume-from-failed.timeout-sec -v … changes the timeout. Broadcom’s 9.0 page describes setting it under a System Properties page, and documents no separate property that turns resume on for every workflow.

The debugger runs the same workflow engine as a normal run, but stops before each element that has a breakpoint and waits for you. Its controls work at two levels. On the canvas, Step over runs the current element and stops at the next one, Step into goes inside it (into its script, or into the schema of a sub-workflow), and Step return finishes the current level and stops in the one above. Continue runs to the next breakpoint. Inside a script, the same controls move line by line. A breakpoint on a workflow element opens the child workflow’s schema when the run reaches it, so you can debug parent and child in one session.

Run replay costs a little on every run, because Orchestrator writes each element’s start and end time, the variables it changed, and its log lines to the database as the run goes. The data belongs to the run, so it’s deleted when the run is.

Back in vRO 5.5–7Find a run under its workflow in the Java client's tree, open its logs, and work out from the last log line which element failed. To try again, start a new run from the beginning.
In Orchestrator 9.xOpen the run under Activity > Workflow Runs, where run replay shows each element's variables and logs, and resume a failed run from the element that failed.

There's more

Only resume what’s safe to repeat. Resuming runs the failed element again. That’s harmless for an element that reads, like the action here. It’s not harmless for an element that creates a VM, posts to a ticketing system, or sends a mail and then fails on its last line. Enable resume on workflows whose steps are safe to repeat, or split the risky step so the part that changes something runs last.

Resume and exception paths don’t mix. If an element’s exception path catches the error, the run never reaches the top as a failure, so there’s nothing to resume. A workflow that ends in a Thrown exception element, as in recipe 3.4, fails at that element, and resuming it only throws the same exception again. Use resume on workflows where an uncaught error should be fixed and retried, and exception paths where the workflow can handle the error itself.

The 9.1.0 debugger and regular expressions. Broadcom KB 446523 describes the 9.1.0 debugger hanging on “loading”, or running the server out of memory, when the paused script holds a JavaScript RegExp or the result of System.getContext(). The action findVmsByName holds a RegExp in pattern, so on 9.1.0 don’t step into it. Set breakpoints in the scriptable task instead, or debug with System.debug and System.log lines.

Needs a lab check. Check whether KB 446523 is fixed in 9.1.1, by stepping into findVmsByName in the lab.

Debugging actions. An action has its own Debug button in Library > Actions, with the same breakpoints and controls. The debugger only works with the default JavaScript runtime. For Python, Node.js, and PowerShell scripts, write log lines instead.

Needs a lab check. Confirm that the 9.1.1 action editor has a Debug button. The documentation for it is from the 8.x client.

Debug logging that you leave in. System.debug("…") writes a log line at debug level. It costs almost nothing and you can filter it out on the Logs tab, so it’s a good place for the values you’d otherwise only see in the debugger. Keep in mind that System.* log lines aren’t persistent: Broadcom’s documentation says they’re lost when the server restarts. Server.log lines are stored in the database, so use them for anything you must still be able to read next week.

Profiling and the other switches on the same page. System Settings > Performance and Features holds every server-wide switch from this recipe. On 9.1.1 it has four sections: Concurrency and Queueing, Run Replay (Enable run replay), Workflow Profiling (Enable profiling) and Environment Repositories (chapter 4). In the lab, profiling and run replay were both off by default. Broadcom describes profiling as recording how long each element of a run takes and what it costs, which feeds the Performance view of Workflow Runs and the CPU-time lists under Requiring Attention on the dashboard (recipe 1.7). Like run replay, it adds a little work to every run on the server, so switch it on while you hunt for a slow workflow and off again afterwards.

Performance and Features page. Concurrency and Queueing: Number of concurrent running workflows 300, Maximum number of preserved runs per workflow 100, Maximum amount of running workflows in the queue 1000. Run Replay: Enable run replay, off. Workflow Profiling: Enable profiling, off. Environment Repositories: Enable Default Public Repository for Environments, on, and Suppress the warning, on.
Figure 3.36. System Settings > Performance and Features: concurrency limits, run replay and profiling in one place.
Needs a lab check. Switch on Enable profiling in the lab, run List VMs by name, and record what the run shows with and without profiling: the per-element timings, and whether the Performance view columns change.

Concurrency limits. Concurrency and Queueing sets three limits. On 9.1.1 the defaults are 300 for Number of concurrent running workflows, 100 for Maximum number of preserved runs per workflow (older runs of a workflow are deleted beyond that) and 1000 for Maximum amount of running workflows in the queue. Leave a field empty and the default applies. Raise them only after checking the server’s memory and CPU, because each running workflow uses memory and a thread while it runs.

Don’t debug in production. A paused debug run holds its token, its variables, and anything it has locked in a target system. Copy the workflow and its inputs to a lab, or use run replay on the production run to see what happened.

See also