Search in sources :

Example 1 with DataValidationFailedException

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

the class ShardTest method testImmediateCommitWithCanCommitPhaseFailure.

private void testImmediateCommitWithCanCommitPhaseFailure(final boolean readWrite) throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final DataTree dataTree = createDelegatingMockDataTree();
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardBuilder().dataTree(dataTree).props().withDispatcher(Dispatchers.DefaultDispatcherId()), "testImmediateCommitWithCanCommitPhaseFailure-" + readWrite);
            waitUntilLeader(shard);
            doThrow(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock canCommit failure")).doNothing().when(dataTree).validate(any(DataTreeModification.class));
            final FiniteDuration duration = duration("5 seconds");
            final TransactionIdentifier transactionID1 = nextTransactionId();
            if (readWrite) {
                shard.tell(prepareForwardedReadyTransaction(shard, transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true), getRef());
            } else {
                shard.tell(prepareBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true), getRef());
            }
            expectMsgClass(duration, akka.actor.Status.Failure.class);
            // Send another can commit to ensure the failed one got cleaned
            // up.
            final TransactionIdentifier transactionID2 = nextTransactionId();
            if (readWrite) {
                shard.tell(prepareForwardedReadyTransaction(shard, transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true), getRef());
            } else {
                shard.tell(prepareBatchedModifications(transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true), getRef());
            }
            expectMsgClass(duration, CommitTransactionReply.class);
        }
    };
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) FiniteDuration(scala.concurrent.duration.FiniteDuration)

Example 2 with DataValidationFailedException

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

the class DataTreeCohortActorTest method testAsyncCohort.

@SuppressWarnings("unchecked")
@Test
public void testAsyncCohort() throws Exception {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    doReturn(Futures.makeChecked(executeWithDelay(executor, mockPostCanCommit), ex -> new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock"))).when(mockCohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
    doReturn(JdkFutureAdapters.listenInPoolThread(executor.submit(() -> mockPostPreCommit), MoreExecutors.directExecutor())).when(mockPostCanCommit).preCommit();
    doReturn(JdkFutureAdapters.listenInPoolThread(executor.submit(() -> null), MoreExecutors.directExecutor())).when(mockPostPreCommit).commit();
    ActorRef cohortActor = newCohortActor("testAsyncCohort");
    TransactionIdentifier txId = nextTransactionId();
    askAndAwait(cohortActor, new CanCommit(txId, CANDIDATES, MOCK_SCHEMA, cohortActor));
    verify(mockCohort).canCommit(txId, CANDIDATES, MOCK_SCHEMA);
    askAndAwait(cohortActor, new PreCommit(txId));
    verify(mockPostCanCommit).preCommit();
    askAndAwait(cohortActor, new Commit(txId));
    verify(mockPostPreCommit).commit();
    executor.shutdownNow();
}
Also used : ThreePhaseCommitStep(org.opendaylight.mdsal.common.api.ThreePhaseCommitStep) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) PreCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit) JdkFutureAdapters(com.google.common.util.concurrent.JdkFutureAdapters) Commit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Commit) PostCanCommitStep(org.opendaylight.mdsal.common.api.PostCanCommitStep) Timeout(akka.util.Timeout) ArrayList(java.util.ArrayList) ActorRef(akka.actor.ActorRef) After(org.junit.After) Patterns(akka.pattern.Patterns) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CommitProtocolCommand(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CommitProtocolCommand) Mockito.doReturn(org.mockito.Mockito.doReturn) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit) TestActorFactory(org.opendaylight.controller.cluster.raft.TestActorFactory) PostPreCommitStep(org.opendaylight.mdsal.common.api.PostPreCommitStep) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Abort(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Abort) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) Executors(java.util.concurrent.Executors) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) TimeUnit(java.util.concurrent.TimeUnit) DOMDataTreeCandidate(org.opendaylight.mdsal.dom.api.DOMDataTreeCandidate) Futures(com.google.common.util.concurrent.Futures) DOMDataTreeCommitCohort(org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort) Success(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Mockito.reset(org.mockito.Mockito.reset) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Await(scala.concurrent.Await) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) PreCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit) Commit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Commit) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit) ActorRef(akka.actor.ActorRef) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ExecutorService(java.util.concurrent.ExecutorService) PreCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit) Collection(java.util.Collection) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit) Test(org.junit.Test)

Example 3 with DataValidationFailedException

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

the class DataTreeCohortActorTest method testFailureOnCanCommit.

@SuppressWarnings("unchecked")
@Test
public void testFailureOnCanCommit() throws Exception {
    DataValidationFailedException failure = new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock");
    doReturn(Futures.immediateFailedCheckedFuture(failure)).when(mockCohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
    ActorRef cohortActor = newCohortActor("testFailureOnCanCommit");
    TransactionIdentifier txId = nextTransactionId();
    try {
        askAndAwait(cohortActor, new CanCommit(txId, CANDIDATES, MOCK_SCHEMA, cohortActor));
    } catch (DataValidationFailedException e) {
        assertEquals("DataValidationFailedException", failure, e);
    }
    resetMockCohort();
    askAndAwait(cohortActor, new CanCommit(txId, CANDIDATES, MOCK_SCHEMA, cohortActor));
    verify(mockCohort).canCommit(txId, CANDIDATES, MOCK_SCHEMA);
}
Also used : DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) ActorRef(akka.actor.ActorRef) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Collection(java.util.Collection) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit) Test(org.junit.Test)

Example 4 with DataValidationFailedException

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

the class LegacyDOMDataBrokerAdapterTest method testWriteOnlyTransaction.

@Test
public void testWriteOnlyTransaction() throws Exception {
    // Test successful write operations and submit
    DOMDataWriteTransaction tx = adapter.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
    verify(mockWriteTx).write(TestModel.TEST_PATH, dataNode);
    tx.merge(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
    verify(mockWriteTx).merge(TestModel.TEST_PATH, dataNode);
    tx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
    verify(mockWriteTx).delete(TestModel.TEST_PATH);
    CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
    submitFuture.get(5, TimeUnit.SECONDS);
    InOrder inOrder = inOrder(mockCommitCohort);
    inOrder.verify(mockCommitCohort).canCommit();
    inOrder.verify(mockCommitCohort).preCommit();
    inOrder.verify(mockCommitCohort).commit();
    // Test cancel
    tx = adapter.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
    tx.cancel();
    verify(mockWriteTx).close();
    // Test submit with OptimisticLockFailedException
    String errorMsg = "mock OptimisticLockFailedException";
    Throwable cause = new ConflictingModificationAppliedException(TestModel.TEST_PATH, "mock");
    doReturn(Futures.immediateFailedFuture(new org.opendaylight.mdsal.common.api.OptimisticLockFailedException(errorMsg, cause))).when(mockCommitCohort).canCommit();
    try {
        tx = adapter.newWriteOnlyTransaction();
        tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
        submitFuture = tx.submit();
        submitFuture.checkedGet(5, TimeUnit.SECONDS);
        fail("Expected OptimisticLockFailedException");
    } catch (OptimisticLockFailedException e) {
        assertEquals("getMessage", errorMsg, e.getMessage());
        assertEquals("getCause", cause, e.getCause());
    }
    // Test submit with TransactionCommitFailedException
    errorMsg = "mock TransactionCommitFailedException";
    cause = new DataValidationFailedException(TestModel.TEST_PATH, "mock");
    doReturn(Futures.immediateFailedFuture(new org.opendaylight.mdsal.common.api.TransactionCommitFailedException(errorMsg, cause))).when(mockCommitCohort).canCommit();
    try {
        tx = adapter.newWriteOnlyTransaction();
        tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
        submitFuture = tx.submit();
        submitFuture.checkedGet(5, TimeUnit.SECONDS);
        fail("Expected TransactionCommitFailedException");
    } catch (TransactionCommitFailedException e) {
        assertEquals("getMessage", errorMsg, e.getMessage());
        assertEquals("getCause", cause, e.getCause());
    }
    // Test submit with DataStoreUnavailableException
    errorMsg = "mock NoShardLeaderException";
    cause = new NoShardLeaderException("mock");
    doReturn(Futures.immediateFailedFuture(cause)).when(mockCommitCohort).canCommit();
    try {
        tx = adapter.newWriteOnlyTransaction();
        tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
        submitFuture = tx.submit();
        submitFuture.checkedGet(5, TimeUnit.SECONDS);
        fail("Expected TransactionCommitFailedException");
    } catch (TransactionCommitFailedException e) {
        assertEquals("getCause type", DataStoreUnavailableException.class, e.getCause().getClass());
        assertEquals("Root cause", cause, e.getCause().getCause());
    }
    // Test submit with RuntimeException
    errorMsg = "mock RuntimeException";
    cause = new RuntimeException(errorMsg);
    doReturn(Futures.immediateFailedFuture(cause)).when(mockCommitCohort).canCommit();
    try {
        tx = adapter.newWriteOnlyTransaction();
        tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
        submitFuture = tx.submit();
        submitFuture.checkedGet(5, TimeUnit.SECONDS);
        fail("Expected TransactionCommitFailedException");
    } catch (TransactionCommitFailedException e) {
        assertEquals("getCause", cause, e.getCause());
    }
}
Also used : DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) InOrder(org.mockito.InOrder) DataStoreUnavailableException(org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) Test(org.junit.Test)

Example 5 with DataValidationFailedException

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

DataValidationFailedException (org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException)7 Test (org.junit.Test)4 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)4 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)3 ActorRef (akka.actor.ActorRef)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 TimeoutException (java.util.concurrent.TimeoutException)2 CanCommit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit)2 PruningDataTreeModification (org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification)2 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)2 OptimisticLockFailedException (org.opendaylight.mdsal.common.api.OptimisticLockFailedException)2 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)2 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException)2 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)2 Patterns (akka.pattern.Patterns)1 Timeout (akka.util.Timeout)1 Futures (com.google.common.util.concurrent.Futures)1 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1