Search in sources :

Example 1 with BundleEngine

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

the class V1JobsServlet method submitBundleJob.

/**
 * v1 service implementation to submit a bundle job
 */
@SuppressWarnings("unchecked")
private JSONObject submitBundleJob(HttpServletRequest request, Configuration conf) throws XServletException {
    JSONObject json = new JSONObject();
    XLog.getLog(getClass()).warn("submitBundleJob " + 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);
        BundleEngine bundleEngine = Services.get().get(BundleEngineService.class).getBundleEngine(user);
        String id = null;
        boolean dryrun = false;
        if (action != null) {
            dryrun = (action.equals(RestConstants.JOB_ACTION_DRYRUN));
        }
        if (dryrun) {
            id = bundleEngine.dryRunSubmit(conf);
        } else {
            id = bundleEngine.submitJob(conf, startJob);
        }
        json.put(JsonTags.JOB_ID, id);
    } catch (BundleEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) BundleEngineService(org.apache.oozie.service.BundleEngineService) BundleEngineException(org.apache.oozie.BundleEngineException) BundleEngine(org.apache.oozie.BundleEngine)

Example 2 with BundleEngine

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

the class V1JobsServlet method getBundleJobs.

@SuppressWarnings("unchecked")
private JSONObject getBundleJobs(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;
        BundleEngine bundleEngine = Services.get().get(BundleEngineService.class).getBundleEngine(getUser(request));
        BundleJobInfo jobs = bundleEngine.getBundleJobs(filter, start, len);
        json = OozieJsonFactory.getBundleJSONObject(jobs, timeZoneId);
    } catch (BundleEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) BundleEngineService(org.apache.oozie.service.BundleEngineService) BundleJobInfo(org.apache.oozie.BundleJobInfo) BundleEngineException(org.apache.oozie.BundleEngineException) BundleEngine(org.apache.oozie.BundleEngine)

Example 3 with BundleEngine

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

the class V1JobsServlet method bulkModifyJobs.

private JSONObject bulkModifyJobs(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException {
    String action = request.getParameter(RestConstants.ACTION_PARAM);
    String jobType = request.getParameter(RestConstants.JOBTYPE_PARAM);
    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;
    JSONObject json;
    List<String> ids = new ArrayList<String>();
    if (jobType.equals("wf")) {
        WorkflowsInfo jobs;
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getDagEngine(getUser(request));
        try {
            switch(action) {
                case RestConstants.JOB_ACTION_KILL:
                    jobs = dagEngine.killJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_SUSPEND:
                    jobs = dagEngine.suspendJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_RESUME:
                    jobs = dagEngine.resumeJobs(filter, start, len);
                    break;
                default:
                    throw new DagEngineException(ErrorCode.E0301, action);
            }
        } catch (DagEngineException ex) {
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
        }
        json = OozieJsonFactory.getWFJSONObject(jobs, timeZoneId);
    } else if (jobType.equals("bundle")) {
        BundleJobInfo jobs;
        BundleEngine bundleEngine = Services.get().get(BundleEngineService.class).getBundleEngine(getUser(request));
        try {
            switch(action) {
                case RestConstants.JOB_ACTION_KILL:
                    jobs = bundleEngine.killJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_SUSPEND:
                    jobs = bundleEngine.suspendJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_RESUME:
                    jobs = bundleEngine.resumeJobs(filter, start, len);
                    break;
                default:
                    throw new BundleEngineException(ErrorCode.E0301, action);
            }
        } catch (BundleEngineException ex) {
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
        }
        json = OozieJsonFactory.getBundleJSONObject(jobs, timeZoneId);
    } else {
        CoordinatorJobInfo jobs;
        CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
        try {
            switch(action) {
                case RestConstants.JOB_ACTION_KILL:
                    jobs = coordEngine.killJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_SUSPEND:
                    jobs = coordEngine.suspendJobs(filter, start, len);
                    break;
                case RestConstants.JOB_ACTION_RESUME:
                    jobs = coordEngine.resumeJobs(filter, start, len);
                    break;
                default:
                    throw new CoordinatorEngineException(ErrorCode.E0301, action);
            }
        } catch (CoordinatorEngineException ex) {
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
        }
        json = OozieJsonFactory.getCoordJSONObject(jobs, timeZoneId);
    }
    json.put(JsonTags.JOB_IDS, toJSONArray(ids));
    return json;
}
Also used : CoordinatorJobInfo(org.apache.oozie.CoordinatorJobInfo) ArrayList(java.util.ArrayList) BundleJobInfo(org.apache.oozie.BundleJobInfo) BundleEngine(org.apache.oozie.BundleEngine) DagEngineService(org.apache.oozie.service.DagEngineService) DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) JSONObject(org.json.simple.JSONObject) WorkflowsInfo(org.apache.oozie.WorkflowsInfo) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) BundleEngineException(org.apache.oozie.BundleEngineException) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException)

Example 4 with BundleEngine

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

the class V1JobsServlet method getBulkJobs.

@SuppressWarnings("unchecked")
private JSONObject getBulkJobs(HttpServletRequest request) throws XServletException, IOException {
    JSONObject json = new JSONObject();
    try {
        // REST API
        String bulkFilter = request.getParameter(RestConstants.JOBS_BULK_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;
        BundleEngine bundleEngine = Services.get().get(BundleEngineService.class).getBundleEngine(getUser(request));
        BulkResponseInfo bulkResponse = bundleEngine.getBulkJobs(bulkFilter, start, len);
        List<BulkResponseImpl> responsesToJson = bulkResponse.getResponses();
        json.put(JsonTags.BULK_RESPONSES, BulkResponseImpl.toJSONArray(responsesToJson, timeZoneId));
        json.put(JsonTags.BULK_RESPONSE_TOTAL, bulkResponse.getTotal());
        json.put(JsonTags.BULK_RESPONSE_OFFSET, bulkResponse.getStart());
        json.put(JsonTags.BULK_RESPONSE_LEN, bulkResponse.getLen());
    } catch (BaseEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl) BundleEngineService(org.apache.oozie.service.BundleEngineService) BulkResponseInfo(org.apache.oozie.BulkResponseInfo) BaseEngineException(org.apache.oozie.BaseEngineException) BundleEngine(org.apache.oozie.BundleEngine)

Example 5 with BundleEngine

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

the class LocalOozie method getClientBundle.

/**
 * <p>
 * The returned instance is configured with the user name of the JVM (the
 * value of the system property 'user.name').
 * <p>
 * The following methods of the client are NOP in the returned instance:
 * {@link org.apache.oozie.client.OozieClient#validateWSVersion},
 * {@link org.apache.oozie.client.OozieClient#setHeader},
 * {@link org.apache.oozie.client.OozieClient#getHeader},
 * {@link org.apache.oozie.client.OozieClient#removeHeader},
 * {@link org.apache.oozie.client.OozieClient#getHeaderNames},
 * {@link org.apache.oozie.client.OozieClient#setSystemMode(OozieClient.SYSTEM_MODE)},
 * {@link org.apache.oozie.client.OozieClient#getHeaders},
 * {@link org.apache.oozie.client.OozieClient#getClientBuildVersion}.
 *
 * @return a {@link org.apache.oozie.client.OozieClient} for LocalOozie.
 */
public static OozieClient getClientBundle(String user) {
    if (!localOozieActive) {
        throw new IllegalStateException("LocalOozie is not initialized");
    }
    ParamChecker.notEmpty(user, "user");
    BundleEngine bundleEngine = Services.get().get(BundleEngineService.class).getBundleEngine(user);
    return new LocalOozieClientBundle(bundleEngine);
}
Also used : LocalOozieClientBundle(org.apache.oozie.LocalOozieClientBundle) BundleEngineService(org.apache.oozie.service.BundleEngineService) BundleEngine(org.apache.oozie.BundleEngine)

Aggregations

BundleEngine (org.apache.oozie.BundleEngine)6 BundleEngineService (org.apache.oozie.service.BundleEngineService)4 JSONObject (org.json.simple.JSONObject)4 BundleEngineException (org.apache.oozie.BundleEngineException)3 BundleJobInfo (org.apache.oozie.BundleJobInfo)2 DagEngineException (org.apache.oozie.DagEngineException)2 ArrayList (java.util.ArrayList)1 BaseEngineException (org.apache.oozie.BaseEngineException)1 BulkResponseInfo (org.apache.oozie.BulkResponseInfo)1 BundleActionBean (org.apache.oozie.BundleActionBean)1 BundleJobBean (org.apache.oozie.BundleJobBean)1 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)1 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)1 CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)1 DagEngine (org.apache.oozie.DagEngine)1 LocalOozieClientBundle (org.apache.oozie.LocalOozieClientBundle)1 WorkflowsInfo (org.apache.oozie.WorkflowsInfo)1 BulkResponseImpl (org.apache.oozie.client.rest.BulkResponseImpl)1 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)1 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)1