use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class SnapshotBackedWriteTransaction method delete.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void delete(final YangInstanceIdentifier path) {
checkNotReady();
final DataTreeModification tree = mutableTree;
LOG.debug("Tx: {} Delete: {}", getIdentifier(), path);
try {
tree.delete(path);
// FIXME: Add checked exception
} catch (RuntimeException e) {
LOG.error("Tx: {}, failed to delete {} in {}", getIdentifier(), path, 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 path to delete.", e);
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class PruningDataTreeModificationTest method testWriteRootNode.
@Test
public void testWriteRootNode() throws Exception {
final DataTree localDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
DataTreeModification mod = localDataTree.takeSnapshot().newModification();
mod.write(CarsModel.BASE_PATH, CarsModel.create());
mod.ready();
localDataTree.validate(mod);
localDataTree.commit(localDataTree.prepare(mod));
NormalizedNode<?, ?> normalizedNode = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get();
pruningDataTreeModification.write(YangInstanceIdentifier.EMPTY, normalizedNode);
dataTree.commit(getCandidate());
Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY);
assertTrue("Root present", actual.isPresent());
assertEquals("Root node", normalizedNode, actual.get());
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class CommitTransactionPayloadTest method testUnmodifiedRootCandidate.
@Test
public void testUnmodifiedRootCandidate() throws Exception {
final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SchemaContextHelper.select(SchemaContextHelper.CARS_YANG));
DataTreeModification modification = dataTree.takeSnapshot().newModification();
modification.ready();
candidate = dataTree.prepare(modification);
CommitTransactionPayload payload = CommitTransactionPayload.create(nextTransactionId(), candidate);
assertCandidateEquals(candidate, payload.getCandidate().getValue());
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class ShardDataTree method applyReplicatedCandidate.
private void applyReplicatedCandidate(final Identifier identifier, final DataTreeCandidate foreign) throws DataValidationFailedException {
LOG.debug("{}: Applying foreign transaction {}", logContext, identifier);
final DataTreeModification mod = dataTree.takeSnapshot().newModification();
DataTreeCandidates.applyToModification(mod, foreign);
mod.ready();
LOG.trace("{}: Applying foreign modification {}", logContext, mod);
dataTree.validate(mod);
final DataTreeCandidate candidate = dataTree.prepare(mod);
dataTree.commit(candidate);
notifyListeners(candidate);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class ShardDataTree method applyRecoveryCandidate.
@SuppressWarnings("checkstyle:IllegalCatch")
private void applyRecoveryCandidate(final DataTreeCandidate candidate) throws DataValidationFailedException {
final PruningDataTreeModification mod = wrapWithPruning(dataTree.takeSnapshot().newModification());
DataTreeCandidates.applyToModification(mod, candidate);
mod.ready();
final DataTreeModification unwrapped = mod.delegate();
LOG.trace("{}: Applying recovery modification {}", logContext, unwrapped);
try {
dataTree.validate(unwrapped);
dataTree.commit(dataTree.prepare(unwrapped));
} catch (Exception e) {
File file = new File(System.getProperty("karaf.data", "."), "failed-recovery-payload-" + logContext + ".out");
DataTreeModificationOutput.toFile(file, unwrapped);
throw new IllegalStateException(String.format("%s: Failed to apply recovery payload. Modification data was written to file %s", logContext, file), e);
}
}
Aggregations