Search in sources :

Example 16 with DataTreeModification

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);
    }
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)

Example 17 with DataTreeModification

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());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardDataTree(org.opendaylight.controller.cluster.datastore.ShardDataTree) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) Test(org.junit.Test)

Example 18 with DataTreeModification

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());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 19 with DataTreeModification

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);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) PruningDataTreeModification(org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)

Example 20 with DataTreeModification

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);
    }
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) PruningDataTreeModification(org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification) PruningDataTreeModification(org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException) IOException(java.io.IOException) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException)

Aggregations

DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)45 Test (org.junit.Test)17 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)13 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)8 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)8 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)6 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)6 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)6 ActorRef (akka.actor.ActorRef)5 PruningDataTreeModification (org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)4 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)4 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)3 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 ActorSelection (akka.actor.ActorSelection)2 TestActorRef (akka.testkit.TestActorRef)2