Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > Cloud Workflow Developer Guide > Definitions

Definitions

Table of Contents

 

 


Table of Contents Sections

 

Cloud workflows consist of a sequence of statements. Each statement consists of one or more expressions. The first expression is the define...end block:

define main(@servers, $wait) return @instances, $duration do
 ​ $now = now()
  @instances = @servers.launch()
  if $wait
   ​ sleep_until(all?(@instances.state, "operational")) timeout: 15mn
  end
  $duration = $now - now()
end

A cloud workflow may contain any number of definitions. The special definition called main is the entry point to the process.

Definitions are scoped by the file that contain them: two definitions in the same file cannot have the same name.

 

Inputs and Outputs

As shown in the snippet above a cloud workflow may specify arguments and return values. There can be zero or more arguments and zero or more return values. Arguments and return values can either be references (@server and @instance) or variables ($wait and $duration), the difference being that references contain resource collections while variables may contain a number, a string, a boolean, a time value, the special null value, an array or a hash (references are described in Cloud Workflow Resources and variables are described in Cloud Workflow Variables).

A cloud workflow may execute children definitions using the call keyword:

define launch_servers(@servers, $wait) return @instances, $duration
  $now = now()
  @instances = @servers.launch()
  if $wait
    sleep_until(all?(@instances.state, "operational")) timeout: 15mn
  end
  $duration = $now - now()
end

define run_application do
 ​@servers = rs.tags.by_tag(resource_type: "servers", tags: ["my_site:role=app"])
  call launch_servers(@servers, true) retrieve @launched_instances, $duration
end

This run_application definition first initializes the @servers resources collection using a tag query then passes the collection of retrieved servers to the launch_servers definition above. The list of references and variables specified after the retrieve keyword matches the list after the return keyword of the definition. These references and variables are initialized with the return values of the definition (so in this example the reference @launched_instances of the caller is initialized with the value of the @instances reference returned by launch_servers). The names can match, but don't have to as shown in the example. 

Note: Using retrieve is optional and can be skipped if the caller does not need the return values.

Structure

A cloud workflow is composed of statements. Each statement is in turn made of expressions. Statements are delimited by newlines, semi-colons or both. Comments all start with the # symbol. Any character following that symbol on the same line is part of the comment. Blank characters include tabs, spaces and newlines. There can be zero or more blank characters before and after a statement (pending there is a semi-colon if there is no newline). There can also be zero or more blank characters between arguments, operands, and keywords:

@instances = @servers.launch() # Comments can appear at the end of a line
sleep_until(all?(@instances.state[], "operational"))

# is equivalent to:
@instances = @servers.launch();
sleep_until(all?(@instances.state[], "operational"));
 
# and to:
@instances = @servers.launch(); sleep_until(all?(@instances.state[], "operational"))

Sequences of statements are encapsulated in blocks. The outer block is the define...end block however blocks can be defined at any time using the sub keyword:

sub do
  @servers = rs.servers.get(filter: ["name==my_server"])
  @servers.launch()
end
sub do
  @servers = rs.servers.get(filter: ["name==my_other_server"])
  @servers.launch()
end

Using blocks as in the snippet above does not change anything to the execution of the Cloud Workflow (and is thus not that useful...). However, blocks can be used to define scopes for error handlers, timeouts, etc. Blocks also allow defining concurrent activities. For more information about blocks, see the Cloud Workflow Processes section.

Expressions

As mentioned above, a statement consists of a series of expressions. There are four categories of expressions:

  • Resource expressions include calls to resource actions and retrieval of resource links and fields, see Cloud Workflow Resources.
  • Flow control expressions include block definitions (definesubconcurrent), conditional expressions (ifelseelsif), and all looping constructs (whileforeachmapconcurrent foreachconcurrent map), see Branching and Looping.
  • Operators (+-*/%[]===~>=<=&|!), see Operators.
  • Assignments (= and <<), see Operators.


Expressions can be adorned with attributes. Attributes do not constitute an expression by themselves. For more information about attributes, see Attributes and Error Handling.

 

 

 RCL Resources ► Cloud Workflows & Definitions Variables Attributes & Error Handling Branching & Looping Processes Functions Operators Mapping
You must to post a comment.
Last modified
15:37, 7 Jan 2015

Tags

Classifications

This page has no classifications.

Announcements

None


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.