Monday, March 23, 2015

Murano: How to check that application parameter is not null

Murano: How to check that application parameter is not null

The topic might look trivial for the guys who are familiar with application development and different programing languages, but Murano is not a generic programming language. Murano uses DSL which is a mixture of YAML domain specific syntax and YAQL (https://github.com/stackforge/yaql).

Lets assume that we have a new Murano class which defines a parameter that is not validated by contract for existence.  You might need this for optional parameters. In my case, I will use monitoring parameter which can be configured by the user, but this is an optional parameter.

Here is an example of such declaration:
Name: MyCoolApp

Extends: std:Application

Properties:  monitoring:
    Contract: $.class('io.murano.apps.monitoring.MonitoringService')

In this example there is no validation that passed monitoring parameter is actually initialized so it is quite possible that its actual value is exactly null.

Murano support conditional expressions, so you can validate the value of the parameter in run time:
- If: $.monitoring != null
  Then:
    - $.monitoring.deploy()
    - $.monitoring.setupCheck(instance => $.node.instance,
                              action_object => $this,
                              action_name => 'none')


Hope this helps!

No comments:

Post a Comment