コード例 #1
0
  public QueuedItemResult queueDispatcherJob(final IDispatchedJob dispatchedJob)
      throws CentralDispatcherException {
    final HashMap<String, String> params = new HashMap<String, String>();
    if (null == dispatchedJob.getJobRef()) {
      throw new IllegalArgumentException("JobRef was null");
    }
    if (null != dispatchedJob.getJobRef().getJobId()) {
      params.put("id", dispatchedJob.getJobRef().getJobId());
    } else {
      if (null != dispatchedJob.getJobRef().getName()) {
        params.put("jobName", dispatchedJob.getJobRef().getName());
      }
      if (null != dispatchedJob.getJobRef().getGroup()) {
        params.put("groupPath", dispatchedJob.getJobRef().getGroup());
      }
    }

    addNodeSetParams(params, dispatchedJob.getNodeSet(), dispatchedJob.isKeepgoing(), "extra.");
    addLoglevelParams(params, dispatchedJob.getLoglevel(), "extra.");
    if (null != dispatchedJob.getArgs() && dispatchedJob.getArgs().length > 0) {
      params.put("extra.argString", CLIUtils.generateArgline(null, dispatchedJob.getArgs()));
    }
    /*
     * submit request to the URL path, expecting standard "queued item list" result
     */
    return submitQueueRequest(null, params, RUNDECK_JOBS_RUN);
  }
コード例 #2
0
  public QueuedItemResult queueDispatcherJob(final IDispatchedJob dispatchedJob)
      throws CentralDispatcherException {
    final HashMap<String, String> params = new HashMap<String, String>();
    if (null == dispatchedJob.getJobRef()) {
      throw new IllegalArgumentException("JobRef was null");
    }
    final String jobid;
    if (null != dispatchedJob.getJobRef().getJobId()) {
      jobid = dispatchedJob.getJobRef().getJobId();
    } else {
      if (null == dispatchedJob.getJobRef().getName()
          || "".equals(dispatchedJob.getJobRef().getName())) {
        throw new CentralDispatcherException("job name input is required");
      }
      final String project = dispatchedJob.getJobRef().getProject();
      final String name = dispatchedJob.getJobRef().getName();
      final String group;
      if (null != dispatchedJob.getJobRef().getGroup()
          && !"".equals(dispatchedJob.getJobRef().getGroup())) {
        group = dispatchedJob.getJobRef().getGroup();
      } else {
        // indicates a top level job
        group = "-";
      }

      // Query to find matching job
      final Collection<IStoredJob> iStoredJobs =
          reallistStoredJobs(new IStoredJobsQueryImpl(name, group, null, project));
      if (null == iStoredJobs) {
        throw new CentralDispatcherException("Unable to query jobs");
      }
      if (iStoredJobs.size() < 1) {
        throw new CentralDispatcherException(
            "Job not found matching query: " + (null != group ? group : "") + "/" + name);
      }
      if (iStoredJobs.size() > 1) {
        ArrayList<String> ids = new ArrayList<String>();
        for (final IStoredJob iStoredJob : iStoredJobs) {
          ids.add(iStoredJob.getJobId());
        }
        throw new CentralDispatcherException(
            "Job was not unique: "
                + (null != group ? group : "")
                + "/"
                + name
                + ": "
                + iStoredJobs.size()
                + " jobs found: "
                + ids);
      }
      // use found id
      final IStoredJob next = iStoredJobs.iterator().next();
      jobid = next.getJobId();
    }

    addAPINodeSetParams(params, dispatchedJob.getNodeSet(), dispatchedJob.isKeepgoing());
    addLoglevelParams(params, dispatchedJob.getLoglevel());
    if (null != dispatchedJob.getArgs() && dispatchedJob.getArgs().length > 0) {
      params.put("argString", CLIUtils.generateArgline(null, dispatchedJob.getArgs()));
    }

    final String apipath = substitutePathVariable(RUNDECK_API_JOBS_RUN, "id", jobid);
    return submitExecutionRequest(null, params, apipath);
  }