use of org.apache.geode.distributed.LocatorLauncher in project geode by apache.
the class StatusLocatorCommand method statusLocator.
@CliCommand(value = CliStrings.STATUS_LOCATOR, help = CliStrings.STATUS_LOCATOR__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_LOCATOR, CliStrings.TOPIC_GEODE_LIFECYCLE })
public Result statusLocator(@CliOption(key = CliStrings.STATUS_LOCATOR__MEMBER, optionContext = ConverterHint.LOCATOR_MEMBER_IDNAME, help = CliStrings.STATUS_LOCATOR__MEMBER__HELP) final String member, @CliOption(key = CliStrings.STATUS_LOCATOR__HOST, help = CliStrings.STATUS_LOCATOR__HOST__HELP) final String locatorHost, @CliOption(key = CliStrings.STATUS_LOCATOR__PORT, help = CliStrings.STATUS_LOCATOR__PORT__HELP) final Integer locatorPort, @CliOption(key = CliStrings.STATUS_LOCATOR__PID, help = CliStrings.STATUS_LOCATOR__PID__HELP) final Integer pid, @CliOption(key = CliStrings.STATUS_LOCATOR__DIR, help = CliStrings.STATUS_LOCATOR__DIR__HELP) final String workingDirectory) {
try {
if (StringUtils.isNotBlank(member)) {
if (isConnectedAndReady()) {
final MemberMXBean locatorProxy = getMemberMXBean(member);
if (locatorProxy != null) {
LocatorLauncher.LocatorState state = LocatorLauncher.LocatorState.fromJson(locatorProxy.status());
return createStatusLocatorResult(state);
} else {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STATUS_LOCATOR__NO_LOCATOR_FOUND_FOR_MEMBER_ERROR_MESSAGE, member));
}
} else {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.STATUS_SERVICE__GFSH_NOT_CONNECTED_ERROR_MESSAGE, LOCATOR_TERM_NAME));
}
} else {
final LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.STATUS).setBindAddress(locatorHost).setDebug(isDebugging()).setPid(pid).setPort(locatorPort).setWorkingDirectory(workingDirectory).build();
final LocatorLauncher.LocatorState state = locatorLauncher.status();
return createStatusLocatorResult(state);
}
} 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_LOCATOR__GENERAL_ERROR_MESSAGE, getLocatorId(locatorHost, locatorPort), StringUtils.defaultIfBlank(workingDirectory, SystemUtils.CURRENT_DIRECTORY), toString(t, getGfsh().getDebug())));
}
}
Aggregations