Search in sources :

Example 6 with TopologyTaskHbInfo

use of backtype.storm.generated.TopologyTaskHbInfo in project jstorm by alibaba.

the class NimbusUtils method updateTopologyTaskHb.

public static void updateTopologyTaskHb(NimbusData data, String topologyId) {
    StormClusterState clusterState = data.getStormClusterState();
    TopologyTaskHbInfo topologyTaskHb = null;
    try {
        topologyTaskHb = clusterState.topology_heartbeat(topologyId);
    } catch (Exception e) {
        LOG.error("updateTopologyTaskHb: Failed to get topology task heartbeat info", e);
    }
    if (topologyTaskHb != null) {
        data.getTasksHeartbeat().put(topologyId, topologyTaskHb);
    }
}
Also used : StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) TopologyTaskHbInfo(backtype.storm.generated.TopologyTaskHbInfo) NotAliveException(backtype.storm.generated.NotAliveException) InvalidParameterException(java.security.InvalidParameterException)

Example 7 with TopologyTaskHbInfo

use of backtype.storm.generated.TopologyTaskHbInfo in project jstorm by alibaba.

the class MonitorRunnable method run.

/**
     * @@@ Todo when one topology is being reassigned, the topology should skip check
     */
@Override
public void run() {
    StormClusterState clusterState = data.getStormClusterState();
    try {
        // Attetion, need first check Assignments
        List<String> active_topologys = clusterState.assignments(null);
        if (active_topologys == null) {
            LOG.info("Failed to get active topologies");
            return;
        }
        for (String topologyid : active_topologys) {
            if (clusterState.storm_base(topologyid, null) == null) {
                continue;
            }
            LOG.debug("Check tasks " + topologyid);
            // Attention, here don't check /ZK-dir/taskbeats/topologyid to
            // get task ids
            Set<Integer> taskIds = clusterState.task_ids(topologyid);
            if (taskIds == null) {
                LOG.info("Failed to get task ids of " + topologyid);
                continue;
            }
            Assignment assignment = clusterState.assignment_info(topologyid, null);
            Set<Integer> deadTasks = new HashSet<Integer>();
            boolean needReassign = false;
            for (Integer task : taskIds) {
                boolean isTaskDead = NimbusUtils.isTaskDead(data, topologyid, task);
                if (isTaskDead) {
                    deadTasks.add(task);
                    needReassign = true;
                }
            }
            TopologyTaskHbInfo topologyHbInfo = data.getTasksHeartbeat().get(topologyid);
            if (needReassign) {
                if (topologyHbInfo != null) {
                    int topologyMasterId = topologyHbInfo.get_topologyMasterId();
                    if (deadTasks.contains(topologyMasterId)) {
                        deadTasks.clear();
                        if (assignment != null) {
                            ResourceWorkerSlot resource = assignment.getWorkerByTaskId(topologyMasterId);
                            if (resource != null)
                                deadTasks.addAll(resource.getTasks());
                            else
                                deadTasks.add(topologyMasterId);
                        }
                    } else {
                        Map<Integer, TaskHeartbeat> taskHbs = topologyHbInfo.get_taskHbs();
                        int launchTime = JStormUtils.parseInt(data.getConf().get(Config.NIMBUS_TASK_LAUNCH_SECS));
                        if (taskHbs == null || taskHbs.get(topologyMasterId) == null || taskHbs.get(topologyMasterId).get_uptime() < launchTime) {
                            /*try {
                                    clusterState.topology_heartbeat(topologyid, topologyHbInfo);
                                } catch (Exception e) {
                                    LOG.error("Failed to update task heartbeat info to ZK for " + topologyid, e);
                                }*/
                            return;
                        }
                    }
                    Map<Integer, ResourceWorkerSlot> deadTaskWorkers = new HashMap<>();
                    for (Integer task : deadTasks) {
                        LOG.info("Found " + topologyid + ",taskid:" + task + " is dead");
                        ResourceWorkerSlot resource = null;
                        if (assignment != null)
                            resource = assignment.getWorkerByTaskId(task);
                        if (resource != null) {
                            deadTaskWorkers.put(task, resource);
                            Date now = new Date();
                            String nowStr = TimeFormat.getSecond(now);
                            String errorInfo = "Task-" + task + " is dead on " + resource.getHostname() + ":" + resource.getPort() + ", " + nowStr;
                            LOG.info(errorInfo);
                            clusterState.report_task_error(topologyid, task, errorInfo, ErrorConstants.ERROR, ErrorConstants.CODE_TASK_DEAD, ErrorConstants.DURATION_SECS_TASK_DEAD);
                        }
                    }
                    if (deadTaskWorkers.size() > 0) {
                        // notify jstorm monitor
                        TaskDeadEvent.pushEvent(topologyid, deadTaskWorkers);
                    }
                }
                NimbusUtils.transition(data, topologyid, false, StatusType.monitor);
            }
            if (topologyHbInfo != null) {
                try {
                    clusterState.topology_heartbeat(topologyid, topologyHbInfo);
                } catch (Exception e) {
                    LOG.error("Failed to update task heartbeat info to ZK for " + topologyid, e);
                }
            }
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) TopologyTaskHbInfo(backtype.storm.generated.TopologyTaskHbInfo) Date(java.util.Date) TaskHeartbeat(backtype.storm.generated.TaskHeartbeat) StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) HashSet(java.util.HashSet) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Example 8 with TopologyTaskHbInfo

use of backtype.storm.generated.TopologyTaskHbInfo in project jstorm by alibaba.

the class ZooKeeperDataViewTest method viewTaskbeats.

@Test
public void viewTaskbeats() throws Exception {
    if (SKIP == true) {
        return;
    }
    List<String> assignments = zkobj.getChildren(zk, Cluster.TASKBEATS_SUBTREE, false);
    for (String child : assignments) {
        byte[] data = zkobj.getData(zk, Cluster.taskbeat_storm_root(child), false);
        TopologyTaskHbInfo taskHbInfo = (TopologyTaskHbInfo) Utils.maybe_deserialize(data);
        System.out.println(gson.toJson(taskHbInfo));
    }
}
Also used : TopologyTaskHbInfo(backtype.storm.generated.TopologyTaskHbInfo) Test(org.junit.Test)

Aggregations

TopologyTaskHbInfo (backtype.storm.generated.TopologyTaskHbInfo)8 TaskHeartbeat (backtype.storm.generated.TaskHeartbeat)5 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)3 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)2 NotAliveException (backtype.storm.generated.NotAliveException)2 ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)2 TaskInfo (com.alibaba.jstorm.task.TaskInfo)2 InvalidParameterException (java.security.InvalidParameterException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AlreadyAliveException (backtype.storm.generated.AlreadyAliveException)1 ComponentSummary (backtype.storm.generated.ComponentSummary)1 ErrorInfo (backtype.storm.generated.ErrorInfo)1 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)1 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)1 MetricInfo (backtype.storm.generated.MetricInfo)1 TaskSummary (backtype.storm.generated.TaskSummary)1 TopologyAssignException (backtype.storm.generated.TopologyAssignException)1 TopologyInfo (backtype.storm.generated.TopologyInfo)1