Validate that cluster configuration intersects with existing nodes when forming cluster

Change-Id: I200b25f2e9ae3380ccd90a6b58cd697f1e3029b4
(cherry picked from commit 9a93304b03dfdd34d3679da1dd52fcc676307af2)
diff --git a/core/net/src/main/java/org/onosproject/cluster/impl/ClusterManager.java b/core/net/src/main/java/org/onosproject/cluster/impl/ClusterManager.java
index d1e926d..56ea048 100644
--- a/core/net/src/main/java/org/onosproject/cluster/impl/ClusterManager.java
+++ b/core/net/src/main/java/org/onosproject/cluster/impl/ClusterManager.java
@@ -166,6 +166,12 @@
         checkNotNull(nodes, "Nodes cannot be null");
         checkArgument(!nodes.isEmpty(), "Nodes cannot be empty");
 
+        // Validate that the given nodes intersect with the currently configured nodes.
+        Set<ControllerNode> existingNodes = Sets.newHashSet(clusterMetadataService.getClusterMetadata().getNodes());
+        checkArgument(
+            !Sets.intersection(nodes, existingNodes).isEmpty(),
+            "Nodes must intersect with current cluster configuration");
+
         ClusterMetadata metadata = new ClusterMetadata("default", nodes, buildDefaultPartitions(nodes, partitionSize));
         clusterMetadataAdminService.setClusterMetadata(metadata);
         try {