Package com.taobao.zeus.model

Examples of com.taobao.zeus.model.JobHistory


*/
public class JobContext {
 
  public static JobContext getTempJobContext(){
    JobContext jobContext=new JobContext();
    JobHistory history=new JobHistory();
    jobContext.setJobHistory(history);
    jobContext.setWorkDir("/tmp");
    jobContext.setProperties(new HierarchyProperties(new HashMap<String, String>()));
    return jobContext;
  }
View Full Code Here


    SocketLog.info("master scan and poll historyId=" + historyId
        + " and run!");
    new Thread() {
      @Override
      public void run() {
        JobHistory history = context.getJobHistoryManager()
            .findJobHistory(historyId);
        history.getLog().appendZeus(
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(new Date()) + " 开始运行");
        context.getJobHistoryManager().updateJobHistoryLog(historyId,
            history.getLog().getContent());
        Exception exception = null;
        Response resp = null;
        try {
          Future<Response> f = new MasterExecuteJob().executeJob(
              context, w, ExecuteKind.ManualKind, historyId);
          resp = f.get();
        } catch (Exception e) {
          exception = e;
          ScheduleInfoLog.error("JobId:" + history.getJobId()
              + " run failed", e);
        }
        boolean success = resp.getStatus() == Status.OK ? true : false;

        if (!success) {
          // 运行失败,更新失败状态,发出失败消息
          ZeusJobException jobException = null;
          if (exception != null) {
            jobException = new ZeusJobException(history.getJobId(),
                String.format("JobId:%s run failed ",
                    history.getJobId()), exception);
          } else {
            jobException = new ZeusJobException(history.getJobId(),
                String.format("JobId:%s run failed ",
                    history.getJobId()));
          }
          ScheduleInfoLog.info("jobId:" + history.getJobId()
              + " run fail ");
          history = context.getJobHistoryManager().findJobHistory(
              historyId);
          JobFailedEvent jfe = new JobFailedEvent(history.getJobId(),
              history.getTriggerType(), history, jobException);
          context.getDispatcher().forwardEvent(jfe);
        } else {
          // 运行成功,发出成功消息
          ScheduleInfoLog.info("manual jobId::" + history.getJobId()
              + " run success");
          JobSuccessEvent jse = new JobSuccessEvent(
              history.getJobId(), history.getTriggerType(),
              historyId);
          context.getDispatcher().forwardEvent(jse);
        }
      };
    }.start();
View Full Code Here

    final String jobId = context.getQueue().poll();
    SocketLog.info("master scan and poll jobId=" + jobId + " and run!");
    new Thread() {
      @Override
      public void run() {
        JobHistory his = context.getJobHistoryManager().findJobHistory(
            context.getGroupManager().getJobStatus(jobId)
                .getHistoryId());
        TriggerType type = his.getTriggerType();
        ScheduleInfoLog.info("JobId:" + jobId + " run start");
        his.getLog().appendZeus(
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(new Date()) + " 开始运行");
        context.getJobHistoryManager().updateJobHistoryLog(his.getId(),
            his.getLog().getContent());
        Exception exception = null;
        Response resp = null;
        try {
          Future<Response> f = new MasterExecuteJob().executeJob(
              context, w, ExecuteKind.ScheduleKind, his.getId());
          resp = f.get();
        } catch (Exception e) {
          exception = e;
          ScheduleInfoLog.error(
              String.format("JobId:%s run failed", jobId), e);
        }
        boolean success = resp.getStatus() == Status.OK ? true : false;

        JobStatus jobstatus = context.getGroupManager().getJobStatus(
            jobId);
        jobstatus
            .setStatus(com.taobao.zeus.model.JobStatus.Status.WAIT);
        if (success
            && (his.getTriggerType() == TriggerType.SCHEDULE || his
                .getTriggerType() == TriggerType.MANUAL_RECOVER)) {
          ScheduleInfoLog.info("JobId:" + jobId
              + " clear ready dependency");
          jobstatus.setReadyDependency(new HashMap<String, String>());
        }
        context.getGroupManager().updateJobStatus(jobstatus);

        if (!success) {
          // 运行失败,更新失败状态,发出失败消息
          ZeusJobException jobException = null;
          if (exception != null) {
            jobException = new ZeusJobException(jobId,
                String.format("JobId:%s run failed ", jobId),
                exception);
          } else {
            jobException = new ZeusJobException(jobId,
                String.format("JobId:%s run failed ", jobId));
          }
          ScheduleInfoLog.info("JobId:" + jobId
              + " run fail and dispatch the fail event");
          JobFailedEvent jfe = new JobFailedEvent(jobId, type,
              context.getJobHistoryManager().findJobHistory(
                  his.getId()), jobException);
          context.getDispatcher().forwardEvent(jfe);
        } else {
          // 运行成功,发出成功消息
          ScheduleInfoLog.info("JobId:" + jobId
              + " run success and dispatch the success event");
          JobSuccessEvent jse = new JobSuccessEvent(jobId,
              his.getTriggerType(), his.getId());
          context.getDispatcher().forwardEvent(jse);
        }
      }
    }.start();
  }
View Full Code Here

        .entrySet()) {
      if (entry.getValue() != null && entry.getValue()) {
        continue;
      }
      String historyId = entry.getKey();
      JobHistory his = context.getJobHistoryManager().findJobHistory(
          historyId);
      long maxTime;
      try {
        JobDescriptor jd = context.getGroupManager()
            .getJobDescriptor(his.getJobId()).getX();
        String maxTimeString = jd.getProperties().get(
            "zeus.job.maxtime");
        if (maxTimeString == null || maxTimeString.trim().isEmpty()) {
          continue;
        }
        maxTime = Long.parseLong(maxTimeString);

        if (maxTime < 0) {
          continue;
        }
      } catch (Exception e) {
        continue;
      }
      long runTime = (System.currentTimeMillis() - his.getStartTime()
          .getTime()) / 1000 / 60;
      if (runTime > maxTime) {
        if (timeOverAlarm(his, null, runTime, maxTime, 1)) {
          w.getManualRunnings().replace(historyId, false, true);
        }
View Full Code Here

        }
      } catch (Exception e) {
        continue;
      }

      JobHistory his = context.getJobHistoryManager().findJobHistory(
          context.getGroupManager().getJobStatus(jobId)
              .getHistoryId());
      long runTime = (System.currentTimeMillis() - his.getStartTime()
          .getTime()) / 1000 / 60;
      if (runTime > maxTime) {
        if (timeOverAlarm(his, null, runTime, maxTime, 0)) {
          w.getRunnings().replace(jobId, false, true);
        }
View Full Code Here

            Thread.sleep(30000);
          } catch (InterruptedException e) {
          }
          for (JobHistory his : hiss) {
            String jobId = his.getJobId();
            JobHistory history = new JobHistory();
            history.setJobId(jobId);
            history.setTriggerType(his.getTriggerType());
            history.setIllustrate("worker断线,重新跑任务");
            history.setOperator(his.getOperator());
            context.getJobHistoryManager().addJobHistory(history);
            Master.this.run(history);
          }
        };
      }.start();
View Full Code Here

  @Override
  public void send(String historyId,String data) throws Exception {
    if(host==null || "".equals(host.trim())){
      return;
    }
    JobHistory history=jobHistoryManager.findJobHistory(historyId);
    String jobId=history.getJobId();
   
   
    String path="/zeus/jobs/"+jobId;
   
    send(host,path,data);
View Full Code Here

  @Qualifier("userManager")
  protected UserManager userManager;
  @Override
  public void alarm(String historyId, String title, String content,ChainException chain)
      throws Exception {
    JobHistory history=jobHistoryManager.findJobHistory(historyId);
    TriggerType type=history.getTriggerType();
    String jobId=history.getJobId();
    List<String> users=new ArrayList<String>();
    if(type==TriggerType.SCHEDULE){
      users=followManager.findActualJobFollowers(jobId);
    }else{
      users.add(groupManager.getJobDescriptor(jobId).getX().getOwner());
      if(history.getOperator()!=null){
        if(!users.contains(history.getOperator())){
          users.add(history.getOperator());
        }
      }
    }
    List<String> result=new ArrayList<String>();
    if(chain==null){
View Full Code Here

public class MasterBeWebExecute {
  public WebResponse beWebExecute(MasterContext context,WebRequest req) {
    if(req.getEk()==ExecuteKind.ManualKind || req.getEk()==ExecuteKind.ScheduleKind){
      String historyId=req.getId();
      JobHistory history=context.getJobHistoryManager().findJobHistory(historyId);
      String jobId=history.getJobId();
      context.getMaster().run(history);
     
      WebResponse resp=WebResponse.newBuilder().setRid(req.getRid()).setOperate(WebOperate.ExecuteJob)
        .setStatus(Status.OK).build();
      SocketLog.info("send web execute response,rid="+req.getRid()+",jobId="+jobId);
View Full Code Here

  private Future<Response> processSchedule(final MasterContext context,final MasterWorkerHolder holder,final String id){
    // 向channel 发送执行job命令
    // 等待worker响应
    // 响应OK 则添加监听器,继续等待任务完成的消息
    // 响应失败,返回失败退出码
    JobHistory history=context.getJobHistoryManager().findJobHistory(id);
    final String jobId=history.getJobId();
    holder.getRunnings().put(jobId,false);
    ExecuteMessage em=ExecuteMessage.newBuilder().setJobId(jobId).build();
    final Request req=Request.newBuilder().setRid(AtomicIncrease.getAndIncrement()).setOperate(Operate.Schedule)
      .setBody(em.toByteString()).build();
    SocketMessage sm=SocketMessage.newBuilder().setKind(Kind.REQUEST).setBody(req.toByteString()).build();
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.