From 8d16bcd8eadcb58ad458f4dde7e9f56ff58b2c7f Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 8 Feb 2023 14:59:07 +0100 Subject: [PATCH] Simplify builder We do not need the intermediate products, we can just pass them to a fluent builder. Change-Id: Id384d2fd54a454b89de7b43b12b23f1f135a767f Signed-off-by: Robert Varga --- .../mount/CallhomeStatusReporter.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java b/apps/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java index 22d664d130..3da56e0d5b 100644 --- a/apps/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java +++ b/apps/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java @@ -37,10 +37,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.Transport; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.SshBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParamsBuilder; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; @@ -196,14 +194,14 @@ final class CallhomeStatusReporter implements DataTreeChangeListener, Stat } catch (IOException e) { LOG.warn("Unable to encode public key to ssh format.", e); } - final SshClientParams sshParams = new SshClientParamsBuilder().setHostKey(sshEncodedKey).build(); - final Transport transport = new SshBuilder().setSshClientParams(sshParams).build(); return new DeviceBuilder() - .setUniqueId(id) - .withKey(new DeviceKey(id)) - .setTransport(transport) - .addAugmentation(new Device1Builder().setDeviceStatus(status).build()) - .build(); + .setUniqueId(id) + .withKey(new DeviceKey(id)) + .setTransport(new SshBuilder() + .setSshClientParams(new SshClientParamsBuilder().setHostKey(sshEncodedKey).build()) + .build()) + .addAugmentation(new Device1Builder().setDeviceStatus(status).build()) + .build(); } private Device readAndGetDevice(final NodeId nodeId) { @@ -304,8 +302,8 @@ final class CallhomeStatusReporter implements DataTreeChangeListener, Stat for (final Device device : getDevicesAsList()) { final String keyString; - if (device.getTransport() instanceof Ssh) { - keyString = ((Ssh) device.getTransport()).getSshClientParams().getHostKey(); + if (device.getTransport() instanceof Ssh ssh) { + keyString = ssh.getSshClientParams().getHostKey(); } else { keyString = device.getSshHostKey(); } -- 2.36.6