Search in sources :

Example 11 with CoordinatorEngine

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

the class V1JobsServlet method submitCoordinatorJob.

/**
 * 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);
        String id = null;
        boolean dryrun = false;
        if (action != null) {
            dryrun = (action.equals(RestConstants.JOB_ACTION_DRYRUN));
        }
        if (dryrun) {
            id = coordEngine.dryRunSubmit(conf);
        } 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;
}
Also used : JSONObject(org.json.simple.JSONObject) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Example 12 with CoordinatorEngine

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

the class V2JobServlet method updateJob.

/**
 * Update coord job.
 *
 * @param request the request
 * @param response the response
 * @return the JSON object
 * @throws XServletException the x servlet exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
@SuppressWarnings("unchecked")
@Override
protected JSONObject updateJob(HttpServletRequest request, HttpServletResponse response, Configuration conf) throws XServletException, IOException {
    CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
    JSONObject json = new JSONObject();
    try {
        String jobId = getResourceName(request);
        boolean dryrun = StringUtils.isEmpty(request.getParameter(RestConstants.JOB_ACTION_DRYRUN)) ? false : Boolean.parseBoolean(request.getParameter(RestConstants.JOB_ACTION_DRYRUN));
        boolean showDiff = StringUtils.isEmpty(request.getParameter(RestConstants.JOB_ACTION_SHOWDIFF)) ? true : Boolean.parseBoolean(request.getParameter(RestConstants.JOB_ACTION_SHOWDIFF));
        String diff = coordEngine.updateJob(conf, jobId, dryrun, showDiff);
        JSONObject diffJson = new JSONObject();
        diffJson.put(JsonTags.COORD_UPDATE_DIFF, diff);
        json.put(JsonTags.COORD_UPDATE, diffJson);
    } catch (CoordinatorEngineException e) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, e);
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService)

Example 13 with CoordinatorEngine

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

the class V2JobServlet method getWfActionByJobIdAndName.

@Override
protected JSONObject getWfActionByJobIdAndName(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException {
    CoordinatorEngine coordEngine = Services.get().get(CoordinatorEngineService.class).getCoordinatorEngine(getUser(request));
    String jobId = getResourceName(request);
    String action = request.getParameter(RestConstants.ACTION_NAME_PARAM);
    String startStr = request.getParameter(RestConstants.OFFSET_PARAM);
    String lenStr = request.getParameter(RestConstants.LEN_PARAM);
    String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM);
    timeZoneId = (timeZoneId == null) ? "GMT" : timeZoneId;
    if (action == null) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0305, RestConstants.ACTION_NAME_PARAM);
    }
    int offset = (startStr != null) ? Integer.parseInt(startStr) : 1;
    offset = (offset < 1) ? 1 : offset;
    /**
     * set default number of wf actions to be retrieved to
     * default number of coordinator actions to be retrieved
     */
    int defaultLen = ConfigurationService.getInt(COORD_ACTIONS_DEFAULT_LENGTH);
    int len = (lenStr != null) ? Integer.parseInt(lenStr) : 0;
    len = getCoordinatorJobLength(defaultLen, len);
    try {
        JSONObject json = new JSONObject();
        List<CoordinatorWfActionBean> coordWfActions = coordEngine.getWfActionByJobIdAndName(jobId, action, offset, len);
        JSONArray array = new JSONArray();
        for (CoordinatorWfActionBean coordWfAction : coordWfActions) {
            array.add(coordWfAction.toJSONObject(timeZoneId));
        }
        json.put(JsonTags.COORDINATOR_JOB_ID, jobId);
        json.put(JsonTags.COORDINATOR_WF_ACTIONS, array);
        return json;
    } catch (CoordinatorEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) JSONArray(org.json.simple.JSONArray) CoordinatorEngineException(org.apache.oozie.CoordinatorEngineException) CoordinatorEngineService(org.apache.oozie.service.CoordinatorEngineService) CoordinatorWfActionBean(org.apache.oozie.CoordinatorWfActionBean)

Example 14 with CoordinatorEngine

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

the class TestSLAAlertXCommand method testCoordSLAAlertCommands.

public void testCoordSLAAlertCommands() throws Exception {
    setupSLAJobs();
    final CoordinatorEngine engine = new CoordinatorEngine("u");
    String jobIdsStr = coord1.getId();
    String actions = "1-3,5";
    String coords = null;
    engine.disableSLAAlert(jobIdsStr, actions, null, coords);
    checkSLAStatus(coord1.getId() + "@1", true);
    checkSLAStatus(coord1.getId() + "@2", true);
    checkSLAStatus(coord1.getId() + "@3", true);
    checkSLAStatus(coord1.getId() + "@5", true);
    checkSLAStatus(coord1.getId() + "@4", false);
    actions = "1-3";
    engine.enableSLAAlert(jobIdsStr, actions, null, null);
    checkSLAStatus(coord1.getId() + "@1", false);
    checkSLAStatus(coord1.getId() + "@2", false);
    checkSLAStatus(coord1.getId() + "@3", false);
    checkSLAStatus(coord1.getId() + "@5", true);
    checkSLAStatus(coord1.getId() + "@4", false);
    engine.enableSLAAlert(jobIdsStr, null, null, null);
    checkSLAStatus(coord1.getId() + "@1", false);
    checkSLAStatus(coord1.getId() + "@2", false);
    checkSLAStatus(coord1.getId() + "@3", false);
    checkSLAStatus(coord1.getId() + "@5", false);
    checkSLAStatus(coord1.getId() + "@4", false);
    CoordinatorJobBean job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, jobIdsStr);
    XConfiguration xConf = new XConfiguration(new StringReader(job.getConf()));
    assertEquals(xConf.get(OozieClient.SLA_DISABLE_ALERT), null);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) StringReader(java.io.StringReader)

Example 15 with CoordinatorEngine

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

the class TestPastActionsTimeOut method _testSubmitJob.

private String _testSubmitJob(String appPath) throws Exception {
    Configuration conf = new XConfiguration();
    String appXml = "<coordinator-app name=\"NAME\" frequency=\"15\" start=\"2009-02-01T01:00Z\"" + " end=\"2009-02-01T02:00Z\" timezone=\"UTC\" " + "xmlns=\"uri:oozie:coordinator:0.1\"> <controls> <timeout>10</timeout> <concurrency>2</concurrency> " + "<execution>LIFO</execution> </controls> <datasets> " + "<dataset name=\"a\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("${YEAR}/${DAY}") + "</uri-template> </dataset> " + "<dataset name=\"local_a\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("${YEAR}/${DAY}") + "</uri-template> </dataset> " + "</datasets> <input-events> " + "<data-in name=\"A\" dataset=\"a\"> <instance>${coord:latest(0)}</instance> </data-in>  " + "</input-events> " + "<output-events> <data-out name=\"LOCAL_A\" dataset=\"local_a\"> " + "<instance>${coord:current(-1)}</instance> </data-out> </output-events> <action> <workflow>" + " <app-path>hdfs:///tmp/workflows/</app-path> " + "<configuration> <property> <name>inputA</name> <value>${coord:dataIn('A')}</value> </property> " + "<property> <name>inputB</name> <value>${coord:dataOut('LOCAL_A')}</value> " + "</property></configuration> </workflow> </action> </coordinator-app>";
    writeToFile(appXml, appPath);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    CoordinatorEngine ce = new CoordinatorEngine(getTestUser());
    String jobId = ce.submitJob(conf, true);
    assertEquals(jobId.substring(jobId.length() - 2), "-C");
    checkCoordJob(jobId);
    return jobId;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CoordinatorEngine(org.apache.oozie.CoordinatorEngine)

Aggregations

CoordinatorEngine (org.apache.oozie.CoordinatorEngine)17 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)7 CoordinatorEngineException (org.apache.oozie.CoordinatorEngineException)6 CoordinatorEngineService (org.apache.oozie.service.CoordinatorEngineService)6 JSONObject (org.json.simple.JSONObject)6 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 IOException (java.io.IOException)3 Date (java.util.Date)3 XConfiguration (org.apache.oozie.util.XConfiguration)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Configuration (org.apache.hadoop.conf.Configuration)2 CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)2 DagEngineException (org.apache.oozie.DagEngineException)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 CoordinatorAction (org.apache.oozie.client.CoordinatorAction)2 CoordinatorJob (org.apache.oozie.client.CoordinatorJob)2 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)2 StoreException (org.apache.oozie.store.StoreException)2