Package com.alibaba.jstorm.cluster

Examples of com.alibaba.jstorm.cluster.StormClusterState


   *     skip check
   * @param data
   */
  @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) {

        LOG.debug("Check tasks " + topologyid);

        // Attention, here don't check /ZK-dir/taskbeats/topologyid to
        // get task ids
        List<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);

        boolean needReassign = false;
        for (Integer task : taskIds) {
          boolean isTaskDead = NimbusUtils.isTaskDead(data,
              topologyid, task);
          if (isTaskDead == true) {
            LOG.info("Found " + topologyid + ",taskid:" + task
                + " is dead");
           
            ResourceWorkerSlot resource = null;
            if (assignment != null)
              resource = assignment.getWorkerByTaskId(task);
            if (resource != null) {
              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);
            }
            needReassign = true;
          }
        }
        if (needReassign == true) {
View Full Code Here


    /*
     * Step 2: create ZK operation instance StromClusterState
     */

    StormClusterState stormClusterState = Cluster
        .mk_storm_cluster_state(conf);

    /*
     * Step 3, create LocalStat LocalStat is one KV database 4.1 create
     * LocalState instance 4.2 get supervisorId, if no supervisorId, create
View Full Code Here

      updateWorkerMetricsToZK(workerMetricList, metricPerf);
      updateUserDefMetricsToZK(metricPerf);
    }
   
    private void updateTaskMetricsToZK(Map<String, List<MetricInfo>> metricMap, boolean metricPerf) {
        StormClusterState clusterState = workerData.getZkCluster();
      String topologyId = workerData.getTopologyId();
     
      for(Entry<String, List<MetricInfo>> entry : metricMap.entrySet()) {
        String taskId = entry.getKey();
        List<MetricInfo> MetricList = entry.getValue();
       
        try {
          String component = clusterState.task_info(topologyId, Integer.valueOf(taskId)).getComponentId();
            TaskMetricInfo taskMetricInfo = new TaskMetricInfo(taskId, component);
           
              for(MetricInfo metricInfo : MetricList) {
              taskMetricInfo.updateMetricData(metricInfo);
              }
             
              List<String> errors = taskMetricInfo.anyQueueFull();
              if (errors.size() > 0) {
                for (String error : errors)
                      clusterState.report_task_error(topologyId, Integer.valueOf(taskId), error);
              }
             
            clusterState.update_task_metric(topologyId, taskId, taskMetricInfo);
        } catch(Exception e) {
          logger.error(marker, "Failed to update metrics data in ZK for topo-{} task-{}.",
                    topologyId, taskId, e);
      }
      }
View Full Code Here

   
    return value;
  }
   
    private void updateWorkerMetricsToZK(List<MetricInfo> metricList, boolean metricPerf) {
        StormClusterState clusterState = workerData.getZkCluster();
      String topologyId = workerData.getTopologyId();
      String hostName;

      hostName = JStormServerUtils.getHostName(workerData.getConf());
      String workerId = hostName + ":" + workerData.getPort();
     
      WorkerMetricInfo workerMetricInfo = new WorkerMetricInfo(hostName, workerData.getPort());
      try {
        //Set metrics data
          for(MetricInfo metricInfo : metricList) {   
          workerMetricInfo.updateMetricData(metricInfo)
        }
         
          //Set cpu & memory usage
          Runtime rt=Runtime.getRuntime();
          long usedMem = rt.totalMemory() - rt.freeMemory();
          workerMetricInfo.setUsedMem(usedMem);  
         
          workerMetricInfo.setUsedCpu(getCpuUsage());
             
          clusterState.update_worker_metric(topologyId, workerId, workerMetricInfo);
      } catch(Exception e) {
        logger.error(marker, "Failed to update metrics data in ZK for topo-{} idStr-{}.",
                topologyId, workerId, e);
      }
    }
View Full Code Here

                topologyId, workerId, e);
      }
    }
   
    private void updateUserDefMetricsToZK(boolean metricPerf) {
      StormClusterState clusterState = workerData.getZkCluster();
      String topologyId = workerData.getTopologyId();
      String hostName =JStormServerUtils.getHostName(workerData.getConf());
      String workerId = hostName + ":" + workerData.getPort();
     
      UserDefMetric userDefMetric = Metrics.getUserDefMetric();
      UserDefMetricData userDefMetricData = new UserDefMetricData();
      userDefMetricData.updateFromGauge(userDefMetric.getGauge());
      userDefMetricData.updateFromCounter(userDefMetric.getCounter());
      userDefMetricData.updateFromMeterData(userDefMetric.getMeter());
      // If metrics performance is disable, Timer & Histogram metrics will not be monitored,
      // and the corresponding metrics data will not be sent to ZK either.
      if (metricPerf == false) {
         userDefMetricData.updateFromHistogramData(userDefMetric.getHistogram());
         userDefMetricData.updateFromTimerData(userDefMetric.getTimer());
      }

      try {
          clusterState.update_userDef_metric(topologyId, workerId, userDefMetricData);
      } catch(Exception e) {
        logger.error(marker, "Failed to update user define metrics data in ZK for topo-{} idStr-{}.",
                topologyId, workerId, e);
      }
     
View Full Code Here

TOP

Related Classes of com.alibaba.jstorm.cluster.StormClusterState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.