{
throw new HelixException("cannot find state model: " + currentIdealState.getStateModelDefRef());
}
String[] states = RebalanceUtil.parseStates(clusterName, stateModDef);
ZNRecord newIdealStateRecord =
DefaultIdealStateCalculator.convertToZNRecord(balancedRecord,
currentIdealState.getResourceName(),
states[0],
states[1]);
Set<String> partitionSet = new HashSet<String>();
partitionSet.addAll(newIdealStateRecord.getMapFields().keySet());
partitionSet.addAll(newIdealStateRecord.getListFields().keySet());
Map<String, String> reversePartitionIndex =
(Map<String, String>) balancedRecord.get("reversePartitionIndex");
for (String partition : partitionSet)
{
if (reversePartitionIndex.containsKey(partition))
{
String originPartitionName = reversePartitionIndex.get(partition);
if (partition.equals(originPartitionName))
{
continue;
}
newIdealStateRecord.getMapFields()
.put(originPartitionName,
newIdealStateRecord.getMapField(partition));
newIdealStateRecord.getMapFields().remove(partition);
newIdealStateRecord.getListFields()
.put(originPartitionName,
newIdealStateRecord.getListField(partition));
newIdealStateRecord.getListFields().remove(partition);
}
}
newIdealStateRecord.getSimpleFields()
.putAll(currentIdealState.getRecord().getSimpleFields());
IdealState newIdealState = new IdealState(newIdealStateRecord);
setResourceIdealState(clusterName, newIdealStateRecord.getId(), newIdealState);
}