Search in sources :

Example 1 with OGremlinResultSet

use of org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet in project open-kilda by telstra.

the class OrientDbIslRepository method findActiveByPathAndBandwidthAndEncapsulationType.

@Override
public Collection<IslImmutableView> findActiveByPathAndBandwidthAndEncapsulationType(PathId pathId, long requiredBandwidth, FlowEncapsulationType flowEncapsulationType) {
    Map<String, String> switches = findActiveSwitchesAndPopByEncapsulationType(flowEncapsulationType);
    OrientGraph orientGraph = graphSupplier.get();
    Map<IslEndpoints, Long> segments = new HashMap<>();
    try (OGremlinResultSet results = orientGraph.querySql(QUERY_FETCH_SEGMENTS_BY_PATH, PathIdConverter.INSTANCE.toGraphProperty(pathId))) {
        results.forEach(gs -> {
            String srcSwitch = gs.getProperty(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY);
            String dstSwitch = gs.getProperty(PathSegmentFrame.DST_SWITCH_ID_PROPERTY);
            if (switches.containsKey(srcSwitch) && switches.containsKey(dstSwitch)) {
                segments.put(new IslEndpoints(srcSwitch, gs.getProperty(PathSegmentFrame.SRC_PORT_PROPERTY), dstSwitch, gs.getProperty(PathSegmentFrame.DST_PORT_PROPERTY)), gs.getProperty(PathSegmentFrame.BANDWIDTH_PROPERTY));
            }
        });
    }
    String islStatusAsStr = IslStatusConverter.INSTANCE.toGraphProperty(IslStatus.ACTIVE);
    List<IslImmutableView> isls = new ArrayList<>(segments.size());
    segments.keySet().forEach(endpoint -> {
        try (OGremlinResultSet results = orientGraph.querySql(QUERY_FETCH_ISLS_BY_ENDPOINTS_AND_BANDWIDTH, endpoint.getSrcSwitch(), endpoint.getSrcPort(), endpoint.getDestSwitch(), endpoint.getDestPort(), islStatusAsStr, requiredBandwidth - segments.get(endpoint))) {
            results.forEach(gs -> isls.add(mapToIslImmutableView(gs, switches.get(endpoint.getSrcSwitch()), switches.get(endpoint.getDestSwitch()))));
        }
    });
    return isls;
}
Also used : OrientGraph(org.apache.tinkerpop.gremlin.orientdb.OrientGraph) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OGremlinResultSet(org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet)

Example 2 with OGremlinResultSet

use of org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet in project open-kilda by telstra.

the class OrientDbIslRepository method findActiveByAvailableBandwidthAndEncapsulationType.

@Override
protected Map<IslEndpoints, IslImmutableView> findActiveByAvailableBandwidthAndEncapsulationType(long requiredBandwidth, FlowEncapsulationType flowEncapsulationType) {
    Map<String, String> switches = findActiveSwitchesAndPopByEncapsulationType(flowEncapsulationType);
    String islStatusAsStr = IslStatusConverter.INSTANCE.toGraphProperty(IslStatus.ACTIVE);
    Map<IslEndpoints, IslImmutableView> isls = new HashMap<>();
    try (OGremlinResultSet results = graphSupplier.get().querySql(QUERY_FETCH_ISLS_BY_STATUS_AND_BANDWIDTH, islStatusAsStr, requiredBandwidth)) {
        results.forEach(gs -> {
            String srcSwitch = gs.getProperty(IslFrame.SRC_SWITCH_ID_PROPERTY);
            String dstSwitch = gs.getProperty(IslFrame.DST_SWITCH_ID_PROPERTY);
            if (switches.containsKey(srcSwitch) && switches.containsKey(dstSwitch)) {
                IslEndpoints key = new IslEndpoints(srcSwitch, gs.getProperty(IslFrame.SRC_PORT_PROPERTY), dstSwitch, gs.getProperty(IslFrame.DST_PORT_PROPERTY));
                isls.put(key, mapToIslImmutableView(gs, switches.get(srcSwitch), switches.get(dstSwitch)));
            }
        });
    }
    return isls;
}
Also used : HashMap(java.util.HashMap) OGremlinResultSet(org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet)

Example 3 with OGremlinResultSet

use of org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet in project open-kilda by telstra.

the class OrientDbIslRepository method findActiveByEncapsulationType.

@Override
public Collection<IslImmutableView> findActiveByEncapsulationType(FlowEncapsulationType flowEncapsulationType) {
    Map<String, String> switches = findActiveSwitchesAndPopByEncapsulationType(flowEncapsulationType);
    List<IslImmutableView> isls = new ArrayList<>();
    try (OGremlinResultSet results = graphSupplier.get().querySql(QUERY_FETCH_ISLS_BY_STATUS, IslStatusConverter.INSTANCE.toGraphProperty(IslStatus.ACTIVE))) {
        results.forEach(gs -> {
            String srcSwitch = gs.getProperty(IslFrame.SRC_SWITCH_ID_PROPERTY);
            String dstSwitch = gs.getProperty(IslFrame.DST_SWITCH_ID_PROPERTY);
            if (switches.containsKey(srcSwitch) && switches.containsKey(dstSwitch)) {
                isls.add(mapToIslImmutableView(gs, switches.get(srcSwitch), switches.get(dstSwitch)));
            }
        });
    }
    return isls;
}
Also used : ArrayList(java.util.ArrayList) OGremlinResultSet(org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet)

Example 4 with OGremlinResultSet

use of org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet in project open-kilda by telstra.

the class OrientDbIslRepository method findActiveSwitchesAndPopByEncapsulationType.

private Map<String, String> findActiveSwitchesAndPopByEncapsulationType(FlowEncapsulationType flowEncapsulationType) {
    String switchStatusAsStr = SwitchStatusConverter.INSTANCE.toGraphProperty(SwitchStatus.ACTIVE);
    String flowEncapType = FlowEncapsulationTypeConverter.INSTANCE.toGraphProperty(flowEncapsulationType);
    Map<String, String> switches = new HashMap<>();
    try (OGremlinResultSet results = graphSupplier.get().querySql(QUERY_FETCH_SWITCHES_BY_STATUS_AND_ENCAPSULATION, switchStatusAsStr, flowEncapType)) {
        results.forEach(gs -> switches.put(gs.getProperty(SwitchFrame.SWITCH_ID_PROPERTY), gs.getProperty(SwitchFrame.POP_PROPERTY)));
    }
    return switches;
}
Also used : HashMap(java.util.HashMap) OGremlinResultSet(org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet)

Example 5 with OGremlinResultSet

use of org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet in project open-kilda by telstra.

the class OrientDbFlowMeterRepository method findFirstUnassignedMeter.

@Override
public Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId) {
    String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
    Long lowestMeterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(lowestMeterId);
    Long highestMeterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(highestMeterId);
    try (OGremlinResultSet results = graphSupplier.get().querySql(format("SELECT FROM (SELECT difference(unionAll($init_meter, $next_to_meters).meter, " + "$meters.meter) as meter " + "LET $init_meter = (SELECT %sL as meter), " + "$meters = (SELECT %s.asLong() as meter FROM %s WHERE %s = ? " + "AND %s >= ? AND %s < ?), " + "$next_to_meters = (SELECT %s.asLong() + 1 as meter FROM %s WHERE %s = ? " + "AND %s >= ? AND %s < ?) " + "UNWIND meter) ORDER by meter LIMIT 1", lowestMeterIdAsLong, FlowMeterFrame.METER_ID_PROPERTY, FlowMeterFrame.FRAME_LABEL, FlowMeterFrame.SWITCH_PROPERTY, FlowMeterFrame.METER_ID_PROPERTY, FlowMeterFrame.METER_ID_PROPERTY, FlowMeterFrame.METER_ID_PROPERTY, FlowMeterFrame.FRAME_LABEL, FlowMeterFrame.SWITCH_PROPERTY, FlowMeterFrame.METER_ID_PROPERTY, FlowMeterFrame.METER_ID_PROPERTY), switchIdAsStr, lowestMeterIdAsLong, highestMeterIdAsLong, switchIdAsStr, lowestMeterIdAsLong, highestMeterIdAsLong)) {
        Iterator<OGremlinResult> it = results.iterator();
        if (it.hasNext()) {
            Number meter = it.next().getProperty("meter");
            if (meter != null) {
                return Optional.of(MeterIdConverter.INSTANCE.toEntityAttribute(meter.longValue()));
            }
        }
        return Optional.empty();
    }
}
Also used : OGremlinResult(org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResult) OGremlinResultSet(org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet)

Aggregations

OGremlinResultSet (org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResultSet)8 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 OrientGraph (org.apache.tinkerpop.gremlin.orientdb.OrientGraph)1 OGremlinResult (org.apache.tinkerpop.gremlin.orientdb.executor.OGremlinResult)1