Search in sources :

Example 6 with MultiValuedMap

use of org.apache.commons.collections4.MultiValuedMap in project open-kilda by telstra.

the class YFlowSwitchFlowEntriesBuilder method getFlowEntries.

/**
 * Construct a set of {@link FlowEntry} that corresponds to the builder's y-flow.
 */
public Map<SwitchId, Collection<FlowEntry>> getFlowEntries() {
    MultiValuedMap<SwitchId, FlowEntry> flowEntries = new ArrayListValuedHashMap<>();
    yFlow.getSubFlows().forEach(subFlow -> {
        Flow flow = subFlow.getFlow();
        SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
        int forwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getForwardPathId()).orElseThrow(IllegalStateException::new);
        int reverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getReversePathId()).orElseThrow(IllegalStateException::new);
        Integer protectedForwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedForwardPathId()).orElse(null);
        Integer protectedReverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedReversePathId()).orElse(null);
        builder.getSwitchFlowEntries(forwardTransitEncId, reverseTransitEncId, protectedForwardTransitEncId, protectedReverseTransitEncId).forEach(entries -> flowEntries.putAll(entries.getSwitchId(), entries.getFlowEntries()));
        FlowPath forwardPath = flow.getForwardPath();
        PathSegment firstSegment = forwardPath.getSegments().get(0);
        FlowSegmentCookie forwardCookie = forwardPath.getCookie().toBuilder().yFlow(true).build();
        boolean isVxlan = flow.getEncapsulationType() == VXLAN;
        flowEntries.put(forwardPath.getSrcSwitchId(), builder.getFlowEntry(forwardCookie.getValue(), flow.getSrcPort(), flow.getSrcVlan(), null, firstSegment.getSrcPort(), isVxlan ? null : forwardTransitEncId, isVxlan ? forwardTransitEncId : null, yFlow.getSharedEndpointMeterId().getValue()));
        if (!yFlow.getYPoint().equals(flow.getSrcSwitchId())) {
            FlowPath reversePath = flow.getReversePath();
            FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
            List<PathSegment> reverseSegments = reversePath.getSegments();
            for (int i = 0; i < reverseSegments.size() - 1; i++) {
                PathSegment nsegment = reverseSegments.get(i);
                PathSegment n1segment = reverseSegments.get(i + 1);
                if (nsegment.getDestSwitchId().equals(yFlow.getYPoint())) {
                    flowEntries.put(yFlow.getYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getMeterId().getValue()));
                }
            }
        }
        if (yFlow.isAllocateProtectedPath() && yFlow.getProtectedPathYPoint() != null && !yFlow.getProtectedPathYPoint().equals(flow.getSrcSwitchId())) {
            FlowPath reversePath = flow.getProtectedReversePath();
            FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
            List<PathSegment> reverseSegments = reversePath.getSegments();
            for (int i = 0; i < reverseSegments.size() - 1; i++) {
                PathSegment nsegment = reverseSegments.get(i);
                PathSegment n1segment = reverseSegments.get(i + 1);
                if (nsegment.getDestSwitchId().equals(yFlow.getProtectedPathYPoint())) {
                    flowEntries.put(yFlow.getProtectedPathYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getProtectedPathMeterId().getValue()));
                }
            }
        }
    });
    return flowEntries.asMap();
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) SwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.validation.SwitchFlowEntriesBuilder) FlowPath(org.openkilda.model.FlowPath) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap)

Example 7 with MultiValuedMap

use of org.apache.commons.collections4.MultiValuedMap in project methods-distance by sevntu-checkstyle.

the class MethodOrder method getMethodInvocationsNesting.

private static MultiValuedMap<MethodInvocation, MethodInvocation> getMethodInvocationsNesting(Map<ResolvedCall, MethodInvocation> callToInvocation) {
    final SetValuedMap<MethodInvocation, MethodInvocation> nestedInside = new HashSetValuedHashMap<>();
    callToInvocation.entrySet().stream().forEach(entry -> {
        final ResolvedCall resolvedCall = entry.getKey();
        final MethodInvocation methodInvocation = entry.getValue();
        callToInvocation.keySet().stream().filter(rc -> !rc.equals(resolvedCall)).filter(resolvedCall::isNestedInside).forEach(rc -> nestedInside.put(methodInvocation, callToInvocation.get(rc)));
    });
    return nestedInside;
}
Also used : ResolvedCall(com.github.sevntu.checkstyle.domain.ResolvedCall) HashSetValuedHashMap(org.apache.commons.collections4.multimap.HashSetValuedHashMap)

Example 8 with MultiValuedMap

use of org.apache.commons.collections4.MultiValuedMap in project dhis2-core by dhis2.

the class QueryPlannerTest method testGetPermutationDimensionalItemValueMapCocDisabled.

@Test
void testGetPermutationDimensionalItemValueMapCocDisabled() {
    MultiValuedMap<String, DimensionItemObjectValue> aggregatedDataMap = new ArrayListValuedHashMap<>();
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deA, 1d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deA, 2d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deA, 3d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deA, 4d));
    aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deB, 5d));
    aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deB, 6d));
    aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deB, 7d));
    aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deB, 8d));
    Map<String, List<DimensionItemObjectValue>> permutationMap = DataQueryParams.getPermutationDimensionalItemValueMap(aggregatedDataMap);
    assertNotNull(permutationMap);
    String ouAM1Key = ouA.getUid() + DIMENSION_SEP + "200101";
    String ouAM2Key = ouA.getUid() + DIMENSION_SEP + "200102";
    String ouBM1Key = ouB.getUid() + DIMENSION_SEP + "200101";
    String ouBM2Key = ouB.getUid() + DIMENSION_SEP + "200102";
    List<DimensionItemObjectValue> ouAM1 = permutationMap.get(ouAM1Key);
    List<DimensionItemObjectValue> ouAM2 = permutationMap.get(ouAM2Key);
    List<DimensionItemObjectValue> ouBM1 = permutationMap.get(ouBM1Key);
    List<DimensionItemObjectValue> ouBM2 = permutationMap.get(ouBM2Key);
    assertEquals(2, ouAM1.size());
    assertEquals(2, ouAM2.size());
    assertEquals(2, ouBM1.size());
    assertEquals(2, ouBM2.size());
    List<DimensionItemObjectValue> ouAM1Expected = new ArrayList<>();
    ouAM1Expected.add(new DimensionItemObjectValue(deA, 1d));
    ouAM1Expected.add(new DimensionItemObjectValue(deB, 5d));
    List<DimensionItemObjectValue> ouAM2Expected = new ArrayList<>();
    ouAM2Expected.add(new DimensionItemObjectValue(deA, 2d));
    ouAM2Expected.add(new DimensionItemObjectValue(deB, 6d));
    List<DimensionItemObjectValue> ouBM1Expected = new ArrayList<>();
    ouBM1Expected.add(new DimensionItemObjectValue(deA, 3d));
    ouBM1Expected.add(new DimensionItemObjectValue(deB, 7d));
    List<DimensionItemObjectValue> ouBM2Expected = new ArrayList<>();
    ouBM2Expected.add(new DimensionItemObjectValue(deA, 4d));
    ouBM2Expected.add(new DimensionItemObjectValue(deB, 8d));
    assertCollectionsMatch(ouAM1Expected, ouAM1);
    assertCollectionsMatch(ouAM2Expected, ouAM2);
    assertCollectionsMatch(ouBM1Expected, ouBM1);
    assertCollectionsMatch(ouBM2Expected, ouBM2);
}
Also used : ArrayList(java.util.ArrayList) DimensionItemObjectValue(org.hisp.dhis.common.DimensionItemObjectValue) List(java.util.List) ArrayList(java.util.ArrayList) DimensionalObjectUtils.getList(org.hisp.dhis.common.DimensionalObjectUtils.getList) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 9 with MultiValuedMap

use of org.apache.commons.collections4.MultiValuedMap in project dhis2-core by dhis2.

the class QueryPlannerTest method testGetPermutationDimensionalItemValueMap.

@Test
void testGetPermutationDimensionalItemValueMap() {
    MultiValuedMap<String, DimensionItemObjectValue> aggregatedDataMap = new ArrayListValuedHashMap<>();
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1", new DimensionItemObjectValue(deA, 1d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2", new DimensionItemObjectValue(deA, 2d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1", new DimensionItemObjectValue(deA, 3d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2", new DimensionItemObjectValue(deA, 4d));
    aggregatedDataMap.put(makeKey(deB, coc, ouA, "2000Q1"), new DimensionItemObjectValue(deB, 5d));
    aggregatedDataMap.put(makeKey(deB, coc, ouA, "2000Q2"), new DimensionItemObjectValue(deB, 6d));
    aggregatedDataMap.put(makeKey(deB, coc, ouB, "2000Q1"), new DimensionItemObjectValue(deB, 7d));
    aggregatedDataMap.put(makeKey(deB, coc, ouB, "2000Q2"), new DimensionItemObjectValue(deB, 8d));
    Map<String, List<DimensionItemObjectValue>> permutationMap = DataQueryParams.getPermutationDimensionalItemValueMap(aggregatedDataMap);
    assertNotNull(permutationMap);
    String ouAQ1Key = ouA.getUid() + DIMENSION_SEP + "2000Q1";
    String ouAQ2Key = ouA.getUid() + DIMENSION_SEP + "2000Q2";
    String ouBQ1Key = ouB.getUid() + DIMENSION_SEP + "2000Q1";
    String ouBQ2Key = ouB.getUid() + DIMENSION_SEP + "2000Q2";
    List<DimensionItemObjectValue> ouAQ1 = permutationMap.get(ouAQ1Key);
    List<DimensionItemObjectValue> ouAQ2 = permutationMap.get(ouAQ2Key);
    List<DimensionItemObjectValue> ouBQ1 = permutationMap.get(ouBQ1Key);
    List<DimensionItemObjectValue> ouBQ2 = permutationMap.get(ouBQ2Key);
    assertEquals(2, ouAQ1.size());
    assertEquals(2, ouAQ2.size());
    assertEquals(2, ouBQ1.size());
    assertEquals(2, ouBQ2.size());
    List<DimensionItemObjectValue> ouAQ1Expected = new ArrayList<>();
    ouAQ1Expected.add(new DimensionItemObjectValue(deA, 1d));
    ouAQ1Expected.add(new DimensionItemObjectValue(deB, 5d));
    List<DimensionItemObjectValue> ouAQ2Expected = new ArrayList<>();
    ouAQ2Expected.add(new DimensionItemObjectValue(deA, 2d));
    ouAQ2Expected.add(new DimensionItemObjectValue(deB, 6d));
    List<DimensionItemObjectValue> ouBQ1Expected = new ArrayList<>();
    ouBQ1Expected.add(new DimensionItemObjectValue(deA, 3d));
    ouBQ1Expected.add(new DimensionItemObjectValue(deB, 7d));
    List<DimensionItemObjectValue> ouBQ2Expected = new ArrayList<>();
    ouBQ2Expected.add(new DimensionItemObjectValue(deA, 4d));
    ouBQ2Expected.add(new DimensionItemObjectValue(deB, 8d));
    assertCollectionsMatch(ouAQ1Expected, ouAQ1);
    assertCollectionsMatch(ouAQ2Expected, ouAQ2);
    assertCollectionsMatch(ouBQ1Expected, ouBQ1);
    assertCollectionsMatch(ouBQ2Expected, ouBQ2);
}
Also used : ArrayList(java.util.ArrayList) DimensionItemObjectValue(org.hisp.dhis.common.DimensionItemObjectValue) List(java.util.List) ArrayList(java.util.ArrayList) DimensionalObjectUtils.getList(org.hisp.dhis.common.DimensionalObjectUtils.getList) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)8 DimensionItemObjectValue (org.hisp.dhis.common.DimensionItemObjectValue)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 DimensionalObjectUtils.getList (org.hisp.dhis.common.DimensionalObjectUtils.getList)3 Test (org.junit.jupiter.api.Test)3 Flow (org.openkilda.model.Flow)3 SwitchId (org.openkilda.model.SwitchId)3 YFlow (org.openkilda.model.YFlow)3 SwitchFlowEntriesBuilder (org.openkilda.wfm.topology.flowhs.fsm.validation.SwitchFlowEntriesBuilder)3 FlowPath (org.openkilda.model.FlowPath)2 ResolvedCall (com.github.sevntu.checkstyle.domain.ResolvedCall)1 HashMap (java.util.HashMap)1 Tuple (javax.persistence.Tuple)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 HashSetValuedHashMap (org.apache.commons.collections4.multimap.HashSetValuedHashMap)1 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)1 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1