Extend the Deploy JBoss Domain plugin

You can extend the Deploy plugin for JBoss Enterprise Application Platform (EAP) 6 and JBoss Application Server (AS)/WildFly 7.1+ using the Deploy plugin API type system and Jython.

The plugin wraps the JBoss CLI with a Jython runtime environment, allowing extenders to interact with JBoss and Deploy from the script. You execute the Jython script on the Deploy server. It has full access to the following Deploy objects:

  • deployed: The current deployed object on which the operation has been triggered.
  • step: The step object that the script is being executed from. This exposes an overthere remote connection for file manipulation and a method to execute JBoss CLI commands.
  • container: The container object to which the deployed is targeted.
  • delta: The delta specification that leads to the script being executed.
  • deployedApplication: The entire deployed application.

The plugin associates Create, Modify, Destroy, Noop and Inspect operations received from Deploy with Jython scripts that need to be executed for the specific operation to be performed.

An advanced method to extend the plugin exists, but the implementation of this form of extension needs to be written in the Java programming language and consists of writing so-called Deployed contributors, PlanPreProcessors and Contributors.

Extend the plugin to support JDBC Driver deployment

You can deploy a JDBC driver jar to a domain (jbossdm.Domain) or stand-alone server (jbossdm.StandaloneServer) as a module, and register the driver with JBoss datasources subsystem.

Define the deployed and deployable to represent a JDBC Driver

The following synthetic.xml snippet shows the definition of the JDBC Driver deployed. The deployed will be targeted to a domain (jbossdm.Domain) or a stand-alone server (jbossdm.StandaloneServer). Please see to the JBoss Application Server 7+ Plugin Reference to see the interfaces and class hierarchy of these types.

    <type type="jbossdm.JdbcDriverModule" extends="jbossdm.CliManagedDeployedArtifact"
          deployable-type="jbossdm.JdbcDriver" container-type="jbossdm.CliManagingContainer">
      <generate-deployable type="jbossdm.JdbcDriver" extends="udm.BaseDeployableArchiveArtifact">

      <property name="driverName"/>
      <property name="driverModuleName"/>
      <property name="driverXaDatasourceClassName/>

      <!-- hidden properties to specify the jython scripts to execute for an operation -->
      <property name="createScript" default="jboss/dm/ds/create-jdbc-driver.py" hidden="true"/>

create-jdbc-driver.py contains:

    from com.xebialabs.overthere.util import OverthereUtils

    #create module directory to copy jar and module.xml to
    driverModuleName = deployed.getProperty("driverModuleName")
    moduleRelPath = driverModuleName.replaceAll("\\.","/")
    moduleAbsolutePath = "%s/modules/%s" % (container.getProperty("home"), moduleRelPath)
    moduleDir = step.getRemoteConnection().getFile(moduleAbsolutePath);
    #upload jar
    moduleJar = moduleDir.getFile(deployed.file.getName())

    moduleXmlContent = """
     <?xml version="1.0" encoding="UTF-8"?>
     <module xmlns="urn:jboss:module:1.0" name="%s">
            <resource-root path="%s"/>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
     """ % (deployed.getProperty("driverModuleName"), deployed.file.getName())

    #create module.xml
    moduleXml = moduleDir.getFile("module.xml")

    #register driver with the datasource subsystem
    driverName = deployed.getProperty("driveName")
    xaClassName = deployed.getProperty("driverXaDatasourceClassName")
    cmd = '/subsystem=datasources/jdbc-driver=%s:add(driver-name="%s",driver-module-name="%s",driver-xa-datasource-class-name="%s")' 		% (driverName, driverName, driverModuleName, xaClasName)
    cmd = prependProfilePath(cmd) #prefix with profile if deploying to domain
    executeCmd(cmd)  #used to execute a JBoss Cli command.

Extend the plugin with custom control task

You can add control tasks to jbossdm.CliManagedDeployed or jbossdm.CliManagedContainer. You can specify the control task as a Jython script that will be executed on the Deploy Server or as an operating system shell script that will be run on the target host. The operating system shell script is first processed with FreeMarker before being executed.

Create a Jython-based control task to list JDBC drivers in a stand-alone server

synthetic.xml snippet:

    <type-modification type="jbossdm.StandaloneServer">
      <property name="listJdbcDriversPythonTaskScript" hidden="true" default="jboss/dm/container/list-jdbc-drivers.py"/>
      <!-- Note "PythonTaskScript" is appended to the method name to determine the script to run. -->
      <method name="listJdbcDrivers"/>

list-jdbc-drivers.py snippet:

    drivers = executeCmd("/subsystem=datasources:installed-drivers-list")
    logOutput(drivers)  #outputs to the step log

Start the stand-alone server

synthetic.xml snippet:

    <type-modification type="jbossdm.StandaloneServer">
      <property name="startShellTaskScript" hidden="true" default="jboss/dm/container/start-standalone"/>
      <!-- Note "ShellTaskScript" is appended to the method name to determine the script to run. -->
      <method name="start"/>

start-standalone.sh snippet:

    nohup ${container.home}/bin/standalone.sh >>nohup.out 2>&1 &
    sleep 2
    echo background process to start standalone server executed.