Search in sources :

Example 21 with DagEngine

use of org.apache.oozie.DagEngine 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 22 with DagEngine

use of org.apache.oozie.DagEngine 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 23 with DagEngine

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

the class V1JobsServlet method submitWorkflowJob.

/**
 * v1 service implementation to submit a workflow job
 */
@SuppressWarnings("unchecked")
private JSONObject submitWorkflowJob(HttpServletRequest request, Configuration conf) throws XServletException {
    JSONObject json = new JSONObject();
    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);
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(user);
        String id;
        boolean dryrun = false;
        if (action != null) {
            dryrun = (action.equals(RestConstants.JOB_ACTION_DRYRUN));
        }
        if (dryrun) {
            id = dagEngine.dryRunSubmit(conf);
        } else {
            id = dagEngine.submitJob(conf, startJob);
        }
        json.put(JsonTags.JOB_ID, id);
    } catch (BaseEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : DagEngine(org.apache.oozie.DagEngine) JSONObject(org.json.simple.JSONObject) BaseEngineException(org.apache.oozie.BaseEngineException) DagEngineService(org.apache.oozie.service.DagEngineService)

Example 24 with DagEngine

use of org.apache.oozie.DagEngine 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)

Example 25 with DagEngine

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

the class V0JobServlet method reRunJob.

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

Aggregations

DagEngine (org.apache.oozie.DagEngine)36 DagEngineService (org.apache.oozie.service.DagEngineService)22 DagEngineException (org.apache.oozie.DagEngineException)19 XConfiguration (org.apache.oozie.util.XConfiguration)15 Reader (java.io.Reader)14 Writer (java.io.Writer)14 Configuration (org.apache.hadoop.conf.Configuration)14 FileWriter (java.io.FileWriter)13 File (java.io.File)12 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)9 JSONObject (org.json.simple.JSONObject)8 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)7 WorkflowActionsGetForJobJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor)5 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)5 IOException (java.io.IOException)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 JPAService (org.apache.oozie.service.JPAService)4 WorkflowStore (org.apache.oozie.store.WorkflowStore)4 Date (java.util.Date)3 WorkflowsInfo (org.apache.oozie.WorkflowsInfo)3