X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fentityownership%2FEntityOwnershipShard.java;h=bb00f2485447c2baef72eafe71fdf614b0decc97;hb=466078ab1dc8a8cc2981b161051f6edecd6af85a;hp=b7321afe5536f07f61136c6f3632df6b774d2ca3;hpb=8db9c583f92f65d03d7688d5b65cecf7a906d918;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java index b7321afe55..bb00f24854 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java @@ -33,6 +33,7 @@ import akka.pattern.Patterns; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.util.ArrayList; import java.util.Collection; @@ -543,13 +544,14 @@ class EntityOwnershipShard extends Shard { } private static Collection getCandidateNames(final MapEntryNode entity) { - Collection candidates = ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getValue(); - Collection candidateNames = new ArrayList<>(candidates.size()); - for (MapEntryNode candidate: candidates) { - candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString()); - } - - return candidateNames; + return entity.getChild(CANDIDATE_NODE_ID).map(child -> { + Collection candidates = ((MapNode) child).getValue(); + Collection candidateNames = new ArrayList<>(candidates.size()); + for (MapEntryNode candidate: candidates) { + candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString()); + } + return candidateNames; + }).orElse(ImmutableList.of()); } private void searchForEntitiesOwnedBy(final Set ownedBy, final EntityWalker walker) { @@ -586,7 +588,8 @@ class EntityOwnershipShard extends Shard { } private static boolean hasCandidate(final MapEntryNode entity, final MemberName candidateName) { - return ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getChild(candidateNodeKey(candidateName.getName())) + return entity.getChild(CANDIDATE_NODE_ID) + .flatMap(child -> ((MapNode)child).getChild(candidateNodeKey(candidateName.getName()))) .isPresent(); }