use of org.apache.geode.management.internal.cli.domain.DataCommandResult in project geode by apache.
the class DataCommandFunctionJUnitTest method testLocateKeyIsString.
@Test
public void testLocateKeyIsString() throws Exception {
DataCommandFunction dataCmdFn = new DataCommandFunction();
DataCommandResult result = dataCmdFn.locateEntry("key_2", String.class.getName(), String.class.getName(), PARTITIONED_REGION, false);
assertNotNull(result);
result.aggregate(null);
List<DataCommandResult.KeyInfo> keyInfos = result.getLocateEntryLocations();
assertEquals(1, keyInfos.size());
}
use of org.apache.geode.management.internal.cli.domain.DataCommandResult in project geode by apache.
the class DataCommands method remove.
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
@CliCommand(value = { CliStrings.REMOVE }, help = CliStrings.REMOVE__HELP)
public Result remove(@CliOption(key = { CliStrings.REMOVE__KEY }, help = CliStrings.REMOVE__KEY__HELP, specifiedDefaultValue = "") String key, @CliOption(key = { CliStrings.REMOVE__REGION }, mandatory = true, help = CliStrings.REMOVE__REGION__HELP, optionContext = ConverterHint.REGION_PATH) String regionPath, @CliOption(key = CliStrings.REMOVE__ALL, help = CliStrings.REMOVE__ALL__HELP, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean removeAllKeys, @CliOption(key = { CliStrings.REMOVE__KEYCLASS }, help = CliStrings.REMOVE__KEYCLASS__HELP) String keyClass) {
InternalCache cache = getCache();
DataCommandResult dataResult;
if (StringUtils.isEmpty(regionPath)) {
return makePresentationResult(DataCommandResult.createRemoveResult(key, null, null, CliStrings.REMOVE__MSG__REGIONNAME_EMPTY, false));
}
if (!removeAllKeys && (key == null)) {
return makePresentationResult(DataCommandResult.createRemoveResult(null, null, null, CliStrings.REMOVE__MSG__KEY_EMPTY, false));
}
if (removeAllKeys) {
this.securityService.authorizeRegionWrite(regionPath);
} else {
this.securityService.authorizeRegionWrite(regionPath, key);
}
@SuppressWarnings("rawtypes") Region region = cache.getRegion(regionPath);
DataCommandFunction removefn = new DataCommandFunction();
if (region == null) {
Set<DistributedMember> memberList = getRegionAssociatedMembers(regionPath, getCache(), false);
if (CollectionUtils.isNotEmpty(memberList)) {
DataCommandRequest request = new DataCommandRequest();
request.setCommand(CliStrings.REMOVE);
request.setKey(key);
request.setKeyClass(keyClass);
request.setRemoveAllKeys(removeAllKeys ? "ALL" : null);
request.setRegionName(regionPath);
dataResult = callFunctionForRegion(request, removefn, memberList);
} else {
dataResult = DataCommandResult.createRemoveInfoResult(key, null, null, CliStrings.format(CliStrings.REMOVE__MSG__REGION_NOT_FOUND_ON_ALL_MEMBERS, regionPath), false);
}
} else {
dataResult = removefn.remove(key, keyClass, regionPath, removeAllKeys ? "ALL" : null);
}
dataResult.setKeyClass(keyClass);
return makePresentationResult(dataResult);
}
use of org.apache.geode.management.internal.cli.domain.DataCommandResult in project geode by apache.
the class DataCommands method locateEntry.
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
@CliCommand(value = { CliStrings.LOCATE_ENTRY }, help = CliStrings.LOCATE_ENTRY__HELP)
public Result locateEntry(@CliOption(key = { CliStrings.LOCATE_ENTRY__KEY }, mandatory = true, help = CliStrings.LOCATE_ENTRY__KEY__HELP) String key, @CliOption(key = { CliStrings.LOCATE_ENTRY__REGIONNAME }, mandatory = true, help = CliStrings.LOCATE_ENTRY__REGIONNAME__HELP, optionContext = ConverterHint.REGION_PATH) String regionPath, @CliOption(key = { CliStrings.LOCATE_ENTRY__KEYCLASS }, help = CliStrings.LOCATE_ENTRY__KEYCLASS__HELP) String keyClass, @CliOption(key = { CliStrings.LOCATE_ENTRY__VALUEKLASS }, help = CliStrings.LOCATE_ENTRY__VALUEKLASS__HELP) String valueClass, @CliOption(key = { CliStrings.LOCATE_ENTRY__RECURSIVE }, help = CliStrings.LOCATE_ENTRY__RECURSIVE__HELP, unspecifiedDefaultValue = "false") boolean recursive) {
this.securityService.authorizeRegionRead(regionPath, key);
DataCommandResult dataResult;
if (StringUtils.isEmpty(regionPath)) {
return makePresentationResult(DataCommandResult.createLocateEntryResult(key, null, null, CliStrings.LOCATE_ENTRY__MSG__REGIONNAME_EMPTY, false));
}
if (StringUtils.isEmpty(key)) {
return makePresentationResult(DataCommandResult.createLocateEntryResult(key, null, null, CliStrings.LOCATE_ENTRY__MSG__KEY_EMPTY, false));
}
DataCommandFunction locateEntry = new DataCommandFunction();
Set<DistributedMember> memberList = getRegionAssociatedMembers(regionPath, getCache(), true);
if (CollectionUtils.isNotEmpty(memberList)) {
DataCommandRequest request = new DataCommandRequest();
request.setCommand(CliStrings.LOCATE_ENTRY);
request.setKey(key);
request.setKeyClass(keyClass);
request.setRegionName(regionPath);
request.setValueClass(valueClass);
request.setRecursive(recursive);
dataResult = callFunctionForRegion(request, locateEntry, memberList);
} else {
dataResult = DataCommandResult.createLocateEntryInfoResult(key, null, null, CliStrings.format(CliStrings.LOCATE_ENTRY__MSG__REGION_NOT_FOUND_ON_ALL_MEMBERS, regionPath), false);
}
dataResult.setKeyClass(keyClass);
if (valueClass != null) {
dataResult.setValueClass(valueClass);
}
return makePresentationResult(dataResult);
}
use of org.apache.geode.management.internal.cli.domain.DataCommandResult in project geode by apache.
the class DataCommands method get.
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
@CliCommand(value = { CliStrings.GET }, help = CliStrings.GET__HELP)
public Result get(@CliOption(key = { CliStrings.GET__KEY }, mandatory = true, help = CliStrings.GET__KEY__HELP) String key, @CliOption(key = { CliStrings.GET__REGIONNAME }, mandatory = true, help = CliStrings.GET__REGIONNAME__HELP, optionContext = ConverterHint.REGION_PATH) String regionPath, @CliOption(key = { CliStrings.GET__KEYCLASS }, help = CliStrings.GET__KEYCLASS__HELP) String keyClass, @CliOption(key = { CliStrings.GET__VALUEKLASS }, help = CliStrings.GET__VALUEKLASS__HELP) String valueClass, @CliOption(key = CliStrings.GET__LOAD, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true", help = CliStrings.GET__LOAD__HELP) Boolean loadOnCacheMiss) {
this.securityService.authorizeRegionRead(regionPath, key);
InternalCache cache = getCache();
DataCommandResult dataResult;
if (StringUtils.isEmpty(regionPath)) {
return makePresentationResult(DataCommandResult.createGetResult(key, null, null, CliStrings.GET__MSG__REGIONNAME_EMPTY, false));
}
if (StringUtils.isEmpty(key)) {
return makePresentationResult(DataCommandResult.createGetResult(key, null, null, CliStrings.GET__MSG__KEY_EMPTY, false));
}
@SuppressWarnings("rawtypes") Region region = cache.getRegion(regionPath);
DataCommandFunction getfn = new DataCommandFunction();
if (region == null) {
Set<DistributedMember> memberList = getRegionAssociatedMembers(regionPath, getCache(), false);
if (CollectionUtils.isNotEmpty(memberList)) {
DataCommandRequest request = new DataCommandRequest();
request.setCommand(CliStrings.GET);
request.setKey(key);
request.setKeyClass(keyClass);
request.setRegionName(regionPath);
request.setValueClass(valueClass);
request.setLoadOnCacheMiss(loadOnCacheMiss);
Subject subject = this.securityService.getSubject();
if (subject != null) {
request.setPrincipal(subject.getPrincipal());
}
dataResult = callFunctionForRegion(request, getfn, memberList);
} else {
dataResult = DataCommandResult.createGetInfoResult(key, null, null, CliStrings.format(CliStrings.GET__MSG__REGION_NOT_FOUND_ON_ALL_MEMBERS, regionPath), false);
}
} else {
dataResult = getfn.get(null, key, keyClass, valueClass, regionPath, loadOnCacheMiss);
}
dataResult.setKeyClass(keyClass);
if (valueClass != null) {
dataResult.setValueClass(valueClass);
}
return makePresentationResult(dataResult);
}
use of org.apache.geode.management.internal.cli.domain.DataCommandResult in project geode by apache.
the class DataCommandFunction method get.
@SuppressWarnings({ "rawtypes" })
public DataCommandResult get(Object principal, String key, String keyClass, String valueClass, String regionName, Boolean loadOnCacheMiss) {
InternalCache cache = getCache();
if (StringUtils.isEmpty(regionName)) {
return DataCommandResult.createGetResult(key, null, null, CliStrings.GET__MSG__REGIONNAME_EMPTY, false);
}
if (StringUtils.isEmpty(key)) {
return DataCommandResult.createGetResult(key, null, null, CliStrings.GET__MSG__KEY_EMPTY, false);
}
Region region = cache.getRegion(regionName);
if (region == null) {
if (logger.isDebugEnabled()) {
logger.debug("Region Not Found - {}", regionName);
}
return DataCommandResult.createGetResult(key, null, null, CliStrings.format(CliStrings.GET__MSG__REGION_NOT_FOUND, regionName), false);
} else {
Object keyObject;
try {
keyObject = getClassObject(key, keyClass);
} catch (ClassNotFoundException e) {
return DataCommandResult.createGetResult(key, null, null, "ClassNotFoundException " + keyClass, false);
} catch (IllegalArgumentException e) {
return DataCommandResult.createGetResult(key, null, null, "Error in converting JSON " + e.getMessage(), false);
}
// TODO determine whether the following conditional logic (assigned to 'doGet') is safer or
// necessary
boolean doGet = Boolean.TRUE.equals(loadOnCacheMiss);
if (doGet || region.containsKey(keyObject)) {
Object value = region.get(keyObject);
// run it through post processor. region.get will return the deserialized object already, so
// we don't need to
// deserialize it anymore to pass it to the postProcessor
value = securityService.postProcess(principal, regionName, keyObject, value, false);
if (logger.isDebugEnabled()) {
logger.debug("Get for key {} value {}", key, value);
}
// return DataCommandResult.createGetResult(key, value, null, null);
Object[] array = getJSONForNonPrimitiveObject(value);
if (value != null) {
DataCommandResult result = DataCommandResult.createGetResult(key, array[1], null, null, true);
if (array[0] != null) {
result.setValueClass((String) array[0]);
}
return result;
} else {
return DataCommandResult.createGetResult(key, array[1], null, null, false);
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Key is not present in the region {}", regionName);
}
return DataCommandResult.createGetInfoResult(key, null, null, CliStrings.GET__MSG__KEY_NOT_FOUND_REGION, false);
}
}
}
Aggregations