Getting Started¶
There is no standardized way to query TOSCA repositories or instance data. Therefore, we introduce Queries4TOSCA which defined a query language for TOSCA. This language provides a graph-based query language which includes path expressions, filters, and pattern matching. This section will give a quick introduction to Queries4TOSCA.
Preparation¶
To run the example queries, we need to install OpenTOSCA Vintner and have a resolved instance of the "Getting Started" template. First, clone the repository.
Then import the template, create an instance, and resolve the variability.
Example Queries¶
Queries start with a FROM
statement, followed by either templates
or instances
and the name of the template or the name of the instance, respectively.
Inside a SELECT
statement, we can enter a path to the data that we want to return.
To get the entire contents of the template, run the following command.
We can return specific elements by specifying their path. Note, that topology_template
can be omitted at the start.
The following command returns the contents of the localhost
node.
We can use an asterisk as a wildcard operator to get all child elements. The following command returns a list of all nodes.
We can also specify a predicate in square brackets after any part of the path expression to filter elements.
The following command will return only nodes of type textfile
.
In cases where we are only interested in some elements of a node, we can use a return structure to restrict the output
to certain variables. To do this, put curly braces with key-value pairs behind your path expression.
The following command will return only the content
property of the first
node.
This also works on arrays. The following command returns an array that consists of the name and type of each node. Note the lack of quotation marks - we are using a value from the template for both key and value of the return object.
MATCH
statements are used to match patterns in the topology of a template. We can "draw" the pattern by surrounding nodes with parentheses and connect them to other nodes via arrows.
The following statement will return all nodes that have a requirement fulfilled by localhost
.
This is just a simple example. In a more complex scenario, it would be possible, e.g., to dynamically access the public address of a virtual machine which hosts a database to which a specific component connects.