Search in sources :

Example 66 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class FlowMirrorPointsFrame method getMirrorGroup.

@Override
public MirrorGroup getMirrorGroup() {
    if (mirrorGroup == null) {
        List<? extends MirrorGroupFrame> mirrorGroupFrames = traverse(v -> v.out(HAS_MIRROR_GROUP_EDGE).hasLabel(MirrorGroupFrame.FRAME_LABEL)).toListExplicit(MirrorGroupFrame.class);
        if (!mirrorGroupFrames.isEmpty()) {
            mirrorGroup = new MirrorGroup((mirrorGroupFrames.get(0)));
            if (!Objects.equals(getMirrorGroupId(), mirrorGroup.getGroupId())) {
                throw new IllegalStateException(format("The flow mirror points %s has inconsistent mirror group %s / %s", getId(), getMirrorGroupId(), mirrorGroup.getGroupId()));
            }
        } else {
            String switchId = getProperty(MIRROR_SWITCH_ID_PROPERTY);
            String pathId = getProperty(FLOW_PATH_ID_PROPERTY);
            log.warn("Fallback to find the mirror group by a reference instead of an edge. " + "The switch {}, the vertex {}", switchId, this);
            mirrorGroup = MirrorGroupFrame.load(getGraph(), switchId, pathId).map(MirrorGroup::new).orElse(null);
        }
    }
    return mirrorGroup;
}
Also used : GroupIdConverter(org.openkilda.persistence.ferma.frames.converters.GroupIdConverter) FlowPath(org.openkilda.model.FlowPath) FlowMirrorPointsData(org.openkilda.model.FlowMirrorPoints.FlowMirrorPointsData) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) Convert(org.openkilda.persistence.ferma.frames.converters.Convert) MirrorGroup(org.openkilda.model.MirrorGroup) Map(java.util.Map) PathId(org.openkilda.model.PathId) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Switch(org.openkilda.model.Switch) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) Property(com.syncleus.ferma.annotations.Property) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) VertexFrame(com.syncleus.ferma.VertexFrame) GroupId(org.openkilda.model.GroupId) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) Collections(java.util.Collections) MirrorGroup(org.openkilda.model.MirrorGroup)

Example 67 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class FlowMirrorPointsFrame method getMirrorSwitch.

@Override
public Switch getMirrorSwitch() {
    if (mirrorSwitch == null) {
        List<? extends SwitchFrame> switchFrames = traverse(v -> v.out(SOURCE_EDGE).hasLabel(SwitchFrame.FRAME_LABEL)).toListExplicit(SwitchFrame.class);
        if (!switchFrames.isEmpty()) {
            mirrorSwitch = new Switch((switchFrames.get(0)));
            if (!Objects.equals(getMirrorSwitchId(), mirrorSwitch.getSwitchId())) {
                throw new IllegalStateException(format("The flow mirror points %s has inconsistent mirror switch %s / %s", getId(), getMirrorSwitchId(), mirrorSwitch.getSwitchId()));
            }
        } else {
            String switchId = getProperty(MIRROR_SWITCH_ID_PROPERTY);
            log.warn("Fallback to find the mirror switch by a reference instead of an edge. " + "The switch {}, the vertex {}", switchId, this);
            mirrorSwitch = SwitchFrame.load(getGraph(), switchId).map(Switch::new).orElse(null);
        }
    }
    return mirrorSwitch;
}
Also used : GroupIdConverter(org.openkilda.persistence.ferma.frames.converters.GroupIdConverter) FlowPath(org.openkilda.model.FlowPath) FlowMirrorPointsData(org.openkilda.model.FlowMirrorPoints.FlowMirrorPointsData) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) Convert(org.openkilda.persistence.ferma.frames.converters.Convert) MirrorGroup(org.openkilda.model.MirrorGroup) Map(java.util.Map) PathId(org.openkilda.model.PathId) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Switch(org.openkilda.model.Switch) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) Property(com.syncleus.ferma.annotations.Property) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) VertexFrame(com.syncleus.ferma.VertexFrame) GroupId(org.openkilda.model.GroupId) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) Collections(java.util.Collections) Switch(org.openkilda.model.Switch)

Example 68 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class FermaFlowMeterRepository 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 (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, P.gte(lowestMeterIdAsLong)).has(FlowMeterFrame.METER_ID_PROPERTY, P.lt(highestMeterIdAsLong)).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr).values(FlowMeterFrame.METER_ID_PROPERTY).order().math("_ + 1").as("a").where(__.not(__.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr).values(FlowMeterFrame.METER_ID_PROPERTY).where(P.eq("a")))).select("a").limit(1)).getRawTraversal()) {
        if (traversal.hasNext()) {
            return traversal.tryNext().map(l -> ((Double) l).longValue()).map(MeterIdConverter.INSTANCE::toEntityAttribute);
        }
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, lowestMeterIdAsLong).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr)).getRawTraversal()) {
        if (!traversal.hasNext()) {
            return Optional.of(lowestMeterId);
        }
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
    return Optional.empty();
}
Also used : FlowMeter(org.openkilda.model.FlowMeter) Collection(java.util.Collection) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) FlowMeterData(org.openkilda.model.FlowMeter.FlowMeterData) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) MeterIdConverter(org.openkilda.persistence.ferma.frames.converters.MeterIdConverter) MeterId(org.openkilda.model.MeterId) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) Optional(java.util.Optional) FlowMeterFrame(org.openkilda.persistence.ferma.frames.FlowMeterFrame) KildaBaseVertexFrame(org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) PathId(org.openkilda.model.PathId) P(org.apache.tinkerpop.gremlin.process.traversal.P) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException)

Example 69 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class FermaFlowMeterRepository method exists.

@Override
public boolean exists(SwitchId switchId, MeterId meterId) {
    String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
    Long meterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(meterId);
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, meterIdAsLong).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr)).getRawTraversal()) {
        return traversal.hasNext();
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
}
Also used : FlowMeter(org.openkilda.model.FlowMeter) Collection(java.util.Collection) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) FlowMeterData(org.openkilda.model.FlowMeter.FlowMeterData) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) MeterIdConverter(org.openkilda.persistence.ferma.frames.converters.MeterIdConverter) MeterId(org.openkilda.model.MeterId) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) Optional(java.util.Optional) FlowMeterFrame(org.openkilda.persistence.ferma.frames.FlowMeterFrame) KildaBaseVertexFrame(org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) PathId(org.openkilda.model.PathId) P(org.apache.tinkerpop.gremlin.process.traversal.P) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException)

Example 70 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class SwitchConnectedDeviceFrame method getSwitchObj.

@Override
public Switch getSwitchObj() {
    if (switchObj == null) {
        List<? extends SwitchFrame> switchFrames = traverse(v -> v.in(HAS_BY_EDGE).hasLabel(SwitchFrame.FRAME_LABEL)).toListExplicit(SwitchFrame.class);
        switchObj = !switchFrames.isEmpty() ? new Switch(switchFrames.get(0)) : null;
        SwitchId switchId = switchObj != null ? switchObj.getSwitchId() : null;
        if (!Objects.equals(getSwitchId(), switchId)) {
            throw new IllegalStateException(format("The connected device %s has inconsistent switch %s / %s", getId(), getSwitchId(), switchId));
        }
    }
    return switchObj;
}
Also used : Switch(org.openkilda.model.Switch) Instant(java.time.Instant) ConnectedDeviceType(org.openkilda.model.ConnectedDeviceType) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) String.format(java.lang.String.format) Objects(java.util.Objects) Direction(org.apache.tinkerpop.gremlin.structure.Direction) List(java.util.List) Convert(org.openkilda.persistence.ferma.frames.converters.Convert) SwitchId(org.openkilda.model.SwitchId) InstantStringConverter(org.openkilda.persistence.ferma.frames.converters.InstantStringConverter) Property(com.syncleus.ferma.annotations.Property) ConnectedDeviceTypeConverter(org.openkilda.persistence.ferma.frames.converters.ConnectedDeviceTypeConverter) SwitchConnectedDeviceData(org.openkilda.model.SwitchConnectedDevice.SwitchConnectedDeviceData) VertexFrame(com.syncleus.ferma.VertexFrame) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId)

Aggregations

SwitchId (org.openkilda.model.SwitchId)339 Test (org.junit.Test)149 Flow (org.openkilda.model.Flow)73 Switch (org.openkilda.model.Switch)69 List (java.util.List)59 FlowPath (org.openkilda.model.FlowPath)49 ArrayList (java.util.ArrayList)44 Collectors (java.util.stream.Collectors)37 PathId (org.openkilda.model.PathId)36 PathComputer (org.openkilda.pce.PathComputer)35 Set (java.util.Set)34 YFlow (org.openkilda.model.YFlow)33 Map (java.util.Map)30 GetPathsResult (org.openkilda.pce.GetPathsResult)30 InfoMessage (org.openkilda.messaging.info.InfoMessage)29 String.format (java.lang.String.format)28 HashSet (java.util.HashSet)27 Optional (java.util.Optional)27 Collection (java.util.Collection)26 Collections (java.util.Collections)26