Create our own Run Engine commands

If the predefined Run Engine commands do not satisfy your requirements, we can create our own commands.

Note: Using Run Engine commands is one approach by which IBM uses to implement environment configurations. Based on your scenario, we can implement a custom solution to modify environment parameters and container configurations that might better suit your needs.


Task info

We can define commands by using two main approaches:


Procedure

  1. Create an empty Java or Groovy project and create three child directories (src, META-INF, script).

    • project

      • src

      • META-INF

      • scripts

  2. Add engine-command.jar as a dependency.

  3. Create a class that inherits from BaseCommand or ScriptCommand. Within the class, create a runCmd method to define your actions.

    • Extend the BaseCommand to implement logic by using Java or Groovy code.

    • Extend the ScriptCommand to implement logic by using other scripting languages such as Python.

    For example, the following class WCCommand inherits from the ScriptCommand and the command outputs a string

      class WCCommand extends ScriptCommand{
      void runCmd(String[] args) {
          println "wc-sample"
      }
      }

  4. Save the class in the src directory.

  5. If needed, create scripts in the script directory to complete a configuration. For example, the following Python script (createJMSQueue.py) uses WebSphere Application Server wsadmin scripting commands to configure IBM MQ JMS resources.

      queueName = sys.argv[1]
      queueManager = sys.argv[2]
      AdminTask.createWMQQueue('server1(cells/localhost/nodes/localhost/servers/server1|server.xml)', '[-name '+ jndiName +' -jndiName '+jndiName+' -queueName '+ queueName + ' -qmgr '+queueManager+' -description JMSQueue ]') 
      print ("Create JMS queues successfully!")  
      AdminConfig.save()

  6. Create a .properties file and save to the META-INF directory. Name the file as the Run Engine command name to use. For example, to use a Run Engine command such as

      run create-jms-queues

    Then create a properties file named create-jms-queues.properties.

  7. In the properties file, specify a main.class name-value pair to specify the class createdd. Also specify a main.script name-value pair if you created a script in step 5. For example,

      main.class=com.ibm.commerce.engine.cmd.twas.WasCommand
      main.script=createJMSQueue.py

  8. Build and package the /src and /META-INF directories into a jar file.

  9. Create or update a Dockerfile to include and use our custom Run Engine command. For more information about creating Dockerfiles, see Building and deploying new Docker images

    • Ensure that you copy your jar file to the /SETUP/lib path in the Docker container.

    • Ensure that you copy your scripts to the /SETUP/scripts path in the Docker container.

    For example,

      FROM <dockerhost>/commerce/ts-app:latest
      COPY new.jar /SETUP/lib
      COPY scripts/ /SETUP/scripts
      RUN  run create-jms-queues inbound mq FVT