use of org.apache.geode.management.internal.cli.result.InfoResultData 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;
}
use of org.apache.geode.management.internal.cli.result.InfoResultData in project geode by apache.
the class ShellCommands method disconnect.
@CliCommand(value = { CliStrings.DISCONNECT }, help = CliStrings.DISCONNECT__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GFSH, CliStrings.TOPIC_GEODE_JMX, CliStrings.TOPIC_GEODE_MANAGER })
public Result disconnect() {
Result result = null;
if (getGfsh() != null && !getGfsh().isConnectedAndReady()) {
result = ResultBuilder.createInfoResult("Not connected.");
} else {
InfoResultData infoResultData = ResultBuilder.createInfoResultData();
try {
Gfsh gfshInstance = getGfsh();
if (gfshInstance.isConnectedAndReady()) {
OperationInvoker operationInvoker = gfshInstance.getOperationInvoker();
Gfsh.println("Disconnecting from: " + operationInvoker);
operationInvoker.stop();
infoResultData.addLine(CliStrings.format(CliStrings.DISCONNECT__MSG__DISCONNECTED, operationInvoker.toString()));
LogWrapper.getInstance().info(CliStrings.format(CliStrings.DISCONNECT__MSG__DISCONNECTED, operationInvoker.toString()));
gfshInstance.setPromptPath(org.apache.geode.management.internal.cli.converters.RegionPathConverter.DEFAULT_APP_CONTEXT_PATH);
} else {
infoResultData.addLine(CliStrings.DISCONNECT__MSG__NOTCONNECTED);
}
result = ResultBuilder.buildResult(infoResultData);
} catch (Exception e) {
result = ResultBuilder.createConnectionErrorResult(CliStrings.format(CliStrings.DISCONNECT__MSG__ERROR, e.getMessage()));
}
}
return result;
}
use of org.apache.geode.management.internal.cli.result.InfoResultData 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)));
}
}
use of org.apache.geode.management.internal.cli.result.InfoResultData in project geode by apache.
the class IndexCommands method createIndex.
@CliCommand(value = CliStrings.CREATE_INDEX, help = CliStrings.CREATE_INDEX__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
public // TODO : Add optionContext for indexName
Result createIndex(@CliOption(key = CliStrings.CREATE_INDEX__NAME, mandatory = true, help = CliStrings.CREATE_INDEX__NAME__HELP) final String indexName, @CliOption(key = CliStrings.CREATE_INDEX__EXPRESSION, mandatory = true, help = CliStrings.CREATE_INDEX__EXPRESSION__HELP) final String indexedExpression, @CliOption(key = CliStrings.CREATE_INDEX__REGION, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = CliStrings.CREATE_INDEX__REGION__HELP) String regionPath, @CliOption(key = CliStrings.CREATE_INDEX__MEMBER, mandatory = false, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.CREATE_INDEX__MEMBER__HELP) final String[] memberNameOrID, @CliOption(key = CliStrings.CREATE_INDEX__TYPE, mandatory = false, unspecifiedDefaultValue = "range", optionContext = ConverterHint.INDEX_TYPE, help = CliStrings.CREATE_INDEX__TYPE__HELP) final String indexType, @CliOption(key = CliStrings.CREATE_INDEX__GROUP, mandatory = false, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.CREATE_INDEX__GROUP__HELP) final String[] group) {
Result result = null;
AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
this.securityService.authorizeRegionManage(regionPath);
try {
final Cache cache = CacheFactory.getAnyInstance();
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.CREATE_INDEX__INVALID__INDEX__TYPE__MESSAGE);
}
if (indexName == null || indexName.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__INDEX__NAME);
}
if (indexedExpression == null || indexedExpression.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__EXPRESSION);
}
if (StringUtils.isBlank(regionPath) || regionPath.equals(Region.SEPARATOR)) {
return ResultBuilder.createUserErrorResult(CliStrings.CREATE_INDEX__INVALID__REGIONPATH);
}
if (!regionPath.startsWith(Region.SEPARATOR)) {
regionPath = Region.SEPARATOR + regionPath;
}
IndexInfo indexInfo = new IndexInfo(indexName, indexedExpression, regionPath, idxType);
final Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrID);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
final ResultCollector<?, ?> rc = CliUtil.executeFunction(createIndexFunction, indexInfo, 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_INDEX__SUCCESS__MSG);
infoResult.addLine(CliStrings.format(CliStrings.CREATE_INDEX__NAME__MSG, indexName));
infoResult.addLine(CliStrings.format(CliStrings.CREATE_INDEX__EXPRESSION__MSG, indexedExpression));
infoResult.addLine(CliStrings.format(CliStrings.CREATE_INDEX__REGIONPATH__MSG, regionPath));
infoResult.addLine(CliStrings.CREATE_INDEX__MEMBER__MSG);
int num = 0;
for (final String memberId : successfulMembers) {
++num;
infoResult.addLine(CliStrings.format(CliStrings.CREATE_INDEX__NUMBER__AND__MEMBER, num, memberId));
}
result = ResultBuilder.buildResult(infoResult);
} else {
// Group members by the exception thrown.
final ErrorResultData erd = ResultBuilder.createErrorResultData();
erd.addLine(CliStrings.format(CliStrings.CREATE_INDEX__FAILURE__MSG, indexName));
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_INDEX__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.cli.result.InfoResultData 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