Search in sources :

Example 6 with WorkflowActionsGetForJobJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor in project oozie by apache.

the class TestWorkflowActionRetryInfoXCommand method validateRetryConsoleUrl.

public void validateRetryConsoleUrl(String wfXml) throws Exception {
    Configuration conf = new XConfiguration();
    File workflowUri = new File(getTestCaseDir(), "workflow.xml");
    writeToFile(wfXml, workflowUri);
    conf.set(OozieClient.APP_PATH, workflowUri.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("external-status", "error");
    conf.set("signal-value", "based_on_action_status");
    conf.set("external-childIds", "1");
    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 action1 = null;
    WorkflowActionBean action2 = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test") && bean.getName().equals("action1")) {
            action1 = bean;
        } else if (bean.getType().equals("test") && bean.getName().equals("action2")) {
            action2 = bean;
        }
    }
    WorkflowActionRetryInfoXCommand command = new WorkflowActionRetryInfoXCommand(action1.getId());
    List<Map<String, String>> retriesList = command.call();
    assertEquals(2, retriesList.size());
    assertEquals(2, action1.getUserRetryCount());
    assertEquals(retriesList.get(0).get(JsonTags.ACTION_ATTEMPT), "1");
    assertEquals(retriesList.get(0).get(JsonTags.WORKFLOW_ACTION_START_TIME), JsonUtils.formatDateRfc822(action1.getStartTime()));
    assertNotNull(retriesList.get(0).get(JsonTags.WORKFLOW_ACTION_CONSOLE_URL));
    assertNotNull(retriesList.get(0).get(JsonTags.WORKFLOW_ACTION_EXTERNAL_CHILD_IDS));
    assertNotNull(retriesList.get(1).get(JsonTags.WORKFLOW_ACTION_CONSOLE_URL));
    assertNotNull(retriesList.get(1).get(JsonTags.WORKFLOW_ACTION_EXTERNAL_CHILD_IDS));
    final Date actionEndTime = action2 == null ? action1.getEndTime() : action2.getEndTime();
    final Date secondRetryEndTime = JsonUtils.parseDateRfc822(retriesList.get(1).get(JsonTags.WORKFLOW_ACTION_END_TIME));
    assertTrue("action end time should be within ten seconds of second retry end time", new Interval(secondRetryEndTime.getTime(), secondRetryEndTime.getTime() + 10_000).contains(actionEndTime.getTime()));
}
Also used : WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) File(java.io.File) Map(java.util.Map) Interval(org.joda.time.Interval)

Example 7 with WorkflowActionsGetForJobJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor in project oozie by apache.

the class KillXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    try {
        jpaService = Services.get().get(JPAService.class);
        if (jpaService != null) {
            this.wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_KILL, wfId);
            this.actionList = jpaService.execute(new WorkflowActionsGetForJobJPAExecutor(wfId));
            LogUtils.setLogInfo(wfJob);
        } else {
            throw new CommandException(ErrorCode.E0610);
        }
        actionService = Services.get().get(ActionService.class);
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) ActionService(org.apache.oozie.service.ActionService)

Example 8 with WorkflowActionsGetForJobJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor in project oozie by apache.

the class TestOozieJobInfo method testInfoWithBundle.

public void testInfoWithBundle() throws Exception {
    Services.get().getConf().setBoolean(OozieJobInfo.CONF_JOB_INFO, true);
    OozieJobInfo.setJobInfo(true);
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    Configuration jobConf = null;
    try {
        jobConf = new XConfiguration(new StringReader(job.getConf()));
    } catch (IOException ioe) {
        log.warn("Configuration parse error. read from DB :" + job.getConf(), ioe);
        throw new CommandException(ErrorCode.E1005, ioe);
    }
    setCoordConf(jobConf);
    Path appPath = new Path(jobConf.get(OozieClient.BUNDLE_APP_PATH), "bundle.xml");
    jobConf.set(OozieClient.BUNDLE_APP_PATH, appPath.toString());
    BundleSubmitXCommand submitCmd = new BundleSubmitXCommand(jobConf);
    submitCmd.call();
    BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(submitCmd.getJob().getId());
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(job.getStatus(), Job.Status.PREP);
    new BundleStartXCommand(job.getId()).call();
    sleep(2000);
    List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
    assertEquals(1, actions.size());
    final String bundleID = job.getId();
    waitFor(200000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, bundleID);
            return actions.get(0).getStatus().equals(Job.Status.RUNNING);
        }
    });
    actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
    final String cordID = actions.get(0).getCoordId();
    waitFor(200000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordJobGetJPAExecutor coordGetCmd2 = new CoordJobGetJPAExecutor(cordID);
            CoordinatorJobBean cc = jpaService.execute(coordGetCmd2);
            return cc.getStatus().equals(Job.Status.RUNNING);
        }
    });
    final String jobID = jpaService.execute(new WorkflowJobsGetFromCoordParentIdJPAExecutor(cordID, 1)).get(0);
    final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobID);
    waitFor(200000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
            WorkflowActionBean action = null;
            for (WorkflowActionBean bean : actions) {
                if (bean.getName().contains("hadoop")) {
                    action = bean;
                    break;
                }
            }
            return action.getStatus().toString().equalsIgnoreCase(Job.Status.RUNNING.toString());
        }
    });
    final WorkflowJobGetJPAExecutor wfeExc = new WorkflowJobGetJPAExecutor(jobID);
    WorkflowJobBean wfbean = jpaService.execute(wfeExc);
    List<WorkflowActionBean> actionList = jpaService.execute(actionsGetExecutor);
    ActionExecutorContext context = new ActionXCommand.ActionExecutorContext(wfbean, actionList.get(1), false, false);
    MapReduceActionExecutor actionExecutor = new MapReduceActionExecutor();
    Configuration conf = actionExecutor.createBaseHadoopConf(context, XmlUtils.parseXml(actionList.get(1).getConf()));
    String user = conf.get("user.name");
    FileSystem fs = getFileSystem();
    Configuration jobXmlConf = new XConfiguration(fs.open(getPathToWorkflowResource(user, wfbean, services, context, LauncherAM.LAUNCHER_JOB_CONF_XML)));
    String jobInfo = jobXmlConf.get(OozieJobInfo.JOB_INFO_KEY);
    // BUNDLE_ID;BUNDLE_NAME;COORDINATOR_NAME;COORDINATOR_NOMINAL_TIME;
    // WORKFLOW_ID;WORKFLOW_NAME;WORKFLOW_DEPTH;WORKFLOW_SUPERPARENT;
    // ACTION_TYPE;ACTION_NAME,JOB_INFO,custom_info;
    assertEquals(jobInfo.split(OozieJobInfo.SEPARATOR).length, 13);
    assertTrue(jobInfo.contains(bundleID));
    assertTrue(jobInfo.contains("bundle.name=test_bundle,"));
    assertTrue(jobInfo.contains(cordID));
    assertTrue(jobInfo.contains("action.type=map-reduce"));
    assertTrue(jobInfo.contains("wf.depth=0"));
    assertTrue(jobInfo.contains("wf.superparent.id=" + cordID));
    assertTrue(jobInfo.contains(",testing=test,"));
    assertTrue(jobInfo.contains(",coord.nominal.time="));
    assertTrue(jobInfo.contains("launcher=true"));
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) FileSystem(org.apache.hadoop.fs.FileSystem) StringReader(java.io.StringReader) List(java.util.List) WorkflowJobsGetFromCoordParentIdJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobsGetFromCoordParentIdJPAExecutor) ActionExecutorContext(org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext) Path(org.apache.hadoop.fs.Path) BundleSubmitXCommand(org.apache.oozie.command.bundle.BundleSubmitXCommand) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) XConfiguration(org.apache.oozie.util.XConfiguration) BundleStartXCommand(org.apache.oozie.command.bundle.BundleStartXCommand) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 9 with WorkflowActionsGetForJobJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor in project oozie by apache.

the class TestActionErrors method _testNonTransientWithCoordActionUpdate.

/**
 * Provides functionality to test non transient failures and coordinator action update
 *
 * @param errorType the error type. (start.non-transient, end.non-transient)
 * @param expStatus1 expected status. (START_MANUAL, END_MANUAL)
 * @param expErrorMsg expected error message.
 * @throws Exception
 */
private void _testNonTransientWithCoordActionUpdate(String errorType, WorkflowActionBean.Status expStatus1, String expErrorMsg) throws Exception {
    String workflowPath = getTestCaseFileUri("workflow.xml");
    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, workflowPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("signal-value", "OK");
    conf.set("external-status", "ok");
    conf.set("error", errorType);
    final String jobId = engine.submitJob(conf, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    final CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", jobId, "RUNNING", 0);
    engine.start(jobId);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUSPENDED);
        }
    });
    assertNotNull(jpaService);
    WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(jobId);
    WorkflowJobBean job = jpaService.execute(wfGetCmd);
    WorkflowActionsGetForJobJPAExecutor actionsGetExe = new WorkflowActionsGetForJobJPAExecutor(jobId);
    List<WorkflowActionBean> actionsList = jpaService.execute(actionsGetExe);
    int n = actionsList.size();
    WorkflowActionBean action = actionsList.get(n - 1);
    assertEquals("TEST_ERROR", action.getErrorCode());
    assertEquals(expErrorMsg, action.getErrorMessage());
    assertEquals(expStatus1, action.getStatus());
    assertFalse(action.isPending());
    assertEquals(WorkflowJob.Status.SUSPENDED, job.getStatus());
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorActionBean coordAction2 = jpaService.execute(new CoordActionGetForExternalIdJPAExecutor(jobId));
            return coordAction2.getStatus().equals(CoordinatorAction.Status.SUSPENDED);
        }
    });
    coordAction = jpaService.execute(new CoordActionGetForExternalIdJPAExecutor(jobId));
    assertEquals(CoordinatorAction.Status.SUSPENDED, coordAction.getStatus());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) FileWriter(java.io.FileWriter) Reader(java.io.Reader) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) JPAService(org.apache.oozie.service.JPAService) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) CoordActionGetForExternalIdJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetForExternalIdJPAExecutor)

Example 10 with WorkflowActionsGetForJobJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor in project oozie by apache.

the class TestWorkflowActionsGetForJobJPAExecutor method _testGetActions.

private void _testGetActions(String jobId) throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowActionsGetForJobJPAExecutor actionsGetExe = new WorkflowActionsGetForJobJPAExecutor(jobId);
    List<WorkflowActionBean> list = jpaService.execute(actionsGetExe);
    assertNotNull(list);
    assertEquals(list.size(), 3);
}
Also used : WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Aggregations

WorkflowActionsGetForJobJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor)12 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)11 JPAService (org.apache.oozie.service.JPAService)10 Configuration (org.apache.hadoop.conf.Configuration)9 XConfiguration (org.apache.oozie.util.XConfiguration)9 File (java.io.File)6 List (java.util.List)6 FileWriter (java.io.FileWriter)5 Reader (java.io.Reader)5 Writer (java.io.Writer)5 DagEngine (org.apache.oozie.DagEngine)5 CommandException (org.apache.oozie.command.CommandException)5 IOException (java.io.IOException)4 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)4 Date (java.util.Date)3 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)3 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)3 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)3 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2 ActionCheckRunnable (org.apache.oozie.service.ActionCheckerService.ActionCheckRunnable)2