Rule examples - Start bundle

This page illustrates how you can execute the same action script as described in Task example - Start bundle, however, in an automated way by using two different trigger types.

The purpose of the action script below is to check whether the already installed software component - fileupload bundle - is active on the relevant devices included in the scope, and to activate it in case it is not.

Below you will find two rule examples which execute the same action script on the same list of devices. The first rule is fired on a timer-basis, whereas the second one - upon the occurrence of a particular device-related event.

Rule example 1

Trigger: Cron trigger

Scope: device scope, defined as a list of devices [device1, device2, device3] and in particular their 'bundle' things e.g. example.dm:gatewayDevice:edge:services:bundles.

Execution options: none

Action:

bundle = target.feature('Bundle:org.apache.commons.fileupload')
if (bundle.state != 'Active') {
bundle.start()
}

This rule will be fired when the time defined in the Cron trigger comes, for example at 15:00:00 p.m., and this will lead to the launching of a task. The scope of such a task will include all three devices' bundle things. The system will check which of these devices are online and will execute the action script on them. If any device is not online at this moment the action script will not be executed automatically on it, even when it comes online later on.

Rule example 2

Trigger: Device event trigger, in particular DeviceOnlineEvent

Scope: device scope, defined as a list of devices [device1, device2, device3] and in particular their 'bundle' things e.g. example.dm:gatewayDevice:edge:services:bundles.

Execution options: none

Action:

bundle = target.feature('Bundle:org.apache.commons.fileupload')
if (bundle.state != 'Active') {
bundle.start()
}

This rule will be fired when any of the devices in the rule scope comes online. As each DeviceOnlineEvent concerns only the particular device which has come online, the rule will launch a separate task for each device, and the scope of this task will consist of one device and its 'bundle' thing.