Hello World
NewNever opened Orchestrator before? Start here. In about fifteen minutes you build two small workflows. The first writes one line to the log. The second gets the same line from an action, a reusable piece of script. Every other recipe in this book builds on these few clicks. New
Getting ready
- A login to VCF Automation with a role that can create Orchestrator content, such as an organization administrator, or a login to a standalone Orchestrator appliance (chapter 1).
- Nothing else. These workflows don’t touch vCenter or any other system.
How to do it
Part 1: a workflow that says hello
Section titled “Part 1: a workflow that says hello”Open Orchestrator
- Open the Orchestrator Client:
- Embedded in VCF Automation: log in to VCF Automation, open your organization portal, and select the Orchestrator tab at the top (in the provider organization it’s called Orchestrate). Recipe 1.1 has the details.
- Standalone appliance: browse to the appliance, for example
https://vco01.vmw.lab, and log in.
- The client opens on the Dashboard. The menu on the left has four groups: Library, Activity, Assets and Administration. Workflows live in Library.
Orchestrator Client Dashboard, with the left-hand menu expanded: Library (Workflows, Actions, Policies), Activity, Assets, Administration. Highlight Library > Workflows.
Create the workflow
- Go to Library > Workflows and click New Workflow.
- Enter the name
Hello Worldand click Create. The workflow editor opens on the Summary tab. - On Summary, set the Version to
1.0.0and the Description toMy first workflow.If you want to keep it tidy, pick a folder too, such as VCF Orchestrator Guide/Hello World. Click Save.
Workflow editor for Hello World on the Summary tab: name, version 1.0.0, folder, description; the tabs Summary, Variables, Inputs/Outputs, Schema, Input Form, Version History, Auditing across the top.
Add a scriptable task
- Open the Schema tab. The canvas shows a green start element and an end element, joined by an arrow. On the left is the palette of elements you can add.
- In the palette, find Scriptable task (in the Generic group) and drag it onto the arrow between start and end. Drop it when the arrow is highlighted, so it’s connected on both sides.
- Click the new element. A properties pane opens on the right. On its General tab, change the Name to
Say hello.
Schema tab of Hello World: the palette on the left with Scriptable task under Generic; on the canvas Start, Say hello, End joined by arrows; properties pane on the right on the General tab with Name Say hello.
Write the script
- In the properties pane, open the Scripting tab and enter one line:
System.log("Hello World, this is vRO!");System.log writes a line to the run’s log. It’s the line you’ll use most in this book.
- Click Save at the bottom of the editor.
Properties pane of Say hello on the Scripting tab, with the line System.log("Hello World, this is vRO!"); in the editor.
Run it
- Click Run at the top of the editor. The workflow has no inputs, so it starts at once.
- When it finishes, the run shows Completed. Open its Logs tab: there’s one line, Hello World, this is vRO!
Run of Hello World with state Completed, Logs tab with the line Hello World, this is vRO!
That’s a workflow: a schema of steps, run by the Orchestrator server, with everything it does written to a log you can read afterwards. Every run is also kept under Activity > Workflow Runs.
Part 2: the same greeting from an action
Section titled “Part 2: the same greeting from an action”A script inside a scriptable task belongs to that one workflow. An action is a script with its own inputs and a return value, kept in Library > Actions, so any workflow can use it.
Create the action
- Go to Library > Actions and click New Action.
- Enter the name
sayHelloand the modulecom.vcfguide.hello. A module is a folder for actions, named like a Java package. Click Create. - On the General tab, set the Version to
1.0.0. - On the Script tab, add an input
nameof typestring, set the Return type tostring, enter this script, and click Save:
// Returns a greeting and writes it to the log.var who = name ? name : "World";var greeting = "Hello " + who + ", this is vRO!";System.log(greeting);return greeting;Action editor for com.vcfguide.hello/sayHello, Script tab: input name (string), return type string, and the script.
Try the action on its own
- Click Run, enter your own name, and click Run. The Last Run Details panel under the editor shows the result, such as
Hello Mayank, this is vRO!, on Result / Inputs, and the same line on Logs.
Use it in a workflow
- Go back to Library > Workflows, click New Workflow, and create
Hello World with an action, with the version1.0.0. - Open the Schema tab. In the palette on the left, type
sayHelloin the search box, and drag sayHello onto the arrow between start and end. Orchestrator wraps it in an action element. - A banner at the top of the canvas says the element’s inputs and outputs aren’t bound yet. Click Promote. In the dialog, set
nameto Input andactionResult, the action’s return value, to Output, and click Promote. Orchestrator creates the workflow input and output and binds them for you. On the Inputs/Outputs tab, rename the output fromactionResulttogreeting; its binding follows the new name. - Click Save, then Run. Enter
Worldand run it. The log shows Hello World, this is vRO!, and the run’s Variables tab shows the outputgreetingwith the same text.
Schema tab of Hello World with an action: Start, the action element sayHello, End; properties pane on Inputs/Outputs with the action's name bound to the workflow input name and its result bound to the output greeting.
World returned greeting = Hello World, this is vRO!How it works
Workflows are schemas, actions are functions. A workflow is a drawing: elements joined by arrows, with inputs, outputs and variables carrying data between them. It can wait, ask a person, run for days and pick up again after a restart. An action is a single function: inputs in, one value out, finished in one go. Most real workflows are a few elements that call well-named actions.
Bindings move the data. The action element doesn’t read the workflow input by itself. Promote in step 20 told Orchestrator which workflow value goes into which action input, and where the result goes. That’s the same for every element you’ll ever add: what goes in, what comes out.
The script is plain JavaScript. Orchestrator runs scripts on Mozilla Rhino, a JavaScript engine for Java, in the style of 2011 (ES5): var, function, and + to join strings. Recipe 4.1 explains why and what to avoid.
There's more
What next? Follow the Learning path for the rest of the building blocks in learning order, or go to 3.1 Workflow basics for inputs, outputs and variables in depth, and 4.2 Writing and reusing actions for actions.
Where things went. Everything you made is ordinary Orchestrator content: the workflows in Library > Workflows, the action in Library > Actions under com.vcfguide.hello, and the two runs in Activity > Workflow Runs. Delete them when you’re done, or keep them as a reference.
