import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+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;
}
@Override
- public List<ListenableFuture<Void>> call() throws Exception {
- List<ListenableFuture<Void>> futures = new ArrayList<>();
+ public List<ListenableFuture<Void>> call() throws TransactionCommitFailedException {
WriteTransaction tx = broker.newWriteOnlyTransaction();
idUtils.updateChildPool(tx, parentPoolName, localPoolName);
if (newIdValues != null && !newIdValues.isEmpty()) {
} else {
tx.delete(CONFIGURATION, idUtils.getIdEntriesInstanceIdentifier(parentPoolName, idKey));
}
- futures.add(tx.submit());
- return futures;
+ tx.submit().checkedGet();
+ 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();
}
}