use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class WriteModificationTest method testApply.
@Test
public void testApply() throws Exception {
// Write something into the datastore
DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
WriteModification writeModification = new WriteModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
writeModification.apply(writeTransaction);
commitTransaction(writeTransaction);
// Check if it's in the datastore
Optional<NormalizedNode<?, ?>> data = readData(TestModel.TEST_PATH);
Assert.assertTrue(data.isPresent());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class ShardDataTreeSnapshotTest method testShardDataTreeSnapshotWithMetadata.
@Test
public void testShardDataTreeSnapshotWithMetadata() throws Exception {
NormalizedNode<?, ?> expectedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
Map<Class<? extends ShardDataTreeSnapshotMetadata<?>>, ShardDataTreeSnapshotMetadata<?>> expMetadata = ImmutableMap.of(TestShardDataTreeSnapshotMetadata.class, new TestShardDataTreeSnapshotMetadata("test"));
MetadataShardDataTreeSnapshot snapshot = new MetadataShardDataTreeSnapshot(expectedNode, expMetadata);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (ObjectOutputStream out = new ObjectOutputStream(bos)) {
snapshot.serialize(out);
}
ShardDataTreeSnapshot deserialized;
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
deserialized = ShardDataTreeSnapshot.deserialize(in);
}
Optional<NormalizedNode<?, ?>> actualNode = deserialized.getRootNode();
assertEquals("rootNode present", true, actualNode.isPresent());
assertEquals("rootNode", expectedNode, actualNode.get());
assertEquals("Deserialized type", MetadataShardDataTreeSnapshot.class, deserialized.getClass());
assertEquals("Metadata", expMetadata, ((MetadataShardDataTreeSnapshot) deserialized).getMetadata());
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class DataChangeListener method dataChanged.
@SuppressWarnings("checkstyle:IllegalCatch")
private void dataChanged(Object message) {
// Do nothing if notifications are not enabled
if (!notificationsEnabled) {
LOG.debug("Notifications not enabled for listener {} - dropping change notification", listener);
return;
}
DataChanged reply = (DataChanged) message;
AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change = reply.getChange();
LOG.debug("Sending change notification {} to listener {}", change, listener);
notificationCount++;
try {
this.listener.onDataChanged(change);
} catch (RuntimeException e) {
LOG.error(String.format("Error notifying listener %s", this.listener), e);
}
if (isValidSender(getSender())) {
getSender().tell(DataChangedReply.INSTANCE, getSelf());
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode 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;
}
use of org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode in project controller by opendaylight.
the class InMemoryDataStoreTest method testTransactionAbort.
@Test
public void testTransactionAbort() throws InterruptedException, ExecutionException {
DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
assertNotNull(writeTx);
assertTestContainerWrite(writeTx);
DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
assertTrue(cohort.canCommit().get().booleanValue());
cohort.preCommit().get();
cohort.abort().get();
Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
assertFalse(afterCommitRead.isPresent());
}
Aggregations