Package com.alibaba.jstorm.cluster

Examples of com.alibaba.jstorm.cluster.StormClusterState


   *
   */
  public static void cleanupCorruptTopologies(NimbusData data)
      throws Exception {

    StormClusterState stormClusterState = data.getStormClusterState();

    // get /local-storm-dir/nimbus/stormdist path
    String master_stormdist_root = StormConfig.masterStormdistRoot(data
        .getConf());

    // listdir /local-storm-dir/nimbus/stormdist
    List<String> code_ids = PathUtils
        .read_dir_contents(master_stormdist_root);

    // get topology in ZK /storms
    List<String> active_ids = data.getStormClusterState().active_storms();
    if (active_ids != null && active_ids.size() > 0) {
      if (code_ids != null) {
        // clean the topology which is in ZK but not in local dir
        active_ids.removeAll(code_ids);
      }

      for (String corrupt : active_ids) {
        LOG.info("Corrupt topology "
            + corrupt
            + " has state on zookeeper but doesn't have a local dir on Nimbus. Cleaning up...");

        /**
         * Just removing the /STORMS is enough
         *
         */
        stormClusterState.remove_storm(corrupt);
      }
    }

    LOG.info("Successfully cleanup all old toplogies");

View Full Code Here


      Integer taskId) {
    String idStr = " topology:" + topologyId + ",taskid:" + taskId;

    Integer zkReportTime = null;

    StormClusterState stormClusterState = data.getStormClusterState();
    TaskHeartbeat zkTaskHeartbeat = null;
    try {
      zkTaskHeartbeat = stormClusterState.task_heartbeat(topologyId,
          taskId);
      if (zkTaskHeartbeat != null) {
        zkReportTime = zkTaskHeartbeat.getTimeSecs();
      }
    } catch (Exception e) {
View Full Code Here

  }

  public static <T> void transitionName(NimbusData data, String topologyName,
      boolean errorOnNoTransition, StatusType transition_status,
      T... args) throws Exception {
    StormClusterState stormClusterState = data.getStormClusterState();
    String topologyId = Cluster.get_topology_id(stormClusterState,
        topologyName);
    if (topologyId == null) {
      throw new NotAliveException(topologyName);
    }
View Full Code Here

  public static void updateMetricsInfo(NimbusData data, String topologyId,
      Assignment assignment) {
    List<Integer> taskList = new ArrayList<Integer>();
    List<String> workerList = new ArrayList<String>();
   
    StormClusterState clusterState = data.getStormClusterState();
   
    Set<ResourceWorkerSlot> workerSlotSet = assignment.getWorkers();
   
    for (ResourceWorkerSlot workerSlot : workerSlotSet) {
      String workerId = workerSlot.getHostname() + ":" + workerSlot.getPort();
      workerList.add(workerId);
     
      taskList.addAll(workerSlot.getTasks());
    }
   
    try {
        //Remove the obsolete tasks of metrics monitor in ZK
        List<String> metricTaskList = clusterState.get_metric_taskIds(topologyId);
        for (String task : metricTaskList) {
          Integer taskId = Integer.valueOf(task);
          if(taskList.contains(taskId) == false)
            clusterState.remove_metric_task(topologyId, String.valueOf(taskId));
        }
       
        //Remove the obsolete workers of metrics monitor in ZK
        List<String> metricWorkerList = clusterState.get_metric_workerIds(topologyId);
        for (String workerId : metricWorkerList) {
          if (workerList.contains(workerId) == false)
            clusterState.remove_metric_worker(topologyId, workerId);
        }
       
        //Remove the obsolete user workers of metrics monitor in ZK
        List<String> metricUserList = clusterState.get_metric_users(topologyId);
        for (String workerId : metricUserList) {
          if (workerList.contains(workerId) == false)
            clusterState.remove_metric_user(topologyId, workerId);
        }
    } catch (Exception e) {
      LOG.error("Failed to update metrics info when rebalance or reassignment, topologyId=" +
                  topologyId, e);
    }
View Full Code Here

      Common.validate_basic(normalizedTopology, totalStormConf,
          topologyId);
      // don't need generate real topology, so skip Common.system_topology
      // Common.system_topology(totalStormConf, topology);

      StormClusterState stormClusterState = data.getStormClusterState();

      // create /local-dir/nimbus/topologyId/xxxx files
      setupStormCode(conf, topologyId, uploadedJarLocation, stormConf,
          normalizedTopology);
View Full Code Here

                FileUtils.writeByteArrayToFile(stormCodeFile, Utils.serialize(normalizedTopology));
        }
       
      // generate TaskInfo for every bolt or spout in ZK
      // /ZK/tasks/topoologyId/xxx
            StormClusterState stormClusterState = data.getStormClusterState();
      setupZkTaskInfo(conf, topologyId, stormClusterState);

      // make assignments for a topology
      LOG.info("Submit for " + topologyname + " with conf " + jsonConf);
            makeAssignment(topologyname, topologyId, TopologyInitialStatus.ACTIVE);
View Full Code Here

  @Override
  public ClusterSummary getClusterInfo() throws TException {

    try {

      StormClusterState stormClusterState = data.getStormClusterState();

      Map<String, Assignment> assignments = new HashMap<String, Assignment>();

      // get nimbus running time
      int uptime = data.uptime();

      // get TopologySummary
      List<TopologySummary> topologySummaries = new ArrayList<TopologySummary>();

      // get all active topology's StormBase
      Map<String, StormBase> bases = Cluster
          .topology_bases(stormClusterState);
      for (Entry<String, StormBase> entry : bases.entrySet()) {

        String topologyId = entry.getKey();
        StormBase base = entry.getValue();

        Assignment assignment = stormClusterState.assignment_info(
            topologyId, null);
        if (assignment == null) {
          LOG.error("Failed to get assignment of " + topologyId);
          continue;
        }
        assignments.put(topologyId, assignment);

        Map<Integer, String> lastErrTimeStamp = null;
        try {
            lastErrTimeStamp = stormClusterState.topo_lastErr_time(topologyId);
        } catch (Exception e) {
          LOG.error("Failed to get last error timestamp map for "+ topologyId +
              ", and begin to remove the corrupt data", e);
          try {
            stormClusterState.remove_lastErr_time(topologyId);
          } catch (Exception rmErr) {
            LOG.error("Failed to remove last error timestamp in ZK for " + topologyId, rmErr);
          }
        }
       
View Full Code Here

  @Override
  public SupervisorWorkers getSupervisorWorkers(String host)
      throws NotAliveException, TException {
    try {
      StormClusterState stormClusterState = data.getStormClusterState();

      String supervisorId = null;
      SupervisorInfo supervisorInfo = null;

      String ip = NetWorkUtils.host2Ip(host);
      String hostName = NetWorkUtils.ip2Host(host);

      // all supervisors
      Map<String, SupervisorInfo> supervisorInfos = Cluster
          .allSupervisorInfo(stormClusterState, null);

      for (Entry<String, SupervisorInfo> entry : supervisorInfos
          .entrySet()) {

        SupervisorInfo info = entry.getValue();
        if (info.getHostName().equals(hostName)
            || info.getHostName().equals(ip)) {
          supervisorId = entry.getKey();
          supervisorInfo = info;
          break;
        }
      }

      if (supervisorId == null) {
        throw new TException("No supervisor of " + host);
      }

      Map<String, Assignment> assignments = new HashMap<String, Assignment>();

      // get all active topology's StormBase
      Map<String, StormBase> bases = Cluster
          .topology_bases(stormClusterState);
      for (Entry<String, StormBase> entry : bases.entrySet()) {

        String topologyId = entry.getKey();
        StormBase base = entry.getValue();

        Assignment assignment = stormClusterState.assignment_info(
            topologyId, null);
        if (assignment == null) {
          LOG.error("Failed to get assignment of " + topologyId);
          continue;
        }
View Full Code Here

  public TopologyInfo getTopologyInfo(String topologyId)
      throws NotAliveException, TException {

    TopologyInfo topologyInfo = new TopologyInfo();

    StormClusterState stormClusterState = data.getStormClusterState();

    try {

      // get topology's StormBase
      StormBase base = stormClusterState.storm_base(topologyId, null);
      if (base == null) {
        throw new NotAliveException("No topology of " + topologyId);
      }
      topologyInfo.set_id(topologyId);
      topologyInfo.set_name(base.getStormName());
      topologyInfo.set_uptime_secs(TimeUtils.time_delta(base
          .getLanchTimeSecs()));
      topologyInfo.set_status(base.getStatusString());

      // get topology's Assignment
      Assignment assignment = stormClusterState.assignment_info(
          topologyId, null);
      if (assignment == null) {
        throw new TException("Failed to get StormBase from ZK of "
            + topologyId);
      }
View Full Code Here

 
  @Override
  public void metricMonitor(String topologyName, MonitorOptions options) throws NotAliveException,
          TException {
    boolean isEnable = options.is_isEnable();
    StormClusterState clusterState = data.getStormClusterState();
   
    try {
        String topologyId = Cluster.get_topology_id(clusterState, topologyName);
        if (null != topologyId) {
          NimbusUtils.updateMetricMonitorStatus(clusterState, topologyId, isEnable);
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.