Search in sources :

Example 11 with DataCommandResult

use of org.apache.geode.management.internal.cli.domain.DataCommandResult 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);
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) Region(org.apache.geode.cache.Region) DataCommandRequest(org.apache.geode.management.internal.cli.domain.DataCommandRequest) DataCommandResult(org.apache.geode.management.internal.cli.domain.DataCommandResult) DataCommandFunction(org.apache.geode.management.internal.cli.functions.DataCommandFunction) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 12 with DataCommandResult

use of org.apache.geode.management.internal.cli.domain.DataCommandResult in project geode by apache.

the class DataCommandFunctionJUnitTest method testLocateKeyIsObject.

/*
   * This test addresses GEODE-184
   */
@Test
public void testLocateKeyIsObject() throws Exception {
    DataCommandFunction dataCmdFn = new DataCommandFunction();
    DataCommandResult result = dataCmdFn.locateEntry("{'cheese': 'key_1'}", StringCheese.class.getName(), String.class.getName(), PARTITIONED_REGION, false);
    assertNotNull(result);
    result.aggregate(null);
    List<DataCommandResult.KeyInfo> keyInfos = result.getLocateEntryLocations();
    assertEquals(1, keyInfos.size());
}
Also used : DataCommandResult(org.apache.geode.management.internal.cli.domain.DataCommandResult) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with DataCommandResult

use of org.apache.geode.management.internal.cli.domain.DataCommandResult in project geode by apache.

the class DataCommandFunctionWithPDXJUnitTest method getTableFromQuery.

private TabularResultData getTableFromQuery(String query) {
    DataCommandRequest request = new DataCommandRequest();
    request.setQuery(query);
    DataCommandResult result = new DataCommandFunction().select(request);
    CompositeResultData r = result.toSelectCommandResult();
    return r.retrieveSectionByIndex(0).retrieveTableByIndex(0);
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) DataCommandRequest(org.apache.geode.management.internal.cli.domain.DataCommandRequest) DataCommandResult(org.apache.geode.management.internal.cli.domain.DataCommandResult)

Aggregations

DataCommandResult (org.apache.geode.management.internal.cli.domain.DataCommandResult)13 InternalCache (org.apache.geode.internal.cache.InternalCache)8 Region (org.apache.geode.cache.Region)7 DistributedMember (org.apache.geode.distributed.DistributedMember)6 DataCommandRequest (org.apache.geode.management.internal.cli.domain.DataCommandRequest)6 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)4 CliMetaData (org.apache.geode.management.cli.CliMetaData)4 DataCommandFunction (org.apache.geode.management.internal.cli.functions.DataCommandFunction)4 GfJsonObject (org.apache.geode.management.internal.cli.json.GfJsonObject)4 CliCommand (org.springframework.shell.core.annotation.CliCommand)4 ArrayList (java.util.ArrayList)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 List (java.util.List)1 DataPolicy (org.apache.geode.cache.DataPolicy)1 ResultCollector (org.apache.geode.cache.execute.ResultCollector)1 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)1 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)1 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)1