Search in sources :

Example 1 with DeleteModification

use of org.opendaylight.controller.cluster.datastore.modification.DeleteModification in project controller by opendaylight.

the class EntityOwnershipShard method removeCandidateFromEntities.

private void removeCandidateFromEntities(final MemberName member) {
    final List<Modification> modifications = new ArrayList<>();
    searchForEntities((entityTypeNode, entityNode) -> {
        if (hasCandidate(entityNode, member)) {
            YangInstanceIdentifier entityId = (YangInstanceIdentifier) entityNode.getIdentifier().getKeyValues().get(ENTITY_ID_QNAME);
            YangInstanceIdentifier candidatePath = candidatePath(entityTypeNode.getIdentifier().getKeyValues().get(ENTITY_TYPE_QNAME).toString(), entityId, member.getName());
            LOG.info("{}: Found entity {}, removing candidate {}, path {}", persistenceId(), entityId, member, candidatePath);
            modifications.add(new DeleteModification(candidatePath));
        }
    });
    commitCoordinator.commitModifications(modifications, this);
}
Also used : Modification(org.opendaylight.controller.cluster.datastore.modification.Modification) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) ArrayList(java.util.ArrayList) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 2 with DeleteModification

use of org.opendaylight.controller.cluster.datastore.modification.DeleteModification in project controller by opendaylight.

the class TransactionProxyTest method testDelete.

@Test
public void testDelete() throws Exception {
    dataStoreContextBuilder.shardBatchedModificationCount(1);
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
    expectBatchedModifications(actorRef, 1);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
    transactionProxy.delete(TestModel.TEST_PATH);
    verifyOneBatchedModification(actorRef, new DeleteModification(TestModel.TEST_PATH), false);
}
Also used : ActorRef(akka.actor.ActorRef) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 3 with DeleteModification

use of org.opendaylight.controller.cluster.datastore.modification.DeleteModification in project controller by opendaylight.

the class LocalTransactionContextTest method testDelete.

@Test
public void testDelete() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    localTransactionContext.executeModification(new DeleteModification(yangInstanceIdentifier));
    verify(readWriteTransaction).delete(yangInstanceIdentifier);
}
Also used : DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 4 with DeleteModification

use of org.opendaylight.controller.cluster.datastore.modification.DeleteModification in project controller by opendaylight.

the class LocalTransactionContextTest method testReadyWithDeleteError.

@Test
public void testReadyWithDeleteError() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    RuntimeException error = new RuntimeException("mock");
    doThrow(error).when(readWriteTransaction).delete(yangInstanceIdentifier);
    localTransactionContext.executeModification(new DeleteModification(yangInstanceIdentifier));
    localTransactionContext.executeModification(new DeleteModification(yangInstanceIdentifier));
    verify(readWriteTransaction).delete(yangInstanceIdentifier);
    doReadyWithExpectedError(error);
}
Also used : DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 5 with DeleteModification

use of org.opendaylight.controller.cluster.datastore.modification.DeleteModification in project controller by opendaylight.

the class BatchedModificationsTest method testSerialization.

@Test
public void testSerialization() {
    YangInstanceIdentifier writePath = TestModel.TEST_PATH;
    NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
    YangInstanceIdentifier mergePath = TestModel.OUTER_LIST_PATH;
    NormalizedNode<?, ?> mergeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
    YangInstanceIdentifier deletePath = TestModel.TEST_PATH;
    final TransactionIdentifier tx1 = nextTransactionId();
    BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
    batched.addModification(new WriteModification(writePath, writeData));
    batched.addModification(new MergeModification(mergePath, mergeData));
    batched.addModification(new DeleteModification(deletePath));
    batched.setReady(true);
    batched.setTotalMessagesSent(5);
    BatchedModifications clone = (BatchedModifications) SerializationUtils.clone((Serializable) batched.toSerializable());
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, clone.getVersion());
    assertEquals("getTransactionID", tx1, clone.getTransactionId());
    assertEquals("isReady", true, clone.isReady());
    assertEquals("getTotalMessagesSent", 5, clone.getTotalMessagesSent());
    assertEquals("getModifications size", 3, clone.getModifications().size());
    WriteModification write = (WriteModification) clone.getModifications().get(0);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, write.getVersion());
    assertEquals("getPath", writePath, write.getPath());
    assertEquals("getData", writeData, write.getData());
    MergeModification merge = (MergeModification) clone.getModifications().get(1);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, merge.getVersion());
    assertEquals("getPath", mergePath, merge.getPath());
    assertEquals("getData", mergeData, merge.getData());
    DeleteModification delete = (DeleteModification) clone.getModifications().get(2);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, delete.getVersion());
    assertEquals("getPath", deletePath, delete.getPath());
    // Test with different params.
    final TransactionIdentifier tx2 = nextTransactionId();
    batched = new BatchedModifications(tx2, (short) 10000);
    clone = (BatchedModifications) SerializationUtils.clone((Serializable) batched.toSerializable());
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, clone.getVersion());
    assertEquals("getTransactionID", tx2, clone.getTransactionId());
    assertEquals("isReady", false, clone.isReady());
    assertEquals("getModifications size", 0, clone.getModifications().size());
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) Serializable(java.io.Serializable) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Aggregations

DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)9 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 Test (org.junit.Test)6 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)5 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)5 ActorRef (akka.actor.ActorRef)4 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)3 InOrder (org.mockito.InOrder)2 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)2 TestActorRef (akka.testkit.TestActorRef)1 TestKit (akka.testkit.javadsl.TestKit)1 Timeout (akka.util.Timeout)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)1 BatchedModificationsReply (org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply)1 Modification (org.opendaylight.controller.cluster.datastore.modification.Modification)1 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)1 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)1