Bump MRI upstreams
[openflowplugin.git] / applications / arbitratorreconciliation / impl / src / main / java / org / opendaylight / openflowplugin / applications / arbitratorreconciliation / impl / ArbitratorReconciliationManagerImpl.java
index e3d819f58e6d6d76104072d0a7e218d9fbb1685e..8eec6568fb3ecc2c58d8897a42a2926238b13967 100644 (file)
@@ -5,22 +5,21 @@
  * 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.openflowplugin.applications.arbitratorreconciliation.impl;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -31,7 +30,6 @@ import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.openflowplugin.api.OFConstants;
@@ -41,7 +39,6 @@ import org.opendaylight.openflowplugin.applications.reconciliation.Reconciliatio
 import org.opendaylight.openflowplugin.applications.reconciliation.ReconciliationNotificationListener;
 import org.opendaylight.serviceutils.upgrade.UpgradeState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
@@ -82,6 +79,7 @@ import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -104,8 +102,9 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
     private static final String SEPARATOR = ":";
 
     private static final BundleRemoveFlowCase DELETE_ALL_FLOW = new BundleRemoveFlowCaseBuilder()
-            .setRemoveFlowCaseData(
-                    new RemoveFlowCaseDataBuilder(new FlowBuilder().setTableId(OFConstants.OFPTT_ALL).build()).build())
+            .setRemoveFlowCaseData(new RemoveFlowCaseDataBuilder()
+                .setTableId(OFConstants.OFPTT_ALL)
+                .build())
             .build();
     private static final BundleRemoveGroupCase DELETE_ALL_GROUP = new BundleRemoveGroupCaseBuilder()
             .setRemoveGroupCaseData(new RemoveGroupCaseDataBuilder(new GroupBuilder()
@@ -126,16 +125,15 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
             ObjectRegistration<? extends RpcService>> rpcRegistrations = new ConcurrentHashMap<>();
 
     @Inject
-    public ArbitratorReconciliationManagerImpl(
-            @Reference ReconciliationManager reconciliationManager, @Reference RpcProviderService rpcProviderService,
-            @Reference final RpcConsumerRegistry rpcRegistry, @Reference UpgradeState upgradeState) {
+    public ArbitratorReconciliationManagerImpl(final ReconciliationManager reconciliationManager,
+            final RpcProviderService rpcProviderService, final RpcConsumerRegistry rpcRegistry,
+            final UpgradeState upgradeState) {
         Preconditions.checkArgument(rpcRegistry != null, "RpcConsumerRegistry cannot be null !");
-        this.reconciliationManager = Preconditions.checkNotNull(reconciliationManager,
-                "ReconciliationManager cannot be null!");
-        this.salBundleService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalBundleService.class),
+        this.reconciliationManager = requireNonNull(reconciliationManager, "ReconciliationManager cannot be null!");
+        salBundleService = requireNonNull(rpcRegistry.getRpcService(SalBundleService.class),
                 "RPC SalBundleService not found.");
         this.rpcProviderService = rpcProviderService;
-        this.upgradeState = Preconditions.checkNotNull(upgradeState, "UpgradeState cannot be null!");
+        this.upgradeState = requireNonNull(upgradeState, "UpgradeState cannot be null!");
     }
 
     @PostConstruct
@@ -156,7 +154,7 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
 
     @Override
     public ListenableFuture<RpcResult<CommitActiveBundleOutput>> commitActiveBundle(
-            CommitActiveBundleInput input) {
+            final CommitActiveBundleInput input) {
         Uint64 nodeId = input.getNodeId();
         if (bundleIdMap.containsKey(nodeId)) {
             BundleId bundleId = bundleIdMap.get(nodeId).getBundleId();
@@ -182,8 +180,8 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
         }
         return RpcResultBuilder.success(new CommitActiveBundleOutputBuilder()
                 .setResult(null).build())
-                .withRpcErrors(Collections.singleton(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION,
-                        null, "No active bundle found for the node" + nodeId.toString()))).buildFuture();
+                .withRpcErrors(List.of(RpcResultBuilder.newError(ErrorType.APPLICATION,
+                        null, "No active bundle found for the node" + nodeId))).buildFuture();
     }
 
     @Override
@@ -199,9 +197,9 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
                         .setResult(bundleDetails.getBundleId())
                         .build())
                         .buildFuture();
-            } catch (InterruptedException | ExecutionException | NullPointerException e) {
+            } catch (InterruptedException | ExecutionException e) {
                 return RpcResultBuilder.<GetActiveBundleOutput>failed()
-                        .withRpcErrors(Collections.singleton(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION,
+                        .withRpcErrors(List.of(RpcResultBuilder.newError(ErrorType.APPLICATION,
                                 null, e.getMessage()))).buildFuture();
             }
         }
@@ -210,7 +208,7 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
     }
 
     @Override
-    public ListenableFuture<Boolean> startReconciliation(DeviceInfo node) {
+    public ListenableFuture<Boolean> startReconciliation(final DeviceInfo node) {
         registerRpc(node);
         if (upgradeState.isUpgradeInProgress()) {
             LOG.trace("Starting arbitrator reconciliation for node {}", node.getDatapathId());
@@ -221,7 +219,7 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
     }
 
     @Override
-    public ListenableFuture<Boolean> endReconciliation(DeviceInfo node) {
+    public ListenableFuture<Boolean> endReconciliation(final DeviceInfo node) {
         Uint64 datapathId = node.getDatapathId();
         LOG.trace("Stopping arbitrator reconciliation for node {}", datapathId);
         bundleIdMap.remove(datapathId);
@@ -244,14 +242,12 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
         return ResultState.DONOTHING;
     }
 
-    private ListenableFuture<Boolean> reconcileConfiguration(DeviceInfo node) {
+    private ListenableFuture<Boolean> reconcileConfiguration(final DeviceInfo node) {
         LOG.info("Triggering arbitrator reconciliation for device {}", node.getDatapathId());
         ArbitratorReconciliationTask upgradeReconTask = new ArbitratorReconciliationTask(node);
         return executor.submit(upgradeReconTask);
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static Messages createMessages(final NodeRef nodeRef) {
         final List<Message> messages = new ArrayList<>();
         messages.add(new MessageBuilder()
@@ -341,13 +337,13 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
         }
 
         @Override
-        public void onSuccess(RpcResult<?> rpcResult) {
+        public void onSuccess(final RpcResult<?> rpcResult) {
             LOG.debug("Completed arbitrator reconciliation for device:{}", nodeId);
             bundleIdMap.remove(nodeId);
         }
 
         @Override
-        public void onFailure(Throwable throwable) {
+        public void onFailure(final Throwable throwable) {
             LOG.error("Error while performing arbitrator reconciliation for device {}", nodeId, throwable);
         }
     }
@@ -366,23 +362,22 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
                 }
             } else {
                 resultSink = RpcResultBuilder.<CommitActiveBundleOutput>failed()
-                        .withError(RpcError.ErrorType.APPLICATION, "action of " + action + " failed");
+                        .withError(ErrorType.APPLICATION, "action of " + action + " failed");
             }
             return resultSink.build();
         };
     }
 
-    private void registerRpc(DeviceInfo node) {
+    private void registerRpc(final DeviceInfo node) {
         KeyedInstanceIdentifier<Node, NodeKey> path = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, new NodeKey(node.getNodeId()));
         LOG.debug("The path is registered : {}", path);
         ObjectRegistration<? extends RpcService> rpcRegistration =
-                rpcProviderService.registerRpcImplementation(ArbitratorReconcileService.class,
-                        this, ImmutableSet.of(path));
+                rpcProviderService.registerRpcImplementation(ArbitratorReconcileService.class, this, Set.of(path));
         rpcRegistrations.put(node.getNodeId().getValue(), rpcRegistration);
     }
 
-    private void deregisterRpc(DeviceInfo node) {
+    private void deregisterRpc(final DeviceInfo node) {
         KeyedInstanceIdentifier<Node, NodeKey> path = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, new NodeKey(node.getNodeId()));
         LOG.debug("The path is unregistered : {}", path);
@@ -397,7 +392,7 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
         private final BundleId bundleId;
         private final ListenableFuture<RpcResult<ControlBundleOutput>> result;
 
-        BundleDetails(BundleId bundleId, ListenableFuture<RpcResult<ControlBundleOutput>> result) {
+        BundleDetails(final BundleId bundleId, final ListenableFuture<RpcResult<ControlBundleOutput>> result) {
             this.bundleId = bundleId;
             this.result = result;
         }
@@ -411,9 +406,7 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
         }
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
-    private static Uint64 getDpnIdFromNodeName(String nodeName) {
+    private static Uint64 getDpnIdFromNodeName(final String nodeName) {
         String dpnId = nodeName.substring(nodeName.lastIndexOf(SEPARATOR) + 1);
         return Uint64.valueOf(dpnId);
     }