use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class DataCommands method query.
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
@MultiStepCommand
@CliCommand(value = { CliStrings.QUERY }, help = CliStrings.QUERY__HELP)
public Object query(@CliOption(key = CliStrings.QUERY__QUERY, help = CliStrings.QUERY__QUERY__HELP, mandatory = true) final String query, @CliOption(key = CliStrings.QUERY__STEPNAME, help = "Step name", unspecifiedDefaultValue = CliStrings.QUERY__STEPNAME__DEFAULTVALUE) String stepName, @CliOption(key = CliStrings.QUERY__INTERACTIVE, help = CliStrings.QUERY__INTERACTIVE__HELP, unspecifiedDefaultValue = "true") final boolean interactive) {
if (!CliUtil.isGfshVM() && stepName.equals(CliStrings.QUERY__STEPNAME__DEFAULTVALUE)) {
return ResultBuilder.createInfoResult(CliStrings.QUERY__MSG__NOT_SUPPORTED_ON_MEMBERS);
}
Object[] arguments = new Object[] { query, stepName, interactive };
CLIStep exec = new DataCommandFunction.SelectExecStep(arguments);
CLIStep display = new DataCommandFunction.SelectDisplayStep(arguments);
CLIStep move = new DataCommandFunction.SelectMoveStep(arguments);
CLIStep quit = new DataCommandFunction.SelectQuitStep(arguments);
CLIStep[] steps = { exec, display, move, quit };
return CLIMultiStepHelper.chooseStep(steps, stepName);
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class DataCommands method importData.
@CliCommand(value = CliStrings.IMPORT_DATA, help = CliStrings.IMPORT_DATA__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
public Result importData(@CliOption(key = CliStrings.IMPORT_DATA__REGION, optionContext = ConverterHint.REGION_PATH, mandatory = true, help = CliStrings.IMPORT_DATA__REGION__HELP) String regionName, @CliOption(key = CliStrings.IMPORT_DATA__FILE, mandatory = true, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.IMPORT_DATA__FILE__HELP) String filePath, @CliOption(key = CliStrings.IMPORT_DATA__MEMBER, mandatory = true, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.IMPORT_DATA__MEMBER__HELP) String memberNameOrId, @CliOption(key = CliStrings.IMPORT_DATA__INVOKE_CALLBACKS, unspecifiedDefaultValue = "false", help = CliStrings.IMPORT_DATA__INVOKE_CALLBACKS__HELP) boolean invokeCallbacks) {
this.securityService.authorizeRegionWrite(regionName);
Result result;
try {
final DistributedMember targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
if (!filePath.endsWith(CliStrings.GEODE_DATA_FILE_EXTENSION)) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, CliStrings.GEODE_DATA_FILE_EXTENSION));
}
if (targetMember != null) {
final Object[] args = { regionName, filePath, invokeCallbacks };
ResultCollector<?, ?> rc = CliUtil.executeFunction(importDataFunction, args, targetMember);
List<Object> results = (List<Object>) rc.getResult();
if (results != null) {
Object resultObj = results.get(0);
if (resultObj instanceof String) {
result = ResultBuilder.createInfoResult((String) resultObj);
} else if (resultObj instanceof Exception) {
result = ResultBuilder.createGemFireErrorResult(((Exception) resultObj).getMessage());
} else {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COMMAND_FAILURE_MESSAGE, CliStrings.IMPORT_DATA));
}
} else {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COMMAND_FAILURE_MESSAGE, CliStrings.IMPORT_DATA));
}
} else {
result = ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.IMPORT_DATA__MEMBER__NOT__FOUND, memberNameOrId));
}
} catch (CacheClosedException e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COMMAND_FAILURE_MESSAGE, CliStrings.IMPORT_DATA));
}
return result;
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class ConfigCommands method exportConfig.
/**
* Export the cache configuration in XML format.
*
* @param member Member for which to write the configuration
* @param group Group or groups for which to write the configuration
* @return Results of the attempt to write the configuration
*/
@CliCommand(value = { CliStrings.EXPORT_CONFIG }, help = CliStrings.EXPORT_CONFIG__HELP)
@CliMetaData(interceptor = "org.apache.geode.management.internal.cli.commands.ConfigCommands$Interceptor", relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result exportConfig(@CliOption(key = { CliStrings.EXPORT_CONFIG__MEMBER }, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.EXPORT_CONFIG__MEMBER__HELP) String[] member, @CliOption(key = { CliStrings.EXPORT_CONFIG__GROUP }, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.EXPORT_CONFIG__GROUP__HELP) String[] group, @CliOption(key = { CliStrings.EXPORT_CONFIG__DIR }, help = CliStrings.EXPORT_CONFIG__DIR__HELP) String dir) {
InfoResultData infoData = ResultBuilder.createInfoResultData();
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, member);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
try {
ResultCollector<?, ?> rc = CliUtil.executeFunction(this.exportConfigFunction, null, targetMembers);
List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
for (CliFunctionResult result : results) {
if (result.getThrowable() != null) {
infoData.addLine(CliStrings.format(CliStrings.EXPORT_CONFIG__MSG__EXCEPTION, result.getMemberIdOrName(), result.getThrowable()));
} else if (result.isSuccessful()) {
String cacheFileName = result.getMemberIdOrName() + "-cache.xml";
String propsFileName = result.getMemberIdOrName() + "-gf.properties";
String[] fileContent = (String[]) result.getSerializables();
infoData.addAsFile(cacheFileName, fileContent[0], "Downloading Cache XML file: {0}", false);
infoData.addAsFile(propsFileName, fileContent[1], "Downloading properties file: {0}", false);
}
}
return ResultBuilder.buildResult(infoData);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
th.printStackTrace(System.err);
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.EXPORT_CONFIG__MSG__EXCEPTION, th.getClass().getName() + ": " + th.getMessage()));
}
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class DiskStoreCommands method destroyDiskStore.
@CliCommand(value = CliStrings.DESTROY_DISK_STORE, help = CliStrings.DESTROY_DISK_STORE__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result destroyDiskStore(@CliOption(key = CliStrings.DESTROY_DISK_STORE__NAME, mandatory = true, help = CliStrings.DESTROY_DISK_STORE__NAME__HELP) String name, @CliOption(key = CliStrings.DESTROY_DISK_STORE__GROUP, help = CliStrings.DESTROY_DISK_STORE__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) String[] groups) {
try {
TabularResultData tabularData = ResultBuilder.createTabularResultData();
boolean accumulatedData = false;
Set<DistributedMember> targetMembers = CliUtil.findMembers(groups, null);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
ResultCollector<?, ?> rc = CliUtil.executeFunction(new DestroyDiskStoreFunction(), new Object[] { name }, targetMembers);
List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
for (CliFunctionResult result : results) {
if (result.getThrowable() != null) {
tabularData.accumulate("Member", result.getMemberIdOrName());
tabularData.accumulate("Result", "ERROR: " + result.getThrowable().getClass().getName() + ": " + result.getThrowable().getMessage());
accumulatedData = true;
tabularData.setStatus(Status.ERROR);
} else if (result.getMessage() != null) {
tabularData.accumulate("Member", result.getMemberIdOrName());
tabularData.accumulate("Result", result.getMessage());
accumulatedData = true;
if (xmlEntity.get() == null) {
xmlEntity.set(result.getXmlEntity());
}
}
}
if (!accumulatedData) {
return ResultBuilder.createInfoResult("No matching disk stores found.");
}
Result result = ResultBuilder.buildResult(tabularData);
if (xmlEntity.get() != null) {
persistClusterConfiguration(result, () -> getSharedConfiguration().deleteXmlEntity(xmlEntity.get(), groups));
}
return result;
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESTROY_DISK_STORE__ERROR_WHILE_DESTROYING_REASON_0, new Object[] { th.getMessage() }));
}
}
use of org.apache.geode.management.cli.CliMetaData in project geode by apache.
the class PDXCommands method configurePDX.
@CliCommand(value = CliStrings.CONFIGURE_PDX, help = CliStrings.CONFIGURE_PDX__HELP)
@CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result configurePDX(@CliOption(key = CliStrings.CONFIGURE_PDX__READ__SERIALIZED, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__READ__SERIALIZED__HELP) Boolean readSerialized, @CliOption(key = CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS__HELP) Boolean ignoreUnreadFields, @CliOption(key = CliStrings.CONFIGURE_PDX__DISKSTORE, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "", help = CliStrings.CONFIGURE_PDX__DISKSTORE__HELP) String diskStore, @CliOption(key = CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES__HELP) String[] patterns, @CliOption(key = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES__HELP) String[] portablePatterns) {
Result result = null;
try {
InfoResultData ird = ResultBuilder.createInfoResultData();
CacheCreation cache = new CacheCreation(true);
if ((portablePatterns != null && portablePatterns.length > 0) && (patterns != null && patterns.length > 0)) {
return ResultBuilder.createUserErrorResult(CliStrings.CONFIGURE_PDX__ERROR__MESSAGE);
}
if (!CliUtil.getAllNormalMembers(CliUtil.getCacheIfExists()).isEmpty()) {
ird.addLine(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING);
}
// Set persistent and the disk-store
if (diskStore != null) {
cache.setPdxPersistent(true);
ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent());
if (!diskStore.equals("")) {
cache.setPdxDiskStore(diskStore);
ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + cache.getPdxDiskStore());
} else {
ird.addLine(CliStrings.CONFIGURE_PDX__DISKSTORE + " = " + "DEFAULT");
}
} else {
cache.setPdxPersistent(CacheConfig.DEFAULT_PDX_PERSISTENT);
ird.addLine(CliStrings.CONFIGURE_PDX__PERSISTENT + " = " + cache.getPdxPersistent());
}
// Set read-serialized
if (readSerialized != null) {
cache.setPdxReadSerialized(readSerialized);
} else {
cache.setPdxReadSerialized(CacheConfig.DEFAULT_PDX_READ_SERIALIZED);
}
ird.addLine(CliStrings.CONFIGURE_PDX__READ__SERIALIZED + " = " + cache.getPdxReadSerialized());
// Set ingoreUnreadFields
if (ignoreUnreadFields != null) {
cache.setPdxIgnoreUnreadFields(ignoreUnreadFields);
} else {
cache.setPdxIgnoreUnreadFields(CacheConfig.DEFAULT_PDX_IGNORE_UNREAD_FIELDS);
}
ird.addLine(CliStrings.CONFIGURE_PDX__IGNORE__UNREAD_FIELDS + " = " + cache.getPdxIgnoreUnreadFields());
if (portablePatterns != null) {
ReflectionBasedAutoSerializer autoSerializer = new ReflectionBasedAutoSerializer(portablePatterns);
cache.setPdxSerializer(autoSerializer);
ird.addLine("PDX Serializer " + cache.getPdxSerializer().getClass().getName());
ird.addLine("Portable classes " + Arrays.toString(portablePatterns));
}
if (patterns != null) {
ReflectionBasedAutoSerializer nonPortableAutoSerializer = new ReflectionBasedAutoSerializer(true, patterns);
cache.setPdxSerializer(nonPortableAutoSerializer);
ird.addLine("PDX Serializer : " + cache.getPdxSerializer().getClass().getName());
ird.addLine("Non portable classes :" + Arrays.toString(patterns));
}
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
CacheXmlGenerator.generate(cache, printWriter, true, false, false);
printWriter.close();
String xmlDefinition = stringWriter.toString();
// TODO jbarrett - shouldn't this use the same loadXmlDefinition that other constructors use?
XmlEntity xmlEntity = XmlEntity.builder().withType(CacheXml.PDX).withConfig(xmlDefinition).build();
result = ResultBuilder.buildResult(ird);
persistClusterConfiguration(result, () -> getSharedConfiguration().addXmlEntity(xmlEntity, null));
} catch (Exception e) {
return ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
Aggregations