Besides changing the basic plug-in configuration options, you can add some code that makes the plug-in complete a task. You can create a scripting object and statically invoke its methods by using a scripting singleton.
Procedure
- Under the {plug-in-home}/o11nplugin-redis-core/src/main/java/com/vmware/o11n/plugin/redis folder, create a directory with the name singleton.
This directory constitutes the com.vmware.o11n.plugin.redis.singleton package of the plug-in.
- Create a ConnectionManager scripting class in the com.vmware.o11n.plugin.redis.singleton package.
- Save the ConnectionManager scripting class as a ConnectionManager.java file in the singleton directory.
package com.vmware.o11n.plugin.redis.singleton; /** * A scripting singleton for managing redis connections. */ public class ConnectionManager { /** * This method creates a redis connection by the provided name, host and * port. * * @param connectionName * the name of the connection, only one with the same name can * exist * @param redisHost * the redis host, cannot be null * @param redisPort * redis port * @return the ID of the newly created connection */ public String save(String connectionName, String redisHost, int redisPort) { return null; } }
- Add the singleton(ConnectionManager.class) line to the CustomMapping.java file so that the plug-in can expose the ConnectionManager class as a scripting object.
package com.vmware.o11n.plugin.redis; import com.vmware.o11n.plugin.redis.singleton.ConnectionManager; import com.vmware.o11n.sdk.modeldrivengen.mapping.AbstractMapping; public class CustomMapping extends AbstractMapping { @Override public void define() { singleton(ConnectionManager.class); } }
- Rebuild the plug-in by running the mvn clean install command.
- Verify the changes in the vso.xml file.
<scripting-objects> <object create="false" java-class="com.vmware.o11n.plugin.redis_gen.ConnectionManager_Wrapper" script-name="_RedisConnectionManager"> <description></description> <singleton script-name="RedisConnectionManager" datasource="main-datasource"/> <attributes/> <constructors/> <methods> <method script-name="save" java-name="save" return-type="String"> <description></description> <parameters> <parameter type="String" name="connectionName"></parameter> <parameter type="String" name="redisHost"></parameter> <parameter type="Number" name="redisPort"></parameter> </parameters> </method> </methods> </object> </scripting-objects>
The Automation Orchestrator platform can interpret the scripting-objects tagRedisConnectionManage
is a scripting object associated to theConnectionManager
class.With model-driven, you can extend objects with different functionalities. In this example, the vso.xml file points to a wrapper class, instead of pointing to the scripting object itself. - Install the modified version of the plug-in. See Deploy a Plug-In.
- Log in to the Automation Orchestrator Client.
- Go to API Explorer.
- Expand the Redis plug-in to browse through the API elements.
The ConnectionManager class is exposed as a scripting object together with the
save
method.Note: By default, the code generator adds the name of the plug-in as a prefix of the plug-in objects. For example,ConnectionManager
becomesRedisConnectionManager
.