// System.out.println(new String(serializer.serialize(record)));
}
public ZNRecord generateConfigForLeaderStandby()
{
ZNRecord record = new ZNRecord("LeaderStandby");
record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(),
"OFFLINE");
List<String> statePriorityList = new ArrayList<String>();
statePriorityList.add("LEADER");
statePriorityList.add("STANDBY");
statePriorityList.add("OFFLINE");
statePriorityList.add("DROPPED");
record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
statePriorityList);
for (String state : statePriorityList)
{
String key = state + ".meta";
Map<String, String> metadata = new HashMap<String, String>();
if (state.equals("LEADER"))
{
metadata.put("count", "1");
record.setMapField(key, metadata);
}
if (state.equals("STANDBY"))
{
metadata.put("count", "R");
record.setMapField(key, metadata);
}
if (state.equals("OFFLINE"))
{
metadata.put("count", "-1");
record.setMapField(key, metadata);
}
if (state.equals("DROPPED"))
{
metadata.put("count", "-1");
record.setMapField(key, metadata);
}
}
for (String state : statePriorityList)
{
String key = state + ".next";
if (state.equals("LEADER"))
{
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("STANDBY", "STANDBY");
metadata.put("OFFLINE", "STANDBY");
metadata.put("DROPPED", "STANDBY");
record.setMapField(key, metadata);
}
if (state.equals("STANDBY"))
{
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("LEADER", "LEADER");
metadata.put("OFFLINE", "OFFLINE");
metadata.put("DROPPED", "OFFLINE");
record.setMapField(key, metadata);
}
if (state.equals("OFFLINE"))
{
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("STANDBY", "STANDBY");
metadata.put("LEADER", "STANDBY");
metadata.put("DROPPED", "DROPPED");
record.setMapField(key, metadata);
}
}
List<String> stateTransitionPriorityList = new ArrayList<String>();
stateTransitionPriorityList.add("LEADER-STANDBY");
stateTransitionPriorityList.add("STANDBY-LEADER");
stateTransitionPriorityList.add("OFFLINE-STANDBY");
stateTransitionPriorityList.add("STANDBY-OFFLINE");
stateTransitionPriorityList.add("OFFLINE-DROPPED");
record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
stateTransitionPriorityList);
return record;
// ZNRecordSerializer serializer = new ZNRecordSerializer();
// System.out.println(new String(serializer.serialize(record)));
}