Search in sources :

Example 16 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class WanCommands method statusGatewayReceiver.

@CliCommand(value = CliStrings.STATUS_GATEWAYRECEIVER, help = CliStrings.STATUS_GATEWAYRECEIVER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result statusGatewayReceiver(@CliOption(key = CliStrings.STATUS_GATEWAYRECEIVER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.STATUS_GATEWAYRECEIVER__GROUP__HELP) String[] onGroup, @CliOption(key = CliStrings.STATUS_GATEWAYRECEIVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STATUS_GATEWAYRECEIVER__MEMBER__HELP) String[] onMember) {
    Result result = null;
    try {
        InternalCache cache = getCache();
        SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
        CompositeResultData crd = ResultBuilder.createCompositeResultData();
        TabularResultData availableReceiverData = crd.addSection(CliStrings.SECTION_GATEWAY_RECEIVER_AVAILABLE).addTable(CliStrings.TABLE_GATEWAY_RECEIVER);
        TabularResultData notAvailableReceiverData = crd.addSection(CliStrings.SECTION_GATEWAY_RECEIVER_NOT_AVAILABLE).addTable(CliStrings.TABLE_GATEWAY_RECEIVER);
        Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
        if (dsMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        for (DistributedMember member : dsMembers) {
            ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
            if (gatewayReceiverObjectName != null) {
                GatewayReceiverMXBean receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
                if (receieverBean != null) {
                    buildReceiverStatus(member.getId(), receieverBean, availableReceiverData);
                    continue;
                }
            }
            buildReceiverStatus(member.getId(), null, notAvailableReceiverData);
        }
        result = ResultBuilder.buildResult(crd);
    } catch (Exception e) {
        LogWrapper.getInstance().warning(CliStrings.GATEWAY_ERROR + CliUtil.stackTraceAsString(e));
        result = ResultBuilder.createGemFireErrorResult(CliStrings.GATEWAY_ERROR + e.getMessage());
    }
    return result;
}
Also used : GatewayReceiverMXBean(org.apache.geode.management.GatewayReceiverMXBean) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ExecutionException(java.util.concurrent.ExecutionException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) ObjectName(javax.management.ObjectName) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 17 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class ShellCommands method setVariable.

@CliCommand(value = { CliStrings.SET_VARIABLE }, help = CliStrings.SET_VARIABLE__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH })
public Result setVariable(@CliOption(key = CliStrings.SET_VARIABLE__VAR, mandatory = true, help = CliStrings.SET_VARIABLE__VAR__HELP) String var, @CliOption(key = CliStrings.SET_VARIABLE__VALUE, mandatory = true, help = CliStrings.SET_VARIABLE__VALUE__HELP) String value) {
    Result result = null;
    try {
        getGfsh().setEnvProperty(var, String.valueOf(value));
        result = ResultBuilder.createInfoResult("Value for variable " + var + " is now: " + value + ".");
    } catch (IllegalArgumentException e) {
        ErrorResultData errorResultData = ResultBuilder.createErrorResultData();
        errorResultData.addLine(e.getMessage());
        result = ResultBuilder.buildResult(errorResultData);
    }
    return result;
}
Also used : ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) Result(org.apache.geode.management.cli.Result) ConnectToLocatorResult(org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 18 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class StartVsdCommand method startVsd.

@CliCommand(value = CliStrings.START_VSD, help = CliStrings.START_VSD__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_M_AND_M, CliStrings.TOPIC_GEODE_STATISTICS })
public Result startVsd(@CliOption(key = CliStrings.START_VSD__FILE, help = CliStrings.START_VSD__FILE__HELP) final String[] statisticsArchiveFilePathnames) {
    try {
        String geodeHome = System.getenv("GEODE_HOME");
        assertState(StringUtils.isNotBlank(geodeHome), CliStrings.GEODE_HOME_NOT_FOUND_ERROR_MESSAGE);
        assertState(IOUtils.isExistingPathname(getPathToVsd()), String.format(CliStrings.START_VSD__NOT_FOUND_ERROR_MESSAGE, geodeHome));
        String[] vsdCommandLine = createdVsdCommandLine(statisticsArchiveFilePathnames);
        if (isDebugging()) {
            getGfsh().printAsInfo(String.format("GemFire VSD command-line (%1$s)", Arrays.toString(vsdCommandLine)));
        }
        Process vsdProcess = Runtime.getRuntime().exec(vsdCommandLine);
        getGfsh().printAsInfo(CliStrings.START_VSD__RUN);
        String vsdProcessOutput = waitAndCaptureProcessStandardErrorStream(vsdProcess);
        InfoResultData infoResultData = ResultBuilder.createInfoResultData();
        if (StringUtils.isNotBlank(vsdProcessOutput)) {
            infoResultData.addLine(StringUtils.LINE_SEPARATOR);
            infoResultData.addLine(vsdProcessOutput);
        }
        return ResultBuilder.buildResult(infoResultData);
    } catch (GemFireException | IllegalStateException | IllegalArgumentException | FileNotFoundException e) {
        return ResultBuilder.createShellClientErrorResult(e.getMessage());
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.START_VSD__ERROR_MESSAGE, toString(t, false)));
    }
}
Also used : GemFireException(org.apache.geode.GemFireException) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) FileNotFoundException(java.io.FileNotFoundException) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 19 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class StatusServerCommand method statusServer.

@CliCommand(value = CliStrings.STATUS_SERVER, help = CliStrings.STATUS_SERVER__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_SERVER, CliStrings.TOPIC_GEODE_LIFECYCLE })
public Result statusServer(@CliOption(key = CliStrings.STATUS_SERVER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.STATUS_SERVER__MEMBER__HELP) final String member, @CliOption(key = CliStrings.STATUS_SERVER__PID, help = CliStrings.STATUS_SERVER__PID__HELP) final Integer pid, @CliOption(key = CliStrings.STATUS_SERVER__DIR, help = CliStrings.STATUS_SERVER__DIR__HELP) final String workingDirectory) {
    try {
        if (StringUtils.isNotBlank(member)) {
            if (isConnectedAndReady()) {
                final MemberMXBean serverProxy = getMemberMXBean(member);
                if (serverProxy != null) {
                    return ResultBuilder.createInfoResult(ServerLauncher.ServerState.fromJson(serverProxy.status()).toString());
                } else {
                    return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STATUS_SERVER__NO_SERVER_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
                }
            } else {
                return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STATUS_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, "Cache Server"));
            }
        } else {
            final ServerLauncher serverLauncher = new ServerLauncher.Builder().setCommand(ServerLauncher.Command.STATUS).setDebug(isDebugging()).setDisableDefaultServer(true).setPid(pid).setWorkingDirectory(workingDirectory).build();
            final ServerLauncher.ServerState status = serverLauncher.status();
            return ResultBuilder.createInfoResult(status.toString());
        }
    } catch (IllegalArgumentException | IllegalStateException e) {
        return ResultBuilder.createUserErrorResult(e.getMessage());
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.STATUS_SERVER__GENERAL_ERROR_MESSAGE, toString(t, getGfsh().getDebug())));
    }
}
Also used : ResultBuilder(org.apache.geode.management.internal.cli.result.ResultBuilder) MemberMXBean(org.apache.geode.management.MemberMXBean) MXBeanProvider.getMemberMXBean(org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean) ServerLauncher(org.apache.geode.distributed.ServerLauncher) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 20 with CliCommand

use of org.springframework.shell.core.annotation.CliCommand in project geode by apache.

the class StopLocatorCommand method stopLocator.

@CliCommand(value = CliStrings.STOP_LOCATOR, help = CliStrings.STOP_LOCATOR__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_LOCATOR, CliStrings.TOPIC_GEODE_LIFECYCLE })
public Result stopLocator(@CliOption(key = CliStrings.STOP_LOCATOR__MEMBER, optionContext = ConverterHint.LOCATOR_MEMBER_IDNAME, help = CliStrings.STOP_LOCATOR__MEMBER__HELP) final String member, @CliOption(key = CliStrings.STOP_LOCATOR__PID, help = CliStrings.STOP_LOCATOR__PID__HELP) final Integer pid, @CliOption(key = CliStrings.STOP_LOCATOR__DIR, help = CliStrings.STOP_LOCATOR__DIR__HELP) final String workingDirectory) {
    LocatorLauncher.LocatorState locatorState;
    try {
        if (StringUtils.isNotBlank(member)) {
            if (isConnectedAndReady()) {
                final MemberMXBean locatorProxy = getMemberMXBean(member);
                if (locatorProxy != null) {
                    if (!locatorProxy.isLocator()) {
                        throw new IllegalStateException(CliStrings.format(CliStrings.STOP_LOCATOR__NOT_LOCATOR_ERROR_MESSAGE, member));
                    }
                    if (locatorProxy.isServer()) {
                        throw new IllegalStateException(CliStrings.format(CliStrings.STOP_LOCATOR__LOCATOR_IS_CACHE_SERVER_ERROR_MESSAGE, member));
                    }
                    locatorState = LocatorLauncher.LocatorState.fromJson(locatorProxy.status());
                    locatorProxy.shutDownMember();
                } else {
                    return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STOP_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
                }
            } else {
                return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STOP_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, LOCATOR_TERM_NAME));
            }
        } else {
            final LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STOP).setDebug(isDebugging()).setPid(pid).setWorkingDirectory(workingDirectory).build();
            locatorState = locatorLauncher.status();
            locatorLauncher.stop();
        }
        if (AbstractLauncher.Status.ONLINE.equals(locatorState.getStatus())) {
            getGfsh().logInfo(String.format(CliStrings.STOP_LOCATOR__STOPPING_LOCATOR_MESSAGE, locatorState.getWorkingDirectory(), locatorState.getServiceLocation(), locatorState.getMemberName(), locatorState.getPid(), locatorState.getLogFile()), null);
            StopWatch stopWatch = new StopWatch(true);
            while (locatorState.isVmWithProcessIdRunning()) {
                Gfsh.print(".");
                if (stopWatch.elapsedTimeMillis() > WAITING_FOR_STOP_TO_MAKE_PID_GO_AWAY_TIMEOUT_MILLIS) {
                    break;
                }
                synchronized (this) {
                    TimeUnit.MILLISECONDS.timedWait(this, 500);
                }
            }
            return ResultBuilder.createInfoResult(StringUtils.EMPTY);
        } else {
            return ResultBuilder.createUserErrorResult(locatorState.toString());
        }
    } catch (IllegalArgumentException | IllegalStateException e) {
        return ResultBuilder.createUserErrorResult(e.getMessage());
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.STOP_LOCATOR__GENERAL_ERROR_MESSAGE, toString(t, getGfsh().getDebug())));
    } finally {
        Gfsh.redirectInternalJavaLoggers();
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) MemberMXBean(org.apache.geode.management.MemberMXBean) MXBeanProvider.getMemberMXBean(org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean) StopWatch(org.apache.geode.internal.util.StopWatch) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Aggregations

CliCommand (org.springframework.shell.core.annotation.CliCommand)100 CliMetaData (org.apache.geode.management.cli.CliMetaData)94 Result (org.apache.geode.management.cli.Result)66 DistributedMember (org.apache.geode.distributed.DistributedMember)60 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)58 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)42 InternalCache (org.apache.geode.internal.cache.InternalCache)37 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)35 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)31 ArrayList (java.util.ArrayList)29 List (java.util.List)24 ConverterHint (org.apache.geode.management.cli.ConverterHint)24 IOException (java.io.IOException)20 InfoResultData (org.apache.geode.management.internal.cli.result.InfoResultData)17 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)16 XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)16 ExecutionException (java.util.concurrent.ExecutionException)15 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)15 HashSet (java.util.HashSet)14 ObjectName (javax.management.ObjectName)14