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;
});
}
Aggregations