use of com.alibaba.jstorm.common.metric.TaskTrack in project jstorm by alibaba.
the class HBaseMetricSendClient method updateTasks.
private void updateTasks(TaskDeadEvent event) {
Map<Integer, ResourceWorkerSlot> deadTasks = event.getDeadTasks();
List<KVSerializable> taskTrackList = new ArrayList<>(deadTasks.size());
for (Map.Entry<Integer, ResourceWorkerSlot> task : deadTasks.entrySet()) {
TaskTrack taskTrack = new TaskTrack(event.getClusterMetricsContext().getClusterName(), event.getTopologyId());
taskTrack.setEnd(new Date(event.getTimestamp()));
taskTrack.setTaskId(task.getKey());
taskTrack.setHost(task.getValue().getHostname());
taskTrack.setPort(task.getValue().getPort());
taskTrackList.add(taskTrack);
}
batchAdd(taskTrackList, TABLE_TASK_TRACK);
}
use of com.alibaba.jstorm.common.metric.TaskTrack in project jstorm by alibaba.
the class HBaseMetricSendClient method insertOrUpdateTasks.
/**
* insert tasks on new assign, update tasks on rebalance.
*/
private void insertOrUpdateTasks(TaskStartEvent event) {
Assignment old = event.getOldAssignment();
Assignment current = event.getNewAssignment();
Map<Integer, String> task2Component = event.getTask2Component();
List<KVSerializable> taskTrackList = new ArrayList<>();
// assign
if (old == null) {
Set<ResourceWorkerSlot> workers = current.getWorkers();
logger.info("old workers are null, assigned workers:{}", Joiner.on(",").join(workers));
for (ResourceWorkerSlot worker : workers) {
Set<Integer> tasks = worker.getTasks();
for (Integer task : tasks) {
TaskTrack track = new TaskTrack(event.getClusterMetricsContext().getClusterName(), event.getTopologyId());
track.setStart(new Date(event.getTimestamp()));
track.setComponent(task2Component.get(task));
track.setHost(worker.getHostname());
track.setPort(worker.getPort());
track.setTaskId(task);
taskTrackList.add(track);
}
}
} else {
// rebalance, we only insert newly assigned tasks
Set<ResourceWorkerSlot> oldWorkers = old.getWorkers();
Joiner joiner = Joiner.on(",");
logger.info("old workers:{}, new workers:{}", joiner.join(oldWorkers), joiner.join(current.getWorkers()));
for (ResourceWorkerSlot worker : current.getWorkers()) {
// a new worker, insert all tasks
if (!oldWorkers.contains(worker)) {
for (Integer task : worker.getTasks()) {
TaskTrack track = new TaskTrack(event.getClusterMetricsContext().getClusterName(), event.getTopologyId());
track.setStart(new Date(event.getTimestamp()));
track.setComponent(task2Component.get(task));
track.setHost(worker.getHostname());
track.setPort(worker.getPort());
track.setTaskId(task);
taskTrackList.add(track);
}
} else {
for (Integer task : worker.getTasks()) {
ResourceWorkerSlot oldWorker = old.getWorkerByTaskId(task);
if (oldWorker != null) {
// update end time of old task
TaskTrack oldTrack = new TaskTrack(event.getClusterMetricsContext().getClusterName(), event.getTopologyId());
oldTrack.setEnd(new Date(event.getTimestamp()));
oldTrack.setTaskId(task);
oldTrack.setHost(oldWorker.getHostname());
oldTrack.setPort(oldWorker.getPort());
taskTrackList.add(oldTrack);
// insert new task
TaskTrack track = new TaskTrack(event.getClusterMetricsContext().getClusterName(), event.getTopologyId());
track.setStart(new Date());
track.setComponent(task2Component.get(task));
track.setHost(worker.getHostname());
track.setPort(worker.getPort());
track.setTaskId(task);
taskTrackList.add(track);
}
}
}
}
}
if (taskTrackList.size() > 0) {
batchAdd(taskTrackList, TABLE_TASK_TRACK);
}
}
Aggregations