import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.channel.nio.NioEventLoopGroup;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Collection;
private int port = 0; // 0 = use default in NetconfCallHomeBuilder
private final CallhomeStatusReporter statusReporter;
- public IetfZeroTouchCallHomeServerProvider(DataBroker dataBroker, CallHomeMountDispatcher mountDispacher) {
+ public IetfZeroTouchCallHomeServerProvider(final DataBroker dataBroker,
+ final CallHomeMountDispatcher mountDispacher) {
this.dataBroker = dataBroker;
this.mountDispacher = mountDispacher;
this.authProvider = new CallHomeAuthProviderImpl(dataBroker);
}
}
- public void setPort(String portStr) {
+ public void setPort(final String portStr) {
try {
Configuration configuration = new Configuration();
configuration.set(CALL_HOME_PORT_KEY, portStr);
if (port > 0) {
builder.setBindAddress(new InetSocketAddress(port));
}
+ builder.setNettyGroup(new NioEventLoopGroup());
server = builder.build();
server.bind();
mountDispacher.createTopology();
}
@VisibleForTesting
- void assertValid(Object obj, String description) {
+ void assertValid(final Object obj, final String description) {
if (obj == null) {
throw new RuntimeException(
String.format("Failed to find %s in IetfZeroTouchCallHomeProvider.initialize()", description));
}
@Override
- public void close() throws Exception {
+ public void close() {
authProvider.close();
statusReporter.close();
}
@Override
- public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<AllowedDevices>> changes) {
+ public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<AllowedDevices>> 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.
}
}
- private void handleDeletedDevices(Set<InstanceIdentifier<?>> deletedDevices) {
+ private void handleDeletedDevices(final Set<InstanceIdentifier<?>> deletedDevices) {
if (deletedDevices.isEmpty()) {
return;
}
ReadWriteTransaction opTx = dataBroker.newReadWriteTransaction();
- int numRemoved = deletedDevices.size();
-
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();
}
- private List<Device> getReadDevices(
- ListenableFuture<Optional<AllowedDevices>> devicesFuture) throws InterruptedException, ExecutionException {
+ private static List<Device> getReadDevices(final ListenableFuture<Optional<AllowedDevices>> devicesFuture)
+ throws InterruptedException, ExecutionException {
Optional<AllowedDevices> opt = devicesFuture.get();
return opt.isPresent() ? opt.get().getDevice() : Collections.emptyList();
}
Device1 devStatus = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.DISCONNECTED).build();
if (opDevGet.isPresent()) {
Device opDevice = opDevGet.get();
- devStatus = opDevice.getAugmentation(Device1.class);
+ devStatus = opDevice.augmentation(Device1.class);
}
cfgDevice = new DeviceBuilder().addAugmentation(Device1.class, devStatus)
.setSshHostKey(cfgDevice.getSshHostKey()).setUniqueId(cfgDevice.getUniqueId()).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, deviceIID, cfgDevice);
- tx.submit();
+ tx.commit();
}
}