if (isNetconfNode(rootNode.getDataAfter())) {
NodeId nodeId = getNodeId(identifier);
if (nodeId != null) {
- NetconfNode nnode = rootNode.getDataAfter().getAugmentation(NetconfNode.class);
+ NetconfNode nnode = rootNode.getDataAfter().augmentation(NetconfNode.class);
handledNetconfNode(nodeId, nnode);
}
}
}
private static boolean isNetconfNode(final Node node) {
- return node.getAugmentation(NetconfNode.class) != null;
+ return node.augmentation(NetconfNode.class) != null;
}
private static NodeId getNodeId(final InstanceIdentifier<?> path) {
Device1 d1 = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.FAILEDNOTALLOWED).build();
DeviceBuilder builder = new DeviceBuilder()
.setUniqueId(id)
- .setKey(new DeviceKey(id))
+ .withKey(new DeviceKey(id))
.setSshHostKey(sshEncodedKey)
.addAugmentation(Device1.class, d1);
InstanceIdentifier<Device> deviceIId =
InstanceIdentifier.create(NetconfCallhomeServer.class)
.child(AllowedDevices.class)
- .child(Device.class, device.getKey());
+ .child(Device.class, device.key());
tx.merge(LogicalDatastoreType.OPERATIONAL, deviceIId, device);
tx.submit();
Device1 devStatus = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.DISCONNECTED).build();
if (opDevGet.isPresent()) {
Device opDevice = opDevGet.get();
- devStatus = opDevice.getAugmentation(Device1.class);
+ devStatus = opDevice.augmentation(Device1.class);
}
cfgDevice = new DeviceBuilder().addAugmentation(Device1.class, devStatus)
}
@Override
- public void onSessionStarted(Session session) {
+ public void onSessionStarted(final Session session) {
final InstanceIdentifier<Session> sessionPath =
- SESSIONS_INSTANCE_IDENTIFIER.child(Session.class, session.getKey());
+ SESSIONS_INSTANCE_IDENTIFIER.child(Session.class, session.key());
runTransaction((tx) -> tx.put(LogicalDatastoreType.OPERATIONAL, sessionPath, session));
}
@Override
- public void onSessionEnded(Session session) {
+ public void onSessionEnded(final Session session) {
final InstanceIdentifier<Session> sessionPath =
- SESSIONS_INSTANCE_IDENTIFIER.child(Session.class, session.getKey());
+ SESSIONS_INSTANCE_IDENTIFIER.child(Session.class, session.key());
runTransaction((tx) -> tx.delete(LogicalDatastoreType.OPERATIONAL, sessionPath));
}
@Override
- public void onSessionsUpdated(Collection<Session> sessions) {
+ public void onSessionsUpdated(final Collection<Session> sessions) {
runTransaction((tx) -> updateSessions(tx, sessions));
}
@Override
- public void onCapabilitiesChanged(Capabilities capabilities) {
+ public void onCapabilitiesChanged(final Capabilities capabilities) {
runTransaction((tx) -> tx.put(LogicalDatastoreType.OPERATIONAL, CAPABILITIES_INSTANCE_IDENTIFIER,
capabilities));
}
@Override
- public void onSchemasChanged(Schemas schemas) {
+ public void onSchemasChanged(final Schemas schemas) {
runTransaction((tx) -> tx.put(LogicalDatastoreType.OPERATIONAL, SCHEMAS_INSTANCE_IDENTIFIER, schemas));
}
serverMonitoringDependency.registerSessionsListener(this);
}
- private void runTransaction(Consumer<WriteTransaction> txUser) {
+ private void runTransaction(final Consumer<WriteTransaction> txUser) {
Preconditions.checkState(dataBroker != null);
final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
txUser.accept(tx);
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
- public void onSuccess(@Nullable Void result) {
+ public void onSuccess(@Nullable final Void result) {
LOG.debug("Netconf state updated successfully");
}
@Override
- public void onFailure(Throwable throwable) {
+ public void onFailure(final Throwable throwable) {
LOG.warn("Unable to update netconf state", throwable);
}
}, MoreExecutors.directExecutor());
}
- private static void updateSessions(WriteTransaction tx, Collection<Session> sessions) {
+ private static void updateSessions(final WriteTransaction tx, final Collection<Session> sessions) {
for (Session session : sessions) {
final InstanceIdentifier<Session> sessionPath =
- SESSIONS_INSTANCE_IDENTIFIER.child(Session.class, session.getKey());
+ SESSIONS_INSTANCE_IDENTIFIER.child(Session.class, session.key());
tx.put(LogicalDatastoreType.OPERATIONAL, sessionPath, session);
}
}
final InstanceIdentifier<Session> id =
InstanceIdentifier.create(NetconfState.class)
.child(Sessions.class)
- .child(Session.class, session.getKey());
+ .child(Session.class, session.key());
writer.start();
writer.onSessionStarted(session);
InOrder inOrder = inOrder(writeTransaction);
final InstanceIdentifier<Session> id =
InstanceIdentifier.create(NetconfState.class)
.child(Sessions.class)
- .child(Session.class, session.getKey());
+ .child(Session.class, session.key());
writer.start();
writer.onSessionEnded(session);
InOrder inOrder = inOrder(writeTransaction);
final InstanceIdentifier<Session> id1 =
InstanceIdentifier.create(NetconfState.class)
.child(Sessions.class)
- .child(Session.class, session1.getKey());
+ .child(Session.class, session1.key());
final InstanceIdentifier<Session> id2 =
InstanceIdentifier.create(NetconfState.class)
.child(Sessions.class)
- .child(Session.class, session2.getKey());
+ .child(Session.class, session2.key());
writer.start();
writer.onSessionsUpdated(sessions);
InOrder inOrder = inOrder(writeTransaction);
package org.opendaylight.controller.config.yang.netconf.mdsal.notification;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
.NetconfNotificationStreamListener {
private static final Logger LOG = LoggerFactory.getLogger(NotificationToMdsalWriter.class);
+ private static final InstanceIdentifier<Streams> STREAMS = InstanceIdentifier.builder(Netconf.class)
+ .child(Streams.class).build();
private final NetconfNotificationCollector netconfNotificationCollector;
private final DataBroker dataBroker;
public void close() {
final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
tx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Netconf.class));
- final CheckedFuture<Void, TransactionCommitFailedException> submit = tx.submit();
- Futures.addCallback(submit, new FutureCallback<Void>() {
+ Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
- public void onSuccess(Void avoid) {
+ public void onSuccess(final Void avoid) {
LOG.debug("Streams cleared successfully");
}
@Override
- public void onFailure(Throwable throwable) {
+ public void onFailure(final Throwable throwable) {
LOG.warn("Unable to clear streams", throwable);
}
}, MoreExecutors.directExecutor());
}
@Override
- public void onStreamRegistered(Stream stream) {
+ public void onStreamRegistered(final Stream stream) {
final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
- final InstanceIdentifier streamIdentifier = InstanceIdentifier.create(Netconf.class).child(Streams.class)
- .builder().child(Stream.class, stream.getKey()).build();
+ final InstanceIdentifier<Stream> streamIdentifier = STREAMS.child(Stream.class, stream.key());
tx.merge(LogicalDatastoreType.OPERATIONAL, streamIdentifier, stream, true);
try {
}
@Override
- public void onStreamUnregistered(StreamNameType stream) {
+ public void onStreamUnregistered(final StreamNameType stream) {
final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
- final StreamKey streamKey = new StreamKey(stream);
- final InstanceIdentifier streamIdentifier = InstanceIdentifier.create(Netconf.class).child(Streams.class)
- .builder().child(Stream.class, streamKey).build();
+ final InstanceIdentifier<Stream> streamIdentifier = STREAMS.child(Stream.class, new StreamKey(stream));
tx.delete(LogicalDatastoreType.OPERATIONAL, streamIdentifier);
@Test
public void testOnDataChangedCreate() {
- final InstanceIdentifier capabilitiesIdentifier =
- InstanceIdentifier.create(NetconfState.class).child(Capabilities.class).builder().build();
+ final InstanceIdentifier<Capabilities> capabilitiesIdentifier =
+ InstanceIdentifier.create(NetconfState.class).child(Capabilities.class);
final List<Uri> newCapabilitiesList =
Lists.newArrayList(new Uri("newCapability"), new Uri("createdCapability"));
Capabilities newCapabilities = new CapabilitiesBuilder().setCapability(newCapabilitiesList).build();
@SuppressWarnings("unchecked")
private void verifyDataTreeChange(final DataObjectModification.ModificationType modificationType,
- Capabilities originalCapabilities, Capabilities updatedCapabilities,
- NetconfCapabilityChange expectedChange) {
+ final Capabilities originalCapabilities, final Capabilities updatedCapabilities,
+ final NetconfCapabilityChange expectedChange) {
final DataTreeModification<Capabilities> treeChange2 = mock(DataTreeModification.class);
final DataObjectModification<Capabilities> objectChange2 = mock(DataObjectModification.class);
doReturn(modificationType).when(objectChange2).getModificationType();
verify(baseNotificationPublisherRegistration).onCapabilityChanged(expectedChange);
}
- private NetconfCapabilityChange changedCapabilitesFrom(List<Uri> added, List<Uri> deleted) {
+ private NetconfCapabilityChange changedCapabilitesFrom(final List<Uri> added, final List<Uri> deleted) {
NetconfCapabilityChangeBuilder netconfCapabilityChangeBuilder = new NetconfCapabilityChangeBuilder();
netconfCapabilityChangeBuilder.setChangedBy(new ChangedByBuilder().setServerOrUser(
new ServerBuilder().setServer(true).build()).build());
public void testStreamRegisteration() {
final StreamNameType testStreamName = new StreamNameType("TESTSTREAM");
final Stream testStream = new StreamBuilder().setName(testStreamName).build();
- final InstanceIdentifier streamIdentifier = InstanceIdentifier.create(Netconf.class).child(Streams.class)
- .builder().child(Stream.class, testStream.getKey()).build();
+ final InstanceIdentifier<Stream> streamIdentifier = InstanceIdentifier.create(Netconf.class)
+ .child(Streams.class).child(Stream.class, testStream.key());
writer.onStreamRegistered(testStream);
public void testClose() {
doNothing().when(notificationRegistration).close();
- final InstanceIdentifier streamIdentifier = InstanceIdentifier.create(Netconf.class);
+ final InstanceIdentifier<Netconf> streamIdentifier = InstanceIdentifier.create(Netconf.class);
writer.close();
@Override
public NodeKey getSourceNodeKey() {
- return mount.getNode().getKey();
+ return mount.getNode().key();
}
@Override
}
@Override
- public void onDataTreeChanged(Collection<DataTreeModification<Node>> changes) {
+ public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
for (DataTreeModification<Node> change: changes) {
LOG.debug("DataTreeModification: {}", change);
final DataObjectModification<Node> rootNode = change.getRootNode();
}
}
- private boolean validateNode(final Node node) {
- if (node == null) {
- return false;
- }
- return isNetconfNode(node);
+ private static boolean validateNode(final Node node) {
+ return node == null ? false : isNetconfNode(node);
}
Map<String, String> getStreamMap() {
*
* @param streamMap Stream map
*/
- public void setStreamMap(Map<String, String> streamMap) {
+ public void setStreamMap(final Map<String, String> streamMap) {
this.streamMap = streamMap;
}
- private boolean isNetconfNode(final Node node) {
- return node.getAugmentation(NetconfNode.class) != null;
+ private static boolean isNetconfNode(final Node node) {
+ return node.augmentation(NetconfNode.class) != null;
}
@Override
}
private static boolean isEventSource(final Node node) {
- final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
if (netconfNode == null) {
return false;
}
}
NetconfNode getNetconfNode() {
- return node.getAugmentation(NetconfNode.class);
+ return node.augmentation(NetconfNode.class);
}
void updateStatus() {
changeStatus(netconfConnStatus);
}
- private boolean checkConnectionStatusType(ConnectionStatus status) {
+ private static boolean checkConnectionStatusType(final ConnectionStatus status) {
return status == ConnectionStatus.Connected || status == ConnectionStatus.Connecting
|| status == ConnectionStatus.UnableToConnect;
}
- private void changeStatus(ConnectionStatus newStatus) {
+ private void changeStatus(final ConnectionStatus newStatus) {
Preconditions.checkNotNull(newStatus);
Preconditions.checkState(this.currentNetconfConnStatus != null);
if (!checkConnectionStatusType(newStatus)) {
this.eventSourceRegistration = registration;
}
- private YangInstanceIdentifier domMountPath(final NodeId nodeId) {
+ private static YangInstanceIdentifier domMountPath(final NodeId nodeId) {
return YangInstanceIdentifier.builder(NETCONF_DEVICE_DOM_PATH)
.nodeWithKey(Node.QNAME, NODE_ID_QNAME, nodeId.getValue()).build();
}
private NetconfTestUtils() {
}
- public static Node getNetconfNode(String nodeIdent, String hostName, ConnectionStatus cs,
- String notificationCapabilityPrefix) {
+ public static Node getNetconfNode(final String nodeIdent, final String hostName, final ConnectionStatus cs,
+ final String notificationCapabilityPrefix) {
DomainName dn = new DomainName(hostName);
Host host = new Host(dn);
NodeId nodeId = new NodeId(nodeIdent);
NodeKey nk = new NodeKey(nodeId);
NodeBuilder nb = new NodeBuilder();
- nb.setKey(nk);
+ nb.withKey(nk);
nb.addAugmentation(NetconfNode.class, nn);
return nb.build();
}
- public static Node getNode(String nodeIdent) {
+ public static Node getNode(final String nodeIdent) {
NodeId nodeId = new NodeId(nodeIdent);
NodeKey nk = new NodeKey(nodeId);
NodeBuilder nb = new NodeBuilder();
- nb.setKey(nk);
+ nb.withKey(nk);
return nb.build();
}
- public static InstanceIdentifier<Node> getInstanceIdentifier(Node node) {
+ public static InstanceIdentifier<Node> getInstanceIdentifier(final Node node) {
TopologyKey netconfTopologyKey = new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName()));
InstanceIdentifier<Node> nodeII = InstanceIdentifier.create(NetworkTopology.class)
- .child(Topology.class, netconfTopologyKey).child(Node.class, node.getKey());
+ .child(Topology.class, netconfTopologyKey).child(Node.class, node.key());
return nodeII;
}
- public static Optional<Streams> getAvailableStream(String name, boolean replaySupport) {
+ public static Optional<Streams> getAvailableStream(final String name, final boolean replaySupport) {
Stream stream = new StreamBuilder().setName(new StreamNameType(name)).setReplaySupport(replaySupport).build();
List<Stream> streamList = new ArrayList<>();
streamList.add(stream);
return Optional.of(streams);
}
- public static NormalizedNode<?, ?> getStreamsNode(String... streamName) {
+ public static NormalizedNode<?, ?> getStreamsNode(final String... streamName) {
QName nameNode = QName.create(Stream.QNAME, "name");
Set<MapEntryNode> streamSet = new HashSet<>();
for (String s : streamName) {
}
final Map<String, Map<String, String>> netconfNodes = new HashMap<>();
for (final Node node : topology.getNode()) {
- final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
final Map<String, String> attributes = new HashMap<>();
attributes.put(NetconfConsoleConstants.NETCONF_ID, node.getNodeId().getValue());
attributes.put(NetconfConsoleConstants.NETCONF_IP,
if (nodeList != null) {
for (final Node node : nodeList) {
if (node != null) {
- final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
final Map<String, List<String>> attributes = new HashMap<>();
attributes.put(NetconfConsoleConstants.NETCONF_ID, ImmutableList.of(node.getNodeId().getValue()));
attributes.put(NetconfConsoleConstants.NETCONF_IP,
final List<Node> nodeList = NetconfConsoleUtils.getNetconfNodeFromId(deviceId, dataBroker);
if (nodeList != null && nodeList.size() > 0) {
for (final Node node : nodeList) {
- final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
final Map<String, List<String>> attributes = new HashMap<>();
attributes.put(NetconfConsoleConstants.NETCONF_ID, ImmutableList.of(node.getNodeId().getValue()));
attributes.put(NetconfConsoleConstants.NETCONF_IP,
}
@Override
- public void connectDevice(NetconfNode netconfNode, String netconfNodeId) {
+ public void connectDevice(final NetconfNode netconfNode, final String netconfNodeId) {
final NodeId nodeId;
if (!Strings.isNullOrEmpty(netconfNodeId)) {
nodeId = new NodeId(netconfNodeId);
nodeId = new NodeId(UUID.randomUUID().toString().replace("-", ""));
}
final Node node = new NodeBuilder()
- .setKey(new NodeKey(nodeId))
+ .withKey(new NodeKey(nodeId))
.setNodeId(nodeId)
.addAugmentation(NetconfNode.class, netconfNode)
.build();
Futures.addCallback(transaction.submit(), new FutureCallback<Void>() {
@Override
- public void onSuccess(Void result) {
+ public void onSuccess(final Void result) {
LOG.debug("NetconfNode={} created successfully", netconfNode);
}
@Override
- public void onFailure(Throwable throwable) {
+ public void onFailure(final Throwable throwable) {
LOG.error("Failed to created NetconfNode={}", netconfNode);
throw new RuntimeException(throwable);
}
}
@Override
- public boolean disconnectDevice(String netconfNodeId) {
+ public boolean disconnectDevice(final String netconfNodeId) {
boolean result = false;
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<Node> iid = NetconfIidFactory.netconfNodeIid(netconfNodeId);
}
@Override
- public String updateDevice(final String netconfNodeId, String username, String password,
- Map<String, String> updated) {
+ public String updateDevice(final String netconfNodeId, final String username, final String password,
+ final Map<String, String> updated) {
final Node node = NetconfConsoleUtils
.read(LogicalDatastoreType.OPERATIONAL, NetconfIidFactory.netconfNodeIid(netconfNodeId), dataBroker);
- if (node != null && node.getAugmentation(NetconfNode.class) != null) {
- final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+ if (node != null && node.augmentation(NetconfNode.class) != null) {
+ final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
// Get NETCONF attributes to update if present else get their original values from NetconfNode instance
final String deviceIp = Strings.isNullOrEmpty(updated.get(NetconfConsoleConstants.NETCONF_IP))
.build();
final Node updatedNode = new NodeBuilder()
- .setKey(node.getKey())
+ .withKey(node.key())
.setNodeId(node.getNodeId())
.addAugmentation(NetconfNode.class, updatedNetconfNode)
.build();
Futures.addCallback(transaction.submit(), new FutureCallback<Void>() {
@Override
- public void onSuccess(Void result) {
+ public void onSuccess(final Void result) {
LOG.debug("NetconfNode={} updated successfully", netconfNode);
}
@Override
- public void onFailure(Throwable throwable) {
+ public void onFailure(final Throwable throwable) {
LOG.error("Failed to updated NetconfNode={}", netconfNode);
throw new RuntimeException(throwable);
}
List<Node> nodes = new ArrayList<>();
if (isNetconfNodesPresent(topology)) {
for (Node node : topology.getNode()) {
- final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
if (netconfNode != null
&& netconfNode.getHost().getIpAddress().getIpv4Address().getValue().equals(deviceIp)) {
nodes.add(node);
}
}
}
- return (nodes.isEmpty()) ? null : nodes;
+ return nodes.isEmpty() ? null : nodes;
}
/**
final Topology topology = read(LogicalDatastoreType.OPERATIONAL, NetconfIidFactory.NETCONF_TOPOLOGY_IID, db);
if (isNetconfNodesPresent(topology)) {
for (Node node : topology.getNode()) {
- final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
if (netconfNode != null
&& netconfNode.getHost().getIpAddress().getIpv4Address().getValue().equals(deviceIp)
&& devicePort.equals(netconfNode.getPort().getValue().toString())) {
assertEquals(2, nodes.size());
final Optional<Node> storedNode = nodes.stream().filter(node ->
- node.getKey().getNodeId().getValue().equals("netconf-ID")).findFirst();
+ node.key().getNodeId().getValue().equals("netconf-ID")).findFirst();
assertTrue(storedNode.isPresent());
- NetconfNode storedNetconfNode = storedNode.get().getAugmentation(NetconfNode.class);
+ NetconfNode storedNetconfNode = storedNode.get().augmentation(NetconfNode.class);
assertEquals(7777, storedNetconfNode.getPort().getValue().longValue());
assertEquals("10.10.1.1", storedNetconfNode.getHost().getIpAddress().getIpv4Address().getValue());
assertEquals(1, nodesDeleted.size());
final Optional<Node> storedNodeDeleted = nodesDeleted.stream().filter(node ->
- node.getKey().getNodeId().getValue().equals("netconf-ID")).findFirst();
+ node.key().getNodeId().getValue().equals("netconf-ID")).findFirst();
assertFalse(storedNodeDeleted.isPresent());
}
assertEquals(1, nodes.size());
final Optional<Node> storedNode = nodes.stream().filter(node ->
- node.getKey().getNodeId().getValue().equals(NODE_ID)).findFirst();
+ node.key().getNodeId().getValue().equals(NODE_ID)).findFirst();
assertTrue(storedNode.isPresent());
- NetconfNode storedNetconfNode = storedNode.get().getAugmentation(NetconfNode.class);
+ NetconfNode storedNetconfNode = storedNode.get().augmentation(NetconfNode.class);
assertEquals("7.7.7.7", storedNetconfNode.getHost().getIpAddress().getIpv4Address().getValue());
}
nodes.add(node);
final Topology topology = new TopologyBuilder()
- .setKey(new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())))
+ .withKey(new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())))
.setTopologyId(new TopologyId(TopologyNetconf.QNAME.getLocalName())).setNode(nodes).build();
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
final NodeId nodeId = new NodeId(nodeIdent);
final NodeKey nk = new NodeKey(nodeId);
final NodeBuilder nb = new NodeBuilder();
- nb.setKey(nk);
+ nb.withKey(nk);
nb.setNodeId(nodeId);
nb.addAugmentation(NetconfNode.class, nn);
return nb.build();
import com.google.common.net.InetAddresses;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelFutureListener;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import java.net.Inet4Address;
}
// delayed close was set, close after the message was sent
if (delayedClose) {
- channelFuture.addListener(new ChannelFutureListener() {
- @Override
- public void operationComplete(final ChannelFuture future) throws Exception {
- close();
- }
- });
+ channelFuture.addListener(future -> close());
}
return channelFuture;
}
builder.setOutNotifications(new ZeroBasedCounter32(outNotification));
- builder.setKey(new SessionKey(getSessionId()));
+ builder.withKey(new SessionKey(getSessionId()));
Session1Builder builder1 = new Session1Builder();
builder1.setSessionIdentifier(header.getSessionIdentifier());
builder.setLocation(transformLocations(cap.getLocation()));
- builder.setKey(new SchemaKey(Yang.class, identifier, version));
+ builder.withKey(new SchemaKey(Yang.class, identifier, version));
schemas.add(builder.build());
}
@XmlTransient
private Session managementSession;
- MonitoringSession(Session managementSession) {
+ MonitoringSession(final Session managementSession) {
this.managementSession = managementSession;
}
MonitoringSession() {
}
- public void setManagementSession(Session managementSession) {
+ public void setManagementSession(final Session managementSession) {
this.managementSession = managementSession;
}
@XmlElement(name = "session-identifier", namespace = MonitoringConstants.EXTENSION_NAMESPACE)
public String getSessionType() {
- return managementSession.getAugmentation(Session1.class).getSessionIdentifier();
+ return managementSession.augmentation(Session1.class).getSessionIdentifier();
}
@XmlElement(name = "username")
String.format(SESSION_XML, IPV6)));
}
- private Schema getMockSchema(final String id, final String version, final Class<Yang> format) {
+ private static Schema getMockSchema(final String id, final String version, final Class<Yang> format) {
final Schema mock = mock(Schema.class);
doReturn(format).when(mock).getFormat();
doReturn(new Uri("localhost")).when(mock).getNamespace();
doReturn(version).when(mock).getVersion();
doReturn(Lists.newArrayList(new Schema.Location(Schema.Location.Enumeration.NETCONF))).when(mock).getLocation();
- doReturn(new SchemaKey(format, id, version)).when(mock).getKey();
+ doReturn(new SchemaKey(format, id, version)).when(mock).key();
return mock;
}
- private Session getMockIPv4Session(final Class<? extends Transport> transportType) {
+ private static Session getMockIPv4Session(final Class<? extends Transport> transportType) {
final Session mocked = getMockSession(transportType);
doReturn(new Host(new IpAddress(new Ipv4Address(IPV4)))).when(mocked).getSourceHost();
return mocked;
}
- private Session getMockIPv6Session(final Class<? extends Transport> transportType) {
+ private static Session getMockIPv6Session(final Class<? extends Transport> transportType) {
final Session mocked = getMockSession(transportType);
doReturn(new Host(new IpAddress(new Ipv6Address(IPV6)))).when(mocked).getSourceHost();
return mocked;
}
- private Session getMockSession(final Class<? extends Transport> transportType) {
+ private static Session getMockSession(final Class<? extends Transport> transportType) {
final Session mocked = mock(Session.class);
final Session1 mockedSession1 = mock(Session1.class);
doReturn("client").when(mockedSession1).getSessionIdentifier();
doReturn(new ZeroBasedCounter32(0L)).when(mocked).getOutRpcErrors();
doReturn(transportType).when(mocked).getTransport();
doReturn("username").when(mocked).getUsername();
- doReturn(mockedSession1).when(mocked).getAugmentation(Session1.class);
+ doReturn(mockedSession1).when(mocked).augmentation(Session1.class);
return mocked;
}
}
static {
BASE_NETCONF_STREAM = new StreamBuilder()
.setName(BASE_STREAM_NAME)
- .setKey(new StreamKey(BASE_STREAM_NAME))
+ .withKey(new StreamKey(BASE_STREAM_NAME))
.setReplaySupport(false)
.setDescription("Default Event Stream")
.build();
listener.onStreamRegistered(availableStream);
}
- return new NotificationRegistration() {
- @Override
- public void close() {
- synchronized (NetconfNotificationManager.this) {
- streamListeners.remove(listener);
- }
+ return () -> {
+ synchronized (NetconfNotificationManager.this) {
+ streamListeners.remove(listener);
}
};
}
baseRegistration.close();
}
- private static NetconfNotification serializeNotification(final Notification notification, SchemaPath path) {
+ private static NetconfNotification serializeNotification(final Notification notification,
+ final SchemaPath path) {
return NotificationsTransformUtil.transform(notification, path);
}
}
@Override
- public void onSessionStarted(NetconfSessionStart start) {
+ public void onSessionStarted(final NetconfSessionStart start) {
baseRegistration.onNotification(BASE_STREAM_NAME, serializeNotification(start, SESSION_START_PATH));
}
@Override
- public void onSessionEnded(NetconfSessionEnd end) {
+ public void onSessionEnded(final NetconfSessionEnd end) {
baseRegistration.onNotification(BASE_STREAM_NAME, serializeNotification(end, SESSION_END_PATH));
}
}
final StreamBuilder streamBuilder = new StreamBuilder();
final StreamNameType base = new StreamNameType("base");
streamBuilder.setName(base);
- streamBuilder.setKey(new StreamKey(base));
+ streamBuilder.withKey(new StreamKey(base));
streamBuilder.setDescription("description");
streamBuilder.setReplaySupport(false);
streamsBuilder.setStream(Lists.newArrayList(streamBuilder.build()));
}
@SuppressWarnings("ConstantConditions")
- final NetconfNode netconfNodeAfter = rootNode.getDataAfter().getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNodeAfter = rootNode.getDataAfter().augmentation(NetconfNode.class);
if (NetconfNodeConnectionStatus.ConnectionStatus.Connected.equals(netconfNodeAfter.getConnectionStatus())) {
lastUpdateCount++;
this.mountService = mountService;
remoteDeviceId = NetconfTopologyUtils.createRemoteDeviceId(netconfTopologyDeviceSetup.getNode().getNodeId(),
- netconfTopologyDeviceSetup.getNode().getAugmentation(NetconfNode.class));
+ netconfTopologyDeviceSetup.getNode().augmentation(NetconfNode.class));
remoteDeviceConnector = new RemoteDeviceConnectorImpl(netconfTopologyDeviceSetup, remoteDeviceId);
final NetconfNodeManager ndm =
new NetconfNodeManager(netconfTopologyDeviceSetup, remoteDeviceId, actorResponseWaitTime, mountService);
ndm.registerDataTreeChangeListener(netconfTopologyDeviceSetup.getTopologyId(),
- netconfTopologyDeviceSetup.getNode().getKey());
+ netconfTopologyDeviceSetup.getNode().key());
return ndm;
}
void refresh(@Nonnull final NetconfTopologySetup setup) {
netconfTopologyDeviceSetup = Preconditions.checkNotNull(setup);
remoteDeviceId = NetconfTopologyUtils.createRemoteDeviceId(netconfTopologyDeviceSetup.getNode().getNodeId(),
- netconfTopologyDeviceSetup.getNode().getAugmentation(NetconfNode.class));
+ netconfTopologyDeviceSetup.getNode().augmentation(NetconfNode.class));
if (isMaster) {
remoteDeviceConnector.stopRemoteDeviceConnection();
// TODO change to a specific documented Exception when changed in ClusterSingletonServiceProvider
@SuppressWarnings("checkstyle:IllegalCatch")
private void startNetconfDeviceContext(final InstanceIdentifier<Node> instanceIdentifier, final Node node) {
- final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
Preconditions.checkNotNull(netconfNode);
Preconditions.checkNotNull(netconfNode.getHost());
Preconditions.checkNotNull(netconfNode.getHost().getIpAddress());
/**
* Sets the private key path from location specified in configuration file using blueprint.
*/
- public void setPrivateKeyPath(String privateKeyPath) {
+ public void setPrivateKeyPath(final String privateKeyPath) {
this.privateKeyPath = privateKeyPath;
}
/**
* Sets the private key passphrase from location specified in configuration file using blueprint.
*/
- public void setPrivateKeyPassphrase(String privateKeyPassphrase) {
+ public void setPrivateKeyPassphrase(final String privateKeyPassphrase) {
this.privateKeyPassphrase = privateKeyPassphrase;
}
@Override
public void startRemoteDeviceConnection(final RemoteDeviceHandler<NetconfSessionPreferences> deviceHandler) {
- final NetconfNode netconfNode = netconfTopologyDeviceSetup.getNode().getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = netconfTopologyDeviceSetup.getNode().augmentation(NetconfNode.class);
final NodeId nodeId = netconfTopologyDeviceSetup.getNode().getNodeId();
Preconditions.checkNotNull(netconfNode.getHost());
Preconditions.checkNotNull(netconfNode.getPort());
}
public static NetconfDevice.SchemaResourcesDTO setupSchemaCacheDTO(final Node node) {
- final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
final String moduleSchemaCacheDirectory = netconfNode.getSchemaCacheDirectory();
final RemoteDeviceId deviceId = createRemoteDeviceId(node.getNodeId(), netconfNode);
Optional<Node> node = readTx.read(LogicalDatastoreType.OPERATIONAL,
NODE_INSTANCE_ID).get(5, TimeUnit.SECONDS);
assertTrue(node.isPresent());
- final NetconfNode netconfNode = node.get().getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = node.get().augmentation(NetconfNode.class);
return netconfNode.getConnectionStatus() != NetconfNodeConnectionStatus.ConnectionStatus.Connected;
}
});
protected ListenableFuture<NetconfDeviceCapabilities> setupConnection(final NodeId nodeId,
final Node configNode) {
- final NetconfNode netconfNode = configNode.getAugmentation(NetconfNode.class);
+ final NetconfNode netconfNode = configNode.augmentation(NetconfNode.class);
Preconditions.checkNotNull(netconfNode.getHost());
Preconditions.checkNotNull(netconfNode.getPort());
*/
package org.opendaylight.netconf.topology.impl;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.netconf.topology.api.NetconfConnectorFactory;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.HostBuilder;
.build();
final Node node = new NodeBuilder()
.setNodeId(nodeId)
- .setKey(nodeKey)
+ .withKey(nodeKey)
.addAugmentation(NetconfNode.class, netconfNode)
.build();
final InstanceIdentifier<Node> nodePath = TOPOLOGY_PATH.child(Node.class, nodeKey);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.CONFIGURATION, nodePath, node);
- final CheckedFuture<Void, TransactionCommitFailedException> submitFuture = transaction.submit();
- Futures.addCallback(submitFuture, new FutureCallback<Void>() {
+ Futures.addCallback(transaction.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
LOG.debug("Node {} was successfully added to the topology", instanceName);
package org.opendaylight.netconf.sal.connect.netconf.sal;
import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
private void commitTransaction(final WriteTransaction transaction, final String txType) {
LOG.trace("{}: Committing Transaction {}:{}", id, txType,
transaction.getIdentifier());
- final CheckedFuture<Void, TransactionCommitFailedException> result = transaction.submit();
- Futures.addCallback(result, new FutureCallback<Void>() {
+ Futures.addCallback(transaction.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
LOG.trace("{}: Transaction({}) {} SUCCESSFUL", id, txType,
private static NodeBuilder getNodeIdBuilder(final RemoteDeviceId id) {
final NodeBuilder nodeBuilder = new NodeBuilder();
- nodeBuilder.setKey(new NodeKey(new NodeId(id.getName())));
+ nodeBuilder.withKey(new NodeKey(new NodeId(id.getName())));
return nodeBuilder;
}
return keyStore;
}
- private java.security.PrivateKey getJavaPrivateKey(final String base64PrivateKey)
+ private static java.security.PrivateKey getJavaPrivateKey(final String base64PrivateKey)
throws GeneralSecurityException {
final byte[] encodedKey = base64Decode(base64PrivateKey);
final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encodedKey);
return key;
}
- private List<X509Certificate> getCertificateChain(final String[] base64Certificates)
+ private static List<X509Certificate> getCertificateChain(final String[] base64Certificates)
throws GeneralSecurityException {
final CertificateFactory factory = CertificateFactory.getInstance("X.509");
final List<X509Certificate> certificates = new ArrayList<>();
return certificates;
}
- private byte[] base64Decode(final String base64) {
+ private static byte[] base64Decode(final String base64) {
return Base64.getMimeDecoder().decode(base64.getBytes(java.nio.charset.StandardCharsets.US_ASCII));
}
pairs.clear();
if (dataAfter != null) {
- dataAfter.getKeyCredential().forEach(pair -> pairs.put(pair.getKey().getKeyId(), pair));
+ dataAfter.getKeyCredential().forEach(pair -> pairs.put(pair.key().getKeyId(), pair));
}
break;
for (KeyCredential keypair : keypairs) {
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
- keystoreIid.child(KeyCredential.class, keypair.getKey()), keypair);
+ keystoreIid.child(KeyCredential.class, keypair.key()), keypair);
}
final SettableFuture<RpcResult<AddKeystoreEntryOutput>> rpcResult = SettableFuture.create();
- final ListenableFuture<Void> submit = writeTransaction.submit();
- Futures.addCallback(submit, new FutureCallback<Void>() {
+ Futures.addCallback(writeTransaction.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
LOG.debug("add-key-pair success. Input: {}");
for (TrustedCertificate certificate : input.getTrustedCertificate()) {
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
- keystoreIid.child(TrustedCertificate.class, certificate.getKey()), certificate);
+ keystoreIid.child(TrustedCertificate.class, certificate.key()), certificate);
}
final SettableFuture<RpcResult<AddTrustedCertificateOutput>> rpcResult = SettableFuture.create();
- final ListenableFuture<Void> submit = writeTransaction.submit();
- Futures.addCallback(submit, new FutureCallback<Void>() {
+ Futures.addCallback(writeTransaction.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
LOG.debug("add-trusted-certificate success. Input: {}", input);
final SettableFuture<RpcResult<RemoveTrustedCertificateOutput>> rpcResult = SettableFuture.create();
- final ListenableFuture<Void> submit = writeTransaction.submit();
- Futures.addCallback(submit, new FutureCallback<Void>() {
+ Futures.addCallback(writeTransaction.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
LOG.debug("remove-trusted-certificate success. Input: {}", input);
for (PrivateKey key: input.getPrivateKey()) {
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
- keystoreIid.child(PrivateKey.class, key.getKey()), key);
+ keystoreIid.child(PrivateKey.class, key.key()), key);
}
final SettableFuture<RpcResult<AddPrivateKeyOutput>> rpcResult = SettableFuture.create();
- final ListenableFuture<Void> submit = writeTransaction.submit();
- Futures.addCallback(submit, new FutureCallback<Void>() {
+ Futures.addCallback(writeTransaction.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
LOG.debug("add-private-key success. Input: {}", input);
final SettableFuture<RpcResult<RemovePrivateKeyOutput>> rpcResult = SettableFuture.create();
- final ListenableFuture<Void> submit = writeTransaction.submit();
- Futures.addCallback(submit, new FutureCallback<Void>() {
+ Futures.addCallback(writeTransaction.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
LOG.debug("remove-private-key success. Input: {}", input);
}
final PrivateKey privateKey = new PrivateKeyBuilder()
- .setKey(new PrivateKeyKey(keyName))
+ .withKey(new PrivateKeyKey(keyName))
.setName(keyName)
.setData(keyData)
.setCertificateChain(certChain)
final String certData = element.getElementsByTagName(XML_ELEMENT_CERT).item(0).getTextContent();
final TrustedCertificate certificate = new TrustedCertificateBuilder()
- .setKey(new TrustedCertificateKey(certName))
+ .withKey(new TrustedCertificateKey(certName))
.setName(certName)
.setCertificate(certData)
.build();
}
final PrivateKey privateKey = new PrivateKeyBuilder()
- .setKey(new PrivateKeyKey(keyName))
+ .withKey(new PrivateKeyKey(keyName))
.setName(keyName)
.setData(keyData)
.setCertificateChain(certChain)
final String certData = element.getElementsByTagName(XML_ELEMENT_CERT).item(0).getTextContent();
final TrustedCertificate certificate = new TrustedCertificateBuilder()
- .setKey(new TrustedCertificateKey(certName))
+ .withKey(new TrustedCertificateKey(certName))
.setName(certName)
.setCertificate(certData)
.build();
private static final Function<Capability, Schema> CAPABILITY_SCHEMA_FUNCTION = new Function<Capability, Schema>() {
@Nullable
@Override
- public Schema apply(@Nonnull Capability capability) {
+ public Schema apply(@Nonnull final Capability capability) {
return new SchemaBuilder()
.setIdentifier(capability.getModuleName().get())
.setNamespace(new Uri(capability.getModuleNamespace().get()))
.setFormat(Yang.class)
.setVersion(capability.getRevision().get())
.setLocation(Collections.singletonList(new Location(Enumeration.NETCONF)))
- .setKey(new SchemaKey(Yang.class, capability.getModuleName().get(), capability.getRevision().get()))
+ .withKey(new SchemaKey(Yang.class, capability.getModuleName().get(),
+ capability.getRevision().get()))
.build();
}
};
private final ArrayListMultimap<String, Capability> capabilityMultiMap;
private final Schemas schemas;
- public DummyMonitoringService(Set<Capability> capabilities) {
+ public DummyMonitoringService(final Set<Capability> capabilities) {
this.capabilities = new CapabilitiesBuilder().setCapability(
Lists.newArrayList(Collections2.transform(capabilities, CAPABILITY_URI_FUNCTION))).build();
public SessionListener getSessionListener() {
return new SessionListener() {
@Override
- public void onSessionUp(NetconfManagementSession session) {
+ public void onSessionUp(final NetconfManagementSession session) {
//no op
}
@Override
- public void onSessionDown(NetconfManagementSession session) {
+ public void onSessionDown(final NetconfManagementSession session) {
//no op
}
@Override
- public void onSessionEvent(SessionEvent event) {
+ public void onSessionEvent(final SessionEvent event) {
//no op
}
};
}
@Override
- public String getSchemaForCapability(String moduleName, Optional<String> revision) {
+ public String getSchemaForCapability(final String moduleName, final Optional<String> revision) {
for (Capability capability : capabilityMultiMap.get(moduleName)) {
if (capability.getRevision().get().equals(revision.get())) {
}
@Override
- public AutoCloseable registerCapabilitiesListener(CapabilitiesListener listener) {
+ public AutoCloseable registerCapabilitiesListener(final CapabilitiesListener listener) {
return null;
}
@Override
- public AutoCloseable registerSessionsListener(SessionsListener listener) {
+ public AutoCloseable registerSessionsListener(final SessionsListener listener) {
return null;
}
adapter.assertGot(getNotifJson(JSON_NOTIF_LEAVES_CREATE));
writeTransaction = dataBroker.newWriteOnlyTransaction();
- builder = new MyList1Builder().setKey(new MyList1Key("Althea")).setMyLeaf12("Bertha");
+ builder = new MyList1Builder().withKey(new MyList1Key("Althea")).setMyLeaf12("Bertha");
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iid, builder.build(), true);
writeTransaction.submit();
adapter.assertGot(getNotifJson(JSON_NOTIF_LEAVES_UPDATE));
adapter.assertGot(getNotifJson(JSON_NOTIF_CREATE));
writeTransaction = dataBroker.newWriteOnlyTransaction();
- builder = new MyList1Builder().setKey(new MyList1Key("Althea")).setMyLeaf12("Bertha");
+ builder = new MyList1Builder().withKey(new MyList1Key("Althea")).setMyLeaf12("Bertha");
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iid, builder.build(), true);
writeTransaction.submit();
adapter.assertGot(getNotifJson(JSON_NOTIF_UPDATE));
adapter.assertGot(getNotifJson(JSON_NOTIF_LEAVES_CREATE));
writeTransaction = dataBroker.newWriteOnlyTransaction();
- builder = new MyList1Builder().setKey(new MyList1Key("Althea")).setMyLeaf12("Bertha");
+ builder = new MyList1Builder().withKey(new MyList1Key("Althea")).setMyLeaf12("Bertha");
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iid, builder.build(), true);
writeTransaction.submit();
adapter.assertGot(getNotifJson(JSON_NOTIF_LEAVES_UPDATE));
adapter.assertGot(getNotifJson(JSON_NOTIF_CREATE));
writeTransaction = dataBroker.newWriteOnlyTransaction();
- builder = new MyList1Builder().setKey(new MyList1Key("Althea")).setMyLeaf12("Bertha");
+ builder = new MyList1Builder().withKey(new MyList1Key("Althea")).setMyLeaf12("Bertha");
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iid, builder.build(), true);
writeTransaction.submit();
adapter.assertGot(getNotifJson(JSON_NOTIF_UPDATE));