use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.
the class DurableClientCommands method closeDurableCqs.
@CliCommand(value = CliStrings.CLOSE_DURABLE_CQS, help = CliStrings.CLOSE_DURABLE_CQS__HELP)
@CliMetaData(shellOnly = false)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result closeDurableCqs(@CliOption(key = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, mandatory = true, help = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID__HELP) final String durableClientId, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__NAME, mandatory = true, help = CliStrings.CLOSE_DURABLE_CQS__NAME__HELP) final String cqName, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__MEMBER, mandatory = false, help = CliStrings.CLOSE_DURABLE_CQS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__GROUP, mandatory = false, help = CliStrings.CLOSE_DURABLE_CQS__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) final String[] group) {
Result result = null;
try {
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
String[] params = new String[2];
params[0] = durableClientId;
params[1] = cqName;
final ResultCollector<?, ?> rc = CliUtil.executeFunction(new CloseDurableCqFunction(), params, targetMembers);
final List<MemberResult> results = (List<MemberResult>) rc.getResult();
String failureHeader = CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__FAILURE__HEADER, cqName, durableClientId);
String successHeader = CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__SUCCESS, cqName, durableClientId);
result = buildResult(results, successHeader, failureHeader);
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.
the class MiscellaneousCommands method showMetrics.
@CliCommand(value = CliStrings.SHOW_METRICS, help = CliStrings.SHOW_METRICS__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_STATISTICS })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result showMetrics(@CliOption(key = { CliStrings.SHOW_METRICS__MEMBER }, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.SHOW_METRICS__MEMBER__HELP) String memberNameOrId, @CliOption(key = { CliStrings.SHOW_METRICS__REGION }, optionContext = ConverterHint.REGION_PATH, help = CliStrings.SHOW_METRICS__REGION__HELP) String regionName, @CliOption(key = { CliStrings.SHOW_METRICS__FILE }, help = CliStrings.SHOW_METRICS__FILE__HELP) String export_to_report_to, @CliOption(key = { CliStrings.SHOW_METRICS__CACHESERVER__PORT }, help = CliStrings.SHOW_METRICS__CACHESERVER__PORT__HELP) String cacheServerPortString, @CliOption(key = { CliStrings.SHOW_METRICS__CATEGORY }, help = CliStrings.SHOW_METRICS__CATEGORY__HELP) String[] categories) {
Result result = null;
try {
if (export_to_report_to != null && !export_to_report_to.isEmpty()) {
if (!export_to_report_to.endsWith(".csv")) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, ".csv"));
}
}
if (regionName != null && !regionName.isEmpty()) {
if (!org.apache.geode.internal.lang.StringUtils.isBlank(cacheServerPortString)) {
return ResultBuilder.createUserErrorResult(CliStrings.SHOW_METRICS__CANNOT__USE__CACHESERVERPORT);
}
// MBean names contain the forward slash
if (!regionName.startsWith("/")) {
regionName = "/" + regionName;
}
if (memberNameOrId == null || memberNameOrId.isEmpty()) {
result = ResultBuilder.buildResult(getDistributedRegionMetrics(regionName, export_to_report_to, categories));
} else {
DistributedMember member = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
if (member != null) {
result = ResultBuilder.buildResult(getRegionMetricsFromMember(regionName, member, export_to_report_to, categories));
} else {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, memberNameOrId));
result = ResultBuilder.buildResult(erd);
}
}
} else if (memberNameOrId != null && !memberNameOrId.isEmpty()) {
DistributedMember member = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
if (member != null) {
int cacheServerPort = -1;
if (cacheServerPortString != null && !cacheServerPortString.isEmpty()) {
try {
cacheServerPort = Integer.parseInt(cacheServerPortString);
} catch (NumberFormatException nfe) {
return ResultBuilder.createUserErrorResult("Invalid port");
}
}
result = ResultBuilder.buildResult(getMemberMetrics(member, export_to_report_to, categories, cacheServerPort));
} else {
ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, memberNameOrId));
result = ResultBuilder.buildResult(erd);
}
} else {
if (!org.apache.geode.internal.lang.StringUtils.isBlank(cacheServerPortString)) {
return ResultBuilder.createUserErrorResult(CliStrings.SHOW_METRICS__CANNOT__USE__CACHESERVERPORT);
}
result = ResultBuilder.buildResult(getSystemWideMetrics(export_to_report_to, categories));
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResultBuilder.createGemFireErrorResult(CliUtil.stackTraceAsString(e));
}
return result;
}
use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.
the class PDXCommands method pdxRename.
@CliCommand(value = CliStrings.PDX_RENAME, help = CliStrings.PDX_RENAME__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result pdxRename(@CliOption(key = CliStrings.PDX_RENAME_OLD, mandatory = true, help = CliStrings.PDX_RENAME_OLD__HELP) String oldClassName, @CliOption(key = CliStrings.PDX_RENAME_NEW, mandatory = true, help = CliStrings.PDX_RENAME_NEW__HELP) String newClassName, @CliOption(key = CliStrings.PDX_DISKSTORE, mandatory = true, help = CliStrings.PDX_DISKSTORE__HELP) String diskStore, @CliOption(key = CliStrings.PDX_DISKDIR, mandatory = true, help = CliStrings.PDX_DISKDIR__HELP) String[] diskDirs) {
try {
final File[] dirs = new File[diskDirs.length];
for (int i = 0; i < diskDirs.length; i++) {
dirs[i] = new File((diskDirs[i]));
}
Collection<Object> results = DiskStoreImpl.pdxRename(diskStore, dirs, oldClassName, newClassName);
if (results.isEmpty()) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.PDX_RENAME__EMPTY));
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream);
for (Object p : results) {
if (p instanceof PdxType) {
((PdxType) p).toStream(printStream, false);
} else {
((EnumInfo) p).toStream(printStream);
}
}
String resultString = CliStrings.format(CliStrings.PDX_RENAME__SUCCESS, outputStream.toString());
return ResultBuilder.createInfoResult(resultString.toString());
} catch (Exception e) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.PDX_RENAME__ERROR, e.getMessage()));
}
}
use of org.apache.geode.management.internal.security.ResourceOperation in project geode by apache.
the class LuceneIndexCommands method searchIndex.
@CliCommand(value = LuceneCliStrings.LUCENE_SEARCH_INDEX, help = LuceneCliStrings.LUCENE_SEARCH_INDEX__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
@ResourceOperation(resource = Resource.DATA, operation = Operation.WRITE)
public Result searchIndex(@CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, mandatory = true, help = LuceneCliStrings.LUCENE_SEARCH_INDEX__NAME__HELP) final String indexName, @CliOption(key = LuceneCliStrings.LUCENE__REGION_PATH, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = LuceneCliStrings.LUCENE_SEARCH_INDEX__REGION_HELP) final String regionPath, @CliOption(key = LuceneCliStrings.LUCENE_SEARCH_INDEX__QUERY_STRING, mandatory = true, help = LuceneCliStrings.LUCENE_SEARCH_INDEX__QUERY_STRING__HELP) final String queryString, @CliOption(key = LuceneCliStrings.LUCENE_SEARCH_INDEX__DEFAULT_FIELD, mandatory = true, help = LuceneCliStrings.LUCENE_SEARCH_INDEX__DEFAULT_FIELD__HELP) final String defaultField, @CliOption(key = LuceneCliStrings.LUCENE_SEARCH_INDEX__LIMIT, unspecifiedDefaultValue = "-1", help = LuceneCliStrings.LUCENE_SEARCH_INDEX__LIMIT__HELP) final int limit, @CliOption(key = LuceneCliStrings.LUCENE_SEARCH_INDEX__KEYSONLY, unspecifiedDefaultValue = "false", help = LuceneCliStrings.LUCENE_SEARCH_INDEX__KEYSONLY__HELP) boolean keysOnly) {
try {
LuceneQueryInfo queryInfo = new LuceneQueryInfo(indexName, regionPath, queryString, defaultField, limit, keysOnly);
int pageSize = Integer.MAX_VALUE;
searchResults = getSearchResults(queryInfo);
return displayResults(pageSize, keysOnly);
} catch (FunctionInvocationTargetException ignore) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, LuceneCliStrings.LUCENE_SEARCH_INDEX));
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (IllegalArgumentException e) {
return ResultBuilder.createInfoResult(e.getMessage());
} catch (Throwable t) {
SystemFailure.checkFailure();
getCache().getLogger().info(t);
return ResultBuilder.createGemFireErrorResult(String.format(LuceneCliStrings.LUCENE_SEARCH_INDEX__ERROR_MESSAGE, toString(t, isDebugging())));
}
}
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;
}
Aggregations