[ONOS-7365] Fix NPE in ECM peersSupplier to avoid exceptions when rebooting container
Change-Id: I9d746c3f8620266ba734ad6f8c32e471e813b06e
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/StorageManager.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/StorageManager.java
index 62a29bf..2474d74 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/StorageManager.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/StorageManager.java
@@ -126,14 +126,23 @@
@Override
public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() {
checkPermission(STORAGE_WRITE);
+
+ // Note: NPE in the usage of ClusterService/MembershipService prevents rebooting the Karaf container.
+ // We need to reference these services outside the following peer suppliers.
+ final MembershipService membershipService = this.membershipService;
+ final ClusterService clusterService = this.clusterService;
+
final NodeId localNodeId = clusterService.getLocalNode().id();
+ // Use the MembershipService to provide peers for the map that are isolated within the current version.
Supplier<List<NodeId>> peersSupplier = () -> membershipService.getMembers().stream()
.map(Member::nodeId)
.filter(nodeId -> !nodeId.equals(localNodeId))
.filter(id -> clusterService.getState(id).isActive())
.collect(Collectors.toList());
+ // If this is the first node in its version, bootstrap from the previous version. Otherwise, bootstrap the
+ // map from members isolated within the current version.
Supplier<List<NodeId>> bootstrapPeersSupplier = () -> {
if (membershipService.getMembers().size() == 1) {
return clusterService.getNodes()
@@ -152,7 +161,6 @@
}
};
-
return new EventuallyConsistentMapBuilderImpl<>(
localNodeId,
clusterCommunicator,