First round of ClusterMetadata improvements:
    Introduced a PartitionId type for identifying partitions
    Introduced a admin service for making metadata updates
    Update cluster.json format to specify all partitions (including p0) and changed partitionId to be an int.

Change-Id: Ia0617f1ed0ce886680dcee4f5396a4bbdfa225da
diff --git a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java
index 6da48fa..a2681e0 100644
--- a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java
+++ b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java
@@ -20,6 +20,8 @@
 import java.util.Set;
 import java.util.stream.Collectors;
 
+import org.apache.commons.collections.CollectionUtils;
+
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Verify.verifyNotNull;
 import static com.google.common.base.Verify.verify;
@@ -32,7 +34,7 @@
 /**
  * Cluster metadata.
  * <p>
- * Metadata specifies the attributes that define a ONOS cluster and comprises the collection
+ * Metadata specifies how a ONOS cluster is constituted and is made up of the collection
  * of {@link org.onosproject.cluster.ControllerNode nodes} and the collection of data
  * {@link org.onosproject.cluster.Partition partitions}.
  */
@@ -71,7 +73,8 @@
     }
 
     /**
-     * Returns the collection of data {@link org.onosproject.cluster.Partition partitions} that make up the cluster.
+     * Returns the collection of {@link org.onosproject.cluster.Partition partitions} that make
+     * up the cluster.
      * @return collection of partitions.
      */
     public Collection<Partition> getPartitions() {
@@ -93,7 +96,7 @@
     }
 
     /*
-     * Provide a deep quality check of the meta data (non-Javadoc)
+     * Provide a deep equality check of the cluster metadata (non-Javadoc)
      *
      * @see java.lang.Object#equals(java.lang.Object)
      */
@@ -146,7 +149,7 @@
         }
 
         /**
-         * Sets the collection of data partitions, returning the cluster metadata builder for method chaining.
+         * Sets the partitions, returning the cluster metadata builder for method chaining.
          * @param partitions collection of partitions
          * @return this cluster metadata builder
          */
@@ -171,10 +174,8 @@
          */
         private void verifyMetadata() {
             verifyNotNull(metadata.getName(), "Cluster name must be specified");
-            verifyNotNull(metadata.getNodes(), "Cluster nodes must be specified");
-            verifyNotNull(metadata.getPartitions(), "Cluster partitions must be specified");
-            verify(!metadata.getNodes().isEmpty(), "Cluster nodes must not be empty");
-            verify(!metadata.getPartitions().isEmpty(), "Cluster nodes must not be empty");
+            verify(CollectionUtils.isEmpty(metadata.getNodes()), "Cluster nodes must be specified");
+            verify(CollectionUtils.isEmpty(metadata.getPartitions()), "Cluster partitions must be specified");
 
             // verify that partitions are constituted from valid cluster nodes.
             boolean validPartitions = Collections2.transform(metadata.getNodes(), ControllerNode::id)
@@ -185,4 +186,4 @@
             verify(validPartitions, "Partition locations must be valid cluster nodes");
         }
     }
-}
+}
\ No newline at end of file
diff --git a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataAdminService.java b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataAdminService.java
new file mode 100644
index 0000000..51bb524
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataAdminService.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cluster;
+
+/**
+ * Service for making updates to {@link ClusterMetadata cluster metadata}.
+ */
+public interface ClusterMetadataAdminService {
+
+    /**
+     * Updates the cluster metadata.
+     * @param metadata new metadata
+     */
+    void setClusterMetadata(ClusterMetadata metadata);
+}
diff --git a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataService.java b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataService.java
index 25a6df6..948ee46 100644
--- a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataService.java
+++ b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataService.java
@@ -15,10 +15,13 @@
  */
 package org.onosproject.cluster;
 
+import org.onosproject.event.ListenerService;
+
 /**
- * Service for obtaining metadata information about the cluster.
+ * Service for accessing {@link ClusterMetadata cluster metadata}.
  */
-public interface ClusterMetadataService {
+public interface ClusterMetadataService
+    extends ListenerService<ClusterMetadataEvent, ClusterMetadataEventListener> {
 
     /**
      * Returns the current cluster metadata.
@@ -27,13 +30,7 @@
     ClusterMetadata getClusterMetadata();
 
     /**
-     * Updates the cluster metadata.
-     * @param metadata new metadata
-     */
-    void setClusterMetadata(ClusterMetadata metadata);
-
-    /**
-     * Returns the local controller node representing this instance.
+     * Returns the {@link ControllerNode controller node} representing this instance.
      * @return local controller node
      */
     ControllerNode getLocalNode();
diff --git a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataStore.java b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataStore.java
index 7e83b5b..99361d8 100644
--- a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataStore.java
+++ b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadataStore.java
@@ -21,14 +21,14 @@
 import org.onosproject.store.service.Versioned;
 
 /**
- * Manages persistence of cluster metadata; not intended for direct use.
+ * Manages persistence of {@link ClusterMetadata cluster metadata}; not intended for direct use.
  */
 public interface ClusterMetadataStore extends Store<ClusterMetadataEvent, ClusterMetadataStoreDelegate> {
 
     /**
      * Returns the cluster metadata.
      * <p>
-     * The returned metadata is versioned to aid determining if a metadata instance is more recent than another.
+     * The retuned metadata is encapsulated as a {@link Versioned versioned} and therefore has a specific version.
      * @return cluster metadata
      */
     Versioned<ClusterMetadata> getClusterMetadata();
@@ -39,39 +39,38 @@
      */
     void setClusterMetadata(ClusterMetadata metadata);
 
-    // TODO: The below methods should move to a separate store interface that is responsible for
-    // tracking cluster partition operational state.
+    /**
+     * Adds a controller node to the list of active members for a partition.
+     * <p>
+     * Active members of a partition are those that are actively participating
+     * in the data replication protocol being employed. When a node first added
+     * to a partition, it is in a passive or catch up mode where it attempts to
+     * bring it self up to speed with other active members in the partition.
+     * @param partitionId partition identifier
+     * @param nodeId identifier of controller node
+     */
+    void addActivePartitionMember(PartitionId partitionId, NodeId nodeId);
 
     /**
-     * Sets a controller node as an active member of a partition.
-     * <p>
-     * Active members are those replicas that are up to speed with the rest of the system and are
-     * usually capable of participating in the replica state management activities in accordance with
-     * the data consistency and replication protocol in use.
+     * Removes a controller node from the list of active members for a partition.
      * @param partitionId partition identifier
      * @param nodeId id of controller node
      */
-    void setActiveReplica(String partitionId, NodeId nodeId);
+    void removeActivePartitionMember(PartitionId partitionId, NodeId nodeId);
 
     /**
-     * Removes a controller node as an active member for a partition.
+     * Returns the collection of controller nodes that are the active members for a partition.
      * <p>
-     * Active members are those replicas that are up to speed with the rest of the system and are
-     * usually capable of participating in the replica state management activities in accordance with
-     * the data consistency and replication protocol in use.
-     * @param partitionId partition identifier
-     * @param nodeId id of controller node
-     */
-    void unsetActiveReplica(String partitionId, NodeId nodeId);
-
-    /**
-     * Returns the collection of controller nodes that are the active replicas for a partition.
+     * Active members of a partition are typically those that are actively
+     * participating in the data replication protocol being employed. When
+     * a node first added to a partition, it is in a passive or catch up mode where
+     * it attempts to bring it self up to speed with other active members in the partition.
      * <p>
-     * Active members are those replicas that are up to speed with the rest of the system and are
-     * usually capable of participating in the replica state management activities in accordance with
-     * the data consistency and replication protocol in use.
+     * <b>Note:</b>If is possible for this list to different from the list of partition members
+     * specified by cluster meta data. The discrepancy can arise due to the fact that
+     * adding/removing members from a partition requires a data hand-off mechanism to complete.
      * @param partitionId partition identifier
-     * @return identifiers of controller nodes that are the active replicas
+     * @return identifiers of controller nodes that are active members
      */
-    Collection<NodeId> getActiveReplicas(String partitionId);
+    Collection<NodeId> getActivePartitionMembers(PartitionId partitionId);
 }
\ No newline at end of file
diff --git a/core/api/src/main/java/org/onosproject/cluster/Partition.java b/core/api/src/main/java/org/onosproject/cluster/Partition.java
index 1eca4ae..e3a1352 100644
--- a/core/api/src/main/java/org/onosproject/cluster/Partition.java
+++ b/core/api/src/main/java/org/onosproject/cluster/Partition.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2016 Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,77 +15,23 @@
  */
 package org.onosproject.cluster;
 
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Set;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
-
-import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
- * A data partition.
- * <p>
- * Partition represents a slice of the data space and is made up of a collection
- * of {@link org.onosproject.cluster.ControllerNode nodes}
- * that all maintain copies of this data.
+ * A partition or shard is a group of controller nodes that are work together to maintain state.
+ * A ONOS cluster is typically made of of one or partitions over which the the data is partitioned.
  */
-public class Partition {
-
-    private final String name;
-    private final Set<NodeId> members;
-
-    private Partition() {
-        name = null;
-        members = null;
-    }
-
-    public Partition(String name, Collection<NodeId> members) {
-        this.name = checkNotNull(name);
-        this.members = ImmutableSet.copyOf(checkNotNull(members));
-    }
+public interface Partition {
 
     /**
-     * Returns the partition name.
-     * <p>
-     * Each partition is identified by a unique name.
-     * @return partition name
+     * Returns the partition identifier.
+     * @return partition identifier
      */
-    public String getName() {
-        return this.name;
-    }
+    PartitionId getId();
 
     /**
-     * Returns the collection of controller node identifiers that make up this partition.
+     * Returns the controller nodes that are members of this partition.
      * @return collection of controller node identifiers
      */
-    public Collection<NodeId> getMembers() {
-        return this.members;
-    }
-
-    @Override
-    public int hashCode() {
-        return Arrays.deepHashCode(new Object[] {name, members});
-    }
-
-    @Override
-    public boolean equals(Object other) {
-        if (this == other) {
-            return true;
-        }
-
-        if (other == null || !Partition.class.isInstance(other)) {
-            return false;
-        }
-
-        Partition that = (Partition) other;
-
-        if (!this.name.equals(that.name) || (this.members == null && that.members != null)
-                || (this.members != null && that.members == null) || this.members.size() != that.members.size()) {
-            return false;
-        }
-
-        return Sets.symmetricDifference(this.members, that.members).isEmpty();
-    }
-}
\ No newline at end of file
+    Collection<NodeId> getMembers();
+}
diff --git a/core/api/src/main/java/org/onosproject/cluster/PartitionId.java b/core/api/src/main/java/org/onosproject/cluster/PartitionId.java
new file mode 100644
index 0000000..1e73d0e
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/cluster/PartitionId.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cluster;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.util.Objects;
+
+/**
+ * {@link Partition} identifier.
+ */
+public class PartitionId implements Comparable<PartitionId> {
+
+    private final int id;
+
+    /**
+     * Creates a partition identifier from an integer.
+     *
+     * @param id input integer
+     */
+    public PartitionId(int id) {
+        checkArgument(id >= 0, "partition id must be non-negative");
+        this.id = id;
+    }
+
+    /**
+     * Creates a partition identifier from an integer.
+     *
+     * @param id input integer
+     */
+    public static PartitionId from(int id) {
+        return new PartitionId(id);
+    }
+
+    /**
+     * Returns the partition identifier as an integer.
+     * @return number
+     */
+    public int asInt() {
+        return id;
+    }
+
+    @Override
+    public int hashCode() {
+        return id;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof PartitionId) {
+            final PartitionId other = (PartitionId) obj;
+            return Objects.equals(this.id, other.id);
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return String.valueOf(id);
+    }
+
+    @Override
+    public int compareTo(PartitionId that) {
+        return Integer.compare(this.id, that.id);
+    }
+}
\ No newline at end of file