Fork me on GitHub

As outlined in the Service Exec Tutorial, the Rio execution framework provides the ability to encapsulate the control and monitoring of external services. Service control adapters represent applications/services, adding network wide visibility and control. Using this approach, we can attach monitoring, metering and SLA control to existing applications.

This section discusses how to declaratively attach SLA behavior in an opstring for an external service.

For this example we will use the Tomcat deployment (as described in the Tomcat example).

import org.rioproject.config.Constants

deployment(name: 'Tomcat Deploy') {
    /* Configuration for the discovery group that the service should join.
     * This first checks if the org.rioproject.groups property is set, if not
     * the user name is used */
    groups System.getProperty(Constants.GROUPS_PROPERTY_NAME,
                              System.getProperty('user.name'))

    serviceExec(name: 'Tomcat') {

        /*
         * This declaration will remove the downloaded Tomcat distribution
         * when the Tomcat service is terminated (undeployed and/or
         * administratively stopped using Rio).
         *
         * If you want to keep the installed software (rather than overwrite
         * it each time), modify the declaration below to include:
         *
         * overwrite: 'no', removeOnDestroy: false
         */
        software(name: 'Tomcat', version: '6.0.16', removeOnDestroy: true) {
            install source: 'https://elastic-grid.s3.amazonaws.com/tomcat/apache-tomcat-6.0.16.zip',
                    target: '${RIO_HOME}/system/external/tomcat',
                    unarchive: true
            postInstall(removeOnCompletion: false) {
                execute command: '/bin/chmod +x ${RIO_HOME}/system/external/tomcat/apache-tomcat-6.0.16/bin/*sh'
            }
        }

        execute(inDirectory: 'bin', command: 'catalina.sh run') {
            environment {
                property name: "CATALINA_OPTS", value: "-Dcom.sun.management.jmxremote"
            }
        }

        sla(id:'ThreadPool', high: 100) {
            policy type: 'notify'
            monitor name: 'Thread Pool',
                    objectName: "Catalina:name=http-8080,type=ThreadPool",
                    attribute: 'currentThreadsBusy', period: 5000
        }


        maintain 1
    }
}    

The opstring above declares that Rio activate an instance of Tomcat. If the software does not exist on the target compute resource it will be installed, and upon service removal, the installed artifacts removed.

From an SLA perspective, Rio will use the JMX Attach API to connect to the co-located JVM, and query the Thread Pool attribute every 5 seconds.

If the Thread Pool exceeds 100, a SLAThresholdEvent is sent to all subscribed consumers. To include different behavior, the policy type can be changed to scaling or even relocation (sometimes a relocating policy handler only makes sense given what you are observing, disk space may make sense in that case).

If the external service is a Java Virtual Machine, this utility will try to attach to the Java Virtual Machine using the JMX Attach API. This is only possible using Java 6 or greater. If the runtime is Java 5, external service utilization monitoring is not provided.

Back to top

Version: 5.6. Last Published: 2017-01-01.