Search in sources :

Example 1 with TaskTrack

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);
}
Also used : KVSerializable(com.alibaba.jstorm.metric.KVSerializable) ArrayList(java.util.ArrayList) TaskTrack(com.alibaba.jstorm.common.metric.TaskTrack) Map(java.util.Map) Date(java.util.Date) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Example 2 with TaskTrack

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);
    }
}
Also used : Joiner(com.google.common.base.Joiner) ArrayList(java.util.ArrayList) Date(java.util.Date) Assignment(com.alibaba.jstorm.schedule.Assignment) KVSerializable(com.alibaba.jstorm.metric.KVSerializable) TaskTrack(com.alibaba.jstorm.common.metric.TaskTrack) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Aggregations

TaskTrack (com.alibaba.jstorm.common.metric.TaskTrack)2 KVSerializable (com.alibaba.jstorm.metric.KVSerializable)2 ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Assignment (com.alibaba.jstorm.schedule.Assignment)1 Joiner (com.google.common.base.Joiner)1 Map (java.util.Map)1