Search in sources :

Example 16 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class PruningDataTreeModificationTest method testMergeWithInvalidNamespace.

@Test
public void testMergeWithInvalidNamespace() throws DataValidationFailedException {
    NormalizedNode<?, ?> normalizedNode = PeopleModel.emptyContainer();
    YangInstanceIdentifier path = PeopleModel.BASE_PATH;
    pruningDataTreeModification.merge(path, normalizedNode);
    verify(mockModification, times(1)).merge(path, normalizedNode);
    DataTreeCandidate candidate = getCandidate();
    assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().getModificationType());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 17 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class ShardDataTree method finishCommit.

@SuppressWarnings("checkstyle:IllegalCatch")
private void finishCommit(final SimpleShardDataTreeCohort cohort) {
    final TransactionIdentifier txId = cohort.getIdentifier();
    final DataTreeCandidate candidate = cohort.getCandidate();
    LOG.debug("{}: Resuming commit of transaction {}", logContext, txId);
    if (tip == candidate) {
        // All pending candidates have been committed, reset the tip to the data tree.
        tip = dataTree;
    }
    try {
        dataTree.commit(candidate);
    } catch (Exception e) {
        LOG.error("{}: Failed to commit transaction {}", logContext, txId, e);
        failCommit(e);
        return;
    }
    shard.getShardMBean().incrementCommittedTransactionCount();
    shard.getShardMBean().setLastCommittedTransactionTime(System.currentTimeMillis());
    // FIXME: propagate journal index
    pendingFinishCommits.poll().cohort.successfulCommit(UnsignedLong.ZERO, () -> {
        LOG.trace("{}: Transaction {} committed, proceeding to notify", logContext, txId);
        notifyListeners(candidate);
        processNextPending();
    });
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) 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)

Example 18 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate 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 19 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class ShardDataTree method applyReplicatedPayload.

/**
 * Apply a payload coming from the leader, which could actually be us. This method assumes the leader and follower
 * SchemaContexts match and does not perform any pruning.
 *
 * @param identifier Payload identifier as returned from RaftActor
 * @param payload Payload
 * @throws IOException when the snapshot fails to deserialize
 * @throws DataValidationFailedException when the snapshot fails to apply
 */
void applyReplicatedPayload(final Identifier identifier, final Payload payload) throws IOException, DataValidationFailedException {
    /*
         * This is a bit more involved than it needs to be due to to the fact we do not want to be touching the payload
         * if we are the leader and it has originated with us.
         *
         * The identifier will only ever be non-null when we were the leader which achieved consensus. Unfortunately,
         * though, this may not be the case anymore, as we are being called some time afterwards and we may not be
         * acting in that capacity anymore.
         *
         * In any case, we know that this is an entry coming from replication, hence we can be sure we will not observe
         * pre-Boron state -- which limits the number of options here.
         */
    if (payload instanceof CommitTransactionPayload) {
        final TransactionIdentifier txId;
        if (identifier == null) {
            final Entry<TransactionIdentifier, DataTreeCandidate> e = ((CommitTransactionPayload) payload).getCandidate();
            txId = e.getKey();
            applyReplicatedCandidate(txId, e.getValue());
        } else {
            Verify.verify(identifier instanceof TransactionIdentifier);
            txId = (TransactionIdentifier) identifier;
            payloadReplicationComplete(txId);
        }
        allMetadataCommittedTransaction(txId);
    } else if (payload instanceof AbortTransactionPayload) {
        if (identifier != null) {
            payloadReplicationComplete((AbortTransactionPayload) payload);
        }
        allMetadataAbortedTransaction(((AbortTransactionPayload) payload).getIdentifier());
    } else if (payload instanceof PurgeTransactionPayload) {
        if (identifier != null) {
            payloadReplicationComplete((PurgeTransactionPayload) payload);
        }
        allMetadataPurgedTransaction(((PurgeTransactionPayload) payload).getIdentifier());
    } else if (payload instanceof CloseLocalHistoryPayload) {
        if (identifier != null) {
            payloadReplicationComplete((CloseLocalHistoryPayload) payload);
        }
        allMetadataClosedLocalHistory(((CloseLocalHistoryPayload) payload).getIdentifier());
    } else if (payload instanceof CreateLocalHistoryPayload) {
        if (identifier != null) {
            payloadReplicationComplete((CreateLocalHistoryPayload) payload);
        }
        allMetadataCreatedLocalHistory(((CreateLocalHistoryPayload) payload).getIdentifier());
    } else if (payload instanceof PurgeLocalHistoryPayload) {
        if (identifier != null) {
            payloadReplicationComplete((PurgeLocalHistoryPayload) payload);
        }
        allMetadataPurgedLocalHistory(((PurgeLocalHistoryPayload) payload).getIdentifier());
    } else {
        LOG.warn("{}: ignoring unhandled identifier {} payload {}", logContext, identifier, payload);
    }
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) CreateLocalHistoryPayload(org.opendaylight.controller.cluster.datastore.persisted.CreateLocalHistoryPayload) CloseLocalHistoryPayload(org.opendaylight.controller.cluster.datastore.persisted.CloseLocalHistoryPayload) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) PurgeTransactionPayload(org.opendaylight.controller.cluster.datastore.persisted.PurgeTransactionPayload) CommitTransactionPayload(org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload) PurgeLocalHistoryPayload(org.opendaylight.controller.cluster.datastore.persisted.PurgeLocalHistoryPayload) AbortTransactionPayload(org.opendaylight.controller.cluster.datastore.persisted.AbortTransactionPayload)

Example 20 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class PruningDataTreeModificationTest method testWriteWithInvalidNamespace.

@Test
public void testWriteWithInvalidNamespace() throws DataValidationFailedException {
    NormalizedNode<?, ?> normalizedNode = PeopleModel.emptyContainer();
    YangInstanceIdentifier path = PeopleModel.BASE_PATH;
    pruningDataTreeModification.write(path, normalizedNode);
    verify(mockModification, times(1)).write(path, normalizedNode);
    DataTreeCandidate candidate = getCandidate();
    assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().getModificationType());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)41 Test (org.junit.Test)19 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)7 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)7 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)6 ActorRef (akka.actor.ActorRef)5 DataTreeChanged (org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged)5 Props (akka.actor.Props)4 TestKit (akka.testkit.javadsl.TestKit)4 DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)4 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)3 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)3 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException)3 DataValidationFailedException (org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException)3 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2