X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fcallhome-provider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fcallhome%2Fmount%2FIetfZeroTouchCallHomeServerProvider.java;h=d2dbec65d27e856154f65c7fb36bd83583d1eb40;hb=f0b0a99508a36b2087b507ad1ab976255599f4af;hp=987fcc03646c64f3806674a533986c8cf96d8db6;hpb=2295d50e7212d80a9bc752f655fa66790ad45022;p=netconf.git 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 987fcc0364..d2dbec65d2 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 @@ -5,29 +5,32 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.netconf.callhome.mount; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; +import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; +import io.netty.channel.nio.NioEventLoopGroup; import java.io.IOException; import java.net.InetSocketAddress; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutionException; -import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; -import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.DataObjectModification; +import org.opendaylight.mdsal.binding.api.DataTreeChangeListener; +import org.opendaylight.mdsal.binding.api.DataTreeIdentifier; +import org.opendaylight.mdsal.binding.api.DataTreeModification; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.binding.api.ReadWriteTransaction; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.netconf.callhome.protocol.CallHomeAuthorizationProvider; import org.opendaylight.netconf.callhome.protocol.NetconfCallHomeServer; import org.opendaylight.netconf.callhome.protocol.NetconfCallHomeServerBuilder; @@ -76,7 +79,7 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataT LOG.info("Initializing provider for {}", APPNAME); initializeServer(); listenerReg = dataBroker.registerDataTreeChangeListener( - new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, ALL_DEVICES), this); + DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, ALL_DEVICES), this); LOG.info("Initialization complete for {}", APPNAME); } catch (IOException | Configuration.ConfigurationException e) { LOG.error("Unable to successfully initialize", e); @@ -106,6 +109,7 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataT if (port > 0) { builder.setBindAddress(new InetSocketAddress(port)); } + builder.setNettyGroup(new NioEventLoopGroup()); server = builder.build(); server.bind(); mountDispacher.createTopology(); @@ -121,7 +125,7 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataT } @Override - public void close() throws Exception { + public void close() { authProvider.close(); statusReporter.close(); @@ -137,13 +141,13 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataT } @Override - public void onDataTreeChanged(@Nonnull final Collection> changes) { + public void onDataTreeChanged(final Collection> changes) { // In case of any changes to the devices datatree, register the changed values with callhome server // As of now, no way to add a new callhome client key to the CallHomeAuthorization instance since // its created under CallHomeAuthorizationProvider. // Will have to redesign a bit here. // CallHomeAuthorization. - ReadOnlyTransaction roConfigTx = dataBroker.newReadOnlyTransaction(); + ReadTransaction roConfigTx = dataBroker.newReadOnlyTransaction(); ListenableFuture> devicesFuture = roConfigTx .read(LogicalDatastoreType.CONFIGURATION, IetfZeroTouchCallHomeServerProvider.ALL_DEVICES); @@ -166,7 +170,7 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataT readAndUpdateStatus(confDevice); } } catch (ExecutionException | InterruptedException e) { - LOG.error("Error trying to read the whitelist devices: {}", e); + LOG.error("Error trying to read the whitelist devices", e); } } @@ -175,44 +179,59 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataT return; } - ReadWriteTransaction opTx = dataBroker.newReadWriteTransaction(); - - int numRemoved = deletedDevices.size(); + WriteTransaction opTx = dataBroker.newWriteOnlyTransaction(); for (InstanceIdentifier removedIID : deletedDevices) { LOG.info("Deleting the entry for callhome device {}", removedIID); opTx.delete(LogicalDatastoreType.OPERATIONAL, removedIID); } - if (numRemoved > 0) { - opTx.submit(); - } + opTx.commit().addCallback(new FutureCallback() { + @Override + public void onSuccess(final CommitInfo result) { + LOG.debug("Device deletions committed"); + } + + @Override + public void onFailure(final Throwable cause) { + LOG.warn("Failed to commit device deletions", cause); + } + }, MoreExecutors.directExecutor()); } private static List getReadDevices(final ListenableFuture> devicesFuture) throws InterruptedException, ExecutionException { - Optional opt = devicesFuture.get(); - return opt.isPresent() ? opt.get().getDevice() : Collections.emptyList(); + return devicesFuture.get().map(AllowedDevices::getDevice).orElse(Collections.emptyList()); } - private void readAndUpdateStatus(Device cfgDevice) throws InterruptedException, ExecutionException { + private void readAndUpdateStatus(final Device cfgDevice) throws InterruptedException, ExecutionException { InstanceIdentifier deviceIID = InstanceIdentifier.create(NetconfCallhomeServer.class) .child(AllowedDevices.class).child(Device.class, new DeviceKey(cfgDevice.getUniqueId())); ReadWriteTransaction tx = dataBroker.newReadWriteTransaction(); ListenableFuture> deviceFuture = tx.read(LogicalDatastoreType.OPERATIONAL, deviceIID); + final Device1 devStatus; Optional opDevGet = deviceFuture.get(); - Device1 devStatus = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.DISCONNECTED).build(); if (opDevGet.isPresent()) { - Device opDevice = opDevGet.get(); - devStatus = opDevice.getAugmentation(Device1.class); + devStatus = opDevGet.get().augmentation(Device1.class); + } else { + devStatus = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.DISCONNECTED).build(); } - cfgDevice = new DeviceBuilder().addAugmentation(Device1.class, devStatus) - .setSshHostKey(cfgDevice.getSshHostKey()).setUniqueId(cfgDevice.getUniqueId()).build(); + tx.merge(LogicalDatastoreType.OPERATIONAL, deviceIID, new DeviceBuilder() + .addAugmentation(Device1.class, devStatus).setSshHostKey(cfgDevice.getSshHostKey()) + .setUniqueId(cfgDevice.getUniqueId()).build()); + tx.commit().addCallback(new FutureCallback() { + @Override + public void onSuccess(final CommitInfo result) { + LOG.debug("Device {} status update committed", cfgDevice.key()); + } - tx.merge(LogicalDatastoreType.OPERATIONAL, deviceIID, cfgDevice); - tx.submit(); + @Override + public void onFailure(final Throwable cause) { + LOG.warn("Failed to commit device {} status update", cfgDevice.key(), cause); + } + }, MoreExecutors.directExecutor()); } }