use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project controller by opendaylight.
the class DOMDataTreeListenerTest method writeContainerEmptyTreeTest.
@Test
public void writeContainerEmptyTreeTest() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
final TestDataTreeListener listener = new TestDataTreeListener(latch);
final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener);
final DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
writeTx.submit();
latch.await(5, TimeUnit.SECONDS);
assertEquals(1, listener.getReceivedChanges().size());
final Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
assertEquals(1, changes.size());
DataTreeCandidate candidate = changes.iterator().next();
assertNotNull(candidate);
DataTreeCandidateNode candidateRoot = candidate.getRootNode();
checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
listenerReg.close();
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project controller by opendaylight.
the class DOMDataTreeListenerTest method rootModificationChildListenerTest.
@Test
public void rootModificationChildListenerTest() throws InterruptedException, TransactionCommitFailedException {
final CountDownLatch latch = new CountDownLatch(2);
DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
writeTx.submit().checkedGet();
final TestDataTreeListener listener = new TestDataTreeListener(latch);
final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener);
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER_2);
writeTx.submit().checkedGet();
latch.await(1, TimeUnit.SECONDS);
assertEquals(2, listener.getReceivedChanges().size());
Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
assertEquals(1, changes.size());
DataTreeCandidate candidate = changes.iterator().next();
assertNotNull(candidate);
DataTreeCandidateNode candidateRoot = candidate.getRootNode();
checkChange(null, OUTER_LIST, ModificationType.WRITE, candidateRoot);
changes = listener.getReceivedChanges().get(1);
assertEquals(1, changes.size());
candidate = changes.iterator().next();
assertNotNull(candidate);
candidateRoot = candidate.getRootNode();
checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, candidateRoot);
listenerReg.close();
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project controller by opendaylight.
the class ResolveDataChangeEventsTask method resolveSubtreeChangeEvent.
private boolean resolveSubtreeChangeEvent(final ResolveDataChangeState state, final DataTreeCandidateNode modification) {
final Optional<NormalizedNode<?, ?>> maybeBefore = modification.getDataBefore();
final Optional<NormalizedNode<?, ?>> maybeAfter = modification.getDataAfter();
Preconditions.checkArgument(maybeBefore.isPresent(), "Subtree change with before-data not present at path %s", state.getPath());
Preconditions.checkArgument(maybeAfter.isPresent(), "Subtree change with after-data not present at path %s", state.getPath());
if (!state.needsProcessing()) {
LOG.trace("Not processing modified subtree {}", state.getPath());
return true;
}
DataChangeScope scope = null;
for (DataTreeCandidateNode childMod : modification.getChildNodes()) {
final ResolveDataChangeState childState = state.child(childMod.getIdentifier());
switch(childMod.getModificationType()) {
case APPEARED:
case DELETE:
case DISAPPEARED:
case WRITE:
if (resolveAnyChangeEvent(childState, childMod)) {
scope = DataChangeScope.ONE;
}
break;
case SUBTREE_MODIFIED:
if (resolveSubtreeChangeEvent(childState, childMod) && scope == null) {
scope = DataChangeScope.SUBTREE;
}
break;
case UNMODIFIED:
// no-op
break;
default:
break;
}
}
final NormalizedNode<?, ?> before = maybeBefore.get();
final NormalizedNode<?, ?> after = maybeAfter.get();
if (scope != null) {
DOMImmutableDataChangeEvent one = DOMImmutableDataChangeEvent.builder(scope).addUpdated(state.getPath(), before, after).build();
state.addEvent(one);
}
state.collectEvents(before, after, collectedEvents);
return scope != null;
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project controller by opendaylight.
the class LazyDataObjectModification method populateList.
private static void populateList(final List<DataObjectModification<? extends DataObject>> result, final BindingCodecTreeNode<?> parentCodec, final Collection<DataTreeCandidateNode> domChildNodes) {
for (final DataTreeCandidateNode domChildNode : domChildNodes) {
final BindingStructuralType type = BindingStructuralType.from(domChildNode);
if (type != BindingStructuralType.NOT_ADDRESSABLE) {
/*
* Even if type is UNKNOWN, from perspective of BindingStructuralType
* we try to load codec for it. We will use that type to further specify
* debug log.
*/
try {
final BindingCodecTreeNode<?> childCodec = parentCodec.yangPathArgumentChild(domChildNode.getIdentifier());
populateList(result, type, childCodec, domChildNode);
} catch (final IllegalArgumentException e) {
if (type == BindingStructuralType.UNKNOWN) {
LOG.debug("Unable to deserialize unknown DOM node {}", domChildNode, e);
} else {
LOG.debug("Binding representation for DOM node {} was not found", domChildNode, e);
}
}
}
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project controller by opendaylight.
the class CarEntryDataTreeCommitCohort method canCommit.
@Override
public CheckedFuture<PostCanCommitStep, DataValidationFailedException> canCommit(final Object txId, final DOMDataTreeCandidate candidate, final SchemaContext ctx) {
// Simple data validation - verify the year, if present, is >= 1990
final DataTreeCandidateNode rootNode = candidate.getRootNode();
final Optional<NormalizedNode<?, ?>> dataAfter = rootNode.getDataAfter();
LOG.info("In canCommit: modificationType: {}, dataBefore: {}, dataAfter: {}", rootNode.getModificationType(), rootNode.getDataBefore(), dataAfter);
// MapEntryNode but we verify anyway.
if (dataAfter.isPresent()) {
final NormalizedNode<?, ?> normalizedNode = dataAfter.get();
Verify.verify(normalizedNode instanceof DataContainerNode, "Expected type DataContainerNode, actual was %s", normalizedNode.getClass());
DataContainerNode<?> entryNode = (DataContainerNode<?>) normalizedNode;
final Optional<DataContainerChild<? extends PathArgument, ?>> possibleYear = entryNode.getChild(YEAR_NODE_ID);
if (possibleYear.isPresent()) {
final Number year = (Number) possibleYear.get().getValue();
LOG.info("year is {}", year);
if (!(year.longValue() >= 1990)) {
return Futures.immediateFailedCheckedFuture(new DataValidationFailedException(DOMDataTreeIdentifier.class, candidate.getRootPath(), String.format("Invalid year %d - year must be >= 1990", year)));
}
}
}
// remaining 3PC stages (pre-commit and commit).
return PostCanCommitStep.NOOP_SUCCESS_FUTURE;
}
Aggregations