From d56371158176659f4dfae6b2befec10204a82849 Mon Sep 17 00:00:00 2001 From: Ivan Hrasko Date: Mon, 15 May 2017 15:50:39 +0200 Subject: [PATCH] Bug 8153: enforce check-style rules for netconf - call-home Change-Id: I1b5e2db2d6b0a4d3591e56d773cfcd4ffc13ae67 Signed-off-by: Ivan Hrasko --- netconf/callhome-protocol/pom.xml | 13 ++++- .../protocol/AuthorizedKeysDecoder.java | 48 +++++++++--------- .../protocol/CallHomeAuthorization.java | 11 +++-- .../CallHomeAuthorizationProvider.java | 2 +- .../protocol/CallHomeChannelActivator.java | 1 + .../CallHomeNetconfSubsystemListener.java | 1 + .../CallHomeProtocolSessionContext.java | 2 +- .../protocol/CallHomeSessionContext.java | 8 +-- .../protocol/MinaSshNettyChannel.java | 6 +-- .../protocol/NetconfCallHomeServer.java | 35 ++++++------- .../protocol/AuthorizedKeysDecoderTest.java | 11 +++-- .../protocol/CallHomeAuthorizationTest.java | 1 - .../protocol/CallHomeSessionContextTest.java | 2 +- .../protocol/MinaSshNettyChannelTest.java | 9 ++-- .../protocol/NetconfCallHomeServerTest.java | 6 ++- netconf/callhome-provider/pom.xml | 12 +++++ .../mount/CallHomeAuthProviderImpl.java | 5 +- .../mount/CallHomeMountDispatcher.java | 6 +-- .../mount/CallHomeMountSessionContext.java | 4 +- .../mount/CallHomeMountSessionManager.java | 6 ++- .../callhome/mount/CallHomeTopology.java | 1 - .../mount/CallhomeStatusReporter.java | 28 ++++++----- .../netconf/callhome/mount/Configuration.java | 18 ++++--- .../netconf/callhome/mount/ContextKey.java | 9 ++-- .../IetfZeroTouchCallHomeServerProvider.java | 28 ++++++----- .../blueprint/callhome-topology.xml | 1 - .../mount/CallHomeMountDispatcherTest.java | 1 + .../CallHomeMountSessionContextTest.java | 49 +++++++++---------- .../callhome/mount/ContextKeyTest.java | 2 - 29 files changed, 189 insertions(+), 137 deletions(-) diff --git a/netconf/callhome-protocol/pom.xml b/netconf/callhome-protocol/pom.xml index bab86e4d82..578d6a26bf 100644 --- a/netconf/callhome-protocol/pom.xml +++ b/netconf/callhome-protocol/pom.xml @@ -38,7 +38,6 @@ org.opendaylight.netconf netconf-client - org.bouncycastle bcpkix-jdk15on @@ -61,4 +60,16 @@ test + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + + + diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/AuthorizedKeysDecoder.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/AuthorizedKeysDecoder.java index 6702a44138..2f73805778 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/AuthorizedKeysDecoder.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/AuthorizedKeysDecoder.java @@ -34,9 +34,8 @@ import org.bouncycastle.jce.ECPointUtil; import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec; import org.bouncycastle.jce.spec.ECNamedCurveSpec; - /** - * FIXME: This should be probably located at AAA library + * FIXME: This should be probably located at AAA library. */ public class AuthorizedKeysDecoder { @@ -62,35 +61,41 @@ public class AuthorizedKeysDecoder { private byte[] bytes = new byte[0]; private int pos = 0; - - public PublicKey decodePublicKey(String keyLine) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException { + public PublicKey decodePublicKey(String keyLine) + throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException { // look for the Base64 encoded part of the line to decode // both ssh-rsa and ssh-dss begin with "AAAA" due to the length bytes bytes = Base64.decodeBase64(keyLine.getBytes()); - if (bytes.length == 0) + if (bytes.length == 0) { throw new IllegalArgumentException("No Base64 part to decode in " + keyLine); + } + pos = 0; String type = decodeType(); - if (type.equals(KEY_TYPE_RSA)) + if (type.equals(KEY_TYPE_RSA)) { return decodeAsRSA(); + } - if (type.equals(KEY_TYPE_DSA)) + if (type.equals(KEY_TYPE_DSA)) { return decodeAsDSA(); + } - if (type.equals(KEY_TYPE_ECDSA)) - return decodeAsECDSA(); + if (type.equals(KEY_TYPE_ECDSA)) { + return decodeAsEcDSA(); + } throw new IllegalArgumentException("Unknown decode key type " + type + " in " + keyLine); } - private PublicKey decodeAsECDSA() + private PublicKey decodeAsEcDSA() throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException { KeyFactory ecdsaFactory = SecurityUtils.getKeyFactory(KEY_FACTORY_TYPE_ECDSA); ECNamedCurveParameterSpec spec256r1 = ECNamedCurveTable.getParameterSpec(ECDSA_SUPPORTED_CURVE_NAME_SPEC); - ECNamedCurveSpec params256r1 = new ECNamedCurveSpec(ECDSA_SUPPORTED_CURVE_NAME_SPEC, spec256r1.getCurve(), spec256r1.getG(), spec256r1.getN()); + ECNamedCurveSpec params256r1 = new ECNamedCurveSpec( + ECDSA_SUPPORTED_CURVE_NAME_SPEC, spec256r1.getCurve(), spec256r1.getG(), spec256r1.getN()); // copy last 65 bytes from ssh key. ECPoint point = ECPointUtil.decodePoint(params256r1.getCurve(), Arrays.copyOfRange(bytes, 39, bytes.length)); ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params256r1); @@ -100,11 +105,11 @@ public class AuthorizedKeysDecoder { private PublicKey decodeAsDSA() throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException { KeyFactory dsaFactory = SecurityUtils.getKeyFactory(KEY_FACTORY_TYPE_DSA); - BigInteger p = decodeBigInt(); - BigInteger q = decodeBigInt(); - BigInteger g = decodeBigInt(); - BigInteger y = decodeBigInt(); - DSAPublicKeySpec spec = new DSAPublicKeySpec(y, p, q, g); + BigInteger prime = decodeBigInt(); + BigInteger subPrime = decodeBigInt(); + BigInteger base = decodeBigInt(); + BigInteger publicKey = decodeBigInt(); + DSAPublicKeySpec spec = new DSAPublicKeySpec(publicKey, prime, subPrime, base); return dsaFactory.generatePublic(spec); } @@ -172,17 +177,16 @@ public class AuthorizedKeysDecoder { dout.writeInt(ECDSA_SUPPORTED_CURVE_NAME.getBytes().length); dout.write(ECDSA_SUPPORTED_CURVE_NAME.getBytes()); - byte[] x = ecPublicKey.getQ().getAffineXCoord().getEncoded(); - byte[] y = ecPublicKey.getQ().getAffineYCoord().getEncoded(); - dout.writeInt(x.length + y.length + 1); + byte[] coordX = ecPublicKey.getQ().getAffineXCoord().getEncoded(); + byte[] coordY = ecPublicKey.getQ().getAffineYCoord().getEncoded(); + dout.writeInt(coordX.length + coordY.length + 1); dout.writeByte(0x04); - dout.write(x); - dout.write(y); + dout.write(coordX); + dout.write(coordY); } else { throw new IllegalArgumentException("Unknown public key encoding: " + publicKey.getAlgorithm()); } publicKeyEncoded = new String(Base64.encodeBase64(byteOs.toByteArray())); return publicKeyEncoded; - } } diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorization.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorization.java index c2b3b2dc61..03edbdac7c 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorization.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorization.java @@ -43,9 +43,11 @@ public abstract class CallHomeAuthorization { /** * Returns CallHomeAuthorization object with intent to * reject incoming connection. + * *

* {@link CallHomeAuthorizationProvider} may use returned object - * as return value for {@link CallHomeAuthorizationProvider#provideAuth(java.net.SocketAddress, java.security.PublicKey)} + * as return value for + * {@link CallHomeAuthorizationProvider#provideAuth(java.net.SocketAddress, java.security.PublicKey)} * if the incoming session should be rejected due to policy implemented * by provider. * @@ -58,6 +60,7 @@ public abstract class CallHomeAuthorization { /** * Creates a builder for CallHomeAuthorization with intent * to accept incoming connection and to provide credentials. + * *

* Note: If session with same sessionName is already opened and * active, incoming session will be rejected. @@ -78,7 +81,7 @@ public abstract class CallHomeAuthorization { public abstract boolean isServerAllowed(); /** - * Applies provided authentification to Mina SSH Client Session + * Applies provided authentification to Mina SSH Client Session. * * @param session Client Session to which authorization parameters will by applied */ @@ -88,6 +91,7 @@ public abstract class CallHomeAuthorization { /** * Builder for CallHomeAuthorization which accepts incoming connection. + * *

* Use {@link CallHomeAuthorization#serverAccepted(String, String)} to instantiate * builder. @@ -140,7 +144,8 @@ public abstract class CallHomeAuthorization { private final Set passwords; private final Set clientKeyPair; - ServerAllowed(String nodeId, String username, Collection passwords, Collection clientKeyPairs) { + ServerAllowed(String nodeId, String username, Collection passwords, + Collection clientKeyPairs) { this.username = Preconditions.checkNotNull(username); this.passwords = ImmutableSet.copyOf(passwords); this.clientKeyPair = ImmutableSet.copyOf(clientKeyPairs); diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorizationProvider.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorizationProvider.java index 40f180d14e..85a1cef2f1 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorizationProvider.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorizationProvider.java @@ -12,7 +12,7 @@ import java.security.PublicKey; import javax.annotation.Nonnull; /** - * Provider responsible for resolving CallHomeAuthorization + * Provider responsible for resolving CallHomeAuthorization. */ public interface CallHomeAuthorizationProvider { diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeChannelActivator.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeChannelActivator.java index 03cba3c42e..0fad0a5b1b 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeChannelActivator.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeChannelActivator.java @@ -18,6 +18,7 @@ import org.opendaylight.netconf.client.NetconfClientSessionListener; public interface CallHomeChannelActivator { /** * Activates Netconf Client Channel with supplied client session listener. + * *

* Activation of channel will result in start of NETCONF client * session negotiation on underlying ssh channel. diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeNetconfSubsystemListener.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeNetconfSubsystemListener.java index 36c3df7d8b..32f1e21f21 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeNetconfSubsystemListener.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeNetconfSubsystemListener.java @@ -15,6 +15,7 @@ import org.opendaylight.netconf.client.NetconfClientSessionListener; public interface CallHomeNetconfSubsystemListener { /** * Invoked when Netconf Subsystem was successfully opened on incoming SSH Call Home connection. + * *

* Implementors of this method should use provided {@link CallHomeChannelActivator} to attach * {@link NetconfClientSessionListener} to session and to start NETCONF client session negotiation. diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeProtocolSessionContext.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeProtocolSessionContext.java index 3985631f37..3814e9d683 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeProtocolSessionContext.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeProtocolSessionContext.java @@ -16,7 +16,7 @@ import java.security.PublicKey; public interface CallHomeProtocolSessionContext { /** - * Returns session identifier provided by CallHomeAuthorizationProvider + * Returns session identifier provided by CallHomeAuthorizationProvider. * * @return Returns application-provided session identifier */ diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContext.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContext.java index 3bdbd5c658..4f37f987d5 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContext.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContext.java @@ -94,15 +94,15 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext { }; } - private void channelOpenFailed(Throwable e) { - LOG.error("Unable to open netconf subsystem, disconnecting.", e); + private void channelOpenFailed(Throwable throwable) { + LOG.error("Unable to open netconf subsystem, disconnecting.", throwable); sshSession.close(false); } private void netconfChannelOpened(ClientChannel netconfChannel) { nettyChannel = newMinaSshNettyChannel(netconfChannel); - factory.getChannelOpenListener().onNetconfSubsystemOpened(CallHomeSessionContext.this, - listener -> doActivate(listener)); + factory.getChannelOpenListener().onNetconfSubsystemOpened( + CallHomeSessionContext.this, this::doActivate); } @GuardedBy("this") diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/MinaSshNettyChannel.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/MinaSshNettyChannel.java index 0188dc72e0..9975c94962 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/MinaSshNettyChannel.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/MinaSshNettyChannel.java @@ -45,8 +45,8 @@ class MinaSshNettyChannel extends AbstractServerChannel { this.context = Preconditions.checkNotNull(context); this.session = Preconditions.checkNotNull(session); this.sshChannel = Preconditions.checkNotNull(sshChannel); - this.sshReadHandler = new AsyncSshHandlerReader(new ConnectionClosedDuringRead(), new FireReadMessage(), "netconf", - sshChannel.getAsyncOut()); + this.sshReadHandler = new AsyncSshHandlerReader( + new ConnectionClosedDuringRead(), new FireReadMessage(), "netconf", sshChannel.getAsyncOut()); this.sshWriteAsyncHandler = new AsyncSshHandlerWriter(sshChannel.getAsyncIn()); pipeline().addFirst(createChannelAdapter()); } @@ -163,7 +163,7 @@ class MinaSshNettyChannel extends AbstractServerChannel { private final class ConnectionClosedDuringRead implements AutoCloseable { /** - * Invoked when SSH session dropped during read using {@link AsyncSshHandlerReader} + * Invoked when SSH session dropped during read using {@link AsyncSshHandlerReader}. */ @Override public void close() throws Exception { diff --git a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServer.java b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServer.java index 4680295462..34658aae55 100644 --- a/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServer.java +++ b/netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServer.java @@ -69,7 +69,6 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier { } } - protected IoServiceFactory createMinaServiceFactory(SshClient sshClient) { return new MinaServiceFactory(sshClient); } @@ -78,14 +77,14 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier { return new SessionListener() { @Override public void sessionEvent(Session session, Event event) { - ClientSession cSession = (ClientSession) session; + ClientSession clientSession = (ClientSession) session; LOG.debug("SSH session {} event {}", session, event); switch (event) { case KeyEstablished: - doAuth(cSession); + doAuth(clientSession); break; case Authenticated: - doPostAuth(cSession); + doPostAuth(clientSession); break; default: break; @@ -108,20 +107,20 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier { }; } - private void doPostAuth(final ClientSession cSession) { - CallHomeSessionContext.getFrom(cSession).openNetconfChannel(); + private void doPostAuth(final ClientSession session) { + CallHomeSessionContext.getFrom(session).openNetconfChannel(); } - private void doAuth(final ClientSession cSession) { + private void doAuth(final ClientSession session) { try { - final AuthFuture authFuture = CallHomeSessionContext.getFrom(cSession).authorize(); - authFuture.addListener(newAuthSshFutureListener(cSession)); + final AuthFuture authFuture = CallHomeSessionContext.getFrom(session).authorize(); + authFuture.addListener(newAuthSshFutureListener(session)); } catch (IOException e) { - LOG.error("Failed to authorize session {}", cSession, e); + LOG.error("Failed to authorize session {}", session, e); } } - private SshFutureListener newAuthSshFutureListener(final ClientSession cSession) { + private SshFutureListener newAuthSshFutureListener(final ClientSession session) { return new SshFutureListener() { @Override public void operationComplete(AuthFuture authFuture) { @@ -140,19 +139,19 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier { } private void onFailure(Throwable throwable) { - ClientSessionImpl impl = (ClientSessionImpl) cSession; - LOG.error("Authorize failed for session {}", cSession, throwable); + ClientSessionImpl impl = (ClientSessionImpl) session; + LOG.error("Authorize failed for session {}", session, throwable); KeyExchange kex = impl.getKex(); PublicKey key = kex.getServerKey(); recorder.reportFailedAuth(key); - cSession.close(true); + session.close(true); } private void onCanceled() { LOG.warn("Authorize cancelled"); - cSession.close(true); + session.close(true); } }; } @@ -165,13 +164,15 @@ public class NetconfCallHomeServer implements AutoCloseable, ServerKeyVerifier { LOG.info("Incoming session {} was rejected by Authorization Provider.", sshClientSession); return false; } - CallHomeSessionContext session = sessionFactory.createIfNotExists(sshClientSession, authorization, remoteAddress); + CallHomeSessionContext session = sessionFactory.createIfNotExists( + sshClientSession, authorization, remoteAddress); // Session was created, session with same name does not exists if (session != null) { return true; } // Session was not created, session with same name exists - LOG.info("Incoming session {} was rejected. Session with same name {} is already active.", sshClientSession, authorization.getSessionName()); + LOG.info("Incoming session {} was rejected. Session with same name {} is already active.", + sshClientSession, authorization.getSessionName()); return false; } diff --git a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/AuthorizedKeysDecoderTest.java b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/AuthorizedKeysDecoderTest.java index 87bc6807e9..a085b49019 100644 --- a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/AuthorizedKeysDecoderTest.java +++ b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/AuthorizedKeysDecoderTest.java @@ -15,7 +15,6 @@ import java.security.PublicKey; import org.junit.Before; import org.junit.Test; - public class AuthorizedKeysDecoderTest { private AuthorizedKeysDecoder instance; @@ -25,6 +24,7 @@ public class AuthorizedKeysDecoderTest { instance = new AuthorizedKeysDecoder(); } + @SuppressWarnings("checkstyle:lineLength") @Test public void authorizedKeysDecoderValidRSAKey() throws GeneralSecurityException { // given @@ -35,6 +35,7 @@ public class AuthorizedKeysDecoderTest { assertEquals(serverKey.getAlgorithm(), "RSA"); } + @SuppressWarnings("checkstyle:lineLength") @Test(expected = Exception.class) public void authorizedKeysDecoderInvalidRSAKey() throws GeneralSecurityException { // given @@ -43,6 +44,7 @@ public class AuthorizedKeysDecoderTest { instance.decodePublicKey(rsaStr); } + @SuppressWarnings("checkstyle:lineLength") @Test public void authorizedKeysDecoderValidDSAKey() throws GeneralSecurityException { // given @@ -53,6 +55,7 @@ public class AuthorizedKeysDecoderTest { assertEquals(serverKey.getAlgorithm(), "DSA"); } + @SuppressWarnings("checkstyle:lineLength") @Test(expected = IllegalArgumentException.class) public void authorizedKeysDecoderInvalidDSAKey() throws GeneralSecurityException { // given @@ -61,8 +64,9 @@ public class AuthorizedKeysDecoderTest { instance.decodePublicKey(dsaStr); } + @SuppressWarnings("checkstyle:lineLength") @Test - public void authorizedKeysDecoderValidECDSAKey() throws GeneralSecurityException { + public void authorizedKeysDecoderValidEcDSAKey() throws GeneralSecurityException { // given String ecdsaStr = "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAP4dTrlwZmz8bZ1f901qWuFk7YelrL2WJG0jrCEAPo9UNM1wywpqjbaYUfoq+cevhLZaukDQ4N2Evux+YQ2zz0="; // when @@ -71,8 +75,9 @@ public class AuthorizedKeysDecoderTest { assertEquals(serverKey.getAlgorithm(), "EC"); } + @SuppressWarnings("checkstyle:lineLength") @Test(expected = IllegalArgumentException.class) - public void authorizedKeysDecoderInvalidECDSAKey() throws GeneralSecurityException { + public void authorizedKeysDecoderInvalidEcDSAKey() throws GeneralSecurityException { // given String ecdsaStr = "AAAAE2VjZHNhLXNoItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAP4dTrlwZmz8bZ1f901qWuFk7YelrL2WJG0jrCEAPo9UNM1wywpqjbaYUfoq+cevhLZaukDQ4N2Evux+YQ2zz0="; // when diff --git a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorizationTest.java b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorizationTest.java index 08f9a5fb85..aa742581ec 100644 --- a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorizationTest.java +++ b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorizationTest.java @@ -24,7 +24,6 @@ import org.apache.sshd.ClientSession; import org.apache.sshd.client.session.ClientSessionImpl; import org.junit.Test; - public class CallHomeAuthorizationTest { @Test public void anAuthorizationOfRejectedIsNotAllowed() { diff --git a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java index 8c80409e0b..032679e94d 100644 --- a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java +++ b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java @@ -188,7 +188,6 @@ public class CallHomeSessionContextTest { // given instance = realFactory.createIfNotExists(mockSession, mockAuth, address); - SshFutureListener listener = instance.newSshFutureListener(mockChannel); OpenFuture mockFuture = mock(OpenFuture.class); Mockito.doReturn(false).when(mockFuture).isOpened(); Mockito.doReturn(new RuntimeException("test")).when(mockFuture).getException(); @@ -196,6 +195,7 @@ public class CallHomeSessionContextTest { doReturn(null).when(mockSession).close(anyBoolean()); // when + SshFutureListener listener = instance.newSshFutureListener(mockChannel); listener.operationComplete(mockFuture); // then // You'll see an error message logged to the console - it is expected. diff --git a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/MinaSshNettyChannelTest.java b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/MinaSshNettyChannelTest.java index 20cd05d2a2..c846f1feea 100644 --- a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/MinaSshNettyChannelTest.java +++ b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/MinaSshNettyChannelTest.java @@ -32,7 +32,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; - public class MinaSshNettyChannelTest { private CallHomeSessionContext mockContext; private ClientSession mockSession; @@ -44,11 +43,12 @@ public class MinaSshNettyChannelTest { IoReadFuture mockFuture = mock(IoReadFuture.class); IoInputStream mockIn = mock(IoInputStream.class); Mockito.doReturn(mockFuture).when(mockIn).read(any(Buffer.class)); - IoOutputStream mockOut = mock(IoOutputStream.class); mockContext = mock(CallHomeSessionContext.class); mockSession = mock(ClientSession.class); mockChannel = mock(ClientChannel.class); Mockito.doReturn(mockIn).when(mockChannel).getAsyncOut(); + + IoOutputStream mockOut = mock(IoOutputStream.class); Mockito.doReturn(mockOut).when(mockChannel).getAsyncIn(); IoWriteFuture mockWrFuture = mock(IoWriteFuture.class); @@ -78,9 +78,6 @@ public class MinaSshNettyChannelTest { Mockito.doReturn(mockHandler).when(ctx).handler(); ChannelPromise promise = mock(ChannelPromise.class); - ByteBufAllocator mockAlloc = mock(ByteBufAllocator.class); - ByteBuf bytes = new EmptyByteBuf(mockAlloc); - // we would really like to just verify that the async handler write() was // called but it is a final class, so no mocking. instead we set up the // mock channel to have no async input, which will cause a failure later @@ -95,6 +92,8 @@ public class MinaSshNettyChannelTest { // when ChannelOutboundHandlerAdapter outadapter = (ChannelOutboundHandlerAdapter) instance.pipeline().first(); + ByteBufAllocator mockAlloc = mock(ByteBufAllocator.class); + ByteBuf bytes = new EmptyByteBuf(mockAlloc); outadapter.write(ctx, bytes, promise); // then diff --git a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServerTest.java b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServerTest.java index 7a68f131cc..d96f17a1f4 100644 --- a/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServerTest.java +++ b/netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServerTest.java @@ -59,7 +59,8 @@ public class NetconfCallHomeServerTest { props.put("nio-workers", "1"); Mockito.doReturn(props).when(mockSshClient).getProperties(); Mockito.doReturn("test").when(mockSession).toString(); - instance = new NetconfCallHomeServer(mockSshClient, mockCallHomeAuthProv, mockFactory, mockAddress, mockStatusRecorder); + instance = new NetconfCallHomeServer( + mockSshClient, mockCallHomeAuthProv, mockFactory, mockAddress, mockStatusRecorder); } @Test @@ -165,7 +166,8 @@ public class NetconfCallHomeServerTest { Mockito.doReturn(mockAcceptor).when(mockMinaFactory).createAcceptor(any(IoHandler.class)); Mockito.doReturn(mockAcceptor).when(mockMinaFactory).createAcceptor(any(IoHandler.class)); Mockito.doNothing().when(mockAcceptor).bind(mockAddress); - instance = new TestableCallHomeServer(mockSshClient, mockCallHomeAuthProv, mockFactory, mockAddress, mockMinaFactory, mockStatusRecorder); + instance = new TestableCallHomeServer( + mockSshClient, mockCallHomeAuthProv, mockFactory, mockAddress, mockMinaFactory, mockStatusRecorder); // when instance.bind(); // then diff --git a/netconf/callhome-provider/pom.xml b/netconf/callhome-provider/pom.xml index a82d63fd12..9b4aaa1406 100644 --- a/netconf/callhome-provider/pom.xml +++ b/netconf/callhome-provider/pom.xml @@ -57,4 +57,16 @@ mockito-core + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + + + diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeAuthProviderImpl.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeAuthProviderImpl.java index 7f50653eed..83869ad286 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeAuthProviderImpl.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeAuthProviderImpl.java @@ -89,10 +89,11 @@ public class CallHomeAuthProviderImpl implements CallHomeAuthorizationProvider, statusReporter.asForceListedDevice(syntheticId, serverKey); } else { Device opDevice = deviceOp.get(serverKey); - if (opDevice == null) + if (opDevice == null) { statusReporter.asUnlistedDevice(syntheticId, serverKey); - else + } else { LOG.info("Repeating rejection of unlisted device with id of {}", opDevice.getUniqueId()); + } return CallHomeAuthorization.rejected(); } } diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcher.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcher.java index 2241d6995a..dab26d92c2 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcher.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcher.java @@ -30,10 +30,9 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHomeNetconfSubsystemListener { - private final static Logger LOG = LoggerFactory.getLogger(CallHomeMountDispatcher.class); + private static final Logger LOG = LoggerFactory.getLogger(CallHomeMountDispatcher.class); private final String topologyId; private final EventExecutor eventExecutor; @@ -99,7 +98,8 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom @Override public void onNetconfSubsystemOpened(final CallHomeProtocolSessionContext session, final CallHomeChannelActivator activator) { - final CallHomeMountSessionContext deviceContext = getSessionManager().createSession(session, activator, onCloseHandler); + final CallHomeMountSessionContext deviceContext = getSessionManager() + .createSession(session, activator, onCloseHandler); final NodeId nodeId = deviceContext.getId(); final Node configNode = deviceContext.getConfigNode(); LOG.info("Provisioning fake config {}", configNode); diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionContext.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionContext.java index 16eed1f208..539f6ab315 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionContext.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionContext.java @@ -95,11 +95,11 @@ class CallHomeMountSessionContext { } @Override - public void onSessionDown(NetconfClientSession session, Exception e) { + public void onSessionDown(NetconfClientSession session, Exception exc) { try { removeSelf(); } finally { - delegate.onSessionDown(session, e); + delegate.onSessionDown(session, exc); } } diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionManager.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionManager.java index 0657740e28..f26d6ba421 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionManager.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionManager.java @@ -23,8 +23,10 @@ import org.opendaylight.netconf.callhome.protocol.CallHomeProtocolSessionContext public class CallHomeMountSessionManager implements CallHomeMountSessionContext.CloseCallback { - private final ConcurrentMap contextByAddress = new ConcurrentHashMap<>(); - private final Multimap contextByPublicKey = MultimapBuilder.hashKeys().hashSetValues().build(); + private final ConcurrentMap contextByAddress = + new ConcurrentHashMap<>(); + private final Multimap contextByPublicKey = MultimapBuilder.hashKeys() + .hashSetValues().build(); @Nullable public CallHomeMountSessionContext getByAddress(InetSocketAddress remoteAddr) { diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeTopology.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeTopology.java index 71a7af1340..c722f615ce 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeTopology.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeTopology.java @@ -20,7 +20,6 @@ import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalFacade; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; import org.opendaylight.netconf.topology.api.SchemaRepositoryProvider; - public class CallHomeTopology extends BaseCallHomeTopology { public CallHomeTopology(final String topologyId, final NetconfClientDispatcher clientDispatcher, diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java index ba551202f9..ee068ec1fb 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java @@ -52,7 +52,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, AutoCloseable { private static final InstanceIdentifier NETCONF_TOPO_IID = InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, @@ -65,15 +64,16 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto CallhomeStatusReporter(DataBroker broker) { this.dataBroker = broker; - this.reg = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, NETCONF_TOPO_IID.child(Node.class), - this, AsyncDataBroker.DataChangeScope.SUBTREE); + this.reg = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, + NETCONF_TOPO_IID.child(Node.class), this, AsyncDataBroker.DataChangeScope.SUBTREE); } @Override public void onDataChanged(AsyncDataChangeEvent, DataObject> change) { for (InstanceIdentifier removedPath : change.getRemovedPaths()) { - if (removedPath.getTargetType() != NetconfNode.class) + if (removedPath.getTargetType() != NetconfNode.class) { continue; + } final NodeId nodeId = getNodeId(removedPath); if (nodeId != null) { @@ -125,8 +125,9 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto LOG.warn("No corresponding callhome device found - exiting."); } else { Device modifiedDevice = withConnectedStatus(opDev); - if (modifiedDevice == null) + if (modifiedDevice == null) { return; + } LOG.info("Setting successful status for callhome device id:{}.", nodeId); writeDevice(nodeId, modifiedDevice); } @@ -140,8 +141,9 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto LOG.warn("No corresponding callhome device found - exiting."); } else { Device modifiedDevice = withDisconnectedStatus(opDev); - if (modifiedDevice == null) + if (modifiedDevice == null) { return; + } LOG.info("Setting disconnected status for callhome device id:{}.", nodeId); writeDevice(nodeId, modifiedDevice); } @@ -158,8 +160,9 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto LOG.warn("No corresponding callhome device found - exiting."); } else { Device modifiedDevice = withFailedStatus(opDev); - if (modifiedDevice == null) + if (modifiedDevice == null) { return; + } LOG.info("Setting failed status for callhome device id:{}.", nodeId); writeDevice(nodeId, modifiedDevice); } @@ -182,8 +185,7 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto try { sshEncodedKey = AuthorizedKeysDecoder.encodePublicKey(serverKey); } catch (IOException e) { - e.printStackTrace(); - LOG.warn("Unable to encode public key to ssh format."); + LOG.warn("Unable to encode public key to ssh format.", e); } Device1 d1 = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.FAILEDNOTALLOWED).build(); DeviceBuilder builder = new DeviceBuilder() @@ -258,16 +260,15 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto private void setDeviceStatus(Device device) { WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); - InstanceIdentifier Device_IID = + InstanceIdentifier deviceIId = InstanceIdentifier.create(NetconfCallhomeServer.class) .child(AllowedDevices.class) .child(Device.class, device.getKey()); - tx.merge(LogicalDatastoreType.OPERATIONAL, Device_IID, device); + tx.merge(LogicalDatastoreType.OPERATIONAL, deviceIId, device); tx.submit(); } - private AllowedDevices getDevices() { ReadOnlyTransaction rxTransaction = dataBroker.newReadOnlyTransaction(); CheckedFuture, ReadFailedException> devicesFuture = @@ -302,8 +303,9 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto PublicKey pubKey = decoder.decodePublicKey(keyString); if (sshKey.getAlgorithm().equals(pubKey.getAlgorithm()) && sshKey.equals(pubKey)) { Device failedDevice = withFailedAuthStatus(device); - if (failedDevice == null) + if (failedDevice == null) { return; + } LOG.info("Setting auth failed status for callhome device id:{}.", failedDevice.getUniqueId()); setDeviceStatus(failedDevice); return; diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/Configuration.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/Configuration.java index bc00292a68..6a5c11b677 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/Configuration.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/Configuration.java @@ -26,8 +26,8 @@ public class Configuration { } public static class ReadException extends ConfigurationException { - ReadException(String msg, Exception e) { - super(msg, e); + ReadException(String msg, Exception exc) { + super(msg, exc); } } @@ -102,20 +102,22 @@ public class Configuration { String get(String key) { String result = (String) properties.get(key); - if (result == null) + if (result == null) { throw new MissingException(key); + } return result; } public int getAsPort(String key) { - String s = get(key); + String keyValue = get(key); try { - int newPort = Integer.parseInt(s); - if (newPort < 0 || newPort > 65535) - throw new IllegalValueException(key, s); + int newPort = Integer.parseInt(keyValue); + if (newPort < 0 || newPort > 65535) { + throw new IllegalValueException(key, keyValue); + } return newPort; } catch (NumberFormatException e) { - throw new IllegalValueException(key, s); + throw new IllegalValueException(key, keyValue); } } } diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/ContextKey.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/ContextKey.java index 124f87d39c..3536d66090 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/ContextKey.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/ContextKey.java @@ -41,12 +41,15 @@ class ContextKey { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } ContextKey other = (ContextKey) obj; return Objects.equal(address, other.address) && Objects.equal(port, other.port); } diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/IetfZeroTouchCallHomeServerProvider.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/IetfZeroTouchCallHomeServerProvider.java index 43479a0b3a..903dd9ce71 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/IetfZeroTouchCallHomeServerProvider.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/IetfZeroTouchCallHomeServerProvider.java @@ -13,7 +13,6 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; -import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; import java.util.ArrayList; @@ -44,10 +43,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataChangeListener { private static final String APPNAME = "CallHomeServer"; - static final InstanceIdentifier ALL_DEVICES = InstanceIdentifier.create(NetconfCallhomeServer.class).child(AllowedDevices.class); + static final InstanceIdentifier ALL_DEVICES = InstanceIdentifier.create(NetconfCallhomeServer.class) + .child(AllowedDevices.class); private static final Logger LOG = LoggerFactory.getLogger(IetfZeroTouchCallHomeServerProvider.class); @@ -75,7 +74,8 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC try { LOG.info("Initializing provider for {}", APPNAME); initializeServer(); - dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, ALL_DEVICES, this, AsyncDataBroker.DataChangeScope.SUBTREE); + dataBroker.registerDataChangeListener( + LogicalDatastoreType.CONFIGURATION, ALL_DEVICES, this, AsyncDataBroker.DataChangeScope.SUBTREE); LOG.info("Initialization complete for {}", APPNAME); } catch (IOException | Configuration.ConfigurationException e) { LOG.error("Unable to successfully initialize", e); @@ -88,7 +88,7 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC configuration.set(CALL_HOME_PORT_KEY, portStr); port = configuration.getAsPort(CALL_HOME_PORT_KEY); LOG.info("Setting port for call home server to {}", portStr); - } catch(Configuration.ConfigurationException e) { + } catch (Configuration.ConfigurationException e) { LOG.error("Problem trying to set port for call home server {}", portStr, e); } } @@ -102,8 +102,9 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC CallHomeAuthorizationProvider provider = this.getCallHomeAuthorization(); NetconfCallHomeServerBuilder builder = new NetconfCallHomeServerBuilder( provider, mountDispacher, statusReporter); - if (port > 0) + if (port > 0) { builder.setBindAddress(new InetSocketAddress(port)); + } server = builder.build(); server.bind(); mountDispacher.createTopology(); @@ -112,8 +113,10 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC @VisibleForTesting void assertValid(Object obj, String description) { - if (obj == null) - throw new RuntimeException(String.format("Failed to find %s in IetfZeroTouchCallHomeProvider.initialize()", description)); + if (obj == null) { + throw new RuntimeException( + String.format("Failed to find %s in IetfZeroTouchCallHomeProvider.initialize()", description)); + } } @Override @@ -144,8 +147,9 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC CheckedFuture, ReadFailedException> devicesFuture = roConfigTx.read(LogicalDatastoreType.CONFIGURATION, IetfZeroTouchCallHomeServerProvider.ALL_DEVICES); - if (hasDeletedDevices(change)) + if (hasDeletedDevices(change)) { handleDeletedDevices(change); + } try { for (Device confDevice : getReadDevices(devicesFuture)) { @@ -175,8 +179,9 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC opTx.delete(LogicalDatastoreType.OPERATIONAL, removedIID); } - if (numRemoved > 0) + if (numRemoved > 0) { opTx.submit(); + } } private List getReadDevices(CheckedFuture, ReadFailedException> devicesFuture) @@ -200,7 +205,8 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC .child(Device.class, new DeviceKey(cfgDevice.getUniqueId())); ReadWriteTransaction tx = dataBroker.newReadWriteTransaction(); - CheckedFuture, ReadFailedException> deviceFuture = tx.read(LogicalDatastoreType.OPERATIONAL, deviceIID); + CheckedFuture, ReadFailedException> deviceFuture = tx.read( + LogicalDatastoreType.OPERATIONAL, deviceIID); Optional opDevGet = deviceFuture.checkedGet(); Device1 devStatus = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.DISCONNECTED).build(); diff --git a/netconf/callhome-provider/src/main/resources/org/opendaylight/blueprint/callhome-topology.xml b/netconf/callhome-provider/src/main/resources/org/opendaylight/blueprint/callhome-topology.xml index d97360476e..201c206282 100755 --- a/netconf/callhome-provider/src/main/resources/org/opendaylight/blueprint/callhome-topology.xml +++ b/netconf/callhome-provider/src/main/resources/org/opendaylight/blueprint/callhome-topology.xml @@ -46,5 +46,4 @@ - \ No newline at end of file diff --git a/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcherTest.java b/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcherTest.java index cca8f5de3d..1b822413a5 100644 --- a/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcherTest.java +++ b/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcherTest.java @@ -73,6 +73,7 @@ public class CallHomeMountDispatcherTest { public CallHomeMountSessionManager getSessionManager() { return mockSessMgr; } + @Override void createTopology() { this.topology = mockTopology; diff --git a/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionContextTest.java b/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionContextTest.java index 1551181eed..6870715261 100644 --- a/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionContextTest.java +++ b/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionContextTest.java @@ -28,7 +28,6 @@ import org.opendaylight.netconf.callhome.protocol.CallHomeProtocolSessionContext import org.opendaylight.netconf.client.NetconfClientSession; import org.opendaylight.netconf.client.NetconfClientSessionListener; - public class CallHomeMountSessionContextTest { private Inet4Address someAddressIpv4; private InetSocketAddress someSocketAddress; @@ -59,13 +58,13 @@ public class CallHomeMountSessionContextTest { public void activationOfListenerSupportsSessionUp() { // given when(mockActivator.activate(any(NetconfClientSessionListener.class))) - .thenAnswer(invocationOnMock -> { - NetconfClientSession mockSession = mock(NetconfClientSession.class); + .thenAnswer(invocationOnMock -> { + NetconfClientSession mockSession = mock(NetconfClientSession.class); - Object arg = invocationOnMock.getArguments()[0]; - ((NetconfClientSessionListener) arg).onSessionUp(mockSession); - return null; - }); + Object arg = invocationOnMock.getArguments()[0]; + ((NetconfClientSessionListener) arg).onSessionUp(mockSession); + return null; + }); NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class); // when @@ -79,13 +78,13 @@ public class CallHomeMountSessionContextTest { // given when(mockActivator.activate(any(NetconfClientSessionListener.class))) .thenAnswer(invocationOnMock -> { - NetconfClientSession mockSession = mock(NetconfClientSession.class); - NetconfTerminationReason mockReason = mock(NetconfTerminationReason.class); + NetconfClientSession mockSession = mock(NetconfClientSession.class); + NetconfTerminationReason mockReason = mock(NetconfTerminationReason.class); - Object arg = invocationOnMock.getArguments()[0]; - ((NetconfClientSessionListener) arg).onSessionTerminated(mockSession, mockReason); - return null; - }); + Object arg = invocationOnMock.getArguments()[0]; + ((NetconfClientSessionListener) arg).onSessionTerminated(mockSession, mockReason); + return null; + }); NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class); // when @@ -100,13 +99,13 @@ public class CallHomeMountSessionContextTest { // given when(mockActivator.activate(any(NetconfClientSessionListener.class))) .thenAnswer(invocationOnMock -> { - NetconfClientSession mockSession = mock(NetconfClientSession.class); - Exception mockException = mock(Exception.class); + NetconfClientSession mockSession = mock(NetconfClientSession.class); + Exception mockException = mock(Exception.class); - Object arg = invocationOnMock.getArguments()[0]; - ((NetconfClientSessionListener) arg).onSessionDown(mockSession, mockException); - return null; - }); + Object arg = invocationOnMock.getArguments()[0]; + ((NetconfClientSessionListener) arg).onSessionDown(mockSession, mockException); + return null; + }); // given NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class); // when @@ -121,13 +120,13 @@ public class CallHomeMountSessionContextTest { // given when(mockActivator.activate(any(NetconfClientSessionListener.class))) .thenAnswer(invocationOnMock -> { - NetconfClientSession mockSession = mock(NetconfClientSession.class); - NetconfMessage mockMsg = mock(NetconfMessage.class); + NetconfClientSession mockSession = mock(NetconfClientSession.class); + NetconfMessage mockMsg = mock(NetconfMessage.class); - Object arg = invocationOnMock.getArguments()[0]; - ((NetconfClientSessionListener) arg).onMessage(mockSession, mockMsg); - return null; - }); + Object arg = invocationOnMock.getArguments()[0]; + ((NetconfClientSessionListener) arg).onMessage(mockSession, mockMsg); + return null; + }); // given NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class); // when diff --git a/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/ContextKeyTest.java b/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/ContextKeyTest.java index eb65226b52..cdb0462d8f 100644 --- a/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/ContextKeyTest.java +++ b/netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/ContextKeyTest.java @@ -8,7 +8,6 @@ package org.opendaylight.netconf.callhome.mount; - import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; @@ -29,7 +28,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; - public class ContextKeyTest { private IpAddress address1; private IpAddress address2; -- 2.36.6