use of org.opendaylight.graph.ConnectedGraph in project bgpcep by opendaylight.
the class PathComputationServer method getConstrainedPath.
@Override
public ListenableFuture<RpcResult<GetConstrainedPathOutput>> getConstrainedPath(final GetConstrainedPathInput input) {
final GetConstrainedPathOutputBuilder output = new GetConstrainedPathOutputBuilder();
LOG.info("Got Path Computation Service request");
/* First, get graph */
final ConnectedGraph cgraph = graphProvider.getConnectedGraph(input.getGraphName());
if (cgraph == null) {
output.setStatus(ComputationStatus.Failed);
return RpcResultBuilder.<GetConstrainedPathOutput>failed().withError(RpcError.ErrorType.RPC, "Unknown Graph Name").buildFuture();
}
/* get a new Path Computation Algorithm according to Input choice */
PathComputationAlgorithm algo = getPathComputationAlgorithm(cgraph, input.getAlgorithm());
if (algo == null) {
output.setStatus(ComputationStatus.Failed);
return RpcResultBuilder.<GetConstrainedPathOutput>failed().withError(RpcError.ErrorType.RPC, "Unknown Path Computation Algorithm").buildFuture();
}
/*
* Request Path Computation for given source, destination and
* constraints
*/
final VertexKey source = new VertexKey(input.getSource());
final VertexKey destination = new VertexKey(input.getDestination());
LOG.info("Call Path Computation {} algorithm for path from {} to {} with contraints {}", input.getAlgorithm().getName(), source, destination, input.getConstraints());
final ConstrainedPath cpath = algo.computeP2pPath(source, destination, input.getConstraints());
/* Send back the Computed Path */
output.setPathDescription(cpath.getPathDescription()).setStatus(cpath.getStatus()).setComputedMetric(cpath.getMetric()).setComputedTeMetric(cpath.getTeMetric()).setComputedDelay(cpath.getDelay());
return RpcResultBuilder.success(output.build()).buildFuture();
}
use of org.opendaylight.graph.ConnectedGraph in project bgpcep by opendaylight.
the class ConnectedGraphServer method createConnectedGraph.
@Override
public ConnectedGraph createConnectedGraph(final String name, final DomainScope scope) {
Graph graph = new GraphBuilder().setName(name).setDomainScope(scope).build();
addToDataStore(getGraphInstanceIdentifier(name), graph, "Graph(" + name + ")");
ConnectedGraphImpl cgraph = new ConnectedGraphImpl(graph, this);
graphs.put(graph.key(), cgraph);
return cgraph;
}
use of org.opendaylight.graph.ConnectedGraph in project bgpcep by opendaylight.
the class GraphListener method onDataTreeChanged.
@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Graph>> changes) {
for (DataTreeModification<Graph> change : changes) {
DataObjectModification<Graph> root = change.getRootNode();
GraphKey key = change.getRootPath().getRootIdentifier().firstKeyOf(Graph.class);
switch(root.getModificationType()) {
case DELETE:
graphProvider.deleteGraph(key);
break;
case SUBTREE_MODIFIED:
/* getModificationType() returns SUBTREE_MODIFIED only when Data Object is already present in the
* Data Store, thus, only for deletion. Thus, to insert children, we must used parseSubTree()
* method (See above). This method is called only when the graph already exists.
*/
case WRITE:
/* First look if the Graph was not already configured */
ConnectedGraph cgraph = this.graphProvider.getConnectedGraph(key);
if (cgraph == null) {
graphProvider.addGraph(root.getDataAfter());
} else {
/* Graph exist, process Children */
parseSubTree(cgraph, root.getModifiedChildren());
}
break;
default:
break;
}
}
}
use of org.opendaylight.graph.ConnectedGraph in project bgpcep by opendaylight.
the class ConnectedGraphServer method destroyOperationalGraphModel.
/**
* Destroy the current operational topology data. Note a valid transaction must be provided.
*/
private synchronized FluentFuture<? extends CommitInfo> destroyOperationalGraphModel() {
requireNonNull(this.chain, "A valid transaction chain must be provided.");
final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
trans.delete(LogicalDatastoreType.OPERATIONAL, GRAPH_TOPOLOGY_IDENTIFIER);
trans.delete(LogicalDatastoreType.CONFIGURATION, GRAPH_TOPOLOGY_IDENTIFIER);
final FluentFuture<? extends CommitInfo> future = trans.commit();
future.addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Operational GraphModel removed {}", GRAPH_TOPOLOGY_IDENTIFIER);
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Unable to reset operational GraphModel {} (transaction {})", GRAPH_TOPOLOGY_IDENTIFIER, trans.getIdentifier(), throwable);
}
}, MoreExecutors.directExecutor());
/* Clear Connected Graph */
for (ConnectedGraph graph : graphs.values()) {
((ConnectedGraphImpl) graph).clear();
}
return future;
}
Aggregations