Search in sources :

Example 36 with RebalanceResults

use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.

the class RebalanceFunction method execute.

@Override
public void execute(FunctionContext context) {
    RebalanceOperation op = null;
    String[] str = new String[0];
    Cache cache = CacheFactory.getAnyInstance();
    ResourceManager manager = cache.getResourceManager();
    Object[] args = (Object[]) context.getArguments();
    String simulate = ((String) args[0]);
    Set<String> includeRegionNames = (Set<String>) args[1];
    Set<String> excludeRegionNames = (Set<String>) args[2];
    RebalanceFactory rbFactory = manager.createRebalanceFactory();
    rbFactory.excludeRegions(excludeRegionNames);
    rbFactory.includeRegions(includeRegionNames);
    RebalanceResults results = null;
    if (simulate.equals("true")) {
        op = rbFactory.simulate();
    } else {
        op = rbFactory.start();
    }
    try {
        results = op.getResults();
        logger.info("Starting RebalanceFunction got results = {}", results);
        StringBuilder str1 = new StringBuilder();
        str1.append(results.getTotalBucketCreateBytes() + "," + results.getTotalBucketCreateTime() + "," + results.getTotalBucketCreatesCompleted() + "," + results.getTotalBucketTransferBytes() + "," + results.getTotalBucketTransferTime() + "," + results.getTotalBucketTransfersCompleted() + "," + results.getTotalPrimaryTransferTime() + "," + results.getTotalPrimaryTransfersCompleted() + "," + results.getTotalTime() + ",");
        Set<PartitionRebalanceInfo> regns1 = results.getPartitionRebalanceDetails();
        Iterator it = regns1.iterator();
        while (it.hasNext()) {
            PartitionRebalanceInfo rgn = (PartitionRebalanceInfo) it.next();
            str1.append(rgn.getRegionPath() + ",");
        }
        logger.info("Starting RebalanceFunction str1={}", str1);
        context.getResultSender().lastResult(str1.toString());
    } catch (CancellationException e) {
        logger.info("Starting RebalanceFunction CancellationException: ", e.getMessage(), e);
        context.getResultSender().lastResult("CancellationException1 " + e.getMessage());
    } catch (InterruptedException e) {
        logger.info("Starting RebalanceFunction InterruptedException: {}", e.getMessage(), e);
        context.getResultSender().lastResult("InterruptedException2 " + e.getMessage());
    }
}
Also used : RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) Set(java.util.Set) PartitionRebalanceInfo(org.apache.geode.cache.partition.PartitionRebalanceInfo) ResourceManager(org.apache.geode.cache.control.ResourceManager) RebalanceFactory(org.apache.geode.cache.control.RebalanceFactory) CancellationException(java.util.concurrent.CancellationException) Iterator(java.util.Iterator) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) Cache(org.apache.geode.cache.Cache)

Example 37 with RebalanceResults

use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.

the class TestFunction method executeWithLastResult.

private void executeWithLastResult(FunctionContext context) {
    RegionFunctionContext rfContext = (RegionFunctionContext) context;
    final PartitionedRegion pr = (PartitionedRegion) rfContext.getDataSet();
    ResourceManager resMan = pr.getCache().getResourceManager();
    RebalanceFactory factory = resMan.createRebalanceFactory();
    RebalanceOperation rebalanceOp = factory.start();
    try {
        RebalanceResults rebalanceResults = rebalanceOp.getResults();
    } catch (CancellationException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    context.getResultSender().lastResult((Serializable) context.getArguments());
}
Also used : RebalanceFactory(org.apache.geode.cache.control.RebalanceFactory) RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) CancellationException(java.util.concurrent.CancellationException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) ResourceManager(org.apache.geode.cache.control.ResourceManager) RebalanceResults(org.apache.geode.cache.control.RebalanceResults)

Example 38 with RebalanceResults

use of org.apache.geode.cache.control.RebalanceResults in project geode by apache.

the class LuceneQueriesAccessorBase method rebalanceRegion.

protected void rebalanceRegion(VM vm) {
    // Do a rebalance
    vm.invoke(() -> {
        RebalanceOperation op = getCache().getResourceManager().createRebalanceFactory().start();
        RebalanceResults results = op.getResults();
    });
}
Also used : RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) RebalanceResults(org.apache.geode.cache.control.RebalanceResults)

Aggregations

RebalanceResults (org.apache.geode.cache.control.RebalanceResults)38 Cache (org.apache.geode.cache.Cache)26 Host (org.apache.geode.test.dunit.Host)26 VM (org.apache.geode.test.dunit.VM)26 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)25 Region (org.apache.geode.cache.Region)22 ResourceManager (org.apache.geode.cache.control.ResourceManager)22 PartitionRebalanceInfo (org.apache.geode.cache.partition.PartitionRebalanceInfo)21 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)21 BucketRegion (org.apache.geode.internal.cache.BucketRegion)20 PartitionRegionInfo (org.apache.geode.cache.partition.PartitionRegionInfo)19 Set (java.util.Set)18 AttributesFactory (org.apache.geode.cache.AttributesFactory)18 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)18 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)18 HashSet (java.util.HashSet)16 TreeSet (java.util.TreeSet)16 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)16 RebalanceOperation (org.apache.geode.cache.control.RebalanceOperation)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)10