use of org.apache.geode.management.cli.CliMetaData 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;
}
use of org.apache.geode.management.cli.CliMetaData 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;
}
use of org.apache.geode.management.cli.CliMetaData 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)));
}
}
use of org.apache.geode.management.cli.CliMetaData 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())));
}
}
use of org.apache.geode.management.cli.CliMetaData 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();
}
}
Aggregations