use of org.apache.geode.management.internal.security.ResourceOperation 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.internal.security.ResourceOperation 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.internal.security.ResourceOperation in project geode by apache.
the class IndexCommands method createDefinedIndexes.
@CliCommand(value = CliStrings.CREATE_DEFINED_INDEXES, help = CliStrings.CREATE_DEFINED__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public // TODO : Add optionContext for indexName
Result createDefinedIndexes(@CliOption(key = CliStrings.CREATE_DEFINED_INDEXES__MEMBER, mandatory = false, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.CREATE_DEFINED_INDEXES__MEMBER__HELP) final String[] memberNameOrID, @CliOption(key = CliStrings.CREATE_DEFINED_INDEXES__GROUP, mandatory = false, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.CREATE_DEFINED_INDEXES__GROUP__HELP) final String[] group) {
Result result = null;
AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
if (indexDefinitions.isEmpty()) {
final InfoResultData infoResult = ResultBuilder.createInfoResultData();
infoResult.addLine(CliStrings.DEFINE_INDEX__FAILURE__MSG);
return ResultBuilder.buildResult(infoResult);
}
try {
final Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrID);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
final Cache cache = CacheFactory.getAnyInstance();
final ResultCollector<?, ?> rc = CliUtil.executeFunction(createDefinedIndexesFunction, indexDefinitions, targetMembers);
final List<Object> funcResults = (List<Object>) rc.getResult();
final Set<String> successfulMembers = new TreeSet<String>();
final Map<String, Set<String>> indexOpFailMap = new HashMap<String, Set<String>>();
for (final Object funcResult : funcResults) {
if (funcResult instanceof CliFunctionResult) {
final CliFunctionResult cliFunctionResult = (CliFunctionResult) funcResult;
if (cliFunctionResult.isSuccessful()) {
successfulMembers.add(cliFunctionResult.getMemberIdOrName());
if (xmlEntity.get() == null) {
xmlEntity.set(cliFunctionResult.getXmlEntity());
}
} else {
final String exceptionMessage = cliFunctionResult.getMessage();
Set<String> failedMembers = indexOpFailMap.get(exceptionMessage);
if (failedMembers == null) {
failedMembers = new TreeSet<String>();
}
failedMembers.add(cliFunctionResult.getMemberIdOrName());
indexOpFailMap.put(exceptionMessage, failedMembers);
}
}
}
if (!successfulMembers.isEmpty()) {
final InfoResultData infoResult = ResultBuilder.createInfoResultData();
infoResult.addLine(CliStrings.CREATE_DEFINED_INDEXES__SUCCESS__MSG);
int num = 0;
for (final String memberId : successfulMembers) {
++num;
infoResult.addLine(CliStrings.format(CliStrings.CREATE_DEFINED_INDEXES__NUMBER__AND__MEMBER, num, memberId));
}
result = ResultBuilder.buildResult(infoResult);
} else {
// Group members by the exception thrown.
final ErrorResultData erd = ResultBuilder.createErrorResultData();
final Set<String> exceptionMessages = indexOpFailMap.keySet();
for (final String exceptionMessage : exceptionMessages) {
erd.addLine(exceptionMessage);
erd.addLine(CliStrings.CREATE_INDEX__EXCEPTION__OCCURRED__ON);
final Set<String> memberIds = indexOpFailMap.get(exceptionMessage);
int num = 0;
for (final String memberId : memberIds) {
++num;
erd.addLine(CliStrings.format(CliStrings.CREATE_DEFINED_INDEXES__NUMBER__AND__MEMBER, num, memberId));
}
}
result = ResultBuilder.buildResult(erd);
}
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
if (xmlEntity.get() != null) {
persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), group));
}
return result;
}
use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.
the class IndexCommands method clearDefinedIndexes.
@CliCommand(value = CliStrings.CLEAR_DEFINED_INDEXES, help = CliStrings.CLEAR_DEFINED__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public // TODO : Add optionContext for indexName
Result clearDefinedIndexes() {
indexDefinitions.clear();
final InfoResultData infoResult = ResultBuilder.createInfoResultData();
infoResult.addLine(CliStrings.CLEAR_DEFINED_INDEX__SUCCESS__MSG);
return ResultBuilder.buildResult(infoResult);
}
use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.
the class MiscellaneousCommands method exportStackTrace.
/**
* Current implementation supports writing it to a file and returning the location of the file
*/
@CliCommand(value = CliStrings.EXPORT_STACKTRACE, help = CliStrings.EXPORT_STACKTRACE__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result exportStackTrace(@CliOption(key = CliStrings.EXPORT_STACKTRACE__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.EXPORT_STACKTRACE__HELP) String[] memberNameOrId, @CliOption(key = CliStrings.EXPORT_STACKTRACE__GROUP, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.EXPORT_STACKTRACE__GROUP) String[] group, @CliOption(key = CliStrings.EXPORT_STACKTRACE__FILE, help = CliStrings.EXPORT_STACKTRACE__FILE__HELP) String fileName, @CliOption(key = CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT, unspecifiedDefaultValue = "false", help = CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT__HELP) boolean failIfFilePresent) {
Result result = null;
StringBuffer filePrefix = new StringBuffer("stacktrace");
if (fileName == null) {
fileName = filePrefix.append("_").append(System.currentTimeMillis()).toString();
}
final File outFile = new File(fileName);
try {
if (outFile.exists() && failIfFilePresent) {
return ResultBuilder.createShellClientErrorResult(CliStrings.format(CliStrings.EXPORT_STACKTRACE__ERROR__FILE__PRESENT, outFile.getCanonicalPath()));
}
InternalCache cache = getCache();
InternalDistributedSystem ads = cache.getInternalDistributedSystem();
InfoResultData resultData = ResultBuilder.createInfoResultData();
Map<String, byte[]> dumps = new HashMap<String, byte[]>();
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
ResultCollector<?, ?> rc = CliUtil.executeFunction(getStackTracesFunction, null, targetMembers);
ArrayList<Object> resultList = (ArrayList<Object>) rc.getResult();
for (Object resultObj : resultList) {
if (resultObj instanceof StackTracesPerMember) {
StackTracesPerMember stackTracePerMember = (StackTracesPerMember) resultObj;
dumps.put(stackTracePerMember.getMemberNameOrId(), stackTracePerMember.getStackTraces());
}
}
String filePath = writeStacksToFile(dumps, fileName);
resultData.addLine(CliStrings.format(CliStrings.EXPORT_STACKTRACE__SUCCESS, filePath));
resultData.addLine(CliStrings.EXPORT_STACKTRACE__HOST + ads.getDistributedMember().getHost());
result = ResultBuilder.buildResult(resultData);
} catch (IOException ex) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.EXPORT_STACKTRACE__ERROR + ex.getMessage());
}
return result;
}
Aggregations