Package com.google.code.lightssh.project.scheduler.entity

Examples of com.google.code.lightssh.project.scheduler.entity.PlanDetail


 
  /**
   * 更新明细状态
   */
  public void updateDetailStatus(String detailId,Status status ){
    PlanDetail detail = getDetail(detailId);
    if( detail == null )
      throw new ApplicationException("执行计划明细["+detailId+"]对应数据不存在!");
   
    detail.setStatus(status);
   
    this.planDetailDao.update(detail);
  }
View Full Code Here


   
    return page.getAllSize();
  }
 
  public void updateStatus(String detailId ){
    PlanDetail detail = getDetail(detailId);
    if( detail != null && detail.getPlan() != null &&
        getDao().updateStatusIfAllDetailFinished( detail.getPlan().getId() ))
      log.info("计划任务在明细[{}]完成执行后,进行状态更新!",detail);
  }
View Full Code Here

 
  /**
   * 更新明细状态
   */
  public void updateDetailStatus(String detailId,boolean success,String errMsg){
    PlanDetail detail = getDetailWithLock(detailId);
    if( detail == null )
      throw new ApplicationException("执行计划明细["+detailId+"]对应数据不存在!");
   
    PlanDetail.Status oldStatus = detail.getStatus();
    if( PlanDetail.Status.WAITING_FOR_REPLY.equals(detail.getStatus())
        || PlanDetail.Status.NEW.equals(detail.getStatus())
        || PlanDetail.Status.FAILURE.equals(detail.getStatus())
        || PlanDetail.Status.EXCEPTION.equals(detail.getStatus()) ){
     
      detail.setStatus(success?PlanDetail.Status.SUCCESS:PlanDetail.Status.FAILURE);
      detail.setFinishTime( Calendar.getInstance() );
      if( StringUtils.isEmpty(errMsg))
        detail.setDescription("回调结果["+(success?"成功":"失败")+"]");
      else
        detail.setDescription( TextFormater.format(errMsg,197,true) );
       
      this.planDetailDao.update(detail);
     
      log.info("执行计划明细["+detailId+"]状态["
          +oldStatus+"]更新为["+detail.getStatus()+"]!");
     
      //TODO 并发可能导致 计划任务状态 不能成功更新
      /*
      if( success ){
        String planId = detail.getPlan().getId();
        int count = getUnsuccessfulCount( planId,detail.getId());
        if( count == 0 ){
          updateFinishTime( planId,Calendar.getInstance());
          log.info("执行计划明细[{}]执行完成,整个任务完成!",detail.getId());
        }
      }
      */
     
      //TODO 可能导致并发问题
      //执行依赖任务
      /*
      List<PlanDetail> replyOnList = planDetailDao.listRelyOnUnsuccessful(detailId);
      if( replyOnList == null || replyOnList.isEmpty() )
        return;
     
      //TODO 线程池处理
      for( PlanDetail item:replyOnList ){
        if( item.getPlan()==null || item.getPlan().getType() == null ){
          log.warn("上级任务执行[{}]依赖任务[{}]无法调用执行,类型为空!",detailId,item.getId());
          continue;
        }else if( success ){
          log.info("回调任务[{}]执行成功,执行依赖任务[{}]。",detailId,item.getId());
          jobQueueManager.jobInQueue(item.getPlan().getType().getId(),item.getId(),1);
        }else{
          item.setStatus(Status.FAILURE);
          item.setDescription("依赖任务["+detailId+"]执行返回失败!");
         
          planDetailDao.update(item);
        }
      }*/
     
    }else{
      log.warn("执行计划明细["+detailId
          +"]状态已改变为["+detail.getStatus()+"]不能进行更新!");
    }
   
  }
 
View Full Code Here

 
  /**
   * 明细入任务队列
   */
  public void detailInQueue(PlanDetail pd){
    PlanDetail detail = this.getDetail( pd.getId() );
    if( detail == null )
      throw new ApplicationException("明细数据["+pd.getId()+"]不存在!");
   
    if( detail.getPlan() == null || detail.getPlan().getType() == null )
      throw new ApplicationException("明细数据["+pd.getId()+"]不完整!");
   
    jobQueueManager.jobInQueue(
        detail.getPlan().getType().getId(),detail.getId(),1,detail.getPlan().getPlanFireTime());
  }
View Full Code Here

    if( results == null || results.isEmpty() )
      return;
   
    String anyTaskId = null;
    for( Result result:results ){
      PlanDetail detail = planDetailDao.readWithLock( result.getKey() );
      if( detail != null ){
        if( detail.getFireTime() == null )
          detail.setFireTime(Calendar.getInstance());
       
        PlanDetail.Status newStatus = PlanDetail.Status.WAITING_FOR_REPLY;
       
        if( result.isInvokeSuccess()){
          newStatus = detail.isSynTask()?PlanDetail.Status
              .WAITING_FOR_REPLY:PlanDetail.Status.SUCCESS;
          detail.setFinishTime( Calendar.getInstance() );
        }else{
          newStatus = result.isException()
            ?PlanDetail.Status.EXCEPTION:PlanDetail.Status.FAILURE;
          detail.setErrMsg( TextFormater.format(result.getMessage(),497,true) );
          detail.incFailureCount( );
        }
       
        //detail.setStatus(newStatus);
        //planDetailDao.update(detail);
       
        planDetailDao.updateFireTimeAfterInvoke(detail.getId(),detail.getFireTime());
       
        //int i = planDetailDao.update(detail.getId(),PlanDetail.Status.NEW, newStatus);
        //int i =planDetailDao.update("id",detail.getId(),"status",detail.getStatus(), newStatus);
       
        int i = planDetailDao.updateStatusAfterInvoke(detail.getId(),newStatus);
       
        log.info("计划任务[{}]状态从["+detail.getStatus()+"]更新为["
            +newStatus+"]-[{}]",detail.getId(),i>0?"成功":"失败");
       
        anyTaskId = detail.getId();
      }
    }//end for
   
    //如果计划任务明细执行完成,确认完成标志更新成功
    updateStatus( anyTaskId );
View Full Code Here

  /**
   * 检查依赖
   */
  protected Result checkRelyOn(JobQueue jq,PlanDetail detail,Map<String,Result> mapResults){
    Result result = new Result(true,jq.getRefId(),jq,null);
    PlanDetail relyOn = detail.getPrecondition();
    if( relyOn != null ){
      String relyOnKey = relyOn.getId();
      //从数据库中取最新记录
      PlanDetail dbRelyOn = planManager.getDetail(relyOnKey);
      if( dbRelyOn != null && dbRelyOn.getStatus() != null
          && !dbRelyOn.getStatus().equals( relyOn.getStatus() )){
        relyOn = dbRelyOn;
        detail.setPrecondition( dbRelyOn );
      }
      boolean relyOnFinished = relyOn.isFinished();//已经完成
      boolean exeRelyOnFinished = mapResults.get(relyOnKey)!=null
View Full Code Here

  public Collection<Result> doBusiness(Collection<JobQueue> items){
    List<PlanDetail> details = new ArrayList<PlanDetail>();
    Map<String,JobQueue> mapQueue = new HashMap<String,JobQueue>();
    String planId = null;
    for( JobQueue item:items ){
      PlanDetail detail = planManager.getDetail(item.getRefId());
      if( detail == null )
        throw new ApplicationException("任务队列["
            +getJobTypeKey()+"]关联["+item.getRefId()+"]业务数据不存在!");
     
      planId = detail.getPlan()==null?null:detail.getPlan().getId();
      details.add( detail );
      mapQueue.put(item.getRefId(), item);
    }
   
    planManager.updateFireTime(planId,Calendar.getInstance());
    details = PlanDetail.sort(details); //排序
   
    List<Result> results = new ArrayList<Result>();//返回结果
    Map<String,Result> mapResults = new HashMap<String,Result>();
    for( PlanDetail detail:details ){
      SchedulerType type = detail.getType();
      String key = detail.getId();
      Result result = null;
      if( type == null || StringUtils.isEmpty(type.getId()) ){
        result = new Result(false,key,mapQueue.get(key)
            ,"关联业务数据["+key+"]类型为空,无法进行业务处理。");
        mapResults.put(key,result);
View Full Code Here

TOP

Related Classes of com.google.code.lightssh.project.scheduler.entity.PlanDetail

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.