use of org.apache.tinkerpop.gremlin.orientdb.OrientGraph in project open-kilda by telstra.
the class OrientDbGraphFactory method getGraph.
/**
* Returns an instance of framed graph which is bound to the current persistence context.
* Create a new one if there's no such.
*/
@Override
public DelegatingFramedGraph<OrientGraph> getGraph() {
Connect effectiveConnect = getConnectCreateIfMissing();
OrientGraphFactory factory = effectiveConnect.getFactory();
log.debug("Opening a framed graph for {}", factory);
OrientGraph orientGraph = Failsafe.with(newPoolAcquireRetryPolicy()).get(() -> {
OrientGraph obtainedGraph = factory.getTx();
validateGraph(obtainedGraph);
return obtainedGraph;
});
log.debug("OrientGraph instance has been created: {}", orientGraph);
return new DelegatingFramedGraph<>(orientGraph, effectiveConnect.getBuilder(), effectiveConnect.getTypeResolver());
}
use of org.apache.tinkerpop.gremlin.orientdb.OrientGraph 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;
}
use of org.apache.tinkerpop.gremlin.orientdb.OrientGraph in project open-kilda by telstra.
the class GraphSupplier method get.
@Override
public OrientGraph get() {
PersistenceContext context = PersistenceContextManager.INSTANCE.getContextCreateIfMissing();
OrientDbContextExtension contextExtension = implementation.getContextExtension(context);
DelegatingFramedGraph<OrientGraph> wrapper = contextExtension.getGraphCreateIfMissing();
if (wrapper == null) {
throw new PersistenceException("Failed to obtain a framed graph");
}
return wrapper.getBaseGraph();
}
use of org.apache.tinkerpop.gremlin.orientdb.OrientGraph in project open-kilda by telstra.
the class OrientDbPersistenceImplementation method onContextClose.
@Override
public void onContextClose(PersistenceContext context) {
OrientDbContextExtension contextExtension = getContextExtension(context);
DelegatingFramedGraph<OrientGraph> currentGraph = contextExtension.removeGraph();
if (currentGraph != null) {
String threadName = Thread.currentThread().getName();
// Commit an implicit transaction to release graph resources.
try {
log.trace("Committing a transaction on the graph: {} in {}", currentGraph, threadName);
currentGraph.getBaseGraph().commit();
} catch (Exception e) {
log.error("Failed to commit a transaction in {}", threadName, e);
}
try {
log.trace("Closing the framed graph: {} in {}", currentGraph, threadName);
currentGraph.close();
} catch (IOException e) {
throw new PersistenceException(String.format("Failed to close graph in %s", threadName), e);
}
}
}
Aggregations