* @author Olivier Dugeon
* @author Philippe Niger
*/
-
public class ConnectedEdgeImpl implements ConnectedEdge {
/* Reference to Source and Destination Connected Vertex within the Connected Graph */
private Edge edge;
/* Edge key in the Connected Graph */
- private Long ceid;
+ private final Long ceid;
/* Total amount of Bandwidth reserved by Constrained Paths */
- private static int MAX_PRIORITY = 8;
+ private static final int MAX_PRIORITY = 8;
private Long globalResvBandwidth = 0L;
- private Long[] cosResvBandwidth = {0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L};
+ private final Long[] cosResvBandwidth = {0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L};
/* List of Connected Edge Trigger */
- private ConcurrentMap<String, ConnectedEdgeTrigger> triggers =
- new ConcurrentHashMap<String, ConnectedEdgeTrigger>();
+ private final ConcurrentMap<String, ConnectedEdgeTrigger> triggers = new ConcurrentHashMap<>();
- public ConnectedEdgeImpl(@NonNull Long key) {
+ public ConnectedEdgeImpl(final @NonNull Long key) {
checkArgument(key != 0, "Edge Key must not be equal to 0");
- this.ceid = key;
- this.edge = null;
+ ceid = key;
+ edge = null;
}
- public ConnectedEdgeImpl(@NonNull Edge edge) {
+ public ConnectedEdgeImpl(final @NonNull Edge edge) {
checkArgument(edge.getEdgeId().longValue() != 0, "Edge Key must not be equal to 0");
this.edge = edge;
- this.ceid = edge.getEdgeId().longValue();
+ ceid = edge.getEdgeId().longValue();
}
/**
* When edge is removed, we must disconnect source and destination Connected Vertices.
*/
void close() {
- this.triggers.clear();
- this.disconnect();
+ triggers.clear();
+ disconnect();
}
/**
*
* @param vertex Vertex
*/
- public ConnectedEdgeImpl setSource(ConnectedVertexImpl vertex) {
+ public ConnectedEdgeImpl setSource(final ConnectedVertexImpl vertex) {
source = vertex;
return this;
}
*
* @param vertex Vertex
*/
- public ConnectedEdgeImpl setDestination(ConnectedVertexImpl vertex) {
+ public ConnectedEdgeImpl setDestination(final ConnectedVertexImpl vertex) {
destination = vertex;
return this;
}
*
* @param edge Edge
*/
- public ConnectedEdgeImpl setEdge(Edge edge) {
+ public ConnectedEdgeImpl setEdge(final Edge edge) {
this.edge = edge;
return this;
}
@Override
public @NonNull Long getKey() {
- return this.ceid;
+ return ceid;
}
@Override
public ConnectedVertex getSource() {
- return this.source;
+ return source;
}
@Override
public ConnectedVertex getDestination() {
- return this.destination;
+ return destination;
}
@Override
public Edge getEdge() {
- return this.edge;
+ return edge;
}
@Override
}
@Override
- public Long getCosResvBandwidth(int cos) {
+ public Long getCosResvBandwidth(final int cos) {
if (cos < 0 || cos > MAX_PRIORITY) {
return null;
} else {
}
@Override
- public void addBandwidth(Long bw, int cos) {
+ public void addBandwidth(final Long bw, final int cos) {
if (cos < 0 || cos > MAX_PRIORITY) {
return;
}
}
@Override
- public void delBandwidth(Long bw, int cos) {
+ public void delBandwidth(final Long bw, final int cos) {
if (cos < 0 || cos > MAX_PRIORITY) {
return;
}
}
@Override
- public boolean registerTrigger(ConnectedEdgeTrigger trigger, String key) {
+ public boolean registerTrigger(final ConnectedEdgeTrigger trigger, final String key) {
return triggers.putIfAbsent(key, trigger) == null;
}
@Override
- public boolean unRegisterTrigger(ConnectedEdgeTrigger trigger, String key) {
+ public boolean unRegisterTrigger(final ConnectedEdgeTrigger trigger, final String key) {
return triggers.remove(key, trigger);
}
public List<ConnectedEdgeTrigger> getTriggers() {
- return new ArrayList<ConnectedEdgeTrigger>(triggers.values());
+ return new ArrayList<>(triggers.values());
}
/**
import org.opendaylight.graph.ConnectedGraph;
import org.opendaylight.graph.ConnectedGraphProvider;
import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
import org.opendaylight.mdsal.binding.api.TransactionChain;
import org.opendaylight.mdsal.binding.api.WriteTransaction;
import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.graph.topology.GraphBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.graph.topology.GraphKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.graph.topology.graph.Edge;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.graph.topology.graph.EdgeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.graph.topology.graph.Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.graph.topology.graph.PrefixKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.graph.topology.graph.Vertex;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.graph.topology.graph.VertexKey;
import org.opendaylight.yangtools.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.binding.DataObjectIdentifier;
+import org.opendaylight.yangtools.binding.DataObjectIdentifier.WithKey;
import org.opendaylight.yangtools.yang.common.Empty;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
@Component(immediate = true, service = ConnectedGraphProvider.class)
public final class ConnectedGraphServer implements ConnectedGraphProvider, FutureCallback<Empty>, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(ConnectedGraphServer.class);
- private static final @NonNull InstanceIdentifier<GraphTopology> GRAPH_TOPOLOGY_IDENTIFIER =
- InstanceIdentifier.create(GraphTopology.class);
+ private static final @NonNull DataObjectIdentifier<GraphTopology> GRAPH_TOPOLOGY_IDENTIFIER =
+ DataObjectIdentifier.builder(GraphTopology.class).build();
private final Map<GraphKey, ConnectedGraphImpl> graphs = new HashMap<>();
private final DataBroker dataBroker;
/**
* DataStore Instance Identifier creation for the various Graph components.
*/
- private static InstanceIdentifier<Graph> getGraphInstanceIdentifier(final String name) {
- return GRAPH_TOPOLOGY_IDENTIFIER.child(Graph.class, new GraphKey(name));
+ private static WithKey<Graph, GraphKey> getGraphInstanceIdentifier(final String name) {
+ return GRAPH_TOPOLOGY_IDENTIFIER.toBuilder().child(Graph.class, new GraphKey(name)).build();
}
- private static InstanceIdentifier<Vertex> getVertexInstanceIdentifier(final Graph graph, final Vertex vertex) {
- return GRAPH_TOPOLOGY_IDENTIFIER.child(Graph.class, graph.key()).child(Vertex.class, vertex.key());
+ private static WithKey<Vertex, VertexKey> getVertexInstanceIdentifier(final Graph graph, final Vertex vertex) {
+ return GRAPH_TOPOLOGY_IDENTIFIER.toBuilder()
+ .child(Graph.class, graph.key())
+ .child(Vertex.class, vertex.key())
+ .build();
}
- private static InstanceIdentifier<Edge> getEdgeInstanceIdentifier(final Graph graph, final Edge edge) {
- return GRAPH_TOPOLOGY_IDENTIFIER.child(Graph.class, graph.key()).child(Edge.class, edge.key());
+ private static WithKey<Edge, EdgeKey> getEdgeInstanceIdentifier(final Graph graph, final Edge edge) {
+ return GRAPH_TOPOLOGY_IDENTIFIER.toBuilder()
+ .child(Graph.class, graph.key())
+ .child(Edge.class, edge.key())
+ .build();
}
- private static InstanceIdentifier<Prefix> getPrefixInstanceIdentifier(final Graph graph, final Prefix prefix) {
- return GRAPH_TOPOLOGY_IDENTIFIER.child(Graph.class, graph.key()).child(Prefix.class, prefix.key());
+ private static WithKey<Prefix, PrefixKey> getPrefixInstanceIdentifier(final Graph graph, final Prefix prefix) {
+ return GRAPH_TOPOLOGY_IDENTIFIER.toBuilder()
+ .child(Graph.class, graph.key())
+ .child(Prefix.class, prefix.key())
+ .build();
}
/**
* @param data Data Object (Graph, Vertex, Edge or Prefix)
* @param info Information to be logged
*/
- private synchronized <T extends DataObject> void addToDataStore(final InstanceIdentifier<T> id, final T data,
+ private synchronized <T extends DataObject> void addToDataStore(final DataObjectIdentifier<T> id, final T data,
final String info) {
- final ReadWriteTransaction trans = chain.newReadWriteTransaction();
- trans.put(LogicalDatastoreType.OPERATIONAL, id, data);
- trans.commit().addCallback(new FutureCallback<CommitInfo>() {
+ final var tx = chain.newWriteOnlyTransaction();
+ tx.put(LogicalDatastoreType.OPERATIONAL, id, data);
+ tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.info("GraphModel: {} has been published in operational datastore ", info);
@Override
public void onFailure(final Throwable throwable) {
LOG.error("GrahModel: Cannot write {} to the operational datastore (transaction: {})", info,
- trans.getIdentifier());
+ tx.getIdentifier());
}
}, MoreExecutors.directExecutor());
}
* @param old Instance Identifier of the previous version of the Data Object
* @param info Information to be logged
*/
- private synchronized <T extends DataObject> void updateToDataStore(final InstanceIdentifier<T> id, final T data,
- final InstanceIdentifier<T> old, final String info) {
- final ReadWriteTransaction trans = chain.newReadWriteTransaction();
+ private synchronized <T extends DataObject> void updateToDataStore(final DataObjectIdentifier<T> id, final T data,
+ final DataObjectIdentifier<T> old, final String info) {
+ final var tx = chain.newWriteOnlyTransaction();
if (old != null) {
- trans.delete(LogicalDatastoreType.OPERATIONAL, old);
+ tx.delete(LogicalDatastoreType.OPERATIONAL, old);
}
- trans.put(LogicalDatastoreType.OPERATIONAL, id, data);
- trans.commit().addCallback(new FutureCallback<CommitInfo>() {
+ tx.put(LogicalDatastoreType.OPERATIONAL, id, data);
+ tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.info("GraphModel: {} has been published in operational datastore ", info);
@Override
public void onFailure(final Throwable throwable) {
LOG.error("GrahModel: Cannot write {} to the operational datastore (transaction: {})", info,
- trans.getIdentifier());
+ tx.getIdentifier());
}
}, MoreExecutors.directExecutor());
}
* @param id Instance Identifier of the Data Object
* @param info Information to be logged
*/
- private synchronized <T extends DataObject> void removeFromDataStore(final InstanceIdentifier<T> id,
+ private synchronized <T extends DataObject> void removeFromDataStore(final DataObjectIdentifier<T> id,
final String info) {
- final ReadWriteTransaction trans = chain.newReadWriteTransaction();
- trans.delete(LogicalDatastoreType.OPERATIONAL, id);
- trans.commit().addCallback(new FutureCallback<CommitInfo>() {
+ final var tx = chain.newWriteOnlyTransaction();
+ tx.delete(LogicalDatastoreType.OPERATIONAL, id);
+ tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.info("GraphModel: {} has been deleted in operational datastore ", info);
@Override
public void onFailure(final Throwable throwable) {
LOG.error("GraphModel: Cannot delete {} to the operational datastore (transaction: {})", info,
- trans.getIdentifier());
+ tx.getIdentifier());
}
}, MoreExecutors.directExecutor());
}
public void addVertex(final Graph graph, final Vertex vertex, final Vertex old) {
checkArgument(graph != null, "Provided Graph is a null object");
checkArgument(vertex != null, "Provided Vertex is a null object");
- InstanceIdentifier<Vertex> oldId = null;
/* Remove old Vertex if it exists before storing the new Vertex */
- if (old != null) {
- oldId = getVertexInstanceIdentifier(graph, old);
- }
+ final var oldId = old != null ? getVertexInstanceIdentifier(graph, old) : null;
updateToDataStore(getVertexInstanceIdentifier(graph, vertex), vertex, oldId,
"Vertex(" + vertex.getName() + ")");
}
public void addEdge(final Graph graph, final Edge edge, final Edge old) {
checkArgument(graph != null, "Provided Graph is a null object");
checkArgument(edge != null, "Provided Edge is a null object");
- InstanceIdentifier<Edge> oldId = null;
/* Remove old Edge if it exists before storing the new Edge */
- if (old != null) {
- oldId = getEdgeInstanceIdentifier(graph, old);
- }
+ final var oldId = old != null ? getEdgeInstanceIdentifier(graph, old) : null;
updateToDataStore(getEdgeInstanceIdentifier(graph, edge), edge, oldId, "Edge(" + edge.getName() + ")");
}
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.graph.ConnectedEdge;
import org.opendaylight.graph.ConnectedVertex;
* @author Olivier Dugeon
* @author Philippe Niger
*/
-
public class ConnectedVertexImpl implements ConnectedVertex {
/* Reference to input and output Connected Edge within the Connected Graph */
- private ArrayList<ConnectedEdgeImpl> input = new ArrayList<>();
- private ArrayList<ConnectedEdgeImpl> output = new ArrayList<>();
+ private final ArrayList<ConnectedEdgeImpl> input = new ArrayList<>();
+ private final ArrayList<ConnectedEdgeImpl> output = new ArrayList<>();
/* List of Prefixes announced by this Vertex */
- private ArrayList<Prefix> prefixes = new ArrayList<>();
+ private final ArrayList<Prefix> prefixes = new ArrayList<>();
/* Reference to the Vertex of the standard Graph associated to the Connected Graph */
private Vertex vertex = null;
/* Connected Vertex Identifier */
- private Long cvid;
+ private final @NonNull Long cvid;
/* List of Connected Edge Trigger */
- private ConcurrentMap<String, ConnectedVertexTrigger> triggers =
- new ConcurrentHashMap<String, ConnectedVertexTrigger>();
+ private final ConcurrentMap<String, ConnectedVertexTrigger> triggers = new ConcurrentHashMap<>();
- public ConnectedVertexImpl(@NonNull Long key) {
+ public ConnectedVertexImpl(final @NonNull Long key) {
checkArgument(key != 0, "Vertex Key must not be equal to 0");
- this.cvid = key;
- this.vertex = null;
+ cvid = key;
+ vertex = null;
}
- public ConnectedVertexImpl(@NonNull Vertex vertex) {
- checkArgument(vertex.getVertexId().longValue() != 0, "Vertex Key must not be equal to 0");
- this.cvid = vertex.getVertexId().longValue();
+ public ConnectedVertexImpl(final @NonNull Vertex vertex) {
+ final var id = vertex.getVertexId().longValue();
+ checkArgument(id != 0, "Vertex Key must not be equal to 0");
+ cvid = id;
this.vertex = vertex;
}
* When vertex is removed, we must disconnect all Connected Edges.
*/
void close() {
- this.triggers.clear();
- this.disconnect();
+ triggers.clear();
+ disconnect();
}
/**
*
* @param vertex Vertex
*/
- public ConnectedVertexImpl setVertex(Vertex vertex) {
+ public ConnectedVertexImpl setVertex(final Vertex vertex) {
this.vertex = vertex;
return this;
}
*
* @param edge Connected Edge
*/
- public ConnectedVertexImpl addInput(ConnectedEdgeImpl edge) {
+ public ConnectedVertexImpl addInput(final ConnectedEdgeImpl edge) {
if (!input.contains(edge)) {
input.add(edge);
}
*
* @param edge Connected Edge
*/
- public ConnectedVertexImpl addOutput(ConnectedEdgeImpl edge) {
+ public ConnectedVertexImpl addOutput(final ConnectedEdgeImpl edge) {
if (!output.contains(edge)) {
output.add(edge);
}
*
* @param edge Connected Edge
*/
- public ConnectedVertexImpl removeInput(ConnectedEdgeImpl edge) {
+ public ConnectedVertexImpl removeInput(final ConnectedEdgeImpl edge) {
input.remove(edge);
return this;
}
*
* @param edge Connected Edge
*/
- public ConnectedVertexImpl removeOutput(ConnectedEdgeImpl edge) {
+ public ConnectedVertexImpl removeOutput(final ConnectedEdgeImpl edge) {
output.remove(edge);
return this;
}
* Disconnect all input and output Connected Edge.
*/
public void disconnect() {
- for (ConnectedEdgeImpl edge : input) {
+ for (var edge : input) {
edge.disconnectDestination();
}
- for (ConnectedEdgeImpl edge : output) {
+ for (var edge : output) {
edge.disconnectSource();
}
}
*
* @param prefix Prefix
*/
- public ConnectedVertexImpl addPrefix(Prefix prefix) {
+ public ConnectedVertexImpl addPrefix(final Prefix prefix) {
if (!prefixes.contains(prefix)) {
prefixes.add(prefix);
}
*
* @param prefix Prefix
*/
- public void removePrefix(Prefix prefix) {
+ public void removePrefix(final Prefix prefix) {
if (prefixes.contains(prefix)) {
prefixes.remove(prefix);
}
@Override
public Long getKey() {
- return this.cvid;
+ return cvid;
}
@Override
public Vertex getVertex() {
- return this.vertex;
+ return vertex;
}
@Override
- public List<ConnectedEdge> getEdgeTo(Long dstRid) {
- ArrayList<ConnectedEdge> edgeList = new ArrayList<ConnectedEdge>();
- for (ConnectedEdge edge : output) {
- if (edge.getDestination().getKey().equals(dstRid)) {
- edgeList.add(edge);
- }
- }
- return edgeList;
+ public List<ConnectedEdge> getEdgeTo(final Long dstRid) {
+ return output.stream()
+ .filter(edge -> edge.getDestination().getKey().equals(dstRid))
+ .collect(Collectors.toList());
}
@Override
public List<Edge> getInputEdges() {
- ArrayList<Edge> edgeList = new ArrayList<Edge>();
- for (ConnectedEdge edge : input) {
- edgeList.add(edge.getEdge());
- }
- return edgeList;
+ return input.stream().map(ConnectedEdgeImpl::getEdge).collect(Collectors.toList());
}
@Override
public List<ConnectedEdge> getInputConnectedEdges() {
- return new ArrayList<ConnectedEdge>(this.input);
+ return new ArrayList<>(input);
}
@Override
public List<Edge> getOutputEdges() {
- ArrayList<Edge> edgeList = new ArrayList<Edge>();
- for (ConnectedEdge edge : output) {
- edgeList.add(edge.getEdge());
- }
- return edgeList;
+ return output.stream().map(ConnectedEdgeImpl::getEdge).collect(Collectors.toList());
}
@Override
public List<ConnectedEdge> getOutputConnectedEdges() {
- return new ArrayList<ConnectedEdge>(this.output);
+ return new ArrayList<>(output);
}
@Override
public List<Prefix> getPrefixes() {
- return this.prefixes;
+ return prefixes;
}
@Override
- public boolean registerTrigger(ConnectedVertexTrigger trigger, String key) {
+ public boolean registerTrigger(final ConnectedVertexTrigger trigger, final String key) {
return triggers.putIfAbsent(key, trigger) == null;
}
@Override
- public boolean unRegisterTrigger(ConnectedVertexTrigger trigger, String key) {
+ public boolean unRegisterTrigger(final ConnectedVertexTrigger trigger, final String key) {
return triggers.remove(key, trigger);
}
public List<ConnectedVertexTrigger> getTriggers() {
- return new ArrayList<ConnectedVertexTrigger>(triggers.values());
+ return new ArrayList<>(triggers.values());
}
/**
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.DataObjectModification;
import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.binding.api.DataTreeModification;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.GraphTopology;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.graph.topology.graph.Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.graph.topology.graph.Vertex;
import org.opendaylight.yangtools.binding.DataObject;
+import org.opendaylight.yangtools.binding.DataObjectReference;
import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
public GraphListener(@Reference final DataBroker dataBroker, @Reference final ConnectedGraphProvider provider) {
graphProvider = requireNonNull(provider);
- final var graphIdentifier = InstanceIdentifier.builder(GraphTopology.class).child(Graph.class).build();
+ final var graphIdentifier = DataObjectReference.builder(GraphTopology.class).child(Graph.class).build();
- listenerRegistration = dataBroker.registerLegacyTreeChangeListener(
- DataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION, graphIdentifier), this);
+ listenerRegistration = dataBroker.registerLegacyTreeChangeListener(LogicalDatastoreType.CONFIGURATION,
+ graphIdentifier, this);
LOG.info("Registered listener {} on Graph Model at {}", this, graphIdentifier);
}
public void onDataTreeChanged(final List<DataTreeModification<Graph>> changes) {
for (var change : changes) {
final var root = change.getRootNode();
- final var key = change.getRootPath().path().firstKeyOf(Graph.class);
+ final var key = change.path().toLegacy().firstKeyOf(Graph.class);
switch (root.modificationType()) {
case DELETE:
graphProvider.deleteGraph(key);