* @return an Optional EntityOwnershipState whose instance is present if the entity is found
*/
Optional<EntityOwnershipState> getOwnershipState(@Nonnull Entity forEntity);
+
+ /**
+ * Check if a local candidate is registered for the given entity
+ *
+ * @param entity
+ * @return true if a candidate was registered locally, false otherwise
+ */
+ boolean isCandidateRegistered(@Nonnull Entity entity);
}
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
+import javax.annotation.Nonnull;
import org.opendaylight.controller.cluster.datastore.DistributedDataStore;
import org.opendaylight.controller.cluster.datastore.config.Configuration;
import org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration;
return Optional.of(new EntityOwnershipState(isOwner, hasOwner));
}
+ @Override
+ public boolean isCandidateRegistered(@Nonnull Entity entity) {
+ return registeredEntities.get(entity) != null;
+ }
+
private DataTree getLocalEntityOwnershipShardDataTree() {
if(localEntityOwnershipShardDataTree == null) {
try {
package org.opendaylight.controller.cluster.datastore.entityownership;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
service.close();
}
+ @Test
+ public void testIsCandidateRegistered() throws CandidateAlreadyRegisteredException {
+ final TestShardBuilder shardBuilder = new TestShardBuilder();
+ DistributedEntityOwnershipService service = new DistributedEntityOwnershipService(dataStore,
+ EntityOwnerSelectionStrategyConfig.newBuilder().build()) {
+ @Override
+ protected EntityOwnershipShard.Builder newShardBuilder() {
+ return shardBuilder;
+ }
+ };
+
+ service.start();
+
+ final Entity test = new Entity("test-type", "test");
+
+ assertFalse(service.isCandidateRegistered(test));
+
+ service.registerCandidate(test);
+
+ assertTrue(service.isCandidateRegistered(test));
+
+ service.close();
+ }
+
private static void verifyGetOwnershipState(DistributedEntityOwnershipService service, Entity entity,
boolean isOwner, boolean hasOwner) {
Optional<EntityOwnershipState> state = service.getOwnershipState(entity);