You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

This articles talks about changes required to add a new gfsh command for a Geode feature (operated using Gfsh).

Adding a new Gfsh command

Take an existing Gfsh command as reference and add/create file for the new command similarly.

All the supported commands can be found under "geode-core/src/main/java/com/gemstone/gemfire/management/cli/commands".

E.g.: QueueCommands.java (to create AsyncEventQueue).

 

The below section shows other parts of the code that needs to be changed.

Adding new parameter to existing command

Here we are using implementation of new API "ignoreEvictionAndExpiration()" with AsyncEventQueue as an example.

The Gfsh command to create AsynEventQueue is defined in "QueueCommands.java".

gfsh>create async-event-queue --id=value --listener=value [--group=value] [--batch-size=value] [--persistent(=value)?] [--disk-store=value] [--max-queue-memory=value] [--listener-param=value(,value)*] 

To support "ignoreEvictionAndExpiration()" new parameter "ignore-eviction-expiration" is added to AsyncEventQueue creation command.

Add new parameter reference

In "geode-core/src/main/java/com/gemstone/gemfire/management/cli/i18n/CliStrings.java", add the new command and help text.

public static final String CREATE_ASYNC_EVENT_QUEUE__IGNORE_EVICTION_EXPIRATION = "ignore-eviction-expiration";

public static final String CREATE_ASYNC_EVENT_QUEUE__IGNORE_EVICTION_EXPIRATION__HELP = "Whether to ignore eviction and expiration events.";

Changes to parameter set

Open the Corresponding Gfsh commands file.

E..g: "geode-core/src/main/java/com/gemstone/gemfire/management/cli/commands/QueueCommands.java"

Look for @CliOption

Add the new parameter (copy/paste one of the existing command and change it to reflect new command)

E.g:

@CliOption(key = CliStrings.CREATE_ASYNC_EVENT_QUEUE__IGNORE_EVICTION_EXPIRATION,

                 unspecifiedDefaultValue = "true",

                 specifiedDefaultValue = "true",

                 help = CliStrings.CREATE_ASYNC_EVENT_QUEUE__IGNORE_EVICTION_EXPIRATION__HELP)

      Boolean ignoreEvictionAndExpiration,

Passing new parameter to associated CreateAsyncEventQueue Function.

In the Gfsh commands file, add new parameter to the argument list passed to function executed by Gfsh command.

AsyncEventQueueFunctionArgs aeqArgs = new AsyncEventQueueFunctionArgs(id, parallel,

          enableBatchConflation, batchSize,batchTimeInterval,

          persistent, diskStore, diskSynchronous, maxQueueMemory, dispatcherThreads, orderPolicy,

          gatewayEventFilters, gatewaySubstitutionListener, listener, listenerProperties,

          ignoreEvictionAndExpiration);

 

ResultCollector<?, ?> rc = CliUtil.executeFunction(new CreateAsyncEventQueueFunction(), aeqArgs, targetMembers);

Changes in Associated function 

Make changes in the function to handle the new command parameter.

E.g.:

In this case "ignore-eviction-expiration" command invokes/sets the value for "AsyncEventQuey.ignoreEvictionAndExpiration()" attribute.

open "geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/functions/CreateAsyncEventQueueFunction.java"

Read the args and use it:

AsyncEventQueueFactory asyncEventQueueFactory = cache.createAsyncEventQueueFactory().

 .setIgnoreEvictionAndExpiration(aeqArgs.isIgnoreEvictionAndExpiration())

Corresponding changes to support REST API

Add "RequestParam" and "Command Option" in the REST API controller.

E.g.: REST API For AsyncEventQueue creation:

in "geode-core/src/main/java/com/gemstone/gemfire/management/internal/web/controllers/QueueCommandsController.java"

@RequestParam(value = CliStrings.CREATE_ASYNC_EVENT_QUEUE__IGNORE_EVICTION_EXPIRATION, defaultValue = "true") final Boolean isIgnoreEvictionAndExpiration,

command.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__IGNORE_EVICTION_EXPIRATION, String.valueOf(isIgnoreEvictionAndExpiration));

Unit Tests:

geode-core/src/main/java/com/gemstone/gemfire/management/cli/commands/QueueCommandsDUnitTest.java

src/test/java/com/com/gemstone/gemfire/management/internal/configuration/SharedConfigurationEndToEndDUnitTest.java


  • No labels