Search in sources :

Example 1 with ColocatedRegionDetails

use of org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails in project geode by apache.

the class DiskStoreCommands method toMissingDiskStoresTabularResult.

protected Result toMissingDiskStoresTabularResult(final List<Object> resultDetails) throws ResultDataException {
    CompositeResultData crd = ResultBuilder.createCompositeResultData();
    List<PersistentMemberPattern> missingDiskStores = new ArrayList<PersistentMemberPattern>();
    List<ColocatedRegionDetails> missingColocatedRegions = new ArrayList<ColocatedRegionDetails>();
    for (Object detail : resultDetails) {
        if (detail instanceof PersistentMemberPattern) {
            missingDiskStores.add((PersistentMemberPattern) detail);
        } else if (detail instanceof ColocatedRegionDetails) {
            missingColocatedRegions.add((ColocatedRegionDetails) detail);
        } else {
            throw new ResultDataException("Unknown type of PersistentRecoveryFailures result");
        }
    }
    boolean hasMissingDiskStores = !missingDiskStores.isEmpty();
    boolean hasMissingColocatedRegions = !missingColocatedRegions.isEmpty();
    if (hasMissingDiskStores) {
        SectionResultData missingDiskStoresSection = crd.addSection();
        missingDiskStoresSection.setHeader("Missing Disk Stores");
        TabularResultData missingDiskStoreData = missingDiskStoresSection.addTable();
        for (PersistentMemberPattern peristentMemberDetails : missingDiskStores) {
            missingDiskStoreData.accumulate("Disk Store ID", peristentMemberDetails.getUUID());
            missingDiskStoreData.accumulate("Host", peristentMemberDetails.getHost());
            missingDiskStoreData.accumulate("Directory", peristentMemberDetails.getDirectory());
        }
    } else {
        SectionResultData noMissingDiskStores = crd.addSection();
        noMissingDiskStores.setHeader("No missing disk store found");
    }
    if (hasMissingDiskStores || hasMissingColocatedRegions) {
        // For clarity, separate disk store and colocated region information
        crd.addSection().setHeader("\n");
    }
    if (hasMissingColocatedRegions) {
        SectionResultData missingRegionsSection = crd.addSection();
        missingRegionsSection.setHeader("Missing Colocated Regions");
        TabularResultData missingRegionData = missingRegionsSection.addTable();
        for (ColocatedRegionDetails colocatedRegionDetails : missingColocatedRegions) {
            missingRegionData.accumulate("Host", colocatedRegionDetails.getHost());
            missingRegionData.accumulate("Distributed Member", colocatedRegionDetails.getMember());
            missingRegionData.accumulate("Parent Region", colocatedRegionDetails.getParent());
            missingRegionData.accumulate("Missing Colocated Region", colocatedRegionDetails.getChild());
        }
    } else {
        SectionResultData noMissingColocatedRegions = crd.addSection();
        noMissingColocatedRegions.setHeader("No missing colocated region found");
    }
    return ResultBuilder.buildResult(crd);
}
Also used : PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ColocatedRegionDetails(org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) ArrayList(java.util.ArrayList) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 2 with ColocatedRegionDetails

use of org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails in project geode by apache.

the class ShowMissingDiskStoresFunction method execute.

@Override
public void execute(FunctionContext context) {
    final Set<PersistentMemberPattern> memberMissingIDs = new HashSet<PersistentMemberPattern>();
    Set<ColocatedRegionDetails> missingColocatedRegions = new HashSet<ColocatedRegionDetails>();
    if (context == null) {
        throw new RuntimeException();
    }
    try {
        final InternalCache cache = getCache();
        if (cache != null && !cache.isClosed()) {
            final DistributedMember member = cache.getMyId();
            // Missing DiskStores
            PersistentMemberManager mm = cache.getPersistentMemberManager();
            Map<String, Set<PersistentMemberID>> waitingRegions = mm.getWaitingRegions();
            for (Set<PersistentMemberID> entry : waitingRegions.values()) {
                for (PersistentMemberID id : entry) {
                    memberMissingIDs.add(new PersistentMemberPattern(id));
                }
            }
            // Missing colocated regions
            Set<PartitionedRegion> prs = cache.getPartitionedRegions();
            for (PartitionedRegion pr : prs) {
                List<String> missingChildRegions = pr.getMissingColocatedChildren();
                for (String child : missingChildRegions) {
                    missingColocatedRegions.add(new ColocatedRegionDetails(member.getHost(), member.getName(), pr.getFullPath(), child));
                }
            }
        }
        if (memberMissingIDs.isEmpty() && missingColocatedRegions.isEmpty()) {
            context.getResultSender().lastResult(null);
        } else {
            if (!memberMissingIDs.isEmpty()) {
                if (missingColocatedRegions.isEmpty()) {
                    context.getResultSender().lastResult(memberMissingIDs);
                } else {
                    context.getResultSender().sendResult(memberMissingIDs);
                }
            }
            if (!missingColocatedRegions.isEmpty()) {
                context.getResultSender().lastResult(missingColocatedRegions);
            }
        }
    } catch (Exception e) {
        context.getResultSender().sendException(e);
    }
}
Also used : PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) Set(java.util.Set) HashSet(java.util.HashSet) InternalCache(org.apache.geode.internal.cache.InternalCache) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) ColocatedRegionDetails(org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DistributedMember(org.apache.geode.distributed.DistributedMember) HashSet(java.util.HashSet)

Example 3 with ColocatedRegionDetails

use of org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails in project geode by apache.

the class ShowMissingDiskStoresFunctionJUnitTest method testExecuteReturnsMissingStoresAndRegions.

@Test
public void testExecuteReturnsMissingStoresAndRegions() throws Throwable {
    ShowMissingDiskStoresFunction smdsFunc = new ShowMissingDiskStoresFunction();
    List<?> results = null;
    when(cache.getPersistentMemberManager()).thenReturn(memberManager);
    // Fake missing disk-stores
    Set<PersistentMemberID> regions1 = new HashSet<PersistentMemberID>();
    regions1.add(new PersistentMemberID(new DiskStoreID(), InetAddress.getLocalHost(), "/diskStore1", 1L, (short) 1));
    regions1.add(new PersistentMemberID(new DiskStoreID(), InetAddress.getLocalHost(), "/diskStore2", 2L, (short) 2));
    Map<String, Set<PersistentMemberID>> mapMember1 = new HashMap<String, Set<PersistentMemberID>>();
    ;
    mapMember1.put("member1", regions1);
    when(memberManager.getWaitingRegions()).thenReturn(mapMember1);
    // Fake missing colocated regions
    Set<PartitionedRegion> prs = new HashSet<PartitionedRegion>();
    prs.add(pr1);
    prs.add(pr2);
    List<String> missing1 = new ArrayList<String>(Arrays.asList("child1", "child2"));
    when(cache.getPartitionedRegions()).thenReturn(prs);
    when(pr1.getMissingColocatedChildren()).thenReturn(missing1);
    when(pr1.getFullPath()).thenReturn("/pr1");
    smdsFunc.execute(context);
    results = resultSender.getResults();
    assertEquals(2, results.size());
    for (Object result : results) {
        Set<?> detailSet = (Set<?>) result;
        if (detailSet.toArray()[0] instanceof PersistentMemberPattern) {
            assertEquals(2, detailSet.toArray().length);
            assertTrue(detailSet.toArray()[1] instanceof PersistentMemberPattern);
            // Results are not sorted so verify results in either order
            if (((PersistentMemberPattern) detailSet.toArray()[0]).getDirectory().equals("/diskStore1")) {
                assertEquals("/diskStore2", ((PersistentMemberPattern) detailSet.toArray()[1]).getDirectory());
            } else if (((PersistentMemberPattern) detailSet.toArray()[0]).getDirectory().equals("/diskStore2")) {
                assertEquals("/diskStore1", ((PersistentMemberPattern) detailSet.toArray()[1]).getDirectory());
            } else {
                fail("Incorrect missing colocated region results");
            }
        } else if (detailSet.toArray()[0] instanceof ColocatedRegionDetails) {
            assertEquals(2, detailSet.toArray().length);
            assertTrue(detailSet.toArray()[1] instanceof ColocatedRegionDetails);
            assertEquals("/pr1", ((ColocatedRegionDetails) detailSet.toArray()[0]).getParent());
            assertEquals("/pr1", ((ColocatedRegionDetails) detailSet.toArray()[1]).getParent());
            // Results are not sorted so verify results in either order
            if (((ColocatedRegionDetails) detailSet.toArray()[0]).getChild().equals("child1")) {
                assertEquals("child2", ((ColocatedRegionDetails) detailSet.toArray()[1]).getChild());
            } else if (((ColocatedRegionDetails) detailSet.toArray()[0]).getChild().equals("child2")) {
                assertEquals("child1", ((ColocatedRegionDetails) detailSet.toArray()[1]).getChild());
            } else {
                fail("Incorrect missing colocated region results");
            }
        } else {
            fail("Unexpected result type: " + detailSet.toArray()[0].getClass());
        }
    }
}
Also used : PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) ColocatedRegionDetails(org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) HashSet(java.util.HashSet) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

ColocatedRegionDetails (org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails)3 PersistentMemberPattern (org.apache.geode.internal.cache.persistence.PersistentMemberPattern)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 PersistentMemberID (org.apache.geode.internal.cache.persistence.PersistentMemberID)2 HashMap (java.util.HashMap)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 DiskStoreID (org.apache.geode.internal.cache.persistence.DiskStoreID)1 PersistentMemberManager (org.apache.geode.internal.cache.persistence.PersistentMemberManager)1 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)1 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)1 ResultDataException (org.apache.geode.management.internal.cli.result.ResultDataException)1 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1 Test (org.junit.Test)1