Bug 7864: Specified Id key does not exist in id pool vpnservices
[genius.git] / idmanager / idmanager-impl / src / main / java / org / opendaylight / genius / idmanager / jobs / UpdateIdEntryJob.java
index e8d9367e898ded73aa412d63165df257aa26b636..2447241e6b10d0ff99acb9341fc428ff80e0e20d 100644 (file)
@@ -17,11 +17,15 @@ import java.util.Optional;
 import java.util.concurrent.Callable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.idmanager.IdUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class UpdateIdEntryJob implements Callable<List<ListenableFuture<Void>>> {
 
+    private static final Logger LOG = LoggerFactory.getLogger(UpdateIdEntryJob.class);
     private final String parentPoolName;
     private final String localPoolName;
     private final String idKey;
@@ -40,7 +44,7 @@ public class UpdateIdEntryJob implements Callable<List<ListenableFuture<Void>>>
     }
 
     @Override
-    public List<ListenableFuture<Void>> call() throws Exception {
+    public List<ListenableFuture<Void>> call() throws TransactionCommitFailedException {
         WriteTransaction tx = broker.newWriteOnlyTransaction();
         idUtils.updateChildPool(tx, parentPoolName, localPoolName);
         if (newIdValues != null && !newIdValues.isEmpty()) {
@@ -50,8 +54,14 @@ public class UpdateIdEntryJob implements Callable<List<ListenableFuture<Void>>>
             tx.delete(CONFIGURATION, idUtils.getIdEntriesInstanceIdentifier(parentPoolName, idKey));
         }
         tx.submit().checkedGet();
-        Optional.ofNullable(idUtils.releaseIdLatchMap.get(parentPoolName + idKey))
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Updated id entry with idValues {}, idKey {}, pool {}", newIdValues, idKey, localPoolName);
+        }
+        String uniqueIdKey = idUtils.getUniqueKey(parentPoolName, idKey);
+        Optional.ofNullable(idUtils.releaseIdLatchMap.get(uniqueIdKey))
             .ifPresent(latch -> latch.countDown());
+        // Once the id is written to DS, removing the id value from map.
+        idUtils.allocatedIdMap.remove(uniqueIdKey);
         return Collections.emptyList();
     }
 }