Search in sources :

Example 11 with DagEngineException

use of org.apache.oozie.DagEngineException in project oozie by apache.

the class CallbackServlet method doPost.

/**
 * POST callback
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String queryString = request.getQueryString();
    CallbackService callbackService = Services.get().get(CallbackService.class);
    if (!callbackService.isValid(queryString)) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0402, queryString);
    }
    String actionId = callbackService.getActionId(queryString);
    if (actionId == null) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0402, queryString);
    }
    log = XLog.getLog(getClass());
    setLogInfo(actionId);
    log.debug("Received a CallbackServlet.doPost() with query string " + queryString);
    validateContentType(request, RestConstants.TEXT_CONTENT_TYPE);
    try {
        log.info(XLog.STD, "callback for action [{0}]", actionId);
        String data = IOUtils.getReaderAsString(request.getReader(), maxDataLen);
        Properties props = PropertiesUtils.stringToProperties(data);
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getSystemDagEngine();
        dagEngine.processCallback(actionId, callbackService.getExternalStatus(queryString), props);
    } catch (IOException ex) {
        if (ex.getMessage().startsWith("stream exceeds limit")) {
            // TODO, WE MUST SET THE ACTION TO ERROR
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0403, "data too long");
        } else {
            throw ex;
        }
    } catch (DagEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
}
Also used : CallbackService(org.apache.oozie.service.CallbackService) DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) DagEngineService(org.apache.oozie.service.DagEngineService) IOException(java.io.IOException) Properties(java.util.Properties)

Example 12 with DagEngineException

use of org.apache.oozie.DagEngineException in project oozie by apache.

the class V1JobsServlet method submitHttpJob.

/**
 * service implementation to submit a http job
 */
private JSONObject submitHttpJob(HttpServletRequest request, Configuration conf, String jobType) throws XServletException {
    JSONObject json = new JSONObject();
    try {
        String user = conf.get(OozieClient.USER_NAME);
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(user);
        String id = dagEngine.submitHttpJob(conf, jobType);
        json.put(JsonTags.JOB_ID, id);
    } catch (DagEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) JSONObject(org.json.simple.JSONObject) DagEngineService(org.apache.oozie.service.DagEngineService)

Example 13 with DagEngineException

use of org.apache.oozie.DagEngineException in project oozie by apache.

the class V1JobsServlet method getWorkflowJobIdForExternalId.

/**
 * v1 service implementation to get a JSONObject representation of a job from its external ID
 */
@SuppressWarnings("unchecked")
private JSONObject getWorkflowJobIdForExternalId(HttpServletRequest request, String externalId) throws XServletException {
    JSONObject json = new JSONObject();
    try {
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(getUser(request));
        String jobId = dagEngine.getJobIdForExternalId(externalId);
        json.put(JsonTags.JOB_ID, jobId);
    } catch (DagEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) JSONObject(org.json.simple.JSONObject) DagEngineService(org.apache.oozie.service.DagEngineService)

Example 14 with DagEngineException

use of org.apache.oozie.DagEngineException in project oozie by apache.

the class V1JobsServlet method getWorkflowJobs.

/**
 * v1 service implementation to get a list of workflows, with filtering or interested windows embedded in the
 * request object
 */
private JSONObject getWorkflowJobs(HttpServletRequest request) throws XServletException {
    JSONObject json;
    try {
        String filter = request.getParameter(RestConstants.JOBS_FILTER_PARAM);
        String startStr = request.getParameter(RestConstants.OFFSET_PARAM);
        String lenStr = request.getParameter(RestConstants.LEN_PARAM);
        String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM) == null ? "GMT" : request.getParameter(RestConstants.TIME_ZONE_PARAM);
        int start = (startStr != null) ? Integer.parseInt(startStr) : 1;
        start = (start < 1) ? 1 : start;
        int len = (lenStr != null) ? Integer.parseInt(lenStr) : 50;
        len = (len < 1) ? 50 : len;
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(getUser(request));
        WorkflowsInfo jobs = dagEngine.getJobs(filter, start, len);
        json = OozieJsonFactory.getWFJSONObject(jobs, timeZoneId);
    } catch (DagEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) JSONObject(org.json.simple.JSONObject) WorkflowsInfo(org.apache.oozie.WorkflowsInfo) DagEngineService(org.apache.oozie.service.DagEngineService)

Example 15 with DagEngineException

use of org.apache.oozie.DagEngineException in project oozie by apache.

the class V0JobServlet method getJob.

/*
     * v0 service method to get a job in JsonBean representation
     */
@Override
protected JsonBean getJob(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException {
    DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(getUser(request));
    JsonBean jobBean = null;
    String jobId = getResourceName(request);
    try {
        jobBean = (JsonBean) dagEngine.getJob(jobId);
    } catch (DagEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return jobBean;
}
Also used : DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) JsonBean(org.apache.oozie.client.rest.JsonBean) DagEngineService(org.apache.oozie.service.DagEngineService)

Aggregations

DagEngine (org.apache.oozie.DagEngine)19 DagEngineException (org.apache.oozie.DagEngineException)19 DagEngineService (org.apache.oozie.service.DagEngineService)18 JSONObject (org.json.simple.JSONObject)7 WorkflowsInfo (org.apache.oozie.WorkflowsInfo)3 IOException (java.io.IOException)2 Date (java.util.Date)2 Configuration (org.apache.hadoop.conf.Configuration)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 JsonBean (org.apache.oozie.client.rest.JsonBean)2 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)2 CallbackService (org.apache.oozie.service.CallbackService)2 XConfiguration (org.apache.oozie.util.XConfiguration)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1