Example #1
0
 @Override
 public void grantJobOwner(String granter, String uid, String jobId) throws ZeusException {
   Tuple<JobDescriptor, JobStatus> job = getJobDescriptor(jobId);
   if (job != null) {
     job.getX().setOwner(uid);
     updateJob(granter, job.getX(), uid, job.getX().getGroupId());
   }
 }
Example #2
0
 @Override
 public JobStatus getJobStatus(String jobId) {
   Tuple<JobDescriptor, JobStatus> tuple = getJobDescriptor(jobId);
   if (tuple == null) {
     return null;
   }
   return tuple.getY();
 }
Example #3
0
  @Override
  public Map<String, Tuple<JobDescriptor, JobStatus>> getJobDescriptor(
      final Collection<String> jobIds) {
    List<Tuple<JobDescriptor, JobStatus>> list =
        (List<Tuple<JobDescriptor, JobStatus>>)
            getHibernateTemplate()
                .execute(
                    new HibernateCallback() {

                      @Override
                      public Object doInHibernate(Session session)
                          throws HibernateException, SQLException {
                        if (jobIds.isEmpty()) {
                          return Collections.emptyList();
                        }
                        List<Long> ids = new ArrayList<Long>();
                        for (String i : jobIds) {
                          ids.add(Long.valueOf(i));
                        }
                        Query query =
                            session.createQuery(
                                "from com.taobao.zeus.store.mysql.persistence.JobPersistence where id in (:list)");
                        query.setParameterList("list", ids);
                        List<JobPersistence> list = query.list();
                        List<Tuple<JobDescriptor, JobStatus>> result =
                            new ArrayList<Tuple<JobDescriptor, JobStatus>>();
                        if (list != null && !list.isEmpty()) {
                          for (JobPersistence persist : list) {
                            result.add(PersistenceAndBeanConvert.convert(persist));
                          }
                        }
                        return result;
                      }
                    });

    Map<String, Tuple<JobDescriptor, JobStatus>> map =
        new HashMap<String, Tuple<JobDescriptor, JobStatus>>();
    for (Tuple<JobDescriptor, JobStatus> jd : list) {
      map.put(jd.getX().getId(), jd);
    }
    return map;
  }
Example #4
0
  @Override
  public GroupBean getDownstreamGroupBean(GroupBean parent) {
    if (parent.isDirectory()) {
      List<GroupDescriptor> children = getChildrenGroup(parent.getGroupDescriptor().getId());
      for (GroupDescriptor child : children) {
        GroupBean childBean = new GroupBean(child);
        getDownstreamGroupBean(childBean);
        childBean.setParentGroupBean(parent);
        parent.getChildrenGroupBeans().add(childBean);
      }
    } else {
      List<Tuple<JobDescriptor, JobStatus>> jobs =
          getChildrenJob(parent.getGroupDescriptor().getId());
      for (Tuple<JobDescriptor, JobStatus> tuple : jobs) {
        JobBean jobBean = new JobBean(tuple.getX(), tuple.getY());
        jobBean.setGroupBean(parent);
        parent.getJobBeans().put(tuple.getX().getId(), jobBean);
      }
    }

    return parent;
  }
Example #5
0
 @Override
 public Tuple<JobDescriptor, JobStatus> getJobDescriptor(String jobId) {
   JobPersistence persist = getJobPersistence(jobId);
   if (persist == null) {
     return null;
   }
   Tuple<JobDescriptor, JobStatus> t = PersistenceAndBeanConvert.convert(persist);
   JobDescriptor jd = t.getX();
   // 如果是周期任务,并且依赖不为空,则需要封装周期任务的依赖
   if (jd.getScheduleType() == JobScheduleType.CyleJob && jd.getDependencies() != null) {
     JobPersistence jp = null;
     for (String jobID : jd.getDependencies()) {
       if (StringUtils.isNotEmpty(jobID)) {
         jp = getJobPersistence(jobID);
         if (jp != null) {
           jd.getDepdCycleJob().put(jobID, jp.getCycle());
         }
       }
     }
   }
   return t;
 }