Search in sources :

Example 11 with ActionExecutorContext

use of org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext in project oozie by apache.

the class TestActionStartXCommand method testActionStart.

public void testActionStart() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP);
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
    new ActionStartXCommand(action.getId(), "map-reduce").call();
    action = jpaService.execute(wfActionGetCmd);
    assertNotNull(action.getExternalId());
    ActionExecutorContext context = new ActionXCommand.ActionExecutorContext(job, action, false, false);
    MapReduceActionExecutor actionExecutor = new MapReduceActionExecutor();
    Configuration conf = actionExecutor.createBaseHadoopConf(context, XmlUtils.parseXml(action.getConf()));
    String launcherId = action.getExternalId();
    waitUntilYarnAppDoneAndAssertSuccess(launcherId);
    Map<String, String> actionData = LauncherHelper.getActionData(getFileSystem(), context.getActionDir(), conf);
    assertTrue(LauncherHelper.hasIdSwap(actionData));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) MapReduceActionExecutor(org.apache.oozie.action.hadoop.MapReduceActionExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) ActionExecutorContext(org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext)

Example 12 with ActionExecutorContext

use of org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext 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

ActionExecutorContext (org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext)12 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)10 Configuration (org.apache.hadoop.conf.Configuration)8 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)8 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)7 JPAService (org.apache.oozie.service.JPAService)7 IOException (java.io.IOException)6 Date (java.util.Date)6 MapReduceActionExecutor (org.apache.oozie.action.hadoop.MapReduceActionExecutor)6 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)6 CommandException (org.apache.oozie.command.CommandException)5 HadoopAccessorService (org.apache.oozie.service.HadoopAccessorService)4 XConfiguration (org.apache.oozie.util.XConfiguration)4 WorkflowException (org.apache.oozie.workflow.WorkflowException)4 ArrayList (java.util.ArrayList)3 JobClient (org.apache.hadoop.mapred.JobClient)3 WorkflowActionQuery (org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery)3 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)3 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)3 Map (java.util.Map)2