add roleInfo structure and backup_changed mastership event
Change-Id: Iedee219fe250d681377d73a50a71f5fa72cd7802
diff --git a/core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java b/core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java
index 15f80f8..28ba049 100644
--- a/core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java
+++ b/core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/DistributedMastershipStore.java
@@ -79,9 +79,9 @@
};
roleMap = new SMap(theInstance.getMap("nodeRoles"), this.serializer);
+ roleMap.addEntryListener((new RemoteMasterShipEventHandler()), true);
terms = new SMap(theInstance.getMap("terms"), this.serializer);
clusterSize = theInstance.getAtomicLong("clustersize");
- roleMap.addEntryListener((new RemoteMasterShipEventHandler()), true);
log.info("Started");
}
diff --git a/core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/RoleValue.java b/core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/RoleValue.java
index f2c3559..51dd293 100644
--- a/core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/RoleValue.java
+++ b/core/store/hz/cluster/src/main/java/org/onlab/onos/store/mastership/impl/RoleValue.java
@@ -8,6 +8,7 @@
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.MastershipRole;
+import org.onlab.onos.store.common.RoleInfo;
/**
* A structure that holds node mastership roles associated with a
@@ -77,7 +78,6 @@
* @param from the old role
* @param to the new role
*/
- // might want to add anyways as default behavior
public void reassign(NodeId nodeId, MastershipRole from, MastershipRole to) {
remove(from, nodeId);
add(to, nodeId);
@@ -91,12 +91,22 @@
* @param to the new NodeId
* @param type the role associated with the old NodeId
*/
- // might want to add anyways as default behavior
public void replace(NodeId from, NodeId to, MastershipRole type) {
remove(type, from);
add(type, to);
}
+ /**
+ * Summarizes this RoleValue as a RoleInfo. Note that master and/or backups
+ * may be empty, so the values should be checked for safety.
+ *
+ * @return the RoleInfo.
+ */
+ public RoleInfo roleInfo() {
+ return new RoleInfo(
+ get(MastershipRole.MASTER), nodesOfRole(MastershipRole.STANDBY));
+ }
+
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();