use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class SyncSupervisorEvent method getAllAssignments.
private void getAllAssignments(Map<String, Integer> assignmentVersion, Map<String, Assignment> localZkAssignments, RunnableCallback callback) throws Exception {
Map<String, Assignment> ret = new HashMap<String, Assignment>();
Map<String, Integer> updateAssignmentVersion = new HashMap<String, Integer>();
// get /assignments {topology_id}
List<String> assignments = stormClusterState.assignments(callback);
if (assignments == null) {
assignmentVersion.clear();
localZkAssignments.clear();
LOG.debug("No assignment of ZK");
return;
}
for (String topology_id : assignments) {
Integer zkVersion = stormClusterState.assignment_version(topology_id, callback);
LOG.debug(topology_id + "'s assigment version of zk is :" + zkVersion);
Integer recordedVersion = assignmentVersion.get(topology_id);
LOG.debug(topology_id + "'s assigment version of local is :" + recordedVersion);
Assignment assignment = null;
if (recordedVersion != null && zkVersion != null && recordedVersion.equals(zkVersion)) {
assignment = localZkAssignments.get(topology_id);
}
//because the first version is 0
if (assignment == null) {
assignment = stormClusterState.assignment_info(topology_id, callback);
}
if (assignment == null) {
LOG.error("Failed to get Assignment of " + topology_id + " from ZK");
continue;
}
updateAssignmentVersion.put(topology_id, zkVersion);
ret.put(topology_id, assignment);
}
assignmentVersion.clear();
assignmentVersion.putAll(updateAssignmentVersion);
localZkAssignments.clear();
localZkAssignments.putAll(ret);
}
use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class SyncSupervisorEvent method getTopologyCodeLocations.
/**
* get mastercodedir for every topology
*
* @throws Exception
* @returns Map: <topologyId, master-code-dir> from zookeeper
*/
public static Map<String, String> getTopologyCodeLocations(Map<String, Assignment> assignments, String supervisorId) throws Exception {
Map<String, String> rtn = new HashMap<String, String>();
for (Entry<String, Assignment> entry : assignments.entrySet()) {
String topologyid = entry.getKey();
Assignment assignmenInfo = entry.getValue();
Set<ResourceWorkerSlot> workers = assignmenInfo.getWorkers();
for (ResourceWorkerSlot worker : workers) {
String node = worker.getNodeId();
if (supervisorId.equals(node)) {
rtn.put(topologyid, assignmenInfo.getMasterCodeDir());
break;
}
}
}
return rtn;
}
use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class SyncSupervisorEvent method getLocalAssign.
/**
* a port must be assigned one topology
*
* @param stormClusterState
* @param supervisorId
* @throws Exception
* @returns map: {port,LocalAssignment}
*/
private Map<Integer, LocalAssignment> getLocalAssign(StormClusterState stormClusterState, String supervisorId, Map<String, Assignment> assignments) throws Exception {
Map<Integer, LocalAssignment> portLA = new HashMap<Integer, LocalAssignment>();
for (Entry<String, Assignment> assignEntry : assignments.entrySet()) {
String topologyId = assignEntry.getKey();
Assignment assignment = assignEntry.getValue();
Map<Integer, LocalAssignment> portTasks = readMyTasks(stormClusterState, topologyId, supervisorId, assignment);
if (portTasks == null) {
continue;
}
// a port must be assigned one storm
for (Entry<Integer, LocalAssignment> entry : portTasks.entrySet()) {
Integer port = entry.getKey();
LocalAssignment la = entry.getValue();
if (!portLA.containsKey(port)) {
portLA.put(port, la);
} else {
throw new RuntimeException("Should not have multiple topologys assigned to one port");
}
}
}
return portLA;
}
use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class ZooKeeperDataViewTest method viewAssignments.
@Test
public void viewAssignments() throws Exception {
if (SKIP == true) {
return;
}
List<String> assignments = zkobj.getChildren(zk, Cluster.ASSIGNMENTS_SUBTREE, false);
for (String child : assignments) {
byte[] data = zkobj.getData(zk, Cluster.assignment_path(child), false);
Assignment assignment = (Assignment) Utils.maybe_deserialize(data);
System.out.println(gson.toJson(assignment));
}
}
Aggregations