Search in sources :

Example 6 with MapReduceActionExecutor

use of org.apache.oozie.action.hadoop.MapReduceActionExecutor in project oozie by apache.

the class TestRecoveryService method testWorkflowActionRecoveryUserRetry.

/**
 * Tests functionality of the Recovery Service Runnable command. </p> Starts an action with USER_RETRY status.
 * Runs the recovery runnable, and ensures the state changes to OK and the job completes successfully.
 *
 * @throws Exception
 */
public void testWorkflowActionRecoveryUserRetry() throws Exception {
    final JPAService jpaService = Services.get().get(JPAService.class);
    WorkflowJobBean job1 = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action1 = this.addRecordToWfActionTable(job1.getId(), "1", WorkflowAction.Status.USER_RETRY);
    WorkflowJobBean job2 = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action2 = createWorkflowActionSetPending(job2.getId(), WorkflowAction.Status.USER_RETRY);
    // Default recovery created time is 7 days.
    action2.setCreatedTime(new Date(new Date().getTime() - 8 * RecoveryService.ONE_DAY_MILLISCONDS));
    WorkflowActionInsertJPAExecutor actionInsertCmd = new WorkflowActionInsertJPAExecutor(action2);
    jpaService.execute(actionInsertCmd);
    Runnable recoveryRunnable = new RecoveryRunnable(0, 60, 60);
    recoveryRunnable.run();
    sleep(3000);
    final WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action1.getId());
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowActionBean a = jpaService.execute(wfActionGetCmd);
            return a.getExternalId() != null;
        }
    });
    action1 = jpaService.execute(wfActionGetCmd);
    assertNotNull(action1.getExternalId());
    assertEquals(WorkflowAction.Status.RUNNING, action1.getStatus());
    // Action 2 should not get recover as it's created time is older then 7 days
    action2 = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, action2.getId());
    assertNull(action2.getExternalId());
    assertEquals(WorkflowAction.Status.USER_RETRY, action2.getStatus());
    ActionExecutorContext context = new ActionXCommand.ActionExecutorContext(job1, action1, false, false);
    MapReduceActionExecutor actionExecutor = new MapReduceActionExecutor();
    Configuration conf = actionExecutor.createBaseHadoopConf(context, XmlUtils.parseXml(action1.getConf()));
    String launcherId = action1.getExternalId();
    waitUntilYarnAppDoneAndAssertSuccess(launcherId);
    Map<String, String> actionData = LauncherHelper.getActionData(getFileSystem(), context.getActionDir(), conf);
    assertTrue(LauncherHelper.hasIdSwap(actionData));
}
Also used : RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) WorkflowActionInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionInsertJPAExecutor) RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) MapReduceActionExecutor(org.apache.oozie.action.hadoop.MapReduceActionExecutor) ActionExecutorContext(org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)6 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)6 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)6 MapReduceActionExecutor (org.apache.oozie.action.hadoop.MapReduceActionExecutor)6 ActionExecutorContext (org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext)6 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)6 JPAService (org.apache.oozie.service.JPAService)5 JobClient (org.apache.hadoop.mapred.JobClient)3 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)3 HadoopAccessorService (org.apache.oozie.service.HadoopAccessorService)3 XConfiguration (org.apache.oozie.util.XConfiguration)3 RunningJob (org.apache.hadoop.mapred.RunningJob)2 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)2 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)2 Services (org.apache.oozie.service.Services)2 IOException (java.io.IOException)1 Date (java.util.Date)1 WorkflowActionInsertJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionInsertJPAExecutor)1 RecoveryRunnable (org.apache.oozie.service.RecoveryService.RecoveryRunnable)1