-
Notifications
You must be signed in to change notification settings - Fork 4
How to use the YAML Transformer
This page describes how you can use the YAML Transformer. If you want to know, what is meant with "YAML Transformer" or what is supported, click here.
You can use the YAML Transformer as a library in your Java project or you can transform YAML documents on your own using a command line. After using the YAML Transformer you still have to inspect the generated XML, because it can be possible that not everything is converted or input values have defaults which can't be read by the TOSCA container.
The yaml file needs to have spaces for indentation as specified by the standard.
Any used artifacts and scripts must be added to the created csar by the user, an automatic inclusion is currently not possible.
If you want to use the YAML Transformer in your command line, invoke the jar (How to create a runnable jar file) and it will start the dialog.
The path for the yaml file can be given as a relative path from the current working directory (e.g. yaml/helloworld.yaml (*nix) or yaml\helloworld.yaml (Windows)) or as an absolute path (e.g. /tmp/helloworld.yaml (*nix) or C:\helloworld.yaml (Winfows)).
If the parsing was successful you'll get the generated XML right away and you can specify a file name if you want to save it, followed by the XSD for it.
After that it can generate a csar file containing the XML and XSD.
In order to use it as a library in your project, you can use the POM.xml identifiers and include <groupId>org.opentosca</groupId> <artifactId>org.opentosca.yamlconverter.yamlmodel</artifactId> <version>0.1</version>
and <groupId>org.opentosca</groupId> <artifactId>org.opentosca.yamlconverter.main</artifactId> <version>0.1</version>
as dependencies into your project. Attention: It may be possible that the Tosca models are not in your or any public repository. Then you need to install it into your local repository.
<groupId>org.opentosca</groupId> <artifactId>org.opentosca.model.tosca</artifactId> <version>0.0.3</version>
and
<groupId>org.opentosca</groupId> <artifactId>org.opentosca.model.staticresources</artifactId> <version>0.0.1-SNAPSHOT</version>
are the projects you need.
If you have included everything, you can use the interface IToscaYamlParser
(implementation: Parser
) which provides methods to parse a YAML string, return XML, XSD and set input parameters. This is the main and only interface you have to use! But you must be careful in the method call order which requires a specific logic:
- Call
parse(String)
by handing over your YAML document. Be careful: If your YAML document is stored in a file, you have to read it by yourself and store the content in a string. This method only accepts YAML as a string! - Optional: You can call
getRequirementsText()
to get a Map of Strings and Strings where the key is the input name and the value is a description of the input. This is useful if you define inputs in your YAML document and want to set their values. In order to set the values, you can take the map and replace the descriptions with their values. Then hand the map over to 3.) - Optional: Call
setInputValues(Map<String, String>)
to set your input values of your YAML document. If you want to use the defaults or don't want to set anything, the YAML Transformer will set a default value, but it's possible that this doesn't match any constraints. - Call
getXML()
to get your XML as a string. - Optional: Call
getXSD()
to get your XSD for the corresponding XML output. - Optional: Call makeCsar(pathname) to create a csar at the denoted filename