Package com.taobao.zeus.model

Examples of com.taobao.zeus.model.DebugHistory


        .setStatus(Status.OK).build();
      SocketLog.info("send web execute response,rid="+req.getRid()+",jobId="+jobId);
      return resp;
    }else if(req.getEk()==ExecuteKind.DebugKind){
      String debugId=req.getId();
      DebugHistory history=context.getDebugHistoryManager().findDebugHistory(debugId);
      SocketLog.info("receive web debug request,rid="+req.getRid()+",debugId="+debugId);
     
      context.getMaster().debug(history);
     
      WebResponse resp=WebResponse.newBuilder().setRid(req.getRid()).setOperate(WebOperate.ExecuteJob)
View Full Code Here


          .setStatus(Status.ERROR).setErrorText("已经在队列中,无法再次运行").build();
        return resp;
      }
    }
   
    DebugHistory debug=context.getDebugHistoryManager().findDebugHistory(debugId);
    context.getMaster().debug(debug);
   
    WebResponse resp=WebResponse.newBuilder().setRid(req.getRid()).setOperate(WebOperate.ExecuteDebug)
      .setStatus(Status.OK).build();
    SocketLog.info("send web debug response,rid="+req.getRid()+",debugId="+debugId);
View Full Code Here

  }

  private WebResponse processDebugCancel(MasterContext context, WebRequest req) {
    WebResponse ret = null;
    String debugId = req.getId();
    DebugHistory history = context.getDebugHistoryManager()
        .findDebugHistory(debugId);
    SocketLog.info("receive web debug cancel request,rid=" + req.getRid()
        + ",debugId=" + debugId);
    for (String debug : new ArrayList<String>(context.getDebugQueue())) {
      if (debug.equals(debugId)) {
        if (context.getDebugQueue().remove(debugId)) {
          ret = WebResponse.newBuilder().setRid(req.getRid())
              .setOperate(req.getOperate()).setStatus(Status.OK)
              .build();
          history.getLog().appendZeus("任务被取消");
          context.getDebugHistoryManager().updateDebugHistoryLog(
              history.getId(), history.getLog().getContent());
          break;
        }
      }
    }
    for (Channel key : new HashSet<Channel>(context.getWorkers().keySet())) {
      MasterWorkerHolder worker = context.getWorkers().get(key);
      if (worker.getDebugRunnings().containsKey(debugId)) {
        Future<Response> f = new MasterCancelJob().cancel(context,
            worker.getChannel(), ExecuteKind.DebugKind, debugId);
        worker.getDebugRunnings().remove(debugId);
        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 debug cancel response,rid="
            + req.getRid() + ",debugId=" + debugId);
      }
    }
    if (ret == null) {
      // 找不到job,失败
      ret = WebResponse.newBuilder().setRid(req.getRid())
          .setOperate(req.getOperate()).setStatus(Status.ERROR)
          .setErrorText("Debug任务中找不到匹配的job("+history.getFileId()+","+history.getId()+"),无法执行取消命令").build();
    }
    // 再查一次,获取最新数据
    history = context.getDebugHistoryManager().findDebugHistory(debugId);
    history.setEndTime(new Date());
    history.setStatus(com.taobao.zeus.model.JobStatus.Status.FAILED);
    context.getDebugHistoryManager().updateDebugHistory(history);
    return ret;
  }
View Full Code Here

    persistence.setGmtModified(file.getGmtModified());
    return persistence;
  }
 
  public static DebugHistory convert(DebugHistoryPersistence persistence){
    DebugHistory debug=new DebugHistory();
    debug.setEndTime(persistence.getEndTime());
    debug.setExecuteHost(persistence.getExecuteHost());
    debug.setFileId(persistence.getFileId()==null?null:persistence.getFileId().toString());
    debug.setId(persistence.getId()==null?null:persistence.getId().toString());
    debug.setStartTime(persistence.getStartTime());
    debug.setStatus(Status.parser(persistence.getStatus()));
    debug.setGmtCreate(persistence.getGmtCreate());
    debug.setGmtModified(persistence.getGmtModified());
    debug.setScript(persistence.getScript());
    debug.setJobRunType(JobRunType.parser(persistence.getRuntype()));
    debug.setLog(persistence.getLog());
    return debug;
  }
View Full Code Here

        query.setMaxResults(limit);
        query.setFirstResult(start);
        List<Object[]> list=query.list();
        List<DebugHistory> result=new ArrayList<DebugHistory>();
        for(Object[] o:list){
          DebugHistory history=new DebugHistory();
          history.setId(String.valueOf(o[0]));
          history.setFileId(String.valueOf(o[1]));
          history.setStartTime((Date) o[2]);
          history.setEndTime((Date) o[3]);
          history.setExecuteHost(String.valueOf(o[4]));
          history.setStatus(o[5]==null?null:Status.parser(String.valueOf(o[5])));
          history.setScript(String.valueOf(o[6]));
          history.setLog(String.valueOf(o[7]));
          result.add(history);
        }
        return result;
      }
    });
View Full Code Here

        }
      }

      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

      throw new RuntimeException("任务已经不存在");
    }
    job.cancel();
    context.getDebugRunnings().remove(debugId);

    DebugHistory his = job.getJobContext().getDebugHistory();
    his.setEndTime(new Date());
    his.setStatus(com.taobao.zeus.model.JobStatus.Status.FAILED);
    context.getDebugHistoryManager().updateDebugHistory(his);
    his.getLog().appendZeus("任务被取消");
    context.getDebugHistoryManager().updateDebugHistoryLog(his.getId(),
        his.getLog().getContent());
  }
View Full Code Here

    SocketLog.info("master scan and poll debugId=" + debugId + " and run!");

    new Thread() {
      @Override
      public void run() {
        DebugHistory history = context.getDebugHistoryManager()
            .findDebugHistory(debugId);
        history.getLog().appendZeus(
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(new Date()) + " 开始运行");
        context.getDebugHistoryManager().updateDebugHistoryLog(debugId,
            history.getLog().getContent());
        Exception exception = null;
        Response resp = null;
        try {
          Future<Response> f = new MasterExecuteJob().executeJob(
              context, w, ExecuteKind.DebugKind, debugId);
          resp = f.get();
        } catch (Exception e) {
          exception = e;
          DebugInfoLog.error(
              String.format("debugId:%s run failed", debugId), e);
        }
        boolean success = resp.getStatus() == Status.OK ? true : false;

        if (!success) {
          // 运行失败,更新失败状态,发出失败消息
          if (exception != null) {
            exception = new ZeusException(String.format(
                "fileId:%s run failed ", history.getFileId()),
                exception);
          } else {
            exception = new ZeusException(String.format(
                "fileId:%s run failed ", history.getFileId()));
          }
          DebugInfoLog.info("debugId:" + debugId + " run fail ");
          history = context.getDebugHistoryManager()
              .findDebugHistory(debugId);
          DebugFailEvent jfe = new DebugFailEvent(
              history.getFileId(), history, exception);
          context.getDispatcher().forwardEvent(jfe);
        } else {
          // 运行成功,发出成功消息
          DebugInfoLog.info("debugId:" + debugId + " run success");
          DebugSuccessEvent dse = new DebugSuccessEvent(
              history.getFileId(), history);
          context.getDispatcher().forwardEvent(dse);
        }
      }
    }.start();
  }
View Full Code Here

    for (Map.Entry<String, Boolean> entry : w.getDebugRunnings().entrySet()) {
      if (entry.getValue() != null && entry.getValue()) {
        continue;
      }
      String historyId = entry.getKey();
      DebugHistory his = context.getDebugHistoryManager()
          .findDebugHistory(historyId);
      long maxTime;
      FileDescriptor fd;
      try {
        fd = context.getFileManager().getFile(his.getFileId());
        Profile pf = context.getProfileManager().findByUid(
            fd.getOwner());
        String maxTimeString = pf.getHadoopConf().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(null, fd, runTime, maxTime, 2)) {
          w.getDebugRunnings().replace(historyId, false, true);
        }
View Full Code Here

  @Override
  public void beforeDispatch(MvcEvent mvce) {
    try {
      if(mvce.getAppEvent() instanceof DebugFailEvent){
        final DebugFailEvent event=(DebugFailEvent) mvce.getAppEvent();
        DebugHistory history=event.getHistory();
        FileDescriptor fd=fileManager.getFile(history.getFileId());
       
        String msg="调试任务:"+fd.getName()+" 运行失败";
        //此处可以发送IM消息
      }else if(mvce.getAppEvent() instanceof DebugSuccessEvent){
        final DebugSuccessEvent event=(DebugSuccessEvent) mvce.getAppEvent();
        DebugHistory history=event.getHistory();
        FileDescriptor fd=fileManager.getFile(history.getFileId());
       
        String msg="调试任务:"+fd.getName()+" 运行成功";
        //此处可以发送IM消息
      }
    } catch (Exception e) {
View Full Code Here

TOP

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

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.