Creating your own Run Engine commands

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

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

About this task

You can define commands by using two main approaches:
  • If you want to use Java or Groovy classes to change configurations, you can define your class to inherit from the BaseCommand class (in Docker_container/SETUP/lib/engine-command.jar).
  • If you want to use other scripting languages, such as Python, you can define your class to inherit from ScriptCommand.

Procedure

  1. Create an empty Java or Groovy project and create three child directories (src, META-INF, scripts).
    • project
      • src
      • META-INF
      • scripts
        Note: The scripts directory is only required when using ScriptCommand.
  2. Add engine-command.jar as a dependency.
  3. Create a class that inherits from BaseCommand or ScriptCommand based on the type of code or script that you want to deploy. Within the class, create a runCmd method to define your actions.
    • Extend the BaseCommand if you want to implement logic by using Java or Groovy code.
    • Extend the ScriptCommand if you want to implement logic by using other scripting languages such as Python.
    For example,
    • The following class WCCommand inherits from ScriptCommand, and the command outputs a string.
      class WCCommand extends ScriptCommand{
      void runCmd(String[] args) {
          println "wc-sample"
      }
      }
      
    • The following class WCCommand inherits from BaseComand.
      import com.ibm.commerce.engine.cmd.BaseCommand
      
      class WCCommmand extends BaseCommand {
      	public void runCmd(String[] args) {
           // ADD logic here to modify environment parameters and container configurations
      	}
      }
      
  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 that you want to use.
    For example, if you want to use a Run Engine command such as
    run create-jms-queues
    Then create a properties file that is named create-jms-queues.properties.
  7. In the properties file, specify a main.class name-value pair to specify the class that you created. Also specify a main.script name-value pair if you created a script in step 5.
    For example,
    • Using the example script created in step 5:
      main.class=com.ibm.commerce.engine.cmd.twas.WasCommand
      main.script=createJMSQueue.py
      
    • Using the BaseComand example created in step 3:
      main.class=WCCommand
  8. Build and package the /src and /META-INF directories into a jar file.
  9. Create or update a Dockerfile to include and use your custom Run Engine command.
    • 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

Results

Your custom Run Engine command is implemented and can now be used to make environment configuration changes.