Package com.taobao.zeus.model

Examples of com.taobao.zeus.model.JobHistory


  private WebResponse processManualCancel(MasterContext context,
      WebRequest req) {
    WebResponse ret = null;
    String historyId = req.getId();
    JobHistory history = context.getJobHistoryManager().findJobHistory(
        historyId);
    SocketLog.info("receive web cancel request,rid=" + req.getRid()
        + ",jobId=" + history.getJobId());
    String jobId = history.getId();
    for (String job : new ArrayList<String>(context.getManualQueue())) {
      if (job.equals(historyId)) {
        if (context.getManualQueue().remove(job)) {
          ret = WebResponse.newBuilder().setRid(req.getRid())
              .setOperate(req.getOperate()).setStatus(Status.OK)
              .build();
          history.getLog().appendZeus("任务被取消");
          context.getJobHistoryManager().updateJobHistoryLog(
              history.getId(), history.getLog().getContent());
          break;
        }
      }
    }
    if (history.getTriggerType() == TriggerType.MANUAL) {
      for (Channel key : new HashSet<Channel>(context.getWorkers()
          .keySet())) {
        MasterWorkerHolder worker = context.getWorkers().get(key);
        if (worker.getManualRunnings().containsKey(historyId)) {
          Future<Response> f = new MasterCancelJob().cancel(context,
              worker.getChannel(), ExecuteKind.ManualKind,
              historyId);
          worker.getManualRunnings().remove(historyId);
          try {
            f.get(30, TimeUnit.SECONDS);
          } catch (Exception e) {
          }
          ret = WebResponse.newBuilder().setRid(req.getRid())
              .setOperate(req.getOperate()).setStatus(Status.OK)
              .build();
          SocketLog.info("send web cancel response,rid="
              + req.getRid() + ",jobId=" + jobId);
        }
      }
    }

    if (ret == null) {
      // 找不到job,失败
      ret = WebResponse.newBuilder().setRid(req.getRid())
          .setOperate(req.getOperate()).setStatus(Status.ERROR)
          .setErrorText("Mannual任务中找不到匹配的job("+history.getJobId()+","+history.getId()+"),无法执行取消命令").build();
    }

    history = context.getJobHistoryManager().findJobHistory(historyId);
    history.setEndTime(new Date());
    history.setStatus(com.taobao.zeus.model.JobStatus.Status.FAILED);
    context.getJobHistoryManager().updateJobHistory(history);

    return ret;
  }
View Full Code Here


  private WebResponse processScheduleCancel(MasterContext context,
      WebRequest req) {
    WebResponse ret = null;
    String historyId = req.getId();
    JobHistory history = context.getJobHistoryManager().findJobHistory(
        historyId);
    SocketLog.info("receive web cancel request,rid=" + req.getRid()
        + ",jobId=" + history.getJobId());
    String jobId = history.getJobId();
    for (String job : new ArrayList<String>(context.getQueue())) {
      if (job.equals(jobId)) {
        if (context.getQueue().remove(job)) {
          ret = WebResponse.newBuilder().setRid(req.getRid())
              .setOperate(req.getOperate()).setStatus(Status.OK)
              .build();
          history.getLog().appendZeus("任务被取消");
          context.getJobHistoryManager().updateJobHistoryLog(
              history.getId(), history.getLog().getContent());
          break;
        }
      }
    }
    for (Channel key : new HashSet<Channel>(context.getWorkers().keySet())) {
      MasterWorkerHolder worker = context.getWorkers().get(key);
      if (worker.getRunnings().containsKey(jobId)) {
        Future<Response> f = new MasterCancelJob().cancel(context,
            worker.getChannel(), ExecuteKind.ScheduleKind,
            historyId);
        worker.getRunnings().remove(jobId);
        try {
          f.get(10, TimeUnit.SECONDS);
        } catch (Exception e) {
        }
        ret = WebResponse.newBuilder().setRid(req.getRid())
            .setOperate(req.getOperate()).setStatus(Status.OK)
            .build();
        SocketLog.info("send web cancel response,rid=" + req.getRid()
            + ",jobId=" + jobId);
      }
    }

    if (ret == null) {
      // 数据库设置状态
      JobStatus js = context.getGroupManager().getJobStatus(jobId);
      js.setStatus(com.taobao.zeus.model.JobStatus.Status.WAIT);
      js.setHistoryId(null);
      context.getGroupManager().updateJobStatus(js);
      // 找不到job,失败
      ret = WebResponse.newBuilder().setRid(req.getRid())
          .setOperate(req.getOperate()).setStatus(Status.ERROR)
          .setErrorText("Schedule任务中找不到匹配的job("+history.getJobId()+","+history.getId()+"),无法执行取消命令").build();
    }
    history = context.getJobHistoryManager().findJobHistory(historyId);
    history.setEndTime(new Date());
    history.setStatus(com.taobao.zeus.model.JobStatus.Status.FAILED);
    context.getJobHistoryManager().updateJobHistory(history);
    return ret;
  }
View Full Code Here

 
  public static JobHistory convert(JobHistoryPersistence persist){
    if(persist==null){
      return null;
    }
    JobHistory history=new JobHistory();
    history.setId(String.valueOf(persist.getId()));
    history.setJobId(String.valueOf(persist.getJobId()));
    history.setStartTime(persist.getStartTime());
    history.setEndTime( persist.getEndTime());
    history.setLog(persist.getLog());
    history.setExecuteHost(persist.getExecuteHost());
    history.setStatus(Status.parser(persist.getStatus()));
    history.setTriggerType(persist.getTriggerType()==null?null:TriggerType.parser(persist.getTriggerType()));
    history.setIllustrate(persist.getIllustrate());
    history.setOperator(persist.getOperator());
    Map<String, String> prop=new HashMap<String, String>();
    if(persist.getProperties()!=null){
      JSONObject json=JSONObject.fromObject(persist.getProperties());
      for(Object key:json.keySet()){
        prop.put(key.toString(), json.getString(key.toString()));
      }
    }
    history.setProperties(prop);
    return history;
  }
View Full Code Here

    service.scheduleAtFixedRate(new Runnable() {

      private void exLog(Job job,Exception e){
        try {
          JobHistory his = job.getJobContext().getJobHistory();
          String jlog = his.getLog().getContent();
          if (jlog == null) {
            jlog = "";
          }
          log.error(new StringBuilder("log output error!\n")
                  .append("[jobId:").append(his.getJobId())
                  .append(", hisId:").append(his.getId())
                  .append(", logLength:")
                  .append(jlog.length()).append("]")
                  .toString(), e);
        } catch (Exception ex) {
          log.error("log exception error!");
        }
      }

      private void exDebugLog(Job job, Exception e) {
        try {
          DebugHistory his = job.getJobContext().getDebugHistory();
          String jlog = his.getLog().getContent();
          if (jlog == null) {
            jlog = "";
          }
          log.error(new StringBuilder("log output error!\n")
                  .append("[fileId:").append(his.getFileId())
                  .append(", hisId:").append(his.getId())
                  .append(", logLength:")
                  .append(jlog.length()).append("]")
                  .toString(), e);
        } catch (Exception ex) {
          log.error("log exception error!");
        }
      }
     
      public void run() {

        for (Job job : new HashSet<Job>(context.getRunnings().values())) {
          try {
            JobHistory his = job.getJobContext().getJobHistory();
            context.getJobHistoryManager().updateJobHistoryLog(
                his.getId(), his.getLog().getContent());
          } catch (Exception e) {
            exLog(job, e);
          }
        }
        for (Job job : new HashSet<Job>(context.getManualRunnings()
            .values())) {
          try {
            JobHistory his = job.getJobContext().getJobHistory();
            context.getJobHistoryManager().updateJobHistoryLog(
                his.getId(), his.getLog().getContent());
          } catch (Exception e) {
            exLog(job, e);
          }
        }
        for (Job job : new HashSet<Job>(context.getDebugRunnings()
            .values())) {
          try {
            DebugHistory his = job.getJobContext()
                .getDebugHistory();
            context.getDebugHistoryManager().updateDebugHistoryLog(
                his.getId(), his.getLog().getContent());
          } catch (Exception e) {
            exDebugLog(job, e);
          }
        }
View Full Code Here

  public void cancelManualJob(String historyId) {
    Job job = context.getManualRunnings().get(historyId);
    context.getManualRunnings().remove(historyId);
    job.cancel();

    JobHistory his = job.getJobContext().getJobHistory();
    his.setEndTime(new Date());
    his.setStatus(com.taobao.zeus.model.JobStatus.Status.FAILED);
    context.getJobHistoryManager().updateJobHistory(his);
    his.getLog().appendZeus("任务被取消");
    context.getJobHistoryManager().updateJobHistoryLog(his.getId(),
        his.getLog().getContent());
  }
View Full Code Here

  public void cancelScheduleJob(String jobId) {
    Job job = context.getRunnings().get(jobId);
    context.getRunnings().remove(jobId);
    job.cancel();

    JobHistory his = job.getJobContext().getJobHistory();
    his.setEndTime(new Date());
    his.setStatus(com.taobao.zeus.model.JobStatus.Status.FAILED);
    context.getJobHistoryManager().updateJobHistory(his);
    his.getLog().appendZeus("任务被取消");
    context.getJobHistoryManager().updateJobHistoryLog(his.getId(),
        his.getLog().getContent());
  }
View Full Code Here

      if(jobStatus.getStatus()==Status.RUNNING){
        log.error("jobId="+jobId+" 处于RUNNING状态,说明该JOB状态丢失,立即进行重试操作...");
        //搜索上一次运行的日志,从日志中提取jobid 进行kill
        String operator=null;
        if(jobStatus.getHistoryId()!=null){
          JobHistory history=jobHistoryManager.findJobHistory(jobStatus.getHistoryId());
          operator=history.getOperator();
          if(history.getStatus()==Status.RUNNING){
            try {
              JobContext temp=JobContext.getTempJobContext();
              temp.setJobHistory(history);
              new CancelHadoopJob(temp).run();
            } catch (Exception e) {
              //忽略
            }
          }
        }
        JobHistory history=new JobHistory();
        history.setIllustrate("启动服务器发现正在running状态,判断状态已经丢失,进行重试操作");
        history.setOperator(operator);
        history.setTriggerType(TriggerType.MANUAL_RECOVER);
        context.getJobHistoryManager().addJobHistory(history);
        master.run(history);
      }
    }
   
View Full Code Here

        break;
      }
    }
    if(allComplete){
      ScheduleInfoLog.info("JobId:"+jobId+" all dependency jobs is ready,run!");
      JobHistory history=new JobHistory();
      history.setIllustrate("依赖任务全部到位,开始执行");
      history.setTriggerType(TriggerType.SCHEDULE);
      history.setJobId(jobId);
      context.getJobHistoryManager().addJobHistory(history);
      history=master.run(history);
      if(history.getStatus()==Status.FAILED){
        ZeusJobException exception=new ZeusJobException(history.getJobId(),history.getLog().getContent());
        JobFailedEvent jfe=new JobFailedEvent(jobDescriptor.getId(),event.getTriggerType(),history,exception);
        ScheduleInfoLog.info("JobId:"+jobId+" is fail,dispatch the fail event");
        //广播消息
        context.getDispatcher().forwardEvent(jfe);
      }
View Full Code Here

        //自身依赖的Job失败了,表明自身也无法继续执行,抛出失败的消息
        ZeusJobException exception=new ZeusJobException(event.getJobException().getCauseJobId(),"jobId:"+jobDescriptor.getId()+" 失败,原因是依赖的Job:"+event.getJobId()+" 执行失败",
            event.getJobException());
        ScheduleInfoLog.info("jobId:"+jobId+" is fail,as dependendy jobId:"+jobDescriptor.getId()+" is failed");
        //记录进History日志
        JobHistory history=new JobHistory();
        history.setStartTime(new Date());
        history.setEndTime(new Date());
        history.setExecuteHost(null);
        history.setJobId(jobId);
        history.setTriggerType(event.getTriggerType());
        history.setStatus(Status.FAILED);
        history.getLog().appendZeusException(exception);
        history=jobHistoryManager.addJobHistory(history);
        jobHistoryManager.updateJobHistoryLog(history.getId(), history.getLog().getContent());
       
       
        JobFailedEvent jfe=new JobFailedEvent(jobDescriptor.getId(),event.getTriggerType(),history,exception);
       
        ScheduleInfoLog.info("JobId:"+jobId+" is fail,dispatch the fail event");
View Full Code Here

    }
    if(!eId.equals(jobDescriptor.getId())){
      return;
    }
    ScheduleInfoLog.info("JobId:"+jobId+" receive a timer trigger event");
    JobHistory history=new JobHistory();
    history.setJobId(jobDescriptor.getId());
    history.setTriggerType(TriggerType.SCHEDULE);
    context.getJobHistoryManager().addJobHistory(history);
    master.run(history);
  }
View Full Code Here

TOP

Related Classes of com.taobao.zeus.model.JobHistory

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.