Search in sources :

Example 26 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestActionStartXCommand method addRecordToWfActionTable.

/* (non-Javadoc)
     * @see org.apache.oozie.test.XDataTestCase#addRecordToWfActionTable(
     * java.lang.String, java.lang.String, org.apache.oozie.client.WorkflowAction.Status)
     */
@Override
protected WorkflowActionBean addRecordToWfActionTable(String wfId, String actionName, WorkflowAction.Status status) throws Exception {
    WorkflowActionBean action = createWorkflowActionSetPending(wfId, status);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        WorkflowActionInsertJPAExecutor actionInsertCmd = new WorkflowActionInsertJPAExecutor(action);
        jpaService.execute(actionInsertCmd);
    } catch (JPAExecutorException ce) {
        ce.printStackTrace();
        fail("Unable to insert the test wf action record to table");
        throw ce;
    }
    return action;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowActionInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionInsertJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 27 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestActionUserRetry method testUserRetryPolicy.

public void testUserRetryPolicy() throws JPAExecutorException, IOException, CommandException {
    Configuration conf = new XConfiguration();
    String workflowUri = getTestCaseFileUri("workflow.xml");
    // @formatter:off
    String appXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.5\" name=\"wf-fork\">" + "<start to=\"fork1\"/>" + "<fork name=\"fork1\">" + "<path start=\"action1\"/>" + "<path start=\"action2\"/>" + "</fork>" + "<action name=\"action1\" retry-max=\"2\" retry-interval=\"1\" retry-policy=\"exponential\">" + "<test xmlns=\"uri:test\">" + "<signal-value>${wf:conf('signal-value')}</signal-value>" + "<external-status>${wf:conf('external-status')}</external-status> " + "<error>${wf:conf('error')}</error>" + "<avoid-set-execution-data>${wf:conf('avoid-set-execution-data')}</avoid-set-execution-data>" + "<avoid-set-end-data>${wf:conf('avoid-set-end-data')}</avoid-set-end-data>" + "<running-mode>${wf:conf('running-mode')}</running-mode>" + "</test>" + "<ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<action name=\"action2\">" + "<fs></fs><ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<join name=\"join1\" to=\"end\"/>" + "<kill name=\"kill\"><message>killed</message></kill>" + "<end name=\"end\"/>" + "</workflow-app>";
    // @Formatter:on
    writeToFile(appXml, workflowUri);
    conf.set(OozieClient.APP_PATH, workflowUri);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("error", "start.error");
    conf.set("external-status", "error");
    conf.set("signal-value", "based_on_action_status");
    SubmitXCommand sc = new SubmitXCommand(conf);
    final String jobId = sc.call();
    new StartXCommand(jobId).call();
    final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
    final JPAService jpaService = Services.get().get(JPAService.class);
    // set a timeout for exponential retry of action with respect to given
    // retry-interval and retry-max.
    // If retry-interval is 1 then, for first retry, delay will be 1 min,
    // for second retry it will be 2 min, 4, 8, 16 & so on.
    int timeout = (1 + 2) * 60 * 1000;
    waitFor(timeout, new Predicate() {

        public boolean evaluate() throws Exception {
            List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
            WorkflowActionBean action = null;
            for (WorkflowActionBean bean : actions) {
                if (bean.getType().equals("test")) {
                    action = bean;
                    break;
                }
            }
            return (action != null && action.getUserRetryCount() == 2);
        }
    });
    List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
    WorkflowActionBean action = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
            break;
        }
    }
    assertNotNull(action);
    assertEquals(2, action.getUserRetryCount());
}
Also used : WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

Example 28 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestActionUserRetry method testUserRetry.

public void testUserRetry() throws JPAExecutorException, IOException, CommandException {
    Configuration conf = new XConfiguration();
    String workflowUri = getTestCaseFileUri("workflow.xml");
    // @formatter:off
    String appXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.3\" name=\"wf-fork\">" + "<start to=\"fork1\"/>" + "<fork name=\"fork1\">" + "<path start=\"action1\"/>" + "<path start=\"action2\"/>" + "</fork>" + "<action name=\"action1\" retry-max=\"2\" retry-interval=\"0\">" + "<test xmlns=\"uri:test\">" + "<signal-value>${wf:conf('signal-value')}</signal-value>" + "<external-status>${wf:conf('external-status')}</external-status> " + "<error>${wf:conf('error')}</error>" + "<avoid-set-execution-data>${wf:conf('avoid-set-execution-data')}</avoid-set-execution-data>" + "<avoid-set-end-data>${wf:conf('avoid-set-end-data')}</avoid-set-end-data>" + "<running-mode>${wf:conf('running-mode')}</running-mode>" + "</test>" + "<ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<action name=\"action2\">" + "<fs></fs><ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<join name=\"join1\" to=\"end\"/>" + "<kill name=\"kill\"><message>killed</message></kill>" + "<end name=\"end\"/>" + "</workflow-app>";
    // @Formatter:on
    writeToFile(appXml, workflowUri);
    conf.set(OozieClient.APP_PATH, workflowUri);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("error", "start.error");
    conf.set("external-status", "error");
    conf.set("signal-value", "based_on_action_status");
    SubmitXCommand sc = new SubmitXCommand(conf);
    final String jobId = sc.call();
    new StartXCommand(jobId).call();
    final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
    final JPAService jpaService = Services.get().get(JPAService.class);
    waitFor(20 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
            WorkflowActionBean action = null;
            for (WorkflowActionBean bean : actions) {
                if (bean.getType().equals("test")) {
                    action = bean;
                    break;
                }
            }
            return (action != null && action.getUserRetryCount() == 2);
        }
    });
    List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
    WorkflowActionBean action = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
            break;
        }
    }
    assertNotNull(action);
    assertEquals(2, action.getUserRetryCount());
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 29 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestCoordRerunXCommand method addRecordToCoordJobTableWithPausedTime.

protected CoordinatorJobBean addRecordToCoordJobTableWithPausedTime(CoordinatorJob.Status status, boolean pending, boolean doneMatd, Date pausedTime) throws Exception {
    CoordinatorJobBean coordJob = createCoordJob(status, pending, doneMatd);
    coordJob.setPauseTime(pausedTime);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        CoordJobInsertJPAExecutor coordInsertCmd = new CoordJobInsertJPAExecutor(coordJob);
        jpaService.execute(coordInsertCmd);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test coord job record to table");
        throw je;
    }
    return coordJob;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInsertJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Example 30 with JPAService

use of org.apache.oozie.service.JPAService in project oozie by apache.

the class TestCoordRerunXCommand method testCoordRerunInDoneWithError.

/**
 * Test : Rerun DONEWITHERROR coordinator job
 *
 * @throws Exception
 */
public void testCoordRerunInDoneWithError() throws Exception {
    Services.get().destroy();
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
    services = new Services();
    services.init();
    CoordinatorJobBean job = this.addRecordToCoordJobTable(Job.Status.DONEWITHERROR, false, false);
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.FAILED, "coord-rerun-action1.xml", 0);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    job = getCoordinatorJob(job.getId());
    assertEquals(Job.Status.DONEWITHERROR, job.getStatus());
    new CoordRerunXCommand(job.getId(), RestConstants.JOB_COORD_SCOPE_DATE, "2009-12-15T01:00Z", false, true, false, null).call();
    job = getCoordinatorJob(job.getId());
    assertEquals(Job.Status.RUNNINGWITHERROR, job.getStatus());
}
Also used : Services(org.apache.oozie.service.Services) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) JPAService(org.apache.oozie.service.JPAService)

Aggregations

JPAService (org.apache.oozie.service.JPAService)449 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)156 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)152 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)113 Date (java.util.Date)95 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)94 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)84 BundleJobBean (org.apache.oozie.BundleJobBean)78 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)78 ArrayList (java.util.ArrayList)76 CommandException (org.apache.oozie.command.CommandException)66 List (java.util.List)59 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)54 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)54 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)49 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)47 HashMap (java.util.HashMap)41 BundleActionBean (org.apache.oozie.BundleActionBean)35 Configuration (org.apache.hadoop.conf.Configuration)32 EntityManager (javax.persistence.EntityManager)31