示例#1
0
  /**
   * Get coord job info
   *
   * @param request servlet request
   * @param response servlet response
   * @return JsonBean CoordinatorJobBean
   * @throws XServletException
   * @throws BaseEngineException
   */
  private JsonBean getCoordinatorJob(HttpServletRequest request, HttpServletResponse response)
      throws XServletException, BaseEngineException {
    JsonBean jobBean = null;
    CoordinatorEngine coordEngine =
        Services.get()
            .get(CoordinatorEngineService.class)
            .getCoordinatorEngine(getUser(request), getAuthToken(request));
    String jobId = getResourceName(request);
    String startStr = request.getParameter(RestConstants.OFFSET_PARAM);
    String lenStr = request.getParameter(RestConstants.LEN_PARAM);
    String filter = request.getParameter(RestConstants.JOB_FILTER_PARAM);
    int start = (startStr != null) ? Integer.parseInt(startStr) : 1;
    start = (start < 1) ? 1 : start;
    // Get default number of coordinator actions to be retrieved
    int defaultLen = Services.get().getConf().getInt(COORD_ACTIONS_DEFAULT_LENGTH, 1000);
    int len = (lenStr != null) ? Integer.parseInt(lenStr) : 0;
    len = (len < 1) ? defaultLen : len;
    try {
      JsonCoordinatorJob coordJob = coordEngine.getCoordJob(jobId, filter, start, len);
      jobBean = coordJob;
    } catch (CoordinatorEngineException ex) {
      throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }

    return jobBean;
  }
示例#2
0
  /**
   * Rerun coordinator actions
   *
   * @param request servlet request
   * @param response servlet response
   * @param conf configuration object
   * @throws XServletException
   */
  @SuppressWarnings("unchecked")
  private JSONObject reRunCoordinatorActions(
      HttpServletRequest request, HttpServletResponse response, Configuration conf)
      throws XServletException {
    JSONObject json = new JSONObject();
    CoordinatorEngine coordEngine =
        Services.get()
            .get(CoordinatorEngineService.class)
            .getCoordinatorEngine(getUser(request), getAuthToken(request));

    String jobId = getResourceName(request);

    String rerunType = request.getParameter(RestConstants.JOB_COORD_RERUN_TYPE_PARAM);
    String scope = request.getParameter(RestConstants.JOB_COORD_RERUN_SCOPE_PARAM);
    String refresh = request.getParameter(RestConstants.JOB_COORD_RERUN_REFRESH_PARAM);
    String noCleanup = request.getParameter(RestConstants.JOB_COORD_RERUN_NOCLEANUP_PARAM);

    XLog.getLog(getClass())
        .info(
            "Rerun coordinator for jobId="
                + jobId
                + ", rerunType="
                + rerunType
                + ",scope="
                + scope
                + ",refresh="
                + refresh
                + ", noCleanup="
                + noCleanup);

    try {
      if (!(rerunType.equals(RestConstants.JOB_COORD_RERUN_DATE)
          || rerunType.equals(RestConstants.JOB_COORD_RERUN_ACTION))) {
        throw new CommandException(ErrorCode.E1018, "date or action expected.");
      }
      CoordinatorActionInfo coordInfo =
          coordEngine.reRun(
              jobId, rerunType, scope, Boolean.valueOf(refresh), Boolean.valueOf(noCleanup));
      List<CoordinatorActionBean> coordActions;
      if (coordInfo != null) {
        coordActions = coordInfo.getCoordActions();
      } else {
        coordActions = CoordRerunXCommand.getCoordActions(rerunType, jobId, scope);
      }
      json.put(
          JsonTags.COORDINATOR_ACTIONS, CoordinatorActionBean.toJSONArray(coordActions, "GMT"));
    } catch (BaseEngineException ex) {
      throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    } catch (CommandException ex) {
      throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }

    return json;
  }
示例#3
0
 /**
  * Kill a coord job
  *
  * @param request servlet request
  * @param response servlet response
  * @throws XServletException
  */
 private void killCoordinatorJob(HttpServletRequest request, HttpServletResponse response)
     throws XServletException {
   CoordinatorEngine coordEngine =
       Services.get()
           .get(CoordinatorEngineService.class)
           .getCoordinatorEngine(getUser(request), getAuthToken(request));
   String jobId = getResourceName(request);
   try {
     coordEngine.kill(jobId);
   } catch (CoordinatorEngineException ex) {
     throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
   }
 }
示例#4
0
 /**
  * Change a coordinator job
  *
  * @param request servlet request
  * @param response servlet response
  * @throws XServletException
  */
 private void changeCoordinatorJob(HttpServletRequest request, HttpServletResponse response)
     throws XServletException {
   CoordinatorEngine coordEngine =
       Services.get()
           .get(CoordinatorEngineService.class)
           .getCoordinatorEngine(getUser(request), getAuthToken(request));
   String jobId = getResourceName(request);
   String changeValue = request.getParameter(RestConstants.JOB_CHANGE_VALUE);
   try {
     coordEngine.change(jobId, changeValue);
   } catch (CoordinatorEngineException ex) {
     throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
   }
 }
示例#5
0
  /**
   * Get coordinator action
   *
   * @param request servlet request
   * @param response servlet response
   * @return JsonBean CoordinatorActionBean
   * @throws XServletException
   * @throws BaseEngineException
   */
  private JsonBean getCoordinatorAction(HttpServletRequest request, HttpServletResponse response)
      throws XServletException, BaseEngineException {
    JsonBean actionBean = null;
    CoordinatorEngine coordEngine =
        Services.get()
            .get(CoordinatorEngineService.class)
            .getCoordinatorEngine(getUser(request), getAuthToken(request));
    String actionId = getResourceName(request);
    try {
      actionBean = coordEngine.getCoordAction(actionId);
    } catch (CoordinatorEngineException ex) {
      throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }

    return actionBean;
  }
示例#6
0
  /**
   * Stream coordinator job log
   *
   * @param request servlet request
   * @param response servlet response
   * @throws XServletException
   * @throws IOException
   */
  private void streamCoordinatorJobLog(HttpServletRequest request, HttpServletResponse response)
      throws XServletException, IOException {

    CoordinatorEngine coordEngine =
        Services.get()
            .get(CoordinatorEngineService.class)
            .getCoordinatorEngine(getUser(request), getAuthToken(request));
    String jobId = getResourceName(request);
    String logRetrievalScope = request.getParameter(RestConstants.JOB_LOG_SCOPE_PARAM);
    String logRetrievalType = request.getParameter(RestConstants.JOB_LOG_TYPE_PARAM);
    try {
      coordEngine.streamLog(jobId, logRetrievalScope, logRetrievalType, response.getWriter());
    } catch (BaseEngineException ex) {
      throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    } catch (CommandException ex) {
      throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
  }
示例#7
0
  /**
   * Get coordinator job definition
   *
   * @param request servlet request
   * @param response servlet response
   * @return String coord definition
   * @throws XServletException
   */
  private String getCoordinatorJobDefinition(
      HttpServletRequest request, HttpServletResponse response) throws XServletException {

    CoordinatorEngine coordEngine =
        Services.get()
            .get(CoordinatorEngineService.class)
            .getCoordinatorEngine(getUser(request), getAuthToken(request));

    String jobId = getResourceName(request);

    String coordDefinition = null;
    try {
      coordDefinition = coordEngine.getDefinition(jobId);
    } catch (BaseEngineException ex) {
      throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return coordDefinition;
  }