//��ȡ���е�supervisor�ڵ���Ϣ��
Map<String, SupervisorInfo> supInfos = allSupervisorInfo(stormClusterState, callback);
//��ȡ<supervisorid,hostname>map���ϣ����磺node->host {"4b83cd41-e863-4bd6-b26d-3e27e5ff7799" "dw-perf-3.alipay.net","b8f1664d-5555-4950-8139-5098fb109a81" "dw-perf-2.alipay.net"}
Map<String, String> nodeHost = getNodeHost(supInfos);
//��ȡָ��topologyid��assignment��Ϣ��
Assignment existingAssignment = stormClusterState.assignment_info(topologyid, null);
//�����ȡtopology�����Ӧ�µ�NodePort
Map<Integer, NodePort> taskNodePort = computeNewTaskToNodePort(data,
topologyid, existingAssignment, stormClusterState, callback,
supInfos, isScratch);
Map<String, String> allNodeHost = new HashMap<String, String>();
if (existingAssignment != null){
allNodeHost = existingAssignment.getNodeHost();//�����Ƿ�ֹsupervisor���ˣ�task������Ȼ������
}
if (nodeHost != null){
allNodeHost.putAll(nodeHost);
}
Set<Integer> reassignIds = null;
if (existingAssignment != null && existingAssignment.getTaskToNodeport() != null){
reassignIds = changeIds(existingAssignment.getTaskToNodeport(),taskNodePort);
}else{
//FIXME changeIds����ִ�У�����startTimes->taskid�п���Ϊnull
reassignIds = changeIds(new HashMap<Integer, NodePort>(),taskNodePort);
}
//��ʼ����ʼʱ��
Map<Integer, Integer> startTimes = new HashMap<Integer, Integer>();
if (existingAssignment != null){
Map<Integer, Integer> taskStartTimeSecs = existingAssignment.getTaskStartTimeSecs();
if (taskStartTimeSecs!= null){
startTimes.putAll(taskStartTimeSecs);
}
}
//������·����ˣ���Ҫ���ó�ʼ��ʱ��
if (reassignIds != null){
int nowSecs = TimeUtils.current_time_secs();
for (Integer reassignid:reassignIds) {
startTimes.put(reassignid, nowSecs);
}
}
//select-keys all-node->host (map first (vals task->node+port))
Map<String, String> storeNodeHosts = new HashMap<String, String>();
if (taskNodePort != null){
HashSet<String> toSaveHosts=new HashSet<String>();
for (Entry<Integer, NodePort> entry:taskNodePort.entrySet()) {
toSaveHosts.add((entry.getValue()).getNode());
}
for(String node:toSaveHosts)
{
String host=allNodeHost.get(node);
storeNodeHosts.put(node, host);
}
}else{
storeNodeHosts.putAll(allNodeHost);
}
Assignment assignment = new Assignment(StormConfig.masterStormdistRoot(
conf, topologyid), taskNodePort, storeNodeHosts, startTimes);
if (assignment.equals(existingAssignment)) {
LOG.debug("Assignment for " + topologyid + " hasn't changed");
} else {
LOG.info("Setting new assignment for storm id " + topologyid + ": "
+ assignment);
stormClusterState.set_assignment(topologyid, assignment);