com.gemstone.gemfire.internal.tools.gfsh.app.function.command.pr Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
The newest version!
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.internal.tools.gfsh.app.function.command;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.distributed.DistributedMember;
import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
import com.gemstone.gemfire.internal.cache.BucketRegion;
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
import com.gemstone.gemfire.internal.tools.gfsh.aggregator.AggregateResults;
import com.gemstone.gemfire.internal.tools.gfsh.app.ServerExecutable;
import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.MapMessage;
import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.Mappable;
import com.gemstone.gemfire.internal.tools.gfsh.app.function.GfshData;
public class pr implements ServerExecutable
{
private byte code = AggregateResults.CODE_NORMAL;
private String codeMessage = null;
public Object execute(String command, String regionPath, Object arg) throws Exception
{
Cache cache = CacheFactory.getAnyInstance();
Object args[] = (Object[])arg;
GfshData data = new GfshData(null);
try {
// Find the value from the partitioned region
if (regionPath == null || regionPath.equals("/")) {
code = AggregateResults.CODE_ERROR;
codeMessage = "Invalid region path " + regionPath;
return data;
}
Region region = cache.getRegion(regionPath);
if (region == null) {
code = AggregateResults.CODE_ERROR;
codeMessage = "Undefined region " + regionPath;
return data;
}
if (region instanceof PartitionedRegion == false) {
code = AggregateResults.CODE_ERROR;
codeMessage = "Not a partitioned region: " + regionPath;
return data;
}
DistributedMember member = cache.getDistributedSystem().getDistributedMember();
// PartitionRegionInfoImpl info = (PartitionRegionInfoImpl)PartitionRegionHelper.getPartitionRegionInfo(region);
// info.getLowRedundancyBucketCount();
PartitionedRegion pr = (PartitionedRegion)region;
if (pr.getDataStore() == null) {
// PROXY - no data store
code = AggregateResults.CODE_NORMAL;
codeMessage = "No data store: " + regionPath;
data.setUserData(pr.getPartitionAttributes().getTotalNumBuckets());
return data;
}
Set set2 = pr.getDataStore().getAllLocalBucketRegions();
// FindBugs - Unused
// TreeMap primaryMap = new TreeMap();
// TreeMap redundantMap = new TreeMap();
// for (BucketRegion br : set2) {
// TreeMap map = new TreeMap();
// map.put("Size", br.size());
// map.put("Bytes", br.getTotalBytes());
// InternalDistributedMember m = pr.getBucketPrimary(br.getId());
// if (m.getId().equals(member.getId())) {
// primaryMap.put(br.getId(), map);
// } else {
// redundantMap.put(br.getId(), map);
// }
// }
List primaryList = new ArrayList();
List redundantList = new ArrayList();
for (BucketRegion br : set2) {
MapMessage map = new MapMessage();
map.put("BucketId", br.getId());
map.put("Size", br.size());
map.put("Bytes", br.getTotalBytes());
InternalDistributedMember m = pr.getBucketPrimary(br.getId());
if (m.getId().equals(member.getId())) {
primaryList.add(map);
} else {
redundantList.add(map);
}
}
TreeMap map = new TreeMap();
// map.put("Primary", primaryMap);
// map.put("Redundant", redundantMap);
map.put("Primary", primaryList);
map.put("Redundant", redundantList);
data.setDataObject(map);
data.setUserData(pr.getPartitionAttributes().getTotalNumBuckets());
} catch (Exception ex) {
code = AggregateResults.CODE_ERROR;
codeMessage = ex.getMessage();
}
return data;
}
public byte getCode()
{
return code;
}
public String getCodeMessage()
{
return codeMessage;
}
}