Search in sources :

Example 16 with DagEngineException

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

Example 17 with DagEngineException

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

the class V0JobServlet method getJobDefinition.

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

Example 18 with DagEngineException

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

the class V0JobsServlet method getJobIdForExternalId.

/**
 * v0 service implementation to get a JSONObject representation of a job from its external ID
 */
@Override
protected JSONObject getJobIdForExternalId(HttpServletRequest request, String externalId) throws XServletException, IOException {
    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 19 with DagEngineException

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

the class TestPurgeService method testPurgeServiceForWorkflow.

/**
 * Tests the {@link org.apache.oozie.service.PurgeService}.
 * </p>
 * Creates and runs a new workflow job to completion.
 * Attempts to purge jobs older than a day. Verifies the presence of the job in the system.
 * </p>
 * Sets the end date for the same job to make it qualify for the purge criteria.
 * Calls the purge service, and ensure the job does not exist in the system.
 */
public void testPurgeServiceForWorkflow() throws Exception {
    Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    final DagEngine engine = new DagEngine("u");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
    conf.setStrings(OozieClient.USER_NAME, getTestUser());
    conf.setStrings(OozieClient.GROUP_NAME, getTestGroup());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("external-status", "ok");
    conf.set("signal-value", "based_on_action_status");
    final String jobId = engine.submitJob(conf, true);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED);
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());
    new PurgeXCommand(1, 1, 1, 10000).call();
    sleep(1000);
    JPAService jpaService = Services.get().get(JPAService.class);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(jobId);
    WorkflowJobBean wfBean = jpaService.execute(wfJobGetCmd);
    Date endDate = new Date(System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000);
    wfBean.setEndTime(endDate);
    wfBean.setLastModifiedTime(new Date());
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END, wfBean);
    Runnable purgeRunnable = new PurgeRunnable(1, 1, 1, 100);
    purgeRunnable.run();
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            try {
                engine.getJob(jobId).getStatus();
            } catch (Exception ex) {
                return true;
            }
            return false;
        }
    });
    try {
        engine.getJob(jobId).getStatus();
        fail("Job should be purged. Should fail.");
    } catch (Exception ex) {
        assertEquals(ex.getClass(), DagEngineException.class);
        DagEngineException dex = (DagEngineException) ex;
        assertEquals(ErrorCode.E0604, dex.getErrorCode());
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) Reader(java.io.Reader) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) DagEngineException(org.apache.oozie.DagEngineException) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) PurgeXCommand(org.apache.oozie.command.PurgeXCommand) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

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