use of org.apache.geode.management.internal.cli.domain.DataCommandRequest 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.DataCommandRequest 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.DataCommandRequest 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.DataCommandRequest in project geode by apache.
the class DataCommandFunction method execute.
@Override
public void execute(FunctionContext functionContext) {
try {
InternalCache cache = getCache();
DataCommandRequest request = (DataCommandRequest) functionContext.getArguments();
if (logger.isDebugEnabled()) {
logger.debug("Executing function : \n{}\n on member {}", request, System.getProperty("memberName"));
}
DataCommandResult result = null;
if (request.isGet()) {
result = get(request);
} else if (request.isLocateEntry()) {
result = locateEntry(request);
} else if (request.isPut()) {
result = put(request);
} else if (request.isRemove()) {
result = remove(request);
} else if (request.isSelect()) {
result = select(request);
}
if (logger.isDebugEnabled()) {
logger.debug("Result is {}", result);
}
functionContext.getResultSender().lastResult(result);
} catch (Exception e) {
logger.info("Exception occurred:", e);
functionContext.getResultSender().sendException(e);
}
}
use of org.apache.geode.management.internal.cli.domain.DataCommandRequest in project geode by apache.
the class DataCommands method put.
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
@CliCommand(value = { CliStrings.PUT }, help = CliStrings.PUT__HELP)
public Result put(@CliOption(key = { CliStrings.PUT__KEY }, mandatory = true, help = CliStrings.PUT__KEY__HELP) String key, @CliOption(key = { CliStrings.PUT__VALUE }, mandatory = true, help = CliStrings.PUT__VALUE__HELP) String value, @CliOption(key = { CliStrings.PUT__REGIONNAME }, mandatory = true, help = CliStrings.PUT__REGIONNAME__HELP, optionContext = ConverterHint.REGION_PATH) String regionPath, @CliOption(key = { CliStrings.PUT__KEYCLASS }, help = CliStrings.PUT__KEYCLASS__HELP) String keyClass, @CliOption(key = { CliStrings.PUT__VALUEKLASS }, help = CliStrings.PUT__VALUEKLASS__HELP) String valueClass, @CliOption(key = { CliStrings.PUT__PUTIFABSENT }, help = CliStrings.PUT__PUTIFABSENT__HELP, unspecifiedDefaultValue = "false") boolean putIfAbsent) {
this.securityService.authorizeRegionWrite(regionPath);
InternalCache cache = getCache();
DataCommandResult dataResult;
if (StringUtils.isEmpty(regionPath)) {
return makePresentationResult(DataCommandResult.createPutResult(key, null, null, CliStrings.PUT__MSG__REGIONNAME_EMPTY, false));
}
if (StringUtils.isEmpty(key)) {
return makePresentationResult(DataCommandResult.createPutResult(key, null, null, CliStrings.PUT__MSG__KEY_EMPTY, false));
}
if (StringUtils.isEmpty(value)) {
return makePresentationResult(DataCommandResult.createPutResult(value, null, null, CliStrings.PUT__MSG__VALUE_EMPTY, false));
}
@SuppressWarnings("rawtypes") Region region = cache.getRegion(regionPath);
DataCommandFunction putfn = new DataCommandFunction();
if (region == null) {
Set<DistributedMember> memberList = getRegionAssociatedMembers(regionPath, getCache(), false);
if (CollectionUtils.isNotEmpty(memberList)) {
DataCommandRequest request = new DataCommandRequest();
request.setCommand(CliStrings.PUT);
request.setValue(value);
request.setKey(key);
request.setKeyClass(keyClass);
request.setRegionName(regionPath);
request.setValueClass(valueClass);
request.setPutIfAbsent(putIfAbsent);
dataResult = callFunctionForRegion(request, putfn, memberList);
} else {
dataResult = DataCommandResult.createPutInfoResult(key, value, null, CliStrings.format(CliStrings.PUT__MSG__REGION_NOT_FOUND_ON_ALL_MEMBERS, regionPath), false);
}
} else {
dataResult = putfn.put(key, value, putIfAbsent, keyClass, valueClass, regionPath);
}
dataResult.setKeyClass(keyClass);
if (valueClass != null) {
dataResult.setValueClass(valueClass);
}
return makePresentationResult(dataResult);
}
Aggregations