ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
Builder keyBuilder = accessor.keyBuilder();
// check the instance is alive
LiveInstance liveInstance =
accessor.getProperty(keyBuilder.liveInstance(instanceName));
if (liveInstance == null)
{
throw new HelixException("Can't reset state for " + resourceName + "/"
+ partitionNames + " on " + instanceName + ", because " + instanceName
+ " is not alive");
}
// check resource group exists
IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resourceName));
if (idealState == null)
{
throw new HelixException("Can't reset state for " + resourceName + "/"
+ partitionNames + " on " + instanceName + ", because " + resourceName
+ " is not added");
}
// check partition exists in resource group
Set<String> resetPartitionNames = new HashSet<String>(partitionNames);
if (idealState.getIdealStateMode() == IdealStateModeProperty.CUSTOMIZED)
{
Set<String> partitions =
new HashSet<String>(idealState.getRecord().getMapFields().keySet());
if (!partitions.containsAll(resetPartitionNames))
{
throw new HelixException("Can't reset state for " + resourceName + "/"
+ partitionNames + " on " + instanceName + ", because not all "
+ partitionNames + " exist");
}
}
else
{
Set<String> partitions =
new HashSet<String>(idealState.getRecord().getListFields().keySet());
if (!partitions.containsAll(resetPartitionNames))
{
throw new HelixException("Can't reset state for " + resourceName + "/"
+ partitionNames + " on " + instanceName + ", because not all "
+ partitionNames + " exist");
}
}
// check partition is in ERROR state
String sessionId = liveInstance.getSessionId();
CurrentState curState =
accessor.getProperty(keyBuilder.currentState(instanceName,
sessionId,
resourceName));
for (String partitionName : resetPartitionNames)