How-to: Define a trigger to monitor and restart a service at multiple hosts.

A trigger can be defined as part of a plugin specific model. A trigger is configured to executed based on some condition. The condition(s) can either be the result of targeting the model to a resource and/or the operation used to invoke the operation.

In this example, we define a trigger which based on the result and the operation.

Creating a trigger to run when a test fails.

Two modules are created. One module my-test contains a test. The other module my-corrective-action contains a corrective action if the test fails.

Creating the test module

alpha is used as the target environment. A model named alpha.xml is defined in the my-test module. The model defines a test to be executed using the infrastructure test plugin.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mmd:models xmlns:mmd="http://pineapple.dev.java.net/ns/module_model_1_0"
        xmlns:shp="http://pineapple.dev.java.net/ns/plugin/ssh_1_0" >
    <mmd:model target-resource="{ssh-host1, ssh-host2, ssh-host3}">
        <mmd:content>
            <shp:ssh>
                <shp:assert-equals command="some-test-action" expected-value="some-expected-value"/>             
            </shp:ssh>
        </mmd:content>
                <mmd:trigger on-target-operation="test" on-result="{failure,error}" module="my-corrective-action" environment="alpha" operation="deploy-configuration" />
    </mmd:model>
</mmd:models>

The model defines a trigger which is executed if the model is executed with the test operation and the model execution concludes with either a failure or an error.

The trigger is defined to invoke the module named my-corrective-action with the model for the alpha environment and the operation deploy-configuration to execute the corrective action.

Creating the corrective action module

A model named alpha for the target environment alpha is defined in the my-corrective-action module. The model defines a corrective action to be taken using SSH. The action is targeted to the hosts: ssh-host1, ssh-host2, ssh-host3.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mmd:models xmlns:mmd="http://pineapple.dev.java.net/ns/module_model_1_0"
        xmlns:shp="http://pineapple.dev.java.net/ns/plugin/ssh_1_0" >
    <mmd:model target-resource="{ssh-host1, ssh-host2, ssh-host3}">
        <mmd:content>
            <shp:ssh>
                <shp:execute command="some-corrective-action" />             
            </shp:ssh>
        </mmd:content>
    </mmd:model>
</mmd:models>

Execution of the test

When the <my-test module (and the alpha environment) is executed with the test operation then the test is executed at each of the targeted hosts.

If the test fails at any of the targeted hosts then the trigger is executed.

The trigger will invoke the my-corrective-action module (in the alpha environment) with the deploy-configuration operation.

The module is targeted to the same set of targeted hosts as the test module. The corrective action will be taken at each of the hosts, even though the test may only have failed at one host. This might prose a problem or at minimum not be necessary.