import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import java.io.IOException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
+import java.security.GeneralSecurityException;
import java.security.PublicKey;
-import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
private final DataBroker dataBroker;
private final ListenerRegistration<CallhomeStatusReporter> reg;
- CallhomeStatusReporter(DataBroker broker) {
+ CallhomeStatusReporter(final DataBroker broker) {
this.dataBroker = broker;
this.reg = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
NETCONF_TOPO_IID.child(Node.class)), this);
}
@Override
- public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> changes) {
+ public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<Node>> changes) {
for (DataTreeModification<Node> change: changes) {
final DataObjectModification<Node> rootNode = change.getRootNode();
final InstanceIdentifier<Node> identifier = change.getRootPath().getRootIdentifier();
}
}
- private boolean isNetconfNode(Node node) {
+ private static boolean isNetconfNode(final Node node) {
return node.getAugmentation(NetconfNode.class) != null;
}
- private NodeId getNodeId(final InstanceIdentifier<?> path) {
+ private static NodeId getNodeId(final InstanceIdentifier<?> path) {
NodeKey key = path.firstKeyOf(Node.class);
return key != null ? key.getNodeId() : null;
}
- private void handledNetconfNode(NodeId nodeId, NetconfNode nnode) {
+ private void handledNetconfNode(final NodeId nodeId, final NetconfNode nnode) {
NetconfNodeConnectionStatus.ConnectionStatus csts = nnode.getConnectionStatus();
switch (csts) {
}
}
- private void handleConnectedNetconfNode(NodeId nodeId) {
+ private void handleConnectedNetconfNode(final NodeId nodeId) {
// Fully connected, all services for remote device are
// available from the MountPointService.
LOG.debug("NETCONF Node: {} is fully connected", nodeId.getValue());
}
}
- private void handleDisconnectedNetconfNode(NodeId nodeId) {
+ private void handleDisconnectedNetconfNode(final NodeId nodeId) {
LOG.debug("NETCONF Node: {} disconnected", nodeId.getValue());
Device opDev = readAndGetDevice(nodeId);
}
}
- private void handleUnableToConnectNetconfNode(NodeId nodeId) {
+ private void handleUnableToConnectNetconfNode(final NodeId nodeId) {
// The maximum configured number of reconnect attempts
// have been reached. No more reconnects will be
// attempted by the Netconf Connector.
}
}
- void asForceListedDevice(String id, PublicKey serverKey) {
+ void asForceListedDevice(final String id, final PublicKey serverKey) {
NodeId nid = new NodeId(id);
Device device = newDevice(id, serverKey, Device1.DeviceStatus.DISCONNECTED);
writeDevice(nid, device);
}
- void asUnlistedDevice(String id, PublicKey serverKey) {
+ void asUnlistedDevice(final String id, final PublicKey serverKey) {
NodeId nid = new NodeId(id);
Device device = newDevice(id, serverKey, Device1.DeviceStatus.FAILEDNOTALLOWED);
writeDevice(nid, device);
}
- private Device newDevice(String id, PublicKey serverKey, Device1.DeviceStatus status) {
+ private static Device newDevice(final String id, final PublicKey serverKey, final Device1.DeviceStatus status) {
String sshEncodedKey = serverKey.toString();
try {
sshEncodedKey = AuthorizedKeysDecoder.encodePublicKey(serverKey);
return builder.build();
}
- private Device readAndGetDevice(NodeId nodeId) {
+ private Device readAndGetDevice(final NodeId nodeId) {
return readDevice(nodeId).orNull();
}
@Nonnull
- private Optional<Device> readDevice(NodeId nodeId) {
+ private Optional<Device> readDevice(final NodeId nodeId) {
ReadOnlyTransaction opTx = dataBroker.newReadOnlyTransaction();
InstanceIdentifier<Device> deviceIID = buildDeviceInstanceIdentifier(nodeId);
}
}
- private void writeDevice(NodeId nodeId, Device modifiedDevice) {
+ private void writeDevice(final NodeId nodeId, final Device modifiedDevice) {
ReadWriteTransaction opTx = dataBroker.newReadWriteTransaction();
opTx.merge(LogicalDatastoreType.OPERATIONAL, buildDeviceInstanceIdentifier(nodeId), modifiedDevice);
opTx.submit();
}
- private InstanceIdentifier<Device> buildDeviceInstanceIdentifier(NodeId nodeId) {
+ private static InstanceIdentifier<Device> buildDeviceInstanceIdentifier(final NodeId nodeId) {
return InstanceIdentifier.create(NetconfCallhomeServer.class)
.child(AllowedDevices.class)
.child(Device.class, new DeviceKey(nodeId.getValue()));
}
- private Device withConnectedStatus(Device opDev) {
+ private static Device withConnectedStatus(final 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();
}
- private Device withFailedStatus(Device opDev) {
+ private static Device withFailedStatus(final Device opDev) {
Device1 status = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.FAILED).build();
return new DeviceBuilder().addAugmentation(Device1.class, status).setUniqueId(opDev.getUniqueId())
.setSshHostKey(opDev.getSshHostKey()).build();
}
- private Device withDisconnectedStatus(Device opDev) {
+ private static Device withDisconnectedStatus(final Device opDev) {
Device1 status = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.DISCONNECTED).build();
return new DeviceBuilder().addAugmentation(Device1.class, status).setUniqueId(opDev.getUniqueId())
.setSshHostKey(opDev.getSshHostKey()).build();
}
- private Device withFailedAuthStatus(Device opDev) {
+ private static Device withFailedAuthStatus(final 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();
}
- private void setDeviceStatus(Device device) {
+ private void setDeviceStatus(final Device device) {
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<Device> deviceIId =
InstanceIdentifier.create(NetconfCallhomeServer.class)
}
@Override
- public void reportFailedAuth(PublicKey sshKey) {
+ public void reportFailedAuth(final PublicKey sshKey) {
AuthorizedKeysDecoder decoder = new AuthorizedKeysDecoder();
for (Device device : getDevicesAsList()) {
setDeviceStatus(failedDevice);
return;
}
- } catch (InvalidKeySpecException | NoSuchAlgorithmException | NoSuchProviderException e) {
+ } catch (GeneralSecurityException e) {
LOG.error("Failed decoding a device key with host key: {} {}", keyString, e);
return;
}