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