From 248cfa601e441e3f3711a9d6629d21af99b41365 Mon Sep 17 00:00:00 2001 From: Tomas Cere Date: Tue, 4 Apr 2017 16:09:38 +0200 Subject: [PATCH] Fix formatting in callhome-provider Change-Id: Iaf85efcc8a1233717f947ada3ff9a47ad2a6d328 Signed-off-by: Tomas Cere --- .../callhome/mount/BaseCallHomeTopology.java | 16 ++++---- .../mount/CallHomeAuthProviderImpl.java | 10 ++--- .../mount/CallHomeMountSessionContext.java | 4 +- .../mount/CallHomeMountSessionManager.java | 10 ++--- .../mount/CallhomeStatusReporter.java | 18 ++++----- .../netconf/callhome/mount/ContextKey.java | 5 ++- .../IetfZeroTouchCallHomeServerProvider.java | 40 +++++++++---------- 7 files changed, 48 insertions(+), 55 deletions(-) diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/BaseCallHomeTopology.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/BaseCallHomeTopology.java index 2b73e4f950..0b1972a3ef 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/BaseCallHomeTopology.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/BaseCallHomeTopology.java @@ -24,14 +24,14 @@ abstract class BaseCallHomeTopology extends AbstractNetconfTopology { protected DOMMountPointService mountPointService = null; BaseCallHomeTopology(String topologyId, NetconfClientDispatcher clientDispatcher, - BindingAwareBroker bindingAwareBroker, - Broker domBroker, - EventExecutor eventExecutor, - ScheduledThreadPool keepaliveExecutor, - ThreadPool processingExecutor, - SchemaRepositoryProvider schemaRepositoryProvider, - DataBroker dataBroker, - DOMMountPointService mountPointService) { + BindingAwareBroker bindingAwareBroker, + Broker domBroker, + EventExecutor eventExecutor, + ScheduledThreadPool keepaliveExecutor, + ThreadPool processingExecutor, + SchemaRepositoryProvider schemaRepositoryProvider, + DataBroker dataBroker, + DOMMountPointService mountPointService) { super(topologyId, clientDispatcher, bindingAwareBroker, domBroker, eventExecutor, keepaliveExecutor, processingExecutor, schemaRepositoryProvider, dataBroker); this.mountPointService = mountPointService; 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 8e582dec26..7f50653eed 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 @@ -9,14 +9,13 @@ package org.opendaylight.netconf.callhome.mount; import com.google.common.base.Objects; import com.google.common.net.InetAddresses; - import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.security.PublicKey; -import java.security.spec.InvalidKeySpecException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; +import java.security.PublicKey; +import java.security.spec.InvalidKeySpecException; import java.util.Collection; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -101,7 +100,7 @@ public class CallHomeAuthProviderImpl implements CallHomeAuthorizationProvider, final Credentials credentials = deviceCred != null ? deviceCred : globalConfig.getCredentials(); if (credentials == null) { - LOG.info("No credentials found for {}, rejecting.",remoteAddress); + LOG.info("No credentials found for {}, rejecting.", remoteAddress); return CallHomeAuthorization.rejected(); } @@ -236,8 +235,7 @@ public class CallHomeAuthProviderImpl implements CallHomeAuthorizationProvider, try { skey = AuthorizedKeysDecoder.encodePublicKey(serverKey); return byPublicKey.get(skey); - } - catch (IOException | IllegalArgumentException e) { + } catch (IOException | IllegalArgumentException e) { LOG.error("Unable to encode server key: {}", skey, e); return null; } 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 7fc1799639..16eed1f208 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 @@ -40,7 +40,7 @@ class CallHomeMountSessionContext { private final ContextKey key; CallHomeMountSessionContext(String nodeId, CallHomeProtocolSessionContext protocol, - CallHomeChannelActivator activator, CloseCallback callback) { + CallHomeChannelActivator activator, CloseCallback callback) { this.nodeId = new NodeId(Preconditions.checkNotNull(nodeId, "nodeId")); this.key = ContextKey.from(protocol.getRemoteAddress()); @@ -73,7 +73,7 @@ class CallHomeMountSessionContext { } @SuppressWarnings("unchecked") - Promise activateNetconfChannel(NetconfClientSessionListener sessionListener) { + Promise activateNetconfChannel(NetconfClientSessionListener sessionListener) { return (Promise) activator.activate(wrap(sessionListener)); } 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 e700a145ca..0657740e28 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 @@ -37,14 +37,14 @@ public class CallHomeMountSessionManager implements CallHomeMountSessionContext. } CallHomeMountSessionContext createSession(CallHomeProtocolSessionContext session, - CallHomeChannelActivator activator, final CloseCallback onCloseHandler) { + CallHomeChannelActivator activator, final CloseCallback onCloseHandler) { String name = session.getSessionName(); CallHomeMountSessionContext deviceContext = new CallHomeMountSessionContext(name, session, activator, devCtxt -> { - CallHomeMountSessionManager.this.onClosed(devCtxt); - onCloseHandler.onClosed(devCtxt); - }); + CallHomeMountSessionManager.this.onClosed(devCtxt); + onCloseHandler.onClosed(devCtxt); + }); contextByAddress.put(deviceContext.getRemoteAddress(), deviceContext); contextByPublicKey.put(deviceContext.getRemoteServerKey(), deviceContext); @@ -55,6 +55,6 @@ public class CallHomeMountSessionManager implements CallHomeMountSessionContext. @Override public synchronized void onClosed(CallHomeMountSessionContext deviceContext) { contextByAddress.remove(deviceContext.getRemoteAddress()); - contextByPublicKey.remove(deviceContext.getRemoteServerKey(),deviceContext); + contextByPublicKey.remove(deviceContext.getRemoteServerKey(), deviceContext); } } 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 016bd57de2..ba551202f9 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 @@ -10,7 +10,6 @@ package org.opendaylight.netconf.callhome.mount; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; - import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; @@ -19,7 +18,6 @@ import java.security.spec.InvalidKeySpecException; import java.util.ArrayList; import java.util.List; import java.util.Map; - import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; @@ -74,7 +72,7 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto @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); @@ -127,8 +125,8 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto LOG.warn("No corresponding callhome device found - exiting."); } else { Device modifiedDevice = withConnectedStatus(opDev); - if(modifiedDevice == null) - return ; + if (modifiedDevice == null) + return; LOG.info("Setting successful status for callhome device id:{}.", nodeId); writeDevice(nodeId, modifiedDevice); } @@ -142,7 +140,7 @@ 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); @@ -160,7 +158,7 @@ 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); @@ -237,7 +235,7 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto private Device withConnectedStatus(Device opDev) { Device1 status = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.CONNECTED).build(); return new DeviceBuilder().addAugmentation(Device1.class, status).setUniqueId(opDev.getUniqueId()) - .setSshHostKey(opDev.getSshHostKey()).build(); + .setSshHostKey(opDev.getSshHostKey()).build(); } private Device withFailedStatus(Device opDev) { @@ -255,7 +253,7 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto private Device withFailedAuthStatus(Device opDev) { Device1 status = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.FAILEDAUTHFAILURE).build(); return new DeviceBuilder().addAugmentation(Device1.class, status).setUniqueId(opDev.getUniqueId()) - .setSshHostKey(opDev.getSshHostKey()).build(); + .setSshHostKey(opDev.getSshHostKey()).build(); } private void setDeviceStatus(Device device) { @@ -304,7 +302,7 @@ 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); 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 6fe0c29894..124f87d39c 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 @@ -38,6 +38,7 @@ class ContextKey { result = prime * result + port.hashCode(); return result; } + @Override public boolean equals(Object obj) { if (this == obj) @@ -68,7 +69,7 @@ class ContextKey { InetAddress ipAddress = inetSocketAddr.getAddress(); final IpAddress yangIp; - if(ipAddress instanceof Inet4Address) { + if (ipAddress instanceof Inet4Address) { yangIp = new IpAddress(IetfInetUtil.INSTANCE.ipv4AddressFor(ipAddress)); } else { Preconditions.checkArgument(ipAddress instanceof Inet6Address); @@ -79,7 +80,7 @@ class ContextKey { @Override public String toString() { - if(address.getIpv4Address() != null) { + if (address.getIpv4Address() != null) { return address.getIpv4Address().getValue() + ":" + port.getValue(); } return address.getIpv6Address().getValue() + ":" + port.getValue(); 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 bcc5707b14..ca26f86064 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,8 +13,8 @@ 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.IOException; import java.io.File; +import java.io.IOException; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Iterator; @@ -45,8 +45,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataChangeListener -{ +public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataChangeListener { private static final String APPNAME = "CallHomeServer"; static final InstanceIdentifier ALL_DEVICES = InstanceIdentifier.create(NetconfCallhomeServer.class).child(AllowedDevices.class); @@ -54,14 +53,14 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC private final DataBroker dataBroker; private final CallHomeMountDispatcher mountDispacher; - private CallHomeAuthProviderImpl authProvider ; + private CallHomeAuthProviderImpl authProvider; protected NetconfCallHomeServer server; private ListenerRegistration listenerReg = null; private static final String CALL_HOME_PORT_KEY = "DefaultCallHomePort"; - private static String configurationPath = "etc"+File.pathSeparator+"ztp-callhome-config.cfg"; + private static String configurationPath = "etc" + File.pathSeparator + "ztp-callhome-config.cfg"; private int port = 0; // 0 = use default in NetconfCallHomeBuilder private CallhomeStatusReporter statusReporter; @@ -78,10 +77,9 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC LOG.info("Initializing provider for {}", APPNAME); loadConfigurableValues(configurationPath); initializeServer(); - dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,ALL_DEVICES,this, AsyncDataBroker.DataChangeScope.SUBTREE); - LOG.info( "Initialization complete for {}", APPNAME); - } - catch(IOException | Configuration.ConfigurationException e) { + 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); } } @@ -91,8 +89,7 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC try { Configuration configuration = new Configuration(configurationPath); port = configuration.getAsPort(CALL_HOME_PORT_KEY); - } - catch(Configuration.ConfigurationException e) { + } catch (Configuration.ConfigurationException e) { LOG.error("Problem trying to load configuration values from {}", configurationPath, e); } } @@ -102,7 +99,7 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC } private void initializeServer() throws IOException { - LOG.info( "Initializing Call Home server instance"); + LOG.info("Initializing Call Home server instance"); CallHomeAuthorizationProvider provider = this.getCallHomeAuthorization(); NetconfCallHomeServerBuilder builder = new NetconfCallHomeServerBuilder( provider, mountDispacher, statusReporter); @@ -111,7 +108,7 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC server = builder.build(); server.bind(); mountDispacher.createTopology(); - LOG.info( "Initialization complete for Call Home server instance"); + LOG.info("Initialization complete for Call Home server instance"); } @VisibleForTesting @@ -126,10 +123,10 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC statusReporter.close(); // FIXME unbind the server - if ( this.listenerReg != null ) { + if (this.listenerReg != null) { listenerReg.close(); } - if(server != null ) { + if (server != null) { server.close(); } @@ -152,11 +149,10 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC handleDeletedDevices(change); try { - for(Device confDevice : getReadDevices(devicesFuture)) { + for (Device confDevice : getReadDevices(devicesFuture)) { readAndUpdateStatus(confDevice); } - } - catch(ReadFailedException e) { + } catch (ReadFailedException e) { LOG.error("Error trying to read the whitelist devices: {}", e); } } @@ -174,9 +170,9 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC int numRemoved = removedDevices.size(); Iterator> iterator = removedDevices.iterator(); - while(iterator.hasNext()){ + while (iterator.hasNext()) { InstanceIdentifier removedIID = iterator.next(); - LOG.info("Deleting the entry for callhome device {}",removedIID); + LOG.info("Deleting the entry for callhome device {}", removedIID); opTx.delete(LogicalDatastoreType.OPERATIONAL, removedIID); } @@ -200,7 +196,7 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC } private void readAndUpdateStatus(Device cfgDevice) throws ReadFailedException { - InstanceIdentifier deviceIID = InstanceIdentifier.create(NetconfCallhomeServer.class) + InstanceIdentifier deviceIID = InstanceIdentifier.create(NetconfCallhomeServer.class) .child(AllowedDevices.class) .child(Device.class, new DeviceKey(cfgDevice.getUniqueId())); @@ -209,7 +205,7 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataC Optional opDevGet = deviceFuture.checkedGet(); Device1 devStatus = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.DISCONNECTED).build(); - if(opDevGet.isPresent()) { + if (opDevGet.isPresent()) { Device opDevice = opDevGet.get(); devStatus = opDevice.getAugmentation(Device1.class); } -- 2.36.6