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);
}
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();
}
}
}
}
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());
}
}
}
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());
}
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);
}
Aggregations