Package com.taobao.zeus.client

Examples of com.taobao.zeus.client.ZeusException


import com.taobao.zeus.model.GroupDescriptor;

public class GroupValidate {
  public static boolean valide(GroupDescriptor group) throws ZeusException{
    if(group.getName()==null || group.getName().trim().equals("")){
      throw new ZeusException("name字段不能为空");
    }
   
    return true;
  }
View Full Code Here


  @Autowired
  private ReadOnlyGroupManager readOnlyGroupManager;

  public boolean valide(JobDescriptor job) throws ZeusException{
    if(job.getJobType()==null){
      throw new ZeusException("任务类型必须填写");
    }
    if(job.getGroupId()==null){
      throw new ZeusException("所属组必须填写");
    }
    if(job.getJobType()==JobRunType.MapReduce){
      if(job.getName()==null || job.getName().trim().equals("")){
        throw new ZeusException("name字段不能为空");
      }
      if(job.getAuto()){
        if(job.getProperties().get("java.main.class")==null ||
            job.getProperties().get("java.main.class").trim().equals("")){
          throw new ZeusException("必须填写Java Main类");
        }
        if(job.getScheduleType()==null){
          throw new ZeusException("调度类型必须填写");
        }
        if(job.getScheduleType()==JobScheduleType.Independent){
          if(job.getCronExpression()==null || job.getCronExpression().trim().equals("")){
            throw new ZeusException("独立任务的定时表达式必须填写");
          }
          job.setDependencies(new ArrayList<String>());
        }
        //如果是依赖任务
        if(job.getScheduleType()==JobScheduleType.Dependent){
          //必须填写依赖项
          if(job.getDependencies()==null || job.getDependencies().isEmpty()){
            throw new ZeusException("依赖任务必须填写依赖项");
          }
          job.setCronExpression("");
        }
      }
    }else if(job.getJobType()==JobRunType.Shell){
      if(job.getScript()==null){
        throw new ZeusException("Shell 脚本不得为空");
      }
    }else if(job.getJobType()==JobRunType.Hive){
      if(job.getScript()==null){
        throw new ZeusException("Hive 脚本不得为空");
      }
    }
   
    if(job.getCronExpression()!=null && !job.getCronExpression().trim().equals("")){
      try {
        new CronTrigger("test", "test", job.getCronExpression());
      } catch (ParseException e) {
        throw new ZeusException("cronExpression表达式格式出错");
      }
    }
   
    //检查依赖的死循环问题
    GroupBean root=readOnlyGroupManager.getGlobeGroupBean();
    Map<String, JobBean> allJobBeans=root.getAllSubJobBeans();
    Set<JobBean> deps=new HashSet<JobBean>();
    if(job.getScheduleType()==JobScheduleType.Dependent){
      for(String jobId:job.getDependencies()){
        if(allJobBeans.get(jobId)==null){
          throw new ZeusException("依赖任务:"+jobId+" 不存在");
        }
        deps.add(allJobBeans.get(jobId));
      }
      check(job.getId(), deps);
    }
View Full Code Here

  }
  //判断死循环问题
  private static void check(String parentJobId,Set<JobBean> deps) throws ZeusException{
    for(JobBean job:deps){
      if(job.getJobDescriptor().getId().equals(parentJobId)){
        throw new ZeusException("存在死循环依赖,请检查!");
      }
      if(job.getJobDescriptor().getScheduleType()==JobScheduleType.Dependent){
        check(parentJobId,job.getDependee());
      }
    }
View Full Code Here

  @Override
  public void deleteGroup(String user, String groupId) throws ZeusException {
    GroupBean group=getDownstreamGroupBean(groupId);
    if(group.isDirectory()){
      if(!group.getChildrenGroupBeans().isEmpty()){
        throw new ZeusException("该组下不为空,无法删除");
      }
    }else{
      if(!group.getJobBeans().isEmpty()){
        throw new ZeusException("该组下不为空,无法删除");
      }
    }
    getHibernateTemplate().delete(getHibernateTemplate().get(GroupPersistence.class, Integer.valueOf(groupId)));
  }
View Full Code Here

    if(!job.getDepender().isEmpty()){
      List<String> deps=new ArrayList<String>();
      for(JobBean jb:job.getDepender()){
        deps.add(jb.getJobDescriptor().getId());
      }
      throw new ZeusException("该Job正在被其他Job"+deps.toString()+"依赖,无法删除");
    }
    getHibernateTemplate().delete(getHibernateTemplate().get(JobPersistence.class, Long.valueOf(jobId)));
  }
View Full Code Here

  @Override
  public GroupDescriptor createGroup(String user, String groupName,
      String parentGroup, boolean isDirectory) throws ZeusException {
    if(parentGroup==null){
      throw new ZeusException("parent group may not be null");
    }
    GroupDescriptor group=new GroupDescriptor();
    group.setOwner(user);
    group.setName(groupName);
    group.setParent(parentGroup);
View Full Code Here

  @Override
  public JobDescriptor createJob(String user, String jobName,
      String parentGroup,JobRunType jobType) throws ZeusException {
    GroupDescriptor parent=getGroupDescriptor(parentGroup);
    if(parent.isDirectory()){
      throw new ZeusException("目录组下不得创建Job");
    }
    JobDescriptor job=new JobDescriptor();
    job.setOwner(user);
    job.setName(jobName);
    job.setGroupId(parentGroup);
View Full Code Here

  @Override
  public void moveJob(String uid,String jobId, String groupId) throws ZeusException {
    JobDescriptor jd=getJobDescriptor(jobId).getX();
    GroupDescriptor gd=getGroupDescriptor(groupId);
    if(gd.isDirectory()){
      throw new ZeusException("非法操作");
    }
    updateJob(uid, jd, jd.getOwner(), groupId);
  }
View Full Code Here

  public void moveGroup(String uid,String groupId, String newParentGroupId)
      throws ZeusException {
    GroupDescriptor gd=getGroupDescriptor(groupId);
    GroupDescriptor parent=getGroupDescriptor(newParentGroupId);
    if(!parent.isDirectory()){
      throw new ZeusException("非法操作");
    }
    updateGroup(uid, gd, gd.getOwner(), newParentGroupId);
  }
View Full Code Here

  public void cancelJobFromWeb(ExecuteKind kind, String id, String operator)
      throws Exception {
    WebResponse resp = new WorkerWebCancel().cancel(context, kind, id,
        operator).get();
    if (resp.getStatus() == Status.ERROR) {
      throw new ZeusException(resp.getErrorText());
    }
  }
View Full Code Here

TOP

Related Classes of com.taobao.zeus.client.ZeusException

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.