Search in sources :

Example 1 with MemberCommandService

use of org.apache.geode.management.internal.cli.remote.MemberCommandService in project geode by apache.

the class MemberMBeanBridge method processCommand.

/**
   * Processes the given command string using the given environment information if it's non-empty.
   * Result returned is in a JSON format.
   * 
   * @param commandString command string to be processed
   * @param env environment information to be used for processing the command
   * @return result of the processing the given command string.
   */
public String processCommand(String commandString, Map<String, String> env) {
    if (commandService == null) {
        throw new JMRuntimeException("Command can not be processed as Command Service did not get initialized. Reason: " + commandServiceInitError);
    }
    boolean isGfshRequest = isGfshRequest(env);
    if (isGfshRequest) {
        CommandExecutionContext.setShellRequest();
    }
    Result result = ((MemberCommandService) commandService).processCommand(commandString, env);
    if (!(result instanceof CommandResult)) {
        // TODO - Abhishek - Shouldn't be needed
        while (result.hasNextLine()) {
            result = ResultBuilder.createInfoResult(result.nextLine());
        }
    }
    if (isGfshRequest) {
        return CommandResponseBuilder.createCommandResponseJson(getMember(), (CommandResult) result);
    } else {
        return ResultBuilder.resultAsString(result);
    }
}
Also used : MemberCommandService(org.apache.geode.management.internal.cli.remote.MemberCommandService) JMRuntimeException(javax.management.JMRuntimeException) DiskBackupResult(org.apache.geode.management.DiskBackupResult) Result(org.apache.geode.management.cli.Result) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Example 2 with MemberCommandService

use of org.apache.geode.management.internal.cli.remote.MemberCommandService in project geode by apache.

the class CommandService method createLocalCommandService.

/* ************** Methods to be implemented by sub-classes END ************ */
/* **************************** factory methods *************************** */
/**
   * Returns a newly created or existing instance of the
   * <code>CommandService<code> associated with the
   * specified <code>Cache</code>.
   *
   * @param cache Underlying <code>Cache</code> instance to be used to create a Command Service.
   * @throws CommandServiceException If command service could not be initialized.
   */
public static CommandService createLocalCommandService(Cache cache) throws CommandServiceException {
    if (cache == null || cache.isClosed()) {
        throw new CacheClosedException("Can not create command service as cache doesn't exist or cache is closed.");
    }
    if (localCommandService == null || !localCommandService.isUsable()) {
        String nonExistingDependency = CliUtil.cliDependenciesExist(false);
        if (nonExistingDependency != null) {
            throw new DependenciesNotFoundException(LocalizedStrings.CommandServiceManager_COULD_NOT_FIND__0__LIB_NEEDED_FOR_CLI_GFSH.toLocalizedString(new Object[] { nonExistingDependency }));
        }
        localCommandService = new MemberCommandService(cache);
    }
    return localCommandService;
}
Also used : CacheClosedException(org.apache.geode.cache.CacheClosedException) DependenciesNotFoundException(org.apache.geode.management.DependenciesNotFoundException) MemberCommandService(org.apache.geode.management.internal.cli.remote.MemberCommandService)

Aggregations

MemberCommandService (org.apache.geode.management.internal.cli.remote.MemberCommandService)2 JMRuntimeException (javax.management.JMRuntimeException)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 DependenciesNotFoundException (org.apache.geode.management.DependenciesNotFoundException)1 DiskBackupResult (org.apache.geode.management.DiskBackupResult)1 Result (org.apache.geode.management.cli.Result)1 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)1