Merge "Changes in different modules"
authorVivek Srivastava <vivek.v.srivastava@ericsson.com>
Wed, 20 Jul 2016 05:15:01 +0000 (05:15 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 20 Jul 2016 05:15:01 +0000 (05:15 +0000)
14 files changed:
features/pom.xml
features/src/main/features/features.xml
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/IdManager.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/IdUtils.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/IfmUtil.java [changed mode: 0644->0755]
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/commons/InterfaceManagerCommonUtils.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceInventoryStateListener.java
interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/HwVTEPConfigurationTest.java
interfacemanager/interfacemanager-impl/src/test/java/org/opendaylight/genius/interfacemanager/test/TopologyStateInterfaceTest.java
interfacemanager/interfacemanager-shell/pom.xml
itm/itm-api/src/main/java/org/opendaylight/genius/itm/globals/ITMConstants.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/cli/TepMonitor.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/impl/ItmUtils.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/datastoreutils/DataStoreJobCoordinator.java

index d40cd15a3200153fa370ac305e6e9a0a25695bf3..1d4511c1cf3ea1efc849940c3e0119930f2207cf 100644 (file)
@@ -159,6 +159,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
       <artifactId>interfacemanager-api</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>interfacemanager-shell</artifactId>
+      <version>${project.version}</version>
+    </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>idmanager-impl</artifactId>
index b9d6adf6c7c4ce0af2775ba7ffa054feabb497c0..3c3ed27c8754f083f091e5737498fbef30c38e88 100644 (file)
@@ -49,6 +49,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <bundle>mvn:org.opendaylight.genius/arputil-impl/{{VERSION}}</bundle>
     <bundle>mvn:org.opendaylight.genius/alivenessmonitor-impl/{{VERSION}}</bundle>
     <bundle>mvn:org.opendaylight.genius/interfacemanager-impl/{{VERSION}}</bundle>
+    <bundle>mvn:org.opendaylight.genius/interfacemanager-shell/{{VERSION}}</bundle>
     <bundle>mvn:org.opendaylight.genius/itm-impl/{{VERSION}}</bundle>
     <bundle>mvn:org.opendaylight.genius/resourcemanager-impl/{{VERSION}}</bundle>
     <configfile finalname="lockmanager-impl-default-config.xml">mvn:org.opendaylight.genius/lockmanager-impl/{{VERSION}}/xml/config</configfile>
index 45a4ddd323eee09066d87295645929db0198020a..a5cc46eda6e62d8e61030a280513b905cb40865c 100644 (file)
@@ -8,17 +8,41 @@
 
 package org.opendaylight.genius.idmanager;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.Futures;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.DeleteIdPoolInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ChildPools;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntriesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService;
@@ -30,8 +54,9 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.*;
-import java.util.concurrent.Future;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
 
 public class IdManager implements IdManagerService, AutoCloseable{
     private static final Logger LOG = LoggerFactory.getLogger(IdManager.class);
@@ -65,7 +90,9 @@ public class IdManager implements IdManagerService, AutoCloseable{
 
     @Override
     public Future<RpcResult<Void>> createIdPool(CreateIdPoolInput input) {
-        LOG.debug("createIdPool called with input {}", input);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("createIdPool called with input {}", input);
+        }
         String poolName = input.getPoolName();
         long low = input.getLow();
         long high = input.getHigh();
@@ -73,15 +100,13 @@ public class IdManager implements IdManagerService, AutoCloseable{
         RpcResultBuilder<Void> createIdPoolRpcBuilder;
         IdUtils.lockPool(lockManager, poolName);
         try {
-            InstanceIdentifier<IdPool> idPoolInstanceIdentifier = IdUtils.getIdPoolInstance(poolName);
+            WriteTransaction tx = broker.newWriteOnlyTransaction();
             poolName = poolName.intern();
             IdPool idPool;
-            idPool = createGlobalPool(poolName, low, high, blockSize, idPoolInstanceIdentifier);
+            idPool = createGlobalPool(tx, poolName, low, high, blockSize);
             String localPoolName = IdUtils.getLocalPoolName(poolName);
-            if (createLocalPool(localPoolName, idPool)) {
-                LOG.debug("Updating global id pool {} with childPool {}", poolName, localPoolName);
-                updateChildPool(poolName, localPoolName);
-            }
+            createLocalPool(tx, localPoolName, idPool);
+            submitTransaction(tx);
             createIdPoolRpcBuilder = RpcResultBuilder.success();
         } catch (Exception ex) {
             LOG.error("Creation of Id Pool {} failed due to {}", poolName, ex);
@@ -95,7 +120,9 @@ public class IdManager implements IdManagerService, AutoCloseable{
 
     @Override
     public Future<RpcResult<AllocateIdOutput>> allocateId(AllocateIdInput input) {
-        LOG.debug("AllocateId called with input {}", input);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("AllocateId called with input {}", input);
+        }
         String idKey = input.getIdKey();
         String poolName = input.getPoolName();
         String localPoolName = IdUtils.getLocalPoolName(poolName);
@@ -117,8 +144,10 @@ public class IdManager implements IdManagerService, AutoCloseable{
     }
 
     @Override
-    public Future<RpcResult<AllocateIdRangeOutput>> allocateIdRange(AllocateIdRangeInput input){
-        LOG.debug("AllocateIdRange called with input {}", input);
+    public Future<RpcResult<AllocateIdRangeOutput>> allocateIdRange(AllocateIdRangeInput input) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("AllocateIdRange called with input {}", input);
+        }
         String idKey = input.getIdKey();
         String poolName = input.getPoolName();
         long size = input.getSize();
@@ -146,7 +175,9 @@ public class IdManager implements IdManagerService, AutoCloseable{
 
     @Override
     public Future<RpcResult<Void>> deleteIdPool(DeleteIdPoolInput input) {
-        LOG.debug("DeleteIdPool called with input {}", input);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("DeleteIdPool called with input {}", input);
+        }
         String poolName = input.getPoolName();
         RpcResultBuilder<Void> deleteIdPoolRpcBuilder;
         try {
@@ -161,7 +192,9 @@ public class IdManager implements IdManagerService, AutoCloseable{
                     }
                 }
                 MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, idPoolToBeDeleted);
-                LOG.debug("Deleted id pool {}", poolName);
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Deleted id pool {}", poolName);
+                }
             }
             deleteIdPoolRpcBuilder = RpcResultBuilder.success();
         }
@@ -190,7 +223,9 @@ public class IdManager implements IdManagerService, AutoCloseable{
     }
 
     private List<Long> allocateIdFromLocalPool(String parentPoolName, String localPoolName, String idKey, long size) {
-        LOG.trace("Allocating id from local pool {}. Parent pool {}. Idkey {}", localPoolName, parentPoolName, idKey);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Allocating id from local pool {}. Parent pool {}. Idkey {}", localPoolName, parentPoolName, idKey);
+        }
         long newIdValue = -1;
         List<Long> newIdValuesList = new ArrayList<>();
         InstanceIdentifier<IdPool> localIdPoolInstanceIdentifier = IdUtils.getIdPoolInstance(localPoolName);
@@ -198,27 +233,7 @@ public class IdManager implements IdManagerService, AutoCloseable{
         synchronized (localPoolName) {
             InstanceIdentifier<IdPool> parentIdPoolInstanceIdentifier = IdUtils.getIdPoolInstance(parentPoolName);
             IdPool parentIdPool = getIdPool(parentIdPoolInstanceIdentifier);
-            IdPool localPool = null;
-            try {
-                localPool = getIdPool(localIdPoolInstanceIdentifier);
-            } catch (NoSuchElementException e){
-                LOG.trace("Creating local pool {} since it was not present", localPoolName);
-                localPool = IdUtils.createLocalIdPool(localPoolName, parentIdPool);
-                MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, localIdPoolInstanceIdentifier, localPool);
-                IdUtils.lockPool(lockManager, parentPoolName);
-                try {
-                    updateChildPool(parentPoolName, localPoolName);
-                } finally {
-                    IdUtils.unlockPool(lockManager, parentPoolName);
-                }
-                LOG.debug("Updating global id pool {} with childPool {}", parentPoolName, localPoolName);
-            }
-            IdEntries newIdEntry;
             List<IdEntries> idEntries = parentIdPool.getIdEntries();
-            AvailableIdsHolderBuilder availableIds = IdUtils.getAvailableIdsHolderBuilder(localPool);
-            ReleasedIdsHolderBuilder releasedIds = IdUtils.getReleaseIdsHolderBuilder(localPool);
-            //Calling cleanupExcessIds since there could be excessive ids.
-            cleanupExcessIds(availableIds, releasedIds, parentPoolName, localPool.getBlockSize());
             if (idEntries == null) {
                 idEntries = new LinkedList<IdEntries>();
             } else {
@@ -226,64 +241,80 @@ public class IdManager implements IdManagerService, AutoCloseable{
                 Optional<IdEntries> existingIdEntry = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, existingId);
                 if (existingIdEntry.isPresent()) {
                     newIdValuesList = existingIdEntry.get().getIdValue();
-                    LOG.debug("Existing ids {} for the key {} ", newIdValuesList, idKey);
-                    InstanceIdentifier<ReleasedIdsHolder> releasedIdsHolderInstanceIdentifier = InstanceIdentifier
-                            .builder(IdPools.class).child(IdPool.class, new IdPoolKey(localPoolName)).child(ReleasedIdsHolder.class).build();
-                    MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, releasedIdsHolderInstanceIdentifier, releasedIds.build());
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Existing ids {} for the key {} ", newIdValuesList, idKey);
+                    }
                     return newIdValuesList;
                 }
             }
+            WriteTransaction tx = broker.newWriteOnlyTransaction();
+            IdPool localPool = null;
+            try {
+                localPool = getIdPool(localIdPoolInstanceIdentifier);
+            } catch (NoSuchElementException e) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Creating local pool {} since it was not present", localPoolName);
+                }
+                localPool = IdUtils.createLocalIdPool(localPoolName, parentIdPool);
+                updateChildPool(tx, localPool.getParentPoolName(), localPoolName);
+            }
+            IdEntries newIdEntry;
+            AvailableIdsHolderBuilder availableIds = IdUtils.getAvailableIdsHolderBuilder(localPool);
+            ReleasedIdsHolderBuilder releasedIds = IdUtils.getReleaseIdsHolderBuilder(localPool);
+            //Calling cleanupExcessIds since there could be excessive ids.
+            cleanupExcessIds(availableIds, releasedIds, parentPoolName, localPool.getBlockSize());
 
             long totalAvailableIdCount = releasedIds.getAvailableIdCount() + IdUtils.getAvailableIdsCount(availableIds);
             AvailableIdsHolderBuilder availableParentIds = IdUtils.getAvailableIdsHolderBuilder(parentIdPool);
             ReleasedIdsHolderBuilder releasedParentIds = IdUtils.getReleaseIdsHolderBuilder(parentIdPool);
             totalAvailableIdCount = totalAvailableIdCount + releasedParentIds.getAvailableIdCount()
                     + IdUtils.getAvailableIdsCount(availableParentIds);
-            if(totalAvailableIdCount>size) {
+            if (totalAvailableIdCount > size) {
                 while (size > 0) {
                     try {
                         newIdValue = getIdFromPool(localPool, availableIds, releasedIds);
                     } catch (RuntimeException e) {
-                        LOG.trace("Releasing IDs to pool {}", localPoolName);
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("Releasing IDs to pool {}", localPoolName);
+                        }
                         //Releasing the IDs added in newIdValuesList since a null list would be returned now, as the
                         //requested size of list IDs exceeds the number of available IDs.
                         updateDelayedEntries(availableIds, releasedIds, newIdValuesList, parentPoolName,
-                                localPool, localIdPoolInstanceIdentifier);
-                        LOG.trace("Released ids ({}, {}) from local pool {}", idKey, newIdValuesList, localPoolName);
+                                localPool, localIdPoolInstanceIdentifier, tx);
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("Released ids ({}, {}) from local pool {}", idKey, newIdValuesList, localPoolName);
+                        }
+                        submitTransaction(tx);
                         return null;
                     }
                     newIdValuesList.add(newIdValue);
                     size--;
                 }
-            } else{
+            } else {
                 return null;
             }
-            LOG.debug("The newIdValues {} for the idKey {}", newIdValuesList, idKey);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("The newIdValues {} for the idKey {}", newIdValuesList, idKey);
+            }
             newIdEntry = IdUtils.createIdEntries(idKey, newIdValuesList);
             idEntries.add(newIdEntry);
-            LOG.debug("The availablelIds are {}", availableIds.build());
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("The availablelIds are {}", availableIds.build());
+            }
             localPool = new IdPoolBuilder(localPool).setAvailableIdsHolder(availableIds.build())
                     .setReleasedIdsHolder(releasedIds.build()).build();
-            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, localIdPoolInstanceIdentifier, localPool);
-            updateChildPool(localPool.getParentPoolName(), localPoolName);
+            tx.put(LogicalDatastoreType.CONFIGURATION, localIdPoolInstanceIdentifier, localPool, true);
+            updateChildPool(tx, localPool.getParentPoolName(), localPoolName);
             //Updating id entries in the parent pool. This will be used for restart scenario
-            IdUtils.lockPool(lockManager, parentPoolName);
-            try {
-                parentIdPool = getIdPool(parentIdPoolInstanceIdentifier);
-                IdPool parentPool = new IdPoolBuilder(parentIdPool).setIdEntries(idEntries).build();
-                MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, parentIdPoolInstanceIdentifier, parentPool);
-            } catch (Exception ex) {
-                LOG.error("Saving of Id entries to parent pool {} failed due to {}", parentPoolName, ex);
-            } finally {
-                IdUtils.unlockPool(lockManager, parentPoolName);
-            }
+            tx.merge(LogicalDatastoreType.CONFIGURATION, IdUtils.getIdEntriesInstanceIdentifier(parentPoolName, idKey), newIdEntry);
+            submitTransaction(tx);
         }
         return newIdValuesList;
     }
 
     private void updateDelayedEntries(AvailableIdsHolderBuilder availableIds, ReleasedIdsHolderBuilder releasedIds,
                                       List<Long> idsList, String parentPoolName, IdPool localPool,
-                                      InstanceIdentifier<IdPool> localIdPoolInstanceIdentifier){
+                                      InstanceIdentifier<IdPool> localIdPoolInstanceIdentifier, WriteTransaction tx){
         long delayTime = System.currentTimeMillis() / 1000 + releasedIds.getDelayedTimeSec();
         List<DelayedIdEntries> delayedIdEntries = releasedIds.getDelayedIdEntries();
         if (delayedIdEntries == null) {
@@ -304,7 +335,7 @@ public class IdManager implements IdManagerService, AutoCloseable{
         localPool = new IdPoolBuilder(localPool)
                 .setAvailableIdsHolder(availableIds.build())
                 .setReleasedIdsHolder(releasedIds.build()).build();
-        MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, localIdPoolInstanceIdentifier, localPool);
+        tx.put(LogicalDatastoreType.CONFIGURATION, localIdPoolInstanceIdentifier, localPool, true);
     }
 
     private long getIdFromPool(IdPool pool, AvailableIdsHolderBuilder availableIds, ReleasedIdsHolderBuilder releasedIds) {
@@ -312,17 +343,23 @@ public class IdManager implements IdManagerService, AutoCloseable{
         while (true) {
             newIdValue = IdUtils.getIdFromReleaseIdsIfAvailable(releasedIds);
             if (newIdValue != -1) {
-                LOG.debug("Retrieved id value {} from released id holder", newIdValue);
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Retrieved id value {} from released id holder", newIdValue);
+                }
                 return newIdValue;
             }
             newIdValue = IdUtils.getIdFromAvailableIds(availableIds);
             if (newIdValue != -1) {
-                LOG.debug("Creating a new id {} for the pool: {} ", newIdValue, pool.getPoolName());
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Creating a new id {} for the pool: {} ", newIdValue, pool.getPoolName());
+                }
                 return newIdValue;
             }
-            long idCount = allocateIdBlockFromParentPool(pool.getParentPoolName(), availableIds, releasedIds);
+            long idCount = getIdBlockFromParentPool(pool.getParentPoolName(), availableIds, releasedIds);
             if (idCount <= 0) {
-                LOG.debug("Unable to allocate Id block from global pool");
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Unable to allocate Id block from global pool");
+                }
                 throw new RuntimeException(String.format("Ids exhausted for pool : %s", pool.getPoolName()));
             }
         }
@@ -350,7 +387,9 @@ public class IdManager implements IdManagerService, AutoCloseable{
                     return;
                 }
                 releasedIdsParent = new ReleasedIdsHolderBuilder(releasedIdsHolder.get());
-                LOG.debug("Releasing excesss Ids from local pool");
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Releasing excesss Ids from local pool");
+                }
                 IdUtils.freeExcessAvailableIds(releasedIds, releasedIdsParent, blockSize);
                 MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, releasedIdInstanceIdentifier, releasedIdsParent.build());
             } finally {
@@ -366,37 +405,56 @@ public class IdManager implements IdManagerService, AutoCloseable{
      * @param releasedIdsBuilder
      * @return
      */
-    private long allocateIdBlockFromParentPool(String parentPoolName,
-                                               AvailableIdsHolderBuilder availableIdsBuilder, ReleasedIdsHolderBuilder releasedIdsBuilder) {
-        LOG.debug("Allocating block of id from parent pool {}", parentPoolName);
+    private long getIdBlockFromParentPool(String parentPoolName,
+            AvailableIdsHolderBuilder availableIdsBuilder, ReleasedIdsHolderBuilder releasedIdsBuilder) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Allocating block of id from parent pool {}", parentPoolName);
+        }
         InstanceIdentifier<IdPool> idPoolInstanceIdentifier = IdUtils.getIdPoolInstance(parentPoolName);
         parentPoolName = parentPoolName.intern();
-        long idCount = -1;
         IdUtils.lockPool(lockManager, parentPoolName);
         try {
+            WriteTransaction tx = broker.newWriteOnlyTransaction();
             IdPool parentIdPool = getIdPool(idPoolInstanceIdentifier);
-            ReleasedIdsHolderBuilder releasedIdsBuilderParent = IdUtils.getReleaseIdsHolderBuilder(parentIdPool);
-            while (true) {
-                idCount = allocateIdBlockFromReleasedIdsHolder(releasedIdsBuilder, releasedIdsBuilderParent, parentIdPool);
-                if (idCount > 0) {
-                    return idCount;
-                }
-                idCount = allocateIdBlockFromAvailableIdsHolder(availableIdsBuilder, parentIdPool);
-                if (idCount > 0) {
-                    return idCount;
-                }
-                idCount = getIdsFromOtherChildPools(releasedIdsBuilderParent, parentIdPool);
-                if (idCount <= 0) {
-                    LOG.debug("Unable to allocate Id block from global pool");
-                    throw new RuntimeException(String.format("Ids exhausted for pool : %s", parentPoolName));
-                }
-            }
+            long idCount = allocateIdBlockFromParentPool(availableIdsBuilder, releasedIdsBuilder, parentIdPool, tx);
+            submitTransaction(tx);
+            return idCount;
         }
         finally {
             IdUtils.unlockPool(lockManager, parentPoolName);
         }
     }
 
+    /**
+     * Changes made to availableIds and releasedIds will not be persisted to the datastore
+     * @param parentPoolName
+     * @param availableIdsBuilder
+     * @param releasedIdsBuilder
+     * @return
+     */
+    private long allocateIdBlockFromParentPool(AvailableIdsHolderBuilder availableIdsBuilder,
+            ReleasedIdsHolderBuilder releasedIdsBuilder, IdPool parentIdPool, WriteTransaction tx) {
+        long idCount = -1;
+        ReleasedIdsHolderBuilder releasedIdsBuilderParent = IdUtils.getReleaseIdsHolderBuilder(parentIdPool);
+        while (true) {
+            idCount = allocateIdBlockFromReleasedIdsHolder(releasedIdsBuilder, releasedIdsBuilderParent, parentIdPool, tx);
+            if (idCount > 0) {
+                return idCount;
+            }
+            idCount = allocateIdBlockFromAvailableIdsHolder(availableIdsBuilder, parentIdPool, tx);
+            if (idCount > 0) {
+                return idCount;
+            }
+            idCount = getIdsFromOtherChildPools(releasedIdsBuilderParent, parentIdPool);
+            if (idCount <= 0) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Unable to allocate Id block from global pool");
+                }
+                throw new RuntimeException(String.format("Ids exhausted for pool : %s", parentIdPool.getPoolName()));
+            }
+        }
+    }
+
     private long getIdsFromOtherChildPools(ReleasedIdsHolderBuilder releasedIdsBuilderParent, IdPool parentIdPool) {
         List<ChildPools> childPoolsList = parentIdPool.getChildPools();
         // Sorting the child pools on last accessed time so that the pool that was not accessed for a long time comes first.
@@ -439,9 +497,11 @@ public class IdManager implements IdManagerService, AutoCloseable{
         return 0;
     }
 
-    private long allocateIdBlockFromReleasedIdsHolder(ReleasedIdsHolderBuilder releasedIdsBuilderChild, ReleasedIdsHolderBuilder releasedIdsBuilderParent, IdPool parentIdPool) {
+    private long allocateIdBlockFromReleasedIdsHolder(ReleasedIdsHolderBuilder releasedIdsBuilderChild, ReleasedIdsHolderBuilder releasedIdsBuilderParent, IdPool parentIdPool, WriteTransaction tx) {
         if (releasedIdsBuilderParent.getAvailableIdCount() == 0) {
-            LOG.debug("Ids unavailable in releasedIds of parent pool {}", parentIdPool);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Ids unavailable in releasedIds of parent pool {}", parentIdPool);
+            }
             return 0;
         }
         List<DelayedIdEntries> delayedIdEntriesParent = releasedIdsBuilderParent.getDelayedIdEntries();
@@ -460,18 +520,22 @@ public class IdManager implements IdManagerService, AutoCloseable{
                 .builder(IdPools.class).child(IdPool.class,
                         new IdPoolKey(parentIdPool.getPoolName())).child(ReleasedIdsHolder.class).build();
         releasedIdsBuilderParent.setAvailableIdCount(releasedIdsBuilderParent.getAvailableIdCount() - idCount);
-        LOG.debug("Allocated {} ids from releasedIds of parent pool {}", idCount, parentIdPool);
-        MDSALUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, releasedIdsHolderInstanceIdentifier, releasedIdsBuilderParent.build());
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Allocated {} ids from releasedIds of parent pool {}", idCount, parentIdPool);
+        }
+        tx.merge(LogicalDatastoreType.CONFIGURATION, releasedIdsHolderInstanceIdentifier, releasedIdsBuilderParent.build(), true);
         return idCount;
     }
 
-    private long allocateIdBlockFromAvailableIdsHolder(AvailableIdsHolderBuilder availableIdsBuilder, IdPool parentIdPool) {
+    private long allocateIdBlockFromAvailableIdsHolder(AvailableIdsHolderBuilder availableIdsBuilder, IdPool parentIdPool, WriteTransaction tx) {
         long idCount = 0;
         AvailableIdsHolderBuilder availableIdsBuilderParent = IdUtils.getAvailableIdsHolderBuilder(parentIdPool);
         long end = availableIdsBuilderParent.getEnd();
         long cur = availableIdsBuilderParent.getCursor();
         if (!IdUtils.isIdAvailable(availableIdsBuilderParent)) {
-            LOG.debug("Ids exhausted in parent pool {}", parentIdPool);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Ids exhausted in parent pool {}", parentIdPool);
+            }
             return idCount;
         }
         // Update availableIdsHolder of Local Pool
@@ -484,8 +548,10 @@ public class IdManager implements IdManagerService, AutoCloseable{
                 .builder(IdPools.class).child(IdPool.class,
                         new IdPoolKey(parentIdPool.getPoolName())).child(AvailableIdsHolder.class).build();
         availableIdsBuilderParent.setCursor(cur + idCount);
-        LOG.debug("Allocated {} ids from availableIds of global pool {}", idCount, parentIdPool);
-        MDSALUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, availableIdsHolderInstanceIdentifier, availableIdsBuilderParent.build());
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Allocated {} ids from availableIds of global pool {}", idCount, parentIdPool);
+        }
+        tx.merge(LogicalDatastoreType.CONFIGURATION, availableIdsHolderInstanceIdentifier, availableIdsBuilderParent.build(), true);
         return idCount;
     }
 
@@ -510,52 +576,64 @@ public class IdManager implements IdManagerService, AutoCloseable{
             IdEntries existingIdEntry = existingIdEntryObject.get();
             List<Long> idValuesList = existingIdEntry.getIdValue();
             boolean isRemoved = newIdEntries.remove(existingIdEntry);
-            LOG.debug("The entry {} is removed {}", existingIdEntry, isRemoved);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("The entry {} is removed {}", existingIdEntry, isRemoved);
+            }
             ReleasedIdsHolderBuilder releasedIds = IdUtils.getReleaseIdsHolderBuilder(localPool);
             AvailableIdsHolderBuilder availableIds = IdUtils.getAvailableIdsHolderBuilder(localPool);
+            WriteTransaction tx = broker.newWriteOnlyTransaction();
             updateDelayedEntries(availableIds, releasedIds, idValuesList, parentPoolName,
-                    localPool, localIdPoolInstanceIdentifier);
-            LOG.trace("Released ids ({}, {}) from pool {}", idKey, idValuesList, poolName);
-            //Updating id entries in the parent pool. This will be used for restart scenario
-            IdUtils.lockPool(lockManager, parentPoolName);
-            try {
-                parentIdPool = getIdPool(parentIdPoolInstanceIdentifier);
-                IdPool parentPool = new IdPoolBuilder(parentIdPool).setIdEntries(newIdEntries).build();
-                MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, parentIdPoolInstanceIdentifier, parentPool);
-            } catch (Exception ex) {
-                LOG.error("Saving of Id entries to parent pool {} failed due to {}", parentPoolName, ex);
-            } finally {
-                IdUtils.unlockPool(lockManager, parentPoolName);
+                    localPool, localIdPoolInstanceIdentifier, tx);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Released ids ({}, {}) from pool {}", idKey, idValuesList, poolName);
             }
+            //Updating id entries in the parent pool. This will be used for restart scenario
+            tx.delete(LogicalDatastoreType.CONFIGURATION, IdUtils.getIdEntriesInstanceIdentifier(parentPoolName, idKey));
+            submitTransaction(tx);
         }
     }
 
-    private IdPool createGlobalPool(String poolName, long low, long high,
-                                    long blockSize, InstanceIdentifier<IdPool> idPoolInstanceIdentifier) {
+    private IdPool createGlobalPool(WriteTransaction tx, String poolName, long low, long high,
+                                    long blockSize) {
         IdPool idPool;
+        InstanceIdentifier<IdPool> idPoolInstanceIdentifier = IdUtils.getIdPoolInstance(poolName);
         Optional<IdPool> existingIdPool = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, idPoolInstanceIdentifier);
         if (!existingIdPool.isPresent()) {
-            LOG.debug("Creating new global pool {}", poolName);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Creating new global pool {}", poolName);
+            }
             idPool = IdUtils.createGlobalPool(poolName, low, high, blockSize);
-            MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, idPoolInstanceIdentifier, idPool);
+            tx.put(LogicalDatastoreType.CONFIGURATION, idPoolInstanceIdentifier, idPool, true);
         }
         else {
             idPool = existingIdPool.get();
-            LOG.debug("GlobalPool exists {}", idPool);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("GlobalPool exists {}", idPool);
+            }
         }
         return idPool;
     }
 
-    private boolean createLocalPool(String localPoolName, IdPool idPool) {
+    private boolean createLocalPool(WriteTransaction tx, String localPoolName, IdPool idPool) {
         localPoolName = localPoolName.intern();
         synchronized (localPoolName) {
             InstanceIdentifier<IdPool> localIdPoolInstanceIdentifier = IdUtils.getIdPoolInstance(localPoolName);
             Optional<IdPool> localIdPool = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, localIdPoolInstanceIdentifier);
             if (!localIdPool.isPresent()) {
-                LOG.debug("Creating new local pool");
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Creating new local pool");
+                }
                 IdPool newLocalIdPool = IdUtils.createLocalIdPool(localPoolName, idPool);
-                MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, localIdPoolInstanceIdentifier, newLocalIdPool);
-                LOG.debug("Local pool created {}", newLocalIdPool);
+                ReleasedIdsHolderBuilder releasedIdsBuilder = IdUtils.getReleaseIdsHolderBuilder(newLocalIdPool);
+                AvailableIdsHolderBuilder availableIdsBuilder = IdUtils.getAvailableIdsHolderBuilder(newLocalIdPool);
+                allocateIdBlockFromParentPool(availableIdsBuilder, releasedIdsBuilder, idPool, tx);
+                newLocalIdPool = new IdPoolBuilder(newLocalIdPool).setAvailableIdsHolder(availableIdsBuilder.build())
+                        .setReleasedIdsHolder(releasedIdsBuilder.build()).build();
+                tx.put(LogicalDatastoreType.CONFIGURATION, localIdPoolInstanceIdentifier, newLocalIdPool, true);
+                updateChildPool(tx, idPool.getPoolName(), localPoolName);
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Local pool created {}", newLocalIdPool);
+                }
                 return true;
             }
         }
@@ -568,7 +646,9 @@ public class IdManager implements IdManagerService, AutoCloseable{
             Optional<IdPool> idPool = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, idPoolToBeDeleted);
             if (idPool.isPresent()) {
                 MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, idPoolToBeDeleted);
-                LOG.debug("Deleted local pool {}", poolName);
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Deleted local pool {}", poolName);
+                }
             }
         }
     }
@@ -578,13 +658,26 @@ public class IdManager implements IdManagerService, AutoCloseable{
         if (!idPool.isPresent()) {
             throw new NoSuchElementException(String.format("Specified pool %s does not exist" , idPool));
         }
-        LOG.trace("GetIdPool : Read id pool {} ", idPool);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("GetIdPool : Read id pool {} ", idPool);
+        }
         return idPool.get();
     }
 
-    private void updateChildPool(String poolName, String localPoolName) {
+    private void updateChildPool(WriteTransaction tx, String poolName, String localPoolName) {
         ChildPools childPool = IdUtils.createChildPool(localPoolName);
         InstanceIdentifier<ChildPools> childPoolInstanceIdentifier = IdUtils.getChildPoolsInstanceIdentifier(poolName, localPoolName);
-        MDSALUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, childPoolInstanceIdentifier, childPool);
+        tx.merge(LogicalDatastoreType.CONFIGURATION, childPoolInstanceIdentifier, childPool, true);
+    }
+
+
+    private void submitTransaction(WriteTransaction tx) {
+        CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
+        try {
+            futures.get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Error writing to datastore tx", tx);
+            throw new RuntimeException(e.getMessage());
+        }
     }
 }
index 88cf6ec8d73c9f9de18b9aac0dbc82ce4ec9acd0..2710e31b0544d1cac424beea387dfcd8b8505872 100644 (file)
@@ -148,8 +148,9 @@ class IdUtils {
     }
 
     protected static IdPool createLocalIdPool(String localPoolName, IdPool parentIdPool) {
+        IdPoolBuilder idPoolBuilder = new IdPoolBuilder();
         ReleasedIdsHolder releasedIdsHolder = createReleasedIdsHolder(DEFAULT_AVAILABLE_ID_COUNT, DEFAULT_DELAY_TIME);
-        return new IdPoolBuilder().setKey(new IdPoolKey(localPoolName))
+        return idPoolBuilder.setKey(new IdPoolKey(localPoolName))
                 .setPoolName(localPoolName)
                 .setParentPoolName(parentIdPool.getPoolName())
                 .setBlockSize(parentIdPool.getBlockSize())
@@ -259,7 +260,9 @@ class IdUtils {
          Future<RpcResult<Void>> result = lockManager.lock(input);
          try {
              if ((result != null) && (result.get().isSuccessful())) {
-                 LOGGER.debug("Acquired lock {}", poolName);
+                 if (LOGGER.isDebugEnabled()) {
+                     LOGGER.debug("Acquired lock {}", poolName);
+                 }
              } else {
                  throw new RuntimeException(String.format("Unable to getLock for pool %s", poolName));
              }
@@ -274,9 +277,13 @@ class IdUtils {
         Future<RpcResult<Void>> result = lockManager.unlock(input);
         try {
             if ((result != null) && (result.get().isSuccessful())) {
-                LOGGER.debug("Unlocked {}", poolName);
+                if (LOGGER.isDebugEnabled()) {
+                    LOGGER.debug("Unlocked {}", poolName);
+                }
             } else {
-                LOGGER.debug("Unable to unlock pool {}", poolName);
+                if (LOGGER.isDebugEnabled()) {
+                    LOGGER.debug("Unable to unlock pool {}", poolName);
+                }
             }
         } catch (InterruptedException | ExecutionException e) {
             LOGGER.error("Unable to unlock for pool {}", poolName);
old mode 100644 (file)
new mode 100755 (executable)
index e09e159..788292d
@@ -394,12 +394,18 @@ public class IfmUtil {
         return interfaceType;
     }
 
-    public static VlanInterfaceInfo getVlanInterfaceInfo(String interfaceName, Interface iface, BigInteger dpId){
-        IfL2vlan vlanIface = iface.getAugmentation(IfL2vlan.class);
+    public static VlanInterfaceInfo getVlanInterfaceInfo(String interfaceName, Interface iface, BigInteger dpId) {
 
         short vlanId = 0;
-        //FIXME :Use this below thing properly
-        VlanInterfaceInfo vlanInterfaceInfo = new VlanInterfaceInfo(dpId, "someString", vlanId);
+        String portName = null;
+        IfL2vlan vlanIface = iface.getAugmentation(IfL2vlan.class);
+        ParentRefs parentRefs = iface.getAugmentation(ParentRefs.class);
+        if (parentRefs != null && parentRefs.getParentInterface() != null) {
+            portName = parentRefs.getParentInterface();
+        }else {
+            LOG.warn("Portname set to null since parentRef is Null");
+        }
+        VlanInterfaceInfo vlanInterfaceInfo = new VlanInterfaceInfo(dpId, portName, vlanId);
 
         if (vlanIface != null) {
             vlanId = vlanIface.getVlanId() == null ? 0 : vlanIface.getVlanId().getValue().shortValue();
index a38f8989deab139a43ce5287519ee26f0f37e4fb..1d12c07690f3e82d0a501cf3bb3e6e2fdeb04722 100644 (file)
@@ -377,7 +377,7 @@ public class InterfaceManagerCommonUtils {
         LOG.debug("updating tep interface state as {} for {}", operStatus.name(), interfaceName);
         InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setOperStatus(operStatus);
         ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceName));
-        transaction.merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
+        transaction.merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), false);
     }
 
     public static boolean isTunnelInterface(Interface interfaceInfo){
index 22523f188cba9f8701c02d221936601230c8f2dd..bf6491fa8b23599ae05130229ca80e18ea57a521 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.genius.interfacemanager.renderer.ovs.statehelpers.OvsInt
 import org.opendaylight.genius.interfacemanager.renderer.ovs.statehelpers.OvsInterfaceStateRemoveHelper;
 import org.opendaylight.genius.interfacemanager.renderer.ovs.statehelpers.OvsInterfaceStateUpdateHelper;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.AlivenessMonitorService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
@@ -74,7 +75,17 @@ public class InterfaceInventoryStateListener extends AsyncDataTreeChangeListener
     protected void remove(InstanceIdentifier<FlowCapableNodeConnector> key,
                           FlowCapableNodeConnector flowCapableNodeConnectorOld) {
         LOG.debug("Received NodeConnector Remove Event: {}, {}", key, flowCapableNodeConnectorOld);
-        remove(key, flowCapableNodeConnectorOld, true);
+        String portName = flowCapableNodeConnectorOld.getName();
+        NodeConnectorId nodeConnectorIdNew = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
+
+        //VM Migration: Skip OFPPR_DELETE event received after OFPPR_ADD for same interface from Older DPN
+        NodeConnectorId nodeConnectorIdOld = IfmUtil.getNodeConnectorIdFromInterface(portName, dataBroker);
+        if(nodeConnectorIdOld != null && !nodeConnectorIdNew.equals(nodeConnectorIdOld)) {
+            LOG.info("Skipping the NodeConnector Remove Event received for the interface exists in newer DPN: {}, {}", nodeConnectorIdNew, nodeConnectorIdOld);
+            return;
+        }
+
+        remove(nodeConnectorIdNew, nodeConnectorIdOld, flowCapableNodeConnectorOld, portName);
     }
 
     @Override
@@ -92,10 +103,16 @@ public class InterfaceInventoryStateListener extends AsyncDataTreeChangeListener
     @Override
     protected void add(InstanceIdentifier<FlowCapableNodeConnector> key, FlowCapableNodeConnector fcNodeConnectorNew) {
         LOG.debug("Received NodeConnector Add Event: {}, {}", key, fcNodeConnectorNew);
-        //VM Migration: Delete existing interface entry for older DPN
-        remove(key, fcNodeConnectorNew, false);
         String portName = fcNodeConnectorNew.getName();
         NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
+
+        //VM Migration: Delete existing interface entry for older DPN
+        NodeConnectorId nodeConnectorIdOld = IfmUtil.getNodeConnectorIdFromInterface(portName, dataBroker);
+        if(nodeConnectorIdOld != null && !nodeConnectorId.equals(nodeConnectorIdOld)) {
+            LOG.info("Received NodeConnector Remove Event for the interface exists in older DPN: {}, {}", nodeConnectorId, nodeConnectorIdOld);
+            remove(nodeConnectorId, nodeConnectorIdOld, fcNodeConnectorNew, portName);
+        }
+
         DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
 
         InterfaceStateAddWorker ifStateAddWorker = new InterfaceStateAddWorker(idManager, nodeConnectorId,
@@ -103,34 +120,12 @@ public class InterfaceInventoryStateListener extends AsyncDataTreeChangeListener
         coordinator.enqueueJob(portName, ifStateAddWorker, 3);
     }
 
-    /**
-     * VM Migration: VM migrated from DPN1 to DPN2.
-     * VM booted from new DPN host will preserves its configuration including ID, name and other properties.
-     * In certain vm migration scenario like nova evacuate, vm reboot
-     * it is expected to receive the events in a non-sequential manner
-     * In Nova evacuate scenario, OFPPR_ADD from DPN2 will be received before OFPPR_DELETE from DPN1.
-     * To cleanup existing entry in OperDS, remove method will be called from add()
-     *
-     */
-    private void remove(InstanceIdentifier<FlowCapableNodeConnector> key,
-                        FlowCapableNodeConnector flowCapableNodeConnectorOld, boolean isNwTrigger) {
-        LOG.debug("Received user/network NodeConnector Remove Event: {}, {}", key, flowCapableNodeConnectorOld);
-        String portName = flowCapableNodeConnectorOld.getName();
-        NodeConnectorId nodeConnectorIdNew = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
-
-        //VM Migration: Skip OFPPR_DELETE event received after OFPPR_ADD for same interface
-        NodeConnectorId nodeConnectorIdOld = IfmUtil.getNodeConnectorIdFromInterface(portName, dataBroker);
-        if(nodeConnectorIdOld != null && !nodeConnectorIdNew.equals(nodeConnectorIdOld)) {
-            if(isNwTrigger) {
-                LOG.info("Received NodeConnector Remove Event for the interface exists in another DPN: {}, {}", nodeConnectorIdNew, nodeConnectorIdOld);
-                return;
-            }
-        }
-
+    private void remove(NodeConnectorId nodeConnectorIdNew, NodeConnectorId nodeConnectorIdOld,
+                        FlowCapableNodeConnector fcNodeConnectorNew, String portName) {
         DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
 
         InterfaceStateRemoveWorker portStateRemoveWorker = new InterfaceStateRemoveWorker(idManager,
-                nodeConnectorIdNew, nodeConnectorIdOld, flowCapableNodeConnectorOld, portName);
+                nodeConnectorIdNew, nodeConnectorIdOld, fcNodeConnectorNew, portName);
         coordinator.enqueueJob(portName, portStateRemoveWorker, 3);
     }
 
index a879548a382d98a08f2cd197ac6e9c538e7a4b31..445c5703e3e27432d14d539e3cba57c236ee5004 100644 (file)
@@ -190,7 +190,7 @@ public class HwVTEPConfigurationTest {
                 IfmUtil.buildStateInterfaceId(hwVTEPInterfaceEnabled.getName());
         InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setOperStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up);
         ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(hwVTEPInterfaceEnabled.getName()));
-        verify(mockWriteTx).merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
+        verify(mockWriteTx).merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), false);
     }
 
     @Test
index b69466826053a91c931b13ba46c3bc48aa0987a2..04683cfdee5dda9f94b028e26a7197541c564bb1 100644 (file)
@@ -214,7 +214,7 @@ public class TopologyStateInterfaceTest {
             IfmUtil.buildStateInterfaceId(InterfaceManagerTestUtil.tunnelInterfaceName);
         InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setOperStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down);
         ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(InterfaceManagerTestUtil.tunnelInterfaceName));
-        verify(mockWriteTx).merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
+        verify(mockWriteTx).merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), false);
 
     }
 }
index 43a3bd576e1444fc5085991667fb203f77e3ad1c..36ed178d6f9e8861597611cf01e0a60e817c83ea 100644 (file)
@@ -17,7 +17,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.opendaylight.genius</groupId>
-  <artifactId>interfacemgr-shell</artifactId>
+  <artifactId>interfacemanager-shell</artifactId>
   <version>${genius.version}</version>
   <packaging>bundle</packaging>
   <dependencies>
index fc5a1622af8bbdae38c3692f3b1423b67f4901b3..456c07090c1d623911861a22e79bc6e294ee1b75 100644 (file)
@@ -23,10 +23,12 @@ public class ITMConstants{
   public static final boolean DEFAULT_MONITOR_ENABLED = true;
   public static final int DEFAULT_MONITOR_INTERVAL = 10000;
   public static final int BFD_DEFAULT_MONITOR_INTERVAL = 1000;
+  public static final int MIN_MONITOR_INTERVAL = 1000;
+  public static final int MAX_MONITOR_INTERVAL = 30000;
   public static final String DUMMY_IP_ADDRESS = "0.0.0.0";
   public static final String TUNNEL_TYPE_VXLAN = "VXLAN";
   public static final String TUNNEL_TYPE_GRE = "GRE";
-  public static final String TUNNEL_TYPE_MPLS_OVER_GRE = "MPLS_OVER_GRE";
+  public static final String TUNNEL_TYPE_MPLSoGRE = "MPLS_OVER_GRE";
   public static final String TUNNEL_TYPE_INVALID = "Invalid";
   public static final String MONITOR_TYPE_LLDP = "LLDP";
   public static final Class<? extends TunnelMonitoringTypeBase> DEFAULT_MONITOR_PROTOCOL =  TunnelMonitoringTypeBfd.class;
index 7706ad3a679580dd4557568ecc9edd69d9da0ec1..83db9561ef880672812df13f4390cefa58b96cc4 100644 (file)
@@ -11,6 +11,7 @@ import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
 import org.opendaylight.genius.itm.api.IITMProvider;
+import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -32,7 +33,7 @@ public class TepMonitor extends OsgiCommandSupport {
   protected Object doExecute() {
     try {
       logger.debug("Executing TEP monitor command with interval: " + "\t" + interval);
-      if(!(interval >=100 && interval <=30000)){
+      if(!(interval >=ITMConstants.MIN_MONITOR_INTERVAL && interval<=ITMConstants.MAX_MONITOR_INTERVAL)){
         System.out.println("Monitoring Interval must be in the range 100 - 30000");
       }
       else {
index b552978424a8f2ac8a976658231e427257741b0a..64106a5012a3ef6fad038df5a5ce7a539a3e5adf 100644 (file)
@@ -927,7 +927,7 @@ public class ItmUtils {
         else if( tunType.equals(TunnelTypeGre.class) )
             tunnelType = ITMConstants.TUNNEL_TYPE_GRE ;
         else if (tunnelType.equals(TunnelTypeMplsOverGre.class))
-            tunnelType = ITMConstants.TUNNEL_TYPE_MPLS_OVER_GRE;
+            tunnelType = ITMConstants.TUNNEL_TYPE_MPLSoGRE;
         return tunnelType ;
     }
 
index 223ff82d7941daed0ce3e6aa1e05b17953aad874..c47d7f3feb021321c31836724b56263e90e747b4 100644 (file)
@@ -21,6 +21,8 @@ import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ForkJoinPool;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
 
 public class DataStoreJobCoordinator {
     private static final Logger LOG = LoggerFactory.getLogger(DataStoreJobCoordinator.class);
@@ -29,6 +31,8 @@ public class DataStoreJobCoordinator {
 
     private ForkJoinPool fjPool;
     private Map<Integer,Map<String, JobQueue>> jobQueueMap = new ConcurrentHashMap<>();
+    private ReentrantLock reentrantLock = new ReentrantLock();
+    private Condition waitCondition = reentrantLock.newCondition();
 
     private static DataStoreJobCoordinator instance;
 
@@ -55,19 +59,19 @@ public class DataStoreJobCoordinator {
     }
 
     public void enqueueJob(String key,
-                           Callable<List<ListenableFuture<Void>>> mainWorker) {
+            Callable<List<ListenableFuture<Void>>> mainWorker) {
         enqueueJob(key, mainWorker, null, 0);
     }
 
     public void enqueueJob(String key,
-                           Callable<List<ListenableFuture<Void>>> mainWorker,
-                           RollbackCallable rollbackWorker) {
+            Callable<List<ListenableFuture<Void>>> mainWorker,
+            RollbackCallable rollbackWorker) {
         enqueueJob(key, mainWorker, rollbackWorker, 0);
     }
 
     public void enqueueJob(String key,
-                           Callable<List<ListenableFuture<Void>>> mainWorker,
-                           int maxRetries) {
+            Callable<List<ListenableFuture<Void>>> mainWorker,
+            int maxRetries) {
         enqueueJob(key, mainWorker, null, maxRetries);
     }
 
@@ -83,9 +87,9 @@ public class DataStoreJobCoordinator {
      */
 
     public void enqueueJob(String key,
-                           Callable<List<ListenableFuture<Void>>> mainWorker,
-                           RollbackCallable rollbackWorker,
-                           int maxRetries) {
+            Callable<List<ListenableFuture<Void>>> mainWorker,
+            RollbackCallable rollbackWorker,
+            int maxRetries) {
         JobEntry jobEntry = new JobEntry(key, mainWorker, rollbackWorker, maxRetries);
         Integer hashKey = getHashKey(key);
         LOG.debug("Obtained Hashkey: {}, for jobkey: {}", hashKey, key);
@@ -101,6 +105,12 @@ public class DataStoreJobCoordinator {
         }
 
         jobQueueMap.put(hashKey, jobEntriesMap); // Is this really needed ?
+        reentrantLock.lock();
+        try {
+            waitCondition.signal();
+        } finally {
+            reentrantLock.unlock();
+        }
     }
 
     /**
@@ -240,7 +250,6 @@ public class DataStoreJobCoordinator {
                 LOG.error("Exception when executing jobEntry: {}, exception: {}", jobEntry, e.getStackTrace());
                 e.printStackTrace();
             }
-
             if (futures == null || futures.isEmpty()) {
                 clearJob(jobEntry);
                 return;
@@ -258,7 +267,6 @@ public class DataStoreJobCoordinator {
             LOG.debug("Starting JobQueue Handler Thread.");
             while (true) {
                 try {
-                    boolean jobAddedToPool = false;
                     for (int i = 0; i < THREADPOOL_SIZE; i++) {
                         Map<String, JobQueue> jobEntriesMap = jobQueueMap.get(i);
                         if (jobEntriesMap.isEmpty()) {
@@ -277,7 +285,6 @@ public class DataStoreJobCoordinator {
                                     entry.getValue().setExecutingEntry(jobEntry);
                                     MainTask worker = new MainTask(jobEntry);
                                     fjPool.execute(worker);
-                                    jobAddedToPool = true;
                                 } else {
                                     it.remove();
                                 }
@@ -285,13 +292,18 @@ public class DataStoreJobCoordinator {
                         }
                     }
 
-                    if (!jobAddedToPool) {
-                        TimeUnit.SECONDS.sleep(1);
+                    if (jobQueueMap.isEmpty()) {
+                        reentrantLock.lock();
+                        try {
+                            waitCondition.await();
+                        } finally {
+                            reentrantLock.unlock();
+                        }
                     }
                 } catch (Exception e) {
-                    e.printStackTrace();
+                    LOG.error("Exception while executing the tasks {} ", e);
                 } catch (Throwable e) {
-                    e.printStackTrace();
+                    LOG.error("Error while executing the tasks {} ", e);
                 }
             }
         }