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:
- To use Java or Groovy classes to change configurations, we can define your class to inherit from the BaseCommand class (in Docker_container/SETUP/lib/engine-command.jar).
- To use other scripting languages, such as Python, we can define your class to inherit from ScriptCommand.
Procedure
- Create an empty Java or Groovy project and create three child directories (src, META-INF, script).
- project
- src
- META-INF
- scripts
- Add engine-command.jar as a dependency.
- 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" } }
- Save the class in the src directory.
- 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()
- For more information about wsadmin commands for IBM MQ, see Configure JMS resources using wsadmin scripting commands.
- For general information about wsadmin commands, see Scripting the application serving environment
- 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-queuesThen create a properties file named create-jms-queues.properties.
- 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
- Build and package the /src and /META-INF directories into a jar file.
- 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