use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class PruningDataTreeModificationTest method testNewModification.
@Test
public void testNewModification() {
realModification.ready();
DataTreeModification dataTreeModification = pruningDataTreeModification.newModification();
assertTrue("new modification not of type PruningDataTreeModification", dataTreeModification instanceof PruningDataTreeModification);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class PruningDataTreeModificationTest method getCandidate.
private DataTreeCandidate getCandidate() throws DataValidationFailedException {
pruningDataTreeModification.ready();
DataTreeModification mod = pruningDataTreeModification.delegate();
mod = mod == proxyModification ? realModification : mod;
dataTree.validate(mod);
return dataTree.prepare(mod);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class ReadyLocalTransactionSerializerTest method testToAndFromBinary.
@Test
public void testToAndFromBinary() throws NotSerializableException {
DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, TestModel.createTestContext());
DataTreeModification modification = dataTree.takeSnapshot().newModification();
ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
TransactionIdentifier txId = nextTransactionId();
ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
final Object deserialized;
try {
final ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer(system);
final byte[] bytes = serializer.toBinary(readyMessage);
deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
} finally {
JavaTestKit.shutdownActorSystem(system);
}
assertNotNull("fromBinary returned null", deserialized);
assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
BatchedModifications batched = (BatchedModifications) deserialized;
assertEquals("getTransactionID", txId, batched.getTransactionId());
assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());
List<Modification> batchedMods = batched.getModifications();
assertEquals("getModifications size", 2, batchedMods.size());
Modification mod = batchedMods.get(0);
assertEquals("Modification type", WriteModification.class, mod.getClass());
assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification) mod).getPath());
assertEquals("Modification getData", writeData, ((WriteModification) mod).getData());
mod = batchedMods.get(1);
assertEquals("Modification type", MergeModification.class, mod.getClass());
assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification) mod).getPath());
assertEquals("Modification getData", mergeData, ((MergeModification) mod).getData());
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class DistributedShardChangePublisher method applyChanges.
synchronized DataTreeCandidate applyChanges(final YangInstanceIdentifier listenerPath, final Collection<DataTreeCandidate> changes) throws DataValidationFailedException {
final DataTreeModification modification = dataTree.takeSnapshot().newModification();
for (final DataTreeCandidate change : changes) {
try {
DataTreeCandidates.applyToModification(modification, change);
} catch (SchemaValidationFailedException e) {
LOG.error("Validation failed {}", e);
}
}
modification.ready();
final DataTreeCandidate candidate;
dataTree.validate(modification);
// strip nodes we dont need since this listener doesn't have to be registered at the root of the DataTree
candidate = dataTree.prepare(modification);
dataTree.commit(candidate);
DataTreeCandidateNode modifiedChild = candidate.getRootNode();
for (final PathArgument pathArgument : listenerPath.getPathArguments()) {
modifiedChild = modifiedChild.getModifiedChild(pathArgument);
}
if (modifiedChild == null) {
modifiedChild = new EmptyDataTreeCandidateNode(dataTree.getRootPath().getLastPathArgument());
}
return DataTreeCandidates.newDataTreeCandidate(dataTree.getRootPath(), modifiedChild);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class SnapshotBackedWriteTransaction method merge.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
checkNotReady();
final DataTreeModification tree = mutableTree;
LOG.debug("Tx: {} Merge: {}:{}", getIdentifier(), path, data);
try {
tree.merge(path, data);
// FIXME: Add checked exception
} catch (RuntimeException e) {
LOG.error("Tx: {}, failed to write {}:{} in {}", getIdentifier(), path, data, tree, e);
// Rethrow original ones if they are subclasses of RuntimeException
// or Error
Throwables.propagateIfPossible(e);
// FIXME: Introduce proper checked exception
throw new IllegalArgumentException("Illegal input data.", e);
}
}
Aggregations