Search in sources :

Example 1 with FramedGraph

use of com.syncleus.ferma.FramedGraph in project open-kilda by telstra.

the class FermaIslRepository method findByPathIds.

@Override
public Collection<Isl> findByPathIds(List<PathId> pathIds) {
    List<String> pathIdAsStr = pathIds.stream().map(PathIdConverter.INSTANCE::toGraphProperty).collect(Collectors.toList());
    List<? extends PathSegmentFrame> segmentFrames = framedGraph().traverse(g -> g.V().hasLabel(PathSegmentFrame.FRAME_LABEL).has(PathSegmentFrame.PATH_ID_PROPERTY, P.within(pathIdAsStr))).toListExplicit(PathSegmentFrame.class);
    if (segmentFrames.isEmpty()) {
        return emptyList();
    }
    List<Isl> result = new ArrayList<>();
    segmentFrames.forEach(segmentFrame -> {
        framedGraph().traverse(g -> g.E().hasLabel(IslFrame.FRAME_LABEL).has(IslFrame.SRC_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(segmentFrame.getSrcSwitchId())).has(IslFrame.DST_SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(segmentFrame.getDestSwitchId())).has(IslFrame.SRC_PORT_PROPERTY, segmentFrame.getSrcPort()).has(IslFrame.DST_PORT_PROPERTY, segmentFrame.getDestPort())).frameExplicit(IslFrame.class).forEachRemaining(frame -> result.add(addIslConfigToIsl(new Isl(frame))));
    });
    return result;
}
Also used : Collectors.groupingBy(java.util.stream.Collectors.groupingBy) PathSegmentFrame(org.openkilda.persistence.ferma.frames.PathSegmentFrame) FlowEncapsulationTypeConverter(org.openkilda.persistence.ferma.frames.converters.FlowEncapsulationTypeConverter) HashMap(java.util.HashMap) IslConfig(org.openkilda.model.IslConfig) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) IslStatusConverter(org.openkilda.persistence.ferma.frames.converters.IslStatusConverter) Collectors.mapping(java.util.stream.Collectors.mapping) IslRepository(org.openkilda.persistence.repositories.IslRepository) Map(java.util.Map) SwitchFrame(org.openkilda.persistence.ferma.frames.SwitchFrame) Collectors.toSet(java.util.stream.Collectors.toSet) PathId(org.openkilda.model.PathId) P(org.apache.tinkerpop.gremlin.process.traversal.P) Edge(org.apache.tinkerpop.gremlin.structure.Edge) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) Switch(org.openkilda.model.Switch) IslFrame(org.openkilda.persistence.ferma.frames.IslFrame) SwitchStatusConverter(org.openkilda.persistence.ferma.frames.converters.SwitchStatusConverter) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Set(java.util.Set) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) IslStatus(org.openkilda.model.IslStatus) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) KildaBaseEdgeFrame(org.openkilda.persistence.ferma.frames.KildaBaseEdgeFrame) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) SwitchPropertiesFrame(org.openkilda.persistence.ferma.frames.SwitchPropertiesFrame) Instant(java.time.Instant) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) IslData(org.openkilda.model.Isl.IslData) SwitchId(org.openkilda.model.SwitchId) FramedGraph(com.syncleus.ferma.FramedGraph) Optional(java.util.Optional) Isl(org.openkilda.model.Isl) SwitchStatus(org.openkilda.model.SwitchStatus) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) Isl(org.openkilda.model.Isl) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) IslFrame(org.openkilda.persistence.ferma.frames.IslFrame) ArrayList(java.util.ArrayList)

Example 2 with FramedGraph

use of com.syncleus.ferma.FramedGraph in project open-kilda by telstra.

the class FermaIslRepository method updateAvailableBandwidthOnIslsOccupiedByPath.

@Override
public Map<IslEndpoints, Long> updateAvailableBandwidthOnIslsOccupiedByPath(PathId pathId) {
    FramedGraph framedGraph = framedGraph();
    Set<IslEndpoints> segmentEndpoints = new HashSet<>();
    framedGraph.traverse(g -> g.V().hasLabel(PathSegmentFrame.FRAME_LABEL).has(PathSegmentFrame.PATH_ID_PROPERTY, PathIdConverter.INSTANCE.toGraphProperty(pathId))).frameExplicit(PathSegmentFrame.class).forEachRemaining(frame -> {
        String srcSwitch = frame.getProperty(PathSegmentFrame.SRC_SWITCH_ID_PROPERTY);
        String dstSwitch = frame.getProperty(PathSegmentFrame.DST_SWITCH_ID_PROPERTY);
        segmentEndpoints.add(new IslEndpoints(srcSwitch, frame.getSrcPort(), dstSwitch, frame.getDestPort()));
    });
    Map<IslEndpoints, Long> updatedEndpoints = new HashMap<>();
    segmentEndpoints.forEach(endpoint -> {
        long usedBandwidth = flowPathRepository.getUsedBandwidthBetweenEndpoints(framedGraph, endpoint.getSrcSwitch(), endpoint.getSrcPort(), endpoint.getDestSwitch(), endpoint.getDestPort());
        long updatedAvailableBandwidth = updateAvailableBandwidth(framedGraph, endpoint.getSrcSwitch(), endpoint.getSrcPort(), endpoint.getDestSwitch(), endpoint.getDestPort(), usedBandwidth);
        updatedEndpoints.put(endpoint, updatedAvailableBandwidth);
    });
    return updatedEndpoints;
}
Also used : FramedGraph(com.syncleus.ferma.FramedGraph) PathSegmentFrame(org.openkilda.persistence.ferma.frames.PathSegmentFrame) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 3 with FramedGraph

use of com.syncleus.ferma.FramedGraph in project open-kilda by telstra.

the class FermaIslRepository method updateAvailableBandwidth.

@Override
public long updateAvailableBandwidth(SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort) {
    FramedGraph framedGraph = framedGraph();
    String srcSwitchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(srcSwitchId);
    String dstSwitchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(dstSwitchId);
    long usedBandwidth = flowPathRepository.getUsedBandwidthBetweenEndpoints(framedGraph, srcSwitchIdAsStr, srcPort, dstSwitchIdAsStr, dstPort);
    return updateAvailableBandwidth(framedGraph, srcSwitchIdAsStr, srcPort, dstSwitchIdAsStr, dstPort, usedBandwidth);
}
Also used : FramedGraph(com.syncleus.ferma.FramedGraph)

Example 4 with FramedGraph

use of com.syncleus.ferma.FramedGraph in project open-kilda by telstra.

the class DatabaseSupportImpl method getPaths.

/**
 * Get all possible paths between source and destination switches.
 *
 * @param src source switch ID
 * @param dst destination switch ID
 * @return list of PathInfoData objects
 */
@Override
@SuppressWarnings("unchecked")
public List<PathInfoData> getPaths(SwitchId src, SwitchId dst) {
    return transactionManager.doInTransaction(() -> {
        FramedGraph framedGraph = getGraph();
        GraphTraversal<?, ?> rawTraversal = framedGraph.traverse(input -> input.V().hasLabel(SwitchFrame.FRAME_LABEL).has(SwitchFrame.SWITCH_ID_PROPERTY, src.toString()).repeat(__.outE(IslFrame.FRAME_LABEL).has(IslFrame.STATUS_PROPERTY, "active").inV().hasLabel(SwitchFrame.FRAME_LABEL).simplePath()).until(__.has(SwitchFrame.SWITCH_ID_PROPERTY, dst.toString()).or().loops().is(DEFAULT_DEPTH)).has(SwitchFrame.SWITCH_ID_PROPERTY, dst.toString()).path()).getRawTraversal();
        List<PathInfoData> deserializedResults = new ArrayList<>();
        while (rawTraversal.hasNext()) {
            ImmutablePath tpPath = (ImmutablePath) rawTraversal.next();
            List<PathNode> resultPath = new ArrayList<>();
            int seqId = 0;
            for (Object hop : tpPath) {
                if (hop instanceof Edge) {
                    Edge edge = (Edge) hop;
                    Vertex srcVertex = edge.outVertex();
                    resultPath.add(new PathNode(new SwitchId((String) srcVertex.property(SwitchFrame.SWITCH_ID_PROPERTY).value()), (Integer) edge.property(IslFrame.SRC_PORT_PROPERTY).value(), seqId++, (Long) edge.property(IslFrame.LATENCY_PROPERTY).value()));
                    Vertex dstVertex = edge.inVertex();
                    resultPath.add(new PathNode(new SwitchId((String) dstVertex.property(SwitchFrame.SWITCH_ID_PROPERTY).value()), (Integer) edge.property(IslFrame.DST_PORT_PROPERTY).value(), seqId++, (Long) edge.property(IslFrame.LATENCY_PROPERTY).value()));
                }
            }
            deserializedResults.add(new PathInfoData(0, resultPath));
        }
        return deserializedResults;
    });
}
Also used : FlowEvent(org.openkilda.model.history.FlowEvent) TransitVlanRepository(org.openkilda.persistence.repositories.TransitVlanRepository) FlowPath(org.openkilda.model.FlowPath) Isl(org.openkilda.testing.model.topology.TopologyDefinition.Isl) FlowEventRepository(org.openkilda.persistence.repositories.history.FlowEventRepository) Flow(org.openkilda.model.Flow) PersistenceContextManager(org.openkilda.persistence.context.PersistenceContextManager) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) SwitchFrame(org.openkilda.persistence.ferma.frames.SwitchFrame) SwitchConnectedDeviceRepository(org.openkilda.persistence.repositories.SwitchConnectedDeviceRepository) IslFrame(org.openkilda.persistence.ferma.frames.IslFrame) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Collection(java.util.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Instant(java.time.Instant) String.format(java.lang.String.format) List(java.util.List) Stream(java.util.stream.Stream) FramedGraph(com.syncleus.ferma.FramedGraph) Optional(java.util.Optional) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) DetachedFactory(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory) TransactionManager(org.openkilda.persistence.tx.TransactionManager) FlowMeter(org.openkilda.model.FlowMeter) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ArrayList(java.util.ArrayList) DEFAULT_COST(org.openkilda.testing.Constants.DEFAULT_COST) OrientDbPersistenceImplementation(org.openkilda.persistence.orientdb.OrientDbPersistenceImplementation) IslRepository(org.openkilda.persistence.repositories.IslRepository) TransitVlan(org.openkilda.model.TransitVlan) PersistenceManager(org.openkilda.persistence.PersistenceManager) PathId(org.openkilda.model.PathId) OrientDbContextExtension(org.openkilda.persistence.orientdb.OrientDbContextExtension) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Switch(org.openkilda.model.Switch) FlowMirrorPointsRepository(org.openkilda.persistence.repositories.FlowMirrorPointsRepository) PersistenceContext(org.openkilda.persistence.context.PersistenceContext) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) ImmutablePath(org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath) PathNode(org.openkilda.messaging.info.event.PathNode) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) MeterId(org.openkilda.model.MeterId) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) SwitchId(org.openkilda.model.SwitchId) SwitchStatus(org.openkilda.model.SwitchStatus) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) PathNode(org.openkilda.messaging.info.event.PathNode) ImmutablePath(org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FramedGraph(com.syncleus.ferma.FramedGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Aggregations

FramedGraph (com.syncleus.ferma.FramedGraph)4 String.format (java.lang.String.format)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Optional (java.util.Optional)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 PathId (org.openkilda.model.PathId)2 Switch (org.openkilda.model.Switch)2 SwitchId (org.openkilda.model.SwitchId)2 SwitchStatus (org.openkilda.model.SwitchStatus)2 IslFrame (org.openkilda.persistence.ferma.frames.IslFrame)2 PathSegmentFrame (org.openkilda.persistence.ferma.frames.PathSegmentFrame)2 SwitchFrame (org.openkilda.persistence.ferma.frames.SwitchFrame)2 IslRepository (org.openkilda.persistence.repositories.IslRepository)2