Search in sources :

Example 1 with Modification

use of org.opendaylight.controller.cluster.datastore.modification.Modification 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 Modification

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

the class EntityOwnershipShardCommitCoordinator method possiblyPrunePendingCommits.

private void possiblyPrunePendingCommits(EntityOwnershipShard shard, boolean isLeader) {
    // commits.
    if (shard.hasLeader() && !isLeader) {
        // We may have already submitted a transaction for replication and commit. We don't need the base Shard to
        // forward it since we also have it stored in the inflightCommit and handle retries. So we just clear
        // pending transactions and drop them.
        shard.convertPendingTransactionsToMessages();
        // Prune the inflightCommit.
        if (inflightCommit != null) {
            inflightCommit = pruneModifications(inflightCommit);
        }
        // Prune the subsequent pending modifications.
        Iterator<Modification> iter = pendingModifications.iterator();
        while (iter.hasNext()) {
            Modification mod = iter.next();
            if (!canForwardModificationToNewLeader(mod)) {
                iter.remove();
            }
        }
    }
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) Modification(org.opendaylight.controller.cluster.datastore.modification.Modification)

Example 3 with Modification

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

the class AbstractTransactionProxyTest method verifyBatchedModifications.

protected void verifyBatchedModifications(final Object message, final boolean expIsReady, final boolean expIsDoCommitOnReady, final Modification... expected) {
    assertEquals("Message type", BatchedModifications.class, message.getClass());
    BatchedModifications batchedModifications = (BatchedModifications) message;
    assertEquals("BatchedModifications size", expected.length, batchedModifications.getModifications().size());
    assertEquals("isReady", expIsReady, batchedModifications.isReady());
    assertEquals("isDoCommitOnReady", expIsDoCommitOnReady, batchedModifications.isDoCommitOnReady());
    for (int i = 0; i < batchedModifications.getModifications().size(); i++) {
        Modification actual = batchedModifications.getModifications().get(i);
        assertEquals("Modification type", expected[i].getClass(), actual.getClass());
        assertEquals("getPath", ((AbstractModification) expected[i]).getPath(), ((AbstractModification) actual).getPath());
        if (actual instanceof WriteModification) {
            assertEquals("getData", ((WriteModification) expected[i]).getData(), ((WriteModification) actual).getData());
        }
    }
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) Modification(org.opendaylight.controller.cluster.datastore.modification.Modification) AbstractModification(org.opendaylight.controller.cluster.datastore.modification.AbstractModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)

Example 4 with Modification

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

the class ReadyLocalTransactionSerializerTest method testToAndFromBinary.

@Test
public void testToAndFromBinary() throws NotSerializableException {
    DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, TestModel.createTestContext());
    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
    MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
    new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
    TransactionIdentifier txId = nextTransactionId();
    ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
    final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
    final Object deserialized;
    try {
        final ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer(system);
        final byte[] bytes = serializer.toBinary(readyMessage);
        deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
    } finally {
        JavaTestKit.shutdownActorSystem(system);
    }
    assertNotNull("fromBinary returned null", deserialized);
    assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
    BatchedModifications batched = (BatchedModifications) deserialized;
    assertEquals("getTransactionID", txId, batched.getTransactionId());
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());
    List<Modification> batchedMods = batched.getModifications();
    assertEquals("getModifications size", 2, batchedMods.size());
    Modification mod = batchedMods.get(0);
    assertEquals("Modification type", WriteModification.class, mod.getClass());
    assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification) mod).getPath());
    assertEquals("Modification getData", writeData, ((WriteModification) mod).getData());
    mod = batchedMods.get(1);
    assertEquals("Modification type", MergeModification.class, mod.getClass());
    assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification) mod).getPath());
    assertEquals("Modification getData", mergeData, ((MergeModification) mod).getData());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) Modification(org.opendaylight.controller.cluster.datastore.modification.Modification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) ExtendedActorSystem(akka.actor.ExtendedActorSystem) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 5 with Modification

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

the class EntityOwnershipShard method selectNewOwnerForEntitiesOwnedBy.

private void selectNewOwnerForEntitiesOwnedBy(final Set<String> ownedBy) {
    final List<Modification> modifications = new ArrayList<>();
    searchForEntitiesOwnedBy(ownedBy, (entityTypeNode, entityNode) -> {
        YangInstanceIdentifier entityPath = YangInstanceIdentifier.builder(ENTITY_TYPES_PATH).node(entityTypeNode.getIdentifier()).node(ENTITY_NODE_ID).node(entityNode.getIdentifier()).node(ENTITY_OWNER_NODE_ID).build();
        String newOwner = newOwner(getCurrentOwner(entityPath), getCandidateNames(entityNode), getEntityOwnerElectionStrategy(entityPath));
        if (!newOwner.isEmpty()) {
            LOG.debug("{}: Found entity {}, writing new owner {}", persistenceId(), entityPath, newOwner);
            modifications.add(new WriteModification(entityPath, ImmutableNodes.leafNode(ENTITY_OWNER_NODE_ID, newOwner)));
        } else {
            LOG.debug("{}: Found entity {} but no other candidates - not clearing owner", persistenceId(), entityPath, newOwner);
        }
    });
    commitCoordinator.commitModifications(modifications, this);
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) 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) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

Modification (org.opendaylight.controller.cluster.datastore.modification.Modification)7 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)7 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)4 ArrayList (java.util.ArrayList)3 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)2 ExtendedActorSystem (akka.actor.ExtendedActorSystem)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)1 AbstractModification (org.opendaylight.controller.cluster.datastore.modification.AbstractModification)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)1 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)1 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)1 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)1