use of org.opendaylight.mdsal.binding.api.DataObjectModification in project netvirt by opendaylight.
the class LocalUcastMacListener method getChildMod.
@Override
protected Map<InstanceIdentifier<LocalUcastMacs>, DataObjectModification<LocalUcastMacs>> getChildMod(final InstanceIdentifier<Node> parentIid, final DataObjectModification<Node> mod) {
Map<InstanceIdentifier<LocalUcastMacs>, DataObjectModification<LocalUcastMacs>> result = new HashMap<>();
DataObjectModification<HwvtepGlobalAugmentation> aug = mod.getModifiedAugmentation(HwvtepGlobalAugmentation.class);
if (aug != null && getModificationType(aug) != null) {
Collection<? extends DataObjectModification<? extends DataObject>> children = aug.getModifiedChildren();
if (children == null) {
return result;
}
children.stream().filter(childMod -> getModificationType(childMod) != null).filter(childMod -> childMod.getDataType() == LocalUcastMacs.class).forEach(childMod -> {
LocalUcastMacs afterMac = (LocalUcastMacs) childMod.getDataAfter();
LocalUcastMacs mac = afterMac != null ? afterMac : (LocalUcastMacs) childMod.getDataBefore();
InstanceIdentifier<LocalUcastMacs> iid = parentIid.augmentation(HwvtepGlobalAugmentation.class).child(LocalUcastMacs.class, mac.key());
result.put(iid, (DataObjectModification<LocalUcastMacs>) childMod);
});
}
return result;
}
use of org.opendaylight.mdsal.binding.api.DataObjectModification in project netvirt by opendaylight.
the class MergeCommandsAggregator method copyModification.
private <D extends Datastore> void copyModification(InstanceIdentifier<Node> dstPath, Class<D> datastoreType, BatchedTransaction tx, String srcNodeId, String dstNodeId, DataObjectModification modification, ManagedNewTransactionRunner txRunner) {
DataObjectModification.ModificationType type = getModificationType(modification);
if (type == null) {
return;
}
String src = datastoreType == OPERATIONAL ? "child" : "parent";
MergeCommand mergeCommand = commands.get(modification.getDataType());
boolean create = false;
switch(type) {
case WRITE:
case SUBTREE_MODIFIED:
DataObject dataAfter = modification.getDataAfter();
if (dataAfter == null) {
return;
}
DataObject before = modification.getDataBefore();
if (Objects.equals(dataAfter, before)) {
LOG.warn("Ha updated skip not modified {}", src);
return;
}
create = true;
break;
case DELETE:
DataObject dataBefore = modification.getDataBefore();
if (dataBefore == null) {
LOG.warn("Ha updated skip delete {}", src);
return;
}
break;
default:
return;
}
DataObject data = create ? modification.getDataAfter() : modification.getDataBefore();
InstanceIdentifier<DataObject> transformedId = mergeCommand.generateId(dstPath, data);
if (tx.updateMetric()) {
LOG.info("Ha updated processing {}", src);
}
if (create) {
DataObject transformedItem = mergeCommand.transform(dstPath, modification.getDataAfter());
tx.put(transformedId, transformedItem);
// if tunnel ip command do this for
if (mergeCommand.getClass() == TunnelIpCmd.class) {
if (Operational.class.equals(datastoreType)) {
txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, configTx -> {
configTx.put(transformedId, transformedItem);
});
}
}
} else {
if (deleteInProgressIids.getIfPresent(transformedId) == null) {
// TODO uncomment this code
/*if (isLocalMacMoved(mergeCommand, transformedId, tx, srcNodeId, txRunner)) {
return;
}*/
tx.delete(transformedId);
if (mergeCommand.getClass() == TunnelIpCmd.class) {
if (Operational.class.equals(datastoreType)) {
txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, configTx -> {
tx.delete(transformedId);
});
}
}
deleteInProgressIids.put(transformedId, Boolean.TRUE);
} else {
return;
}
}
String created = create ? "created" : "deleted";
Futures.addCallback(tx.getFt(transformedId), new FutureCallback<Void>() {
@Override
public void onSuccess(Void voidResult) {
LOG.info("Ha updated skip not modified {}", mergeCommand.getDescription());
deleteInProgressIids.invalidate(transformedId);
}
@Override
public void onFailure(Throwable throwable) {
LOG.error("Ha failed {}", mergeCommand.getDescription());
deleteInProgressIids.invalidate(transformedId);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.binding.api.DataObjectModification in project netvirt by opendaylight.
the class MergeCommandsAggregator method mergeUpdate.
@SuppressWarnings("illegalcatch")
public <D extends Datastore> void mergeUpdate(InstanceIdentifier<Node> dstPath, DataObjectModification mod, Class<D> datastoreType, TypedReadWriteTransaction<D> transaction, ManagedNewTransactionRunner txRunner) {
BatchedTransaction tx = null;
if (mod == null || mod.getModifiedChildren() == null) {
return;
}
if (!(transaction instanceof BatchedTransaction)) {
return;
} else {
tx = (BatchedTransaction) transaction;
}
final BatchedTransaction transaction1 = tx;
String srcNodeId = transaction1.getSrcNodeId().getValue();
String dstNodeId = dstPath.firstKeyOf(Node.class).getNodeId().getValue();
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 -> {
try {
copyModification(dstPath, datastoreType, transaction1, srcNodeId, dstNodeId, modification, txRunner);
} catch (Exception e) {
LOG.error("Failed to copy mod from {} to {} {} {} id {}", srcNodeId, dstNodeId, modification.getDataType().getSimpleName(), modification, modification.getIdentifier(), e);
}
});
}
Aggregations