use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class DefaultTopologyScheduler method freeUsed.
/**
* @@@ Here maybe exist one problem, some dead slots have been free
*
* @param context
*/
protected void freeUsed(TopologyAssignContext context) {
Set<Integer> canFree = new HashSet<Integer>();
canFree.addAll(context.getAllTaskIds());
canFree.removeAll(context.getUnstoppedTaskIds());
Map<String, SupervisorInfo> cluster = context.getCluster();
Assignment oldAssigns = context.getOldAssignment();
for (Integer task : canFree) {
ResourceWorkerSlot worker = oldAssigns.getWorkerByTaskId(task);
if (worker == null) {
LOG.warn("When free rebalance resource, no ResourceAssignment of task " + task);
continue;
}
SupervisorInfo supervisorInfo = cluster.get(worker.getNodeId());
if (supervisorInfo == null) {
continue;
}
supervisorInfo.getAvailableWorkerPorts().add(worker.getPort());
}
}
use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class UpdateTopologyTransitionCallback method execute.
@Override
public <T> Object execute(T... args) {
StormClusterState clusterState = data.getStormClusterState();
try {
Map userConf = (Map) args[0];
Map topoConf = StormConfig.read_nimbus_topology_conf(topologyId, data.getBlobStore());
topoConf.putAll(userConf);
Assignment assignment = clusterState.assignment_info(topologyId, null);
assignment.setAssignmentType(AssignmentType.UpdateTopology);
assignment.updateTimeStamp();
clusterState.set_assignment(topologyId, assignment);
LOG.info("Successfully update topology information to ZK for " + topologyId);
} catch (Exception e) {
LOG.error("Failed to update topology.", e);
}
return currentStatus;
}
use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class Cluster method get_all_assignment.
public static Map<String, Assignment> get_all_assignment(StormClusterState stormClusterState, RunnableCallback callback) throws Exception {
Map<String, Assignment> ret = new HashMap<String, Assignment>();
// get /assignments {topology_id}
List<String> assignments = stormClusterState.assignments(callback);
if (assignments == null) {
LOG.debug("No assignment of ZK");
return ret;
}
for (String topology_id : assignments) {
Assignment assignment = stormClusterState.assignment_info(topology_id, callback);
if (assignment == null) {
LOG.error("Failed to get Assignment of " + topology_id + " from ZK");
continue;
}
ret.put(topology_id, assignment);
}
return ret;
}
use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class ServiceHandler method getTopologyTasksToSupervisorIds.
@Override
public Map<Integer, String> getTopologyTasksToSupervisorIds(String topologyName) throws NotAliveException, TException {
StormClusterState stormClusterState = data.getStormClusterState();
String topologyId = getTopologyId(topologyName);
Map<Integer, String> ret = new HashMap<>();
try {
Assignment assignment = stormClusterState.assignment_info(topologyId, null);
Set<ResourceWorkerSlot> workers = assignment.getWorkers();
for (ResourceWorkerSlot worker : workers) {
String supervisorId = worker.getNodeId();
for (Integer task : worker.getTasks()) {
ret.put(task, supervisorId);
}
}
} catch (Exception ex) {
LOG.error("Error:", ex);
}
return ret;
}
use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class ServiceHandler method getClusterInfo.
/**
* get cluster's summary, it will contain SupervisorSummary and TopologySummary
*
* @return ClusterSummary
*/
@Override
public ClusterSummary getClusterInfo() throws TException {
long start = System.nanoTime();
try {
StormClusterState stormClusterState = data.getStormClusterState();
Map<String, Assignment> assignments = new HashMap<String, Assignment>();
// get TopologySummary
List<TopologySummary> topologySummaries = NimbusUtils.getTopologySummary(stormClusterState, assignments);
// all supervisors
Map<String, SupervisorInfo> supervisorInfos = Cluster.get_all_SupervisorInfo(stormClusterState, null);
// generate SupervisorSummaries
List<SupervisorSummary> supervisorSummaries = NimbusUtils.mkSupervisorSummaries(supervisorInfos, assignments);
NimbusSummary nimbusSummary = NimbusUtils.getNimbusSummary(stormClusterState, supervisorSummaries, data);
return new ClusterSummary(nimbusSummary, supervisorSummaries, topologySummaries);
} catch (TException e) {
LOG.info("Failed to get ClusterSummary ", e);
throw e;
} catch (Exception e) {
LOG.info("Failed to get ClusterSummary ", e);
throw new TException(e);
} finally {
long end = System.nanoTime();
SimpleJStormMetric.updateNimbusHistogram("getClusterInfo", (end - start) / TimeUtils.NS_PER_US);
}
}
Aggregations