Switch to MD-SAL APIs
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / impl / SimplifiedConfigListener.java
index 6f86def8a6a9ef71f5a7c00edac2e730759ae36d..595a85d27f82f0413592036d9bc3f31390890e23 100644 (file)
@@ -1,19 +1,19 @@
-/**
+/*
  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * 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.frsync.impl;
 
-import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collection;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import java.util.Optional;
+import javax.annotation.Nonnull;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
 import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeDao;
 import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeSnapshotDao;
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
  * Listens to config changes and delegates sync entry to {@link SyncReactor}.
  */
 public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapableNode> {
+
     private static final Logger LOG = LoggerFactory.getLogger(SimplifiedConfigListener.class);
     private final SyncReactor reactor;
     private final FlowCapableNodeSnapshotDao configSnapshot;
@@ -43,27 +44,26 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     }
 
     @Override
-    public void onDataTreeChanged(Collection<DataTreeModification<FlowCapableNode>> modifications) {
-        LOG.trace("Config changes: {}", modifications.size());
+    public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<FlowCapableNode>> modifications) {
         super.onDataTreeChanged(modifications);
     }
 
     /**
      * Update cache. If operational data are present, choose appropriate data and start syncup.
      * Otherwise skip incoming change.
-     * @throws InterruptedException from syncup
      */
+    @Override
     protected Optional<ListenableFuture<Boolean>> processNodeModification(
-            DataTreeModification<FlowCapableNode> modification) throws InterruptedException {
+            final DataTreeModification<FlowCapableNode> modification) {
         final InstanceIdentifier<FlowCapableNode> nodePath = modification.getRootPath().getRootIdentifier();
         final NodeId nodeId = PathUtil.digNodeId(nodePath);
 
-        configSnapshot.updateCache(nodeId, Optional.fromNullable(modification.getRootNode().getDataAfter()));
+        configSnapshot.updateCache(nodeId, Optional.ofNullable(modification.getRootNode().getDataAfter()));
 
         final Optional<FlowCapableNode> operationalNode = operationalDao.loadByNodeId(nodeId);
         if (!operationalNode.isPresent()) {
-            LOG.info("Skip syncup, {} operational is not present", nodeId.getValue());
-            return Optional.absent();
+            LOG.debug("Skip syncup, {} operational is not present", nodeId.getValue());
+            return Optional.empty();
         }
 
         final DataObjectModification<FlowCapableNode> configModification = modification.getRootNode();
@@ -82,16 +82,15 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     }
 
     /**
-     * Add only what is missing on device. If node was added to config DS and it is already present
-     * in operational DS (connected) diff between current new configuration and actual configuration
-     * (seen in operational) should be calculated and sent to device.
+     * If node was added to config DS and it is already present in operational DS (connected) diff between current
+     * new configuration and actual configuration (seen in operational) should be calculated and sent to device.
      */
     private ListenableFuture<Boolean> onNodeAdded(final InstanceIdentifier<FlowCapableNode> nodePath,
                                                   final FlowCapableNode dataAfter,
-                                                  final FlowCapableNode operationalNode) throws InterruptedException {
-        NodeId nodeId = PathUtil.digNodeId(nodePath);
-        LOG.trace("onNodeAdded {}", nodeId.getValue());
-        final SyncupEntry syncupEntry = new SyncupEntry(dataAfter, dsType(), operationalNode, LogicalDatastoreType.OPERATIONAL);
+                                                  final FlowCapableNode operationalNode) {
+        LOG.debug("Reconciliation {}: {}", dsType(), PathUtil.digNodeId(nodePath).getValue());
+        final SyncupEntry syncupEntry = new SyncupEntry(dataAfter, dsType(), operationalNode,
+                LogicalDatastoreType.OPERATIONAL);
         return reactor.syncup(nodePath, syncupEntry);
     }
 
@@ -104,9 +103,7 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
      */
     private ListenableFuture<Boolean> onNodeUpdated(final InstanceIdentifier<FlowCapableNode> nodePath,
                                                     final FlowCapableNode dataBefore,
-                                                    final FlowCapableNode dataAfter) throws InterruptedException {
-        NodeId nodeId = PathUtil.digNodeId(nodePath);
-        LOG.trace("onNodeUpdated {}", nodeId.getValue());
+                                                    final FlowCapableNode dataAfter) {
         final SyncupEntry syncupEntry = new SyncupEntry(dataAfter, dsType(), dataBefore, dsType());
         return reactor.syncup(nodePath, syncupEntry);
     }
@@ -116,9 +113,7 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
      * Note, this could be probably optimized using dedicated wipe-out RPC.
      */
     private ListenableFuture<Boolean> onNodeDeleted(final InstanceIdentifier<FlowCapableNode> nodePath,
-                                                    final FlowCapableNode dataBefore) throws InterruptedException {
-        NodeId nodeId = PathUtil.digNodeId(nodePath);
-        LOG.trace("onNodeDeleted {}", nodeId.getValue());
+                                                    final FlowCapableNode dataBefore) {
         final SyncupEntry syncupEntry = new SyncupEntry(null, dsType(), dataBefore, dsType());
         return reactor.syncup(nodePath, syncupEntry);
     }
@@ -127,5 +122,4 @@ public class SimplifiedConfigListener extends AbstractFrmSyncListener<FlowCapabl
     public LogicalDatastoreType dsType() {
         return LogicalDatastoreType.CONFIGURATION;
     }
-
 }