use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class FunctionCommands method destroyFunction.
@CliCommand(value = CliStrings.DESTROY_FUNCTION, help = CliStrings.DESTROY_FUNCTION__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_FUNCTION }, interceptor = "org.apache.geode.management.internal.cli.commands.FunctionCommands$Interceptor")
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public // TODO: Add optioncontext for functionId
Result destroyFunction(@CliOption(key = CliStrings.DESTROY_FUNCTION__ID, mandatory = true, help = CliStrings.DESTROY_FUNCTION__HELP) String functionId, @CliOption(key = CliStrings.DESTROY_FUNCTION__ONGROUPS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.DESTROY_FUNCTION__ONGROUPS__HELP) String[] groups, @CliOption(key = CliStrings.DESTROY_FUNCTION__ONMEMBER, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.DESTROY_FUNCTION__ONMEMBER__HELP) String memberId) {
Result result = null;
try {
InternalCache cache = getCache();
Set<DistributedMember> dsMembers = new HashSet<DistributedMember>();
if (groups != null && memberId != null) {
return ResultBuilder.createUserErrorResult(CliStrings.DESTROY_FUNCTION__MSG__PROVIDE_OPTION);
} else if (groups != null && groups.length > 0) {
// execute on group members
for (String grp : groups) {
dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(grp));
}
@SuppressWarnings("unchecked") Result results = executeFunction(cache, dsMembers, functionId);
return results;
} else if (memberId != null) {
// execute on member
dsMembers.add(getMember(cache, memberId));
@SuppressWarnings("unchecked") Result results = executeFunction(cache, dsMembers, functionId);
return results;
} else {
// no option provided.
@SuppressWarnings("unchecked") Result results = executeFunction(cache, cache.getMembers(), functionId);
return results;
}
} catch (Exception e) {
ErrorResultData errorResultData = ResultBuilder.createErrorResultData().setErrorCode(ResultBuilder.ERRORCODE_DEFAULT).addLine(e.getMessage());
result = ResultBuilder.buildResult(errorResultData);
return result;
}
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class IndexCommands method defineIndex.
@CliCommand(value = CliStrings.DEFINE_INDEX, help = CliStrings.DEFINE_INDEX__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
public // TODO : Add optionContext for indexName
Result defineIndex(@CliOption(key = CliStrings.DEFINE_INDEX_NAME, mandatory = true, help = CliStrings.DEFINE_INDEX__HELP) final String indexName, @CliOption(key = CliStrings.DEFINE_INDEX__EXPRESSION, mandatory = true, help = CliStrings.DEFINE_INDEX__EXPRESSION__HELP) final String indexedExpression, @CliOption(key = CliStrings.DEFINE_INDEX__REGION, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = CliStrings.DEFINE_INDEX__REGION__HELP) String regionPath, @CliOption(key = CliStrings.DEFINE_INDEX__TYPE, mandatory = false, unspecifiedDefaultValue = "range", optionContext = ConverterHint.INDEX_TYPE, help = CliStrings.DEFINE_INDEX__TYPE__HELP) final String indexType) {
Result result = null;
XmlEntity xmlEntity = null;
this.securityService.authorizeRegionManage(regionPath);
int idxType = IndexInfo.RANGE_INDEX;
// Index type check
if ("range".equalsIgnoreCase(indexType)) {
idxType = IndexInfo.RANGE_INDEX;
} else if ("hash".equalsIgnoreCase(indexType)) {
idxType = IndexInfo.HASH_INDEX;
} else if ("key".equalsIgnoreCase(indexType)) {
idxType = IndexInfo.KEY_INDEX;
} else {
return ResultBuilder.createUserErrorResult(CliStrings.DEFINE_INDEX__INVALID__INDEX__TYPE__MESSAGE);
}
if (indexName == null || indexName.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.DEFINE_INDEX__INVALID__INDEX__NAME);
}
if (indexedExpression == null || indexedExpression.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.DEFINE_INDEX__INVALID__EXPRESSION);
}
if (StringUtils.isBlank(regionPath) || regionPath.equals(Region.SEPARATOR)) {
return ResultBuilder.createUserErrorResult(CliStrings.DEFINE_INDEX__INVALID__REGIONPATH);
}
if (!regionPath.startsWith(Region.SEPARATOR)) {
regionPath = Region.SEPARATOR + regionPath;
}
IndexInfo indexInfo = new IndexInfo(indexName, indexedExpression, regionPath, idxType);
indexDefinitions.add(indexInfo);
final InfoResultData infoResult = ResultBuilder.createInfoResultData();
infoResult.addLine(CliStrings.DEFINE_INDEX__SUCCESS__MSG);
infoResult.addLine(CliStrings.format(CliStrings.DEFINE_INDEX__NAME__MSG, indexName));
infoResult.addLine(CliStrings.format(CliStrings.DEFINE_INDEX__EXPRESSION__MSG, indexedExpression));
infoResult.addLine(CliStrings.format(CliStrings.DEFINE_INDEX__REGIONPATH__MSG, regionPath));
result = ResultBuilder.buildResult(infoResult);
return result;
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class DiskStoreCommands method upgradeOfflineDiskStore.
@CliCommand(value = CliStrings.UPGRADE_OFFLINE_DISK_STORE, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
public Result upgradeOfflineDiskStore(@CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__NAME, mandatory = true, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__NAME__HELP) String diskStoreName, @CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS, mandatory = true, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS__HELP) String[] diskDirs, @CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE, unspecifiedDefaultValue = "-1", help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE__HELP) long maxOplogSize, @CliOption(key = CliStrings.UPGRADE_OFFLINE_DISK_STORE__J, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.UPGRADE_OFFLINE_DISK_STORE__J__HELP) String[] jvmProps) throws InterruptedException {
Result result = null;
LogWrapper logWrapper = LogWrapper.getInstance();
StringBuilder output = new StringBuilder();
StringBuilder error = new StringBuilder();
String errorMessage = "";
Process upgraderProcess = null;
try {
String validatedDirectories = validatedDirectories(diskDirs);
if (validatedDirectories != null) {
throw new IllegalArgumentException("Could not find " + CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS + ": \"" + validatedDirectories + "\"");
}
List<String> commandList = new ArrayList<String>();
commandList.add(System.getProperty("java.home") + File.separatorChar + "bin" + File.separatorChar + "java");
configureLogging(commandList);
if (jvmProps != null && jvmProps.length != 0) {
for (int i = 0; i < jvmProps.length; i++) {
commandList.add(jvmProps[i]);
}
}
commandList.add("-classpath");
commandList.add(System.getProperty("java.class.path", "."));
commandList.add(DiskStoreUpgrader.class.getName());
commandList.add(CliStrings.UPGRADE_OFFLINE_DISK_STORE__NAME + "=" + diskStoreName);
if (diskDirs != null && diskDirs.length != 0) {
StringBuilder builder = new StringBuilder();
int arrayLength = diskDirs.length;
for (int i = 0; i < arrayLength; i++) {
if (File.separatorChar == '\\') {
// see 46120
builder.append(diskDirs[i].replace("\\", "/"));
} else {
builder.append(diskDirs[i]);
}
if (i + 1 != arrayLength) {
builder.append(',');
}
}
commandList.add(CliStrings.UPGRADE_OFFLINE_DISK_STORE__DISKDIRS + "=" + builder.toString());
}
// -1 is ignore as maxOplogSize
commandList.add(CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE + "=" + maxOplogSize);
ProcessBuilder procBuilder = new ProcessBuilder(commandList);
// procBuilder.redirectErrorStream(true);
upgraderProcess = procBuilder.start();
InputStream inputStream = upgraderProcess.getInputStream();
InputStream errorStream = upgraderProcess.getErrorStream();
BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream));
BufferedReader errorReader = new BufferedReader(new InputStreamReader(errorStream));
String line = null;
while ((line = inputReader.readLine()) != null) {
output.append(line).append(GfshParser.LINE_SEPARATOR);
}
line = null;
boolean switchToStackTrace = false;
while ((line = errorReader.readLine()) != null) {
if (!switchToStackTrace && DiskStoreUpgrader.STACKTRACE_START.equals(line)) {
switchToStackTrace = true;
} else if (switchToStackTrace) {
error.append(line).append(GfshParser.LINE_SEPARATOR);
} else {
errorMessage = errorMessage + line;
}
}
if (!errorMessage.isEmpty()) {
throw new GemFireIOException(errorMessage);
}
upgraderProcess.destroy();
result = ResultBuilder.createInfoResult(output.toString());
} catch (IOException e) {
if (output.length() != 0) {
Gfsh.println(output.toString());
}
String fieldsMessage = (maxOplogSize != -1 ? CliStrings.UPGRADE_OFFLINE_DISK_STORE__MAXOPLOGSIZE + "=" + maxOplogSize + "," : "");
fieldsMessage += CliUtil.arrayToString(diskDirs);
String errorString = CliStrings.format(CliStrings.UPGRADE_OFFLINE_DISK_STORE__MSG__ERROR_WHILE_COMPACTING_DISKSTORE_0_WITH_1_REASON_2, new Object[] { diskStoreName, fieldsMessage });
result = ResultBuilder.createUserErrorResult(errorString);
if (logWrapper.fineEnabled()) {
logWrapper.fine(e.getMessage(), e);
}
} catch (GemFireIOException e) {
if (output.length() != 0) {
Gfsh.println(output.toString());
}
result = ResultBuilder.createUserErrorResult(errorMessage);
if (logWrapper.fineEnabled()) {
logWrapper.fine(error.toString());
}
} catch (IllegalArgumentException e) {
if (output.length() != 0) {
Gfsh.println(output.toString());
}
result = ResultBuilder.createUserErrorResult(e.getMessage());
} finally {
if (upgraderProcess != null) {
try {
// just to check whether the process has exited
// Process.exitValue() throws IllegalStateException if Process is alive
upgraderProcess.exitValue();
} catch (IllegalThreadStateException itse) {
// not yet terminated, destroy the process
upgraderProcess.destroy();
}
}
}
return result;
}
use of org.apache.geode.management.cli.CliMetaData 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.cli.CliMetaData 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;
}
Aggregations