Tuesday, March 24, 2015

Murano: Exception handling

Oh My! There are exceptions!

Yes, there is an exception concept implemented in Murano DSL. Murano engine can raise an exception in case of invalid command or agent call failure. Workflows itself can throw exceptions as a part of the flow to stop the deployment, for example. As there are exceptions there is a syntax for Try and Catch sections where it is possible to handle exceptional situations.

Here is an example of real life application which needs to register itself in a master app:

- Try:
    - $.node.setupNodes(        role => 'dea',
        core_ip => $.core.host,
        apiURL => $.core.apiURL
        )
  Catch:
    - With: 'murano.engine.system.agent.AgentException'
      As: exc
      Do: 
        - $.core.restart()
        - $.node.setupNodes(role => 'dea',
              core_ip => $.core.host,
              apiURL => $.core.apiURL
              )
- $.environment.reporter.report($this, 'Cluster is created')

The code is pretty self explanatory. If setupNodes method fails due to agent execution error then we will try to restart a master (core) node as most probably it has no registry up and running and then retry the operation. If second attempt fails this exception will not be caught and Murano will stop the deployment.

You can throw a new exception with Throw: command like - Throw: 'exception message'. If you are inside Catch block it is possible to throw the same exception we caught by using - Rethrow: command inside Catch block.

Happy coding with Murano!

No comments:

Post a Comment