Search in sources :

Example 1 with ImmutablePath

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath 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)1 String.format (java.lang.String.format)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)1 ImmutablePath (org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1 DetachedFactory (org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory)1 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)1 PathNode (org.openkilda.messaging.info.event.PathNode)1 Flow (org.openkilda.model.Flow)1 FlowMeter (org.openkilda.model.FlowMeter)1 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)1