use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION in project netvirt by opendaylight.
the class MergeCommandsAggregator method mergeUpdate.
public void mergeUpdate(InstanceIdentifier<Node> dstPath, DataObjectModification mod, LogicalDatastoreType datastoreType, ReadWriteTransaction tx) {
if (mod == null) {
return;
}
Collection<DataObjectModification> modifications = mod.getModifiedChildren();
modifications.stream().filter(modification -> skipCopy.negate().test(datastoreType, modification.getDataType())).filter(modification -> commands.get(modification.getDataType()) != null).peek(modification -> LOG.debug("Received {} modification {} copy/delete to {}", datastoreType, modification, dstPath)).forEach(modification -> {
MergeCommand mergeCommand = commands.get(modification.getDataType());
boolean create = modification.getDataAfter() != null;
DataObject data = create ? modification.getDataAfter() : modification.getDataBefore();
InstanceIdentifier<DataObject> transformedId = mergeCommand.generateId(dstPath, data);
DataObject transformedItem = mergeCommand.transform(dstPath, data);
Optional<DataObject> existingDataOptional = null;
try {
existingDataOptional = tx.read(datastoreType, transformedId).checkedGet();
} catch (ReadFailedException ex) {
LOG.error("Failed to read data {} from {}", transformedId, datastoreType);
return;
}
String destination = datastoreType == CONFIGURATION ? "child" : "parent";
if (create) {
if (isDataUpdated(existingDataOptional, transformedItem)) {
LOG.debug("Copy to {} {} {}", destination, datastoreType, transformedId);
tx.put(datastoreType, transformedId, transformedItem, true);
} else {
LOG.debug("Data not updated skip copy to {}", transformedId);
}
} else {
if (existingDataOptional.isPresent()) {
LOG.debug("Delete from {} {} {}", destination, datastoreType, transformedId);
tx.delete(datastoreType, transformedId);
} else {
LOG.debug("Delete skipped for {}", transformedId);
}
}
});
}
use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION in project genius by opendaylight.
the class UpdateIdEntryJob method call.
@Override
public List<ListenableFuture<Void>> call() throws TransactionCommitFailedException {
String uniqueIdKey = idUtils.getUniqueKey(parentPoolName, idKey);
try {
txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
idUtils.updateChildPool(tx, parentPoolName, localPoolName);
if (!newIdValues.isEmpty()) {
IdEntries newIdEntry = idUtils.createIdEntries(idKey, newIdValues);
tx.merge(CONFIGURATION, idUtils.getIdEntriesInstanceIdentifier(parentPoolName, idKey), newIdEntry);
} else {
tx.delete(CONFIGURATION, idUtils.getIdEntriesInstanceIdentifier(parentPoolName, idKey));
}
}).get();
LOG.info("Updated id entry with idValues {}, idKey {}, pool {}", newIdValues, idKey, localPoolName);
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error updating id entry job", e);
} finally {
CountDownLatch latch = idUtils.getReleaseIdLatch(uniqueIdKey);
if (latch != null) {
latch.countDown();
}
// Once the id is written to DS, removing the id value from map.
idUtils.removeAllocatedIds(uniqueIdKey);
idUtils.unlock(lockManager, uniqueIdKey);
}
return Collections.emptyList();
}
use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION in project genius by opendaylight.
the class IdManager method populateCache.
private void populateCache() throws ReadFailedException {
// If IP changes during reboot, then there will be orphaned child pools.
InstanceIdentifier<IdPools> idPoolsInstance = idUtils.getIdPools();
Optional<IdPools> idPoolsOptional = singleTxDB.syncReadOptional(CONFIGURATION, idPoolsInstance);
if (!idPoolsOptional.isPresent()) {
return;
}
IdPools idPools = idPoolsOptional.get();
List<IdPool> idPoolList = idPools.getIdPool();
idPoolList.stream().filter(idPool -> idPool.getParentPoolName() != null && !idPool.getParentPoolName().isEmpty() && idUtils.getLocalPoolName(idPool.getParentPoolName()).equals(idPool.getPoolName())).forEach(idPool -> updateLocalIdPoolCache(idPool, idPool.getParentPoolName()));
}
use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION in project genius by opendaylight.
the class IdHolderSyncJob method call.
@Override
public List<ListenableFuture<Void>> call() {
IdPoolBuilder idPool = new IdPoolBuilder().setKey(new IdPoolKey(localPoolName));
idHolder.refreshDataStore(idPool);
InstanceIdentifier<IdPool> localPoolInstanceIdentifier = idUtils.getIdPoolInstance(localPoolName);
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
tx.merge(CONFIGURATION, localPoolInstanceIdentifier, idPool.build(), true);
idUtils.incrementPoolUpdatedMap(localPoolName);
if (LOG.isDebugEnabled()) {
LOG.debug("IdHolder synced {}", idHolder);
}
}));
}
Aggregations