Exemple #1
0
  /** v1 service implementation to submit a coordinator job */
  @SuppressWarnings("unchecked")
  private JSONObject submitCoordinatorJob(HttpServletRequest request, Configuration conf)
      throws XServletException {

    JSONObject json = new JSONObject();
    XLog.getLog(getClass()).warn("submitCoordinatorJob " + XmlUtils.prettyPrint(conf).toString());
    try {
      String action = request.getParameter(RestConstants.ACTION_PARAM);
      if (action != null
          && !action.equals(RestConstants.JOB_ACTION_START)
          && !action.equals(RestConstants.JOB_ACTION_DRYRUN)) {
        throw new XServletException(
            HttpServletResponse.SC_BAD_REQUEST,
            ErrorCode.E0303,
            RestConstants.ACTION_PARAM,
            action);
      }
      boolean startJob = (action != null);
      String user = conf.get(OozieClient.USER_NAME);
      CoordinatorEngine coordEngine =
          Services.get()
              .get(CoordinatorEngineService.class)
              .getCoordinatorEngine(user, getAuthToken(request));
      String id = null;
      boolean dryrun = false;
      if (action != null) {
        dryrun = (action.equals(RestConstants.JOB_ACTION_DRYRUN));
      }
      if (dryrun) {
        id = coordEngine.dryrunSubmit(conf, startJob);
      } else {
        id = coordEngine.submitJob(conf, startJob);
      }
      json.put(JsonTags.JOB_ID, id);
    } catch (CoordinatorEngineException ex) {
      throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }

    return json;
  }