use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class WanCommands method listGateway.
@CliCommand(value = CliStrings.LIST_GATEWAY, help = CliStrings.LIST_GATEWAY__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listGateway(@CliOption(key = CliStrings.LIST_GATEWAY__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.LIST_GATEWAY__MEMBER__HELP) String[] onMember, @CliOption(key = CliStrings.LIST_GATEWAY__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.LIST_GATEWAY__GROUP__HELP) String[] onGroup) {
Result result = null;
InternalCache cache = getCache();
try {
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
Set<DistributedMember> dsMembers = CliUtil.findMembers(onGroup, onMember);
if (dsMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
Map<String, Map<String, GatewaySenderMXBean>> gatewaySenderBeans = new TreeMap<String, Map<String, GatewaySenderMXBean>>();
Map<String, GatewayReceiverMXBean> gatewayReceiverBeans = new TreeMap<String, GatewayReceiverMXBean>();
DistributedSystemMXBean dsMXBean = service.getDistributedSystemMXBean();
for (DistributedMember member : dsMembers) {
String memberName = member.getName();
String memberNameOrId = (memberName != null && !memberName.isEmpty()) ? memberName : member.getId();
ObjectName[] gatewaySenderObjectNames = dsMXBean.listGatewaySenderObjectNames(memberNameOrId);
// on it
if (gatewaySenderObjectNames != null) {
for (ObjectName name : gatewaySenderObjectNames) {
GatewaySenderMXBean senderBean = service.getMBeanProxy(name, GatewaySenderMXBean.class);
if (senderBean != null) {
if (gatewaySenderBeans.containsKey(senderBean.getSenderId())) {
Map<String, GatewaySenderMXBean> memberToBeanMap = gatewaySenderBeans.get(senderBean.getSenderId());
memberToBeanMap.put(member.getId(), senderBean);
} else {
Map<String, GatewaySenderMXBean> memberToBeanMap = new TreeMap<String, GatewaySenderMXBean>();
memberToBeanMap.put(member.getId(), senderBean);
gatewaySenderBeans.put(senderBean.getSenderId(), memberToBeanMap);
}
}
}
}
// gateway receivers : a member can have only one gateway receiver
ObjectName gatewayReceiverObjectName = MBeanJMXAdapter.getGatewayReceiverMBeanName(member);
if (gatewayReceiverObjectName != null) {
GatewayReceiverMXBean receieverBean = null;
receieverBean = service.getMBeanProxy(gatewayReceiverObjectName, GatewayReceiverMXBean.class);
if (receieverBean != null) {
gatewayReceiverBeans.put(member.getId(), receieverBean);
}
}
}
if (gatewaySenderBeans.isEmpty() && gatewayReceiverBeans.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.GATEWAYS_ARE_NOT_AVAILABLE_IN_CLUSTER);
}
CompositeResultData crd = ResultBuilder.createCompositeResultData();
crd.setHeader(CliStrings.HEADER_GATEWAYS);
accumulateListGatewayResult(crd, gatewaySenderBeans, gatewayReceiverBeans);
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 WanCommands method loadBalanceGatewaySender.
@CliCommand(value = CliStrings.LOAD_BALANCE_GATEWAYSENDER, help = CliStrings.LOAD_BALANCE_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result loadBalanceGatewaySender(@CliOption(key = CliStrings.LOAD_BALANCE_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.LOAD_BALANCE_GATEWAYSENDER__ID__HELP) String senderId) {
Result result = null;
if (senderId != null) {
senderId = senderId.trim();
}
try {
InternalCache cache = getCache();
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
TabularResultData resultData = ResultBuilder.createTabularResultData();
Set<DistributedMember> dsMembers = CliUtil.getAllNormalMembers(cache);
if (dsMembers.isEmpty()) {
result = ResultBuilder.createInfoResult(CliStrings.GATEWAY_MSG_MEMBERS_NOT_FOUND);
} else {
boolean gatewaySenderExists = false;
for (DistributedMember member : dsMembers) {
GatewaySenderMXBean bean = null;
if (cache.getDistributedSystem().getDistributedMember().getId().equals(member.getId())) {
bean = service.getLocalGatewaySenderMXBean(senderId);
} else {
ObjectName objectName = service.getGatewaySenderMBeanName(member, senderId);
bean = service.getMBeanProxy(objectName, GatewaySenderMXBean.class);
}
if (bean != null) {
gatewaySenderExists = true;
bean.rebalance();
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_OK, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_REBALANCED_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
} else {
accumulateStartResult(resultData, member.getId(), CliStrings.GATEWAY_ERROR, CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_AVAILABLE_ON_MEMBER_1, new Object[] { senderId, member.getId() }));
}
}
if (gatewaySenderExists) {
result = ResultBuilder.buildResult(resultData);
} else {
result = ResultBuilder.createInfoResult(CliStrings.format(CliStrings.GATEWAY_SENDER_0_IS_NOT_FOUND_ON_ANY_MEMBER, new Object[] { senderId }));
}
}
} 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 WanCommands method destroyGatewaySender.
@CliCommand(value = CliStrings.DESTROY_GATEWAYSENDER, help = CliStrings.DESTROY_GATEWAYSENDER__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_WAN)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result destroyGatewaySender(@CliOption(key = CliStrings.DESTROY_GATEWAYSENDER__GROUP, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.DESTROY_GATEWAYSENDER__GROUP__HELP) String[] onGroups, @CliOption(key = CliStrings.DESTROY_GATEWAYSENDER__MEMBER, optionContext = ConverterHint.MEMBERIDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.DESTROY_GATEWAYSENDER__MEMBER__HELP) String[] onMember, @CliOption(key = CliStrings.DESTROY_GATEWAYSENDER__ID, mandatory = true, optionContext = ConverterHint.GATEWAY_SENDER_ID, help = CliStrings.DESTROY_GATEWAYSENDER__ID__HELP) String id) {
Result result = null;
try {
GatewaySenderDestroyFunctionArgs gatewaySenderDestroyFunctionArgs = new GatewaySenderDestroyFunctionArgs(id);
Set<DistributedMember> membersToDestroyGatewaySenderOn = CliUtil.findMembers(onGroups, onMember);
if (membersToDestroyGatewaySenderOn.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
ResultCollector<?, ?> resultCollector = CliUtil.executeFunction(GatewaySenderDestroyFunction.INSTANCE, gatewaySenderDestroyFunctionArgs, membersToDestroyGatewaySenderOn);
@SuppressWarnings("unchecked") List<CliFunctionResult> gatewaySenderDestroyResults = (List<CliFunctionResult>) resultCollector.getResult();
TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
final String errorPrefix = "ERROR: ";
for (CliFunctionResult gatewaySenderDestroyResult : gatewaySenderDestroyResults) {
boolean success = gatewaySenderDestroyResult.isSuccessful();
tabularResultData.accumulate("Member", gatewaySenderDestroyResult.getMemberIdOrName());
tabularResultData.accumulate("Status", (success ? "" : errorPrefix) + gatewaySenderDestroyResult.getMessage());
}
result = ResultBuilder.buildResult(tabularResultData);
} catch (IllegalArgumentException e) {
LogWrapper.getInstance().info(e.getMessage());
result = ResultBuilder.createUserErrorResult(e.getMessage());
}
return result;
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class StartJConsoleCommand method startJConsole.
@CliCommand(value = CliStrings.START_JCONSOLE, help = CliStrings.START_JCONSOLE__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_MANAGER, CliStrings.TOPIC_GEODE_JMX, CliStrings.TOPIC_GEODE_M_AND_M })
public Result startJConsole(@CliOption(key = CliStrings.START_JCONSOLE__INTERVAL, unspecifiedDefaultValue = "4", help = CliStrings.START_JCONSOLE__INTERVAL__HELP) final int interval, @CliOption(key = CliStrings.START_JCONSOLE__NOTILE, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.START_JCONSOLE__NOTILE__HELP) final boolean notile, @CliOption(key = CliStrings.START_JCONSOLE__PLUGINPATH, help = CliStrings.START_JCONSOLE__PLUGINPATH__HELP) final String pluginpath, @CliOption(key = CliStrings.START_JCONSOLE__VERSION, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CliStrings.START_JCONSOLE__VERSION__HELP) final boolean version, @CliOption(key = CliStrings.START_JCONSOLE__J, optionContext = GfshParser.J_OPTION_CONTEXT, help = CliStrings.START_JCONSOLE__J__HELP) final String[] jvmArgs) {
try {
String[] jconsoleCommandLine = createJConsoleCommandLine(null, interval, notile, pluginpath, version, jvmArgs);
if (isDebugging()) {
getGfsh().printAsInfo(String.format("JConsole command-line ($1%s)", Arrays.toString(jconsoleCommandLine)));
}
Process jconsoleProcess = Runtime.getRuntime().exec(jconsoleCommandLine);
StringBuilder message = new StringBuilder();
if (version) {
jconsoleProcess.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(jconsoleProcess.getErrorStream()));
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
message.append(line);
message.append(StringUtils.LINE_SEPARATOR);
}
IOUtils.close(reader);
} else {
getGfsh().printAsInfo(CliStrings.START_JCONSOLE__RUN);
String jconsoleProcessOutput = waitAndCaptureProcessStandardErrorStream(jconsoleProcess);
if (StringUtils.isNotBlank(jconsoleProcessOutput)) {
message.append(StringUtils.LINE_SEPARATOR);
message.append(jconsoleProcessOutput);
}
}
return ResultBuilder.createInfoResult(message.toString());
} catch (GemFireException | IllegalStateException | IllegalArgumentException e) {
return ResultBuilder.createShellClientErrorResult(e.getMessage());
} catch (IOException e) {
return ResultBuilder.createShellClientErrorResult(CliStrings.START_JCONSOLE__IO_EXCEPTION_MESSAGE);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
return ResultBuilder.createShellClientErrorResult(String.format(CliStrings.START_JCONSOLE__CATCH_ALL_ERROR_MESSAGE, toString(t, false)));
}
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class StartJVisualVMCommand method startJVisualVM.
@CliCommand(value = CliStrings.START_JVISUALVM, help = CliStrings.START_JVISUALVM__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_MANAGER, CliStrings.TOPIC_GEODE_JMX, CliStrings.TOPIC_GEODE_M_AND_M })
public Result startJVisualVM(@CliOption(key = CliStrings.START_JCONSOLE__J, optionContext = GfshParser.J_OPTION_CONTEXT, help = CliStrings.START_JCONSOLE__J__HELP) final String[] jvmArgs) {
try {
String[] jvisualvmCommandLine = createJVisualVMCommandLine(jvmArgs);
if (isDebugging()) {
getGfsh().printAsInfo(String.format("JVisualVM command-line (%1$s)", Arrays.toString(jvisualvmCommandLine)));
}
Process jvisualvmProcess = Runtime.getRuntime().exec(jvisualvmCommandLine);
getGfsh().printAsInfo(CliStrings.START_JVISUALVM__RUN);
String jvisualvmProcessOutput = waitAndCaptureProcessStandardErrorStream(jvisualvmProcess);
InfoResultData infoResultData = ResultBuilder.createInfoResultData();
if (StringUtils.isNotBlank(jvisualvmProcessOutput)) {
infoResultData.addLine(StringUtils.LINE_SEPARATOR);
infoResultData.addLine(jvisualvmProcessOutput);
}
return ResultBuilder.buildResult(infoResultData);
} catch (GemFireException | IllegalStateException | IllegalArgumentException 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_JVISUALVM__ERROR_MESSAGE, toString(t, false)));
}
}
Aggregations