Search in sources :

Example 56 with CoordJobGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor 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 57 with CoordJobGetJPAExecutor

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

the class TestCoordResumeXCommand method testCoordSuspendAndResumeForPrep.

/**
 * Test : suspend a PREP coordinator job and resume to PREP
 *
 * @throws Exception
 */
public void testCoordSuspendAndResumeForPrep() throws Exception {
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, false, false);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.PREP);
    new CoordSuspendXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.PREPSUSPENDED);
    new CoordResumeXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.PREP);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Example 58 with CoordJobGetJPAExecutor

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

the class TestCoordResumeXCommand method testCoordSuspendAndResumeForPrepWithBackwardCompatibility.

/**
 * Test : suspend a PREP coordinator job and resume to PREP
 *
 * @throws Exception
 */
public void testCoordSuspendAndResumeForPrepWithBackwardCompatibility() throws Exception {
    Services.get().destroy();
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_COORD_STATUS, "true");
    services = new Services();
    services.init();
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, false, false);
    job.setAppNamespace(SchemaService.COORDINATOR_NAMESPACE_URI_1);
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_APPNAMESPACE, job);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.PREP);
    new CoordSuspendXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.SUSPENDED);
    new CoordResumeXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNING);
}
Also used : Services(org.apache.oozie.service.Services) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Example 59 with CoordJobGetJPAExecutor

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

the class TestCoordResumeXCommand method testCoordSuspendAndResumeForRunning.

/**
 * Test : suspend a RUNNING coordinator job and resume to RUNNING
 *
 * @throws Exception
 */
public void testCoordSuspendAndResumeForRunning() throws Exception {
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(job.getId());
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNING);
    new CoordSuspendXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.SUSPENDED);
    new CoordResumeXCommand(job.getId()).call();
    job = jpaService.execute(coordJobGetCmd);
    assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNING);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Example 60 with CoordJobGetJPAExecutor

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

the class TestCoordSubmitXCommand method checkCoordJobs.

/**
 * Helper methods
 *
 * @param jobId
 */
private CoordinatorJobBean checkCoordJobs(String jobId) {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        CoordinatorJobBean job = jpaService.execute(new CoordJobGetJPAExecutor(jobId));
        return job;
    } catch (JPAExecutorException e) {
        fail("Job ID " + jobId + " was not stored properly in db");
    }
    return null;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Aggregations

CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)121 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)114 JPAService (org.apache.oozie.service.JPAService)85 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)79 Date (java.util.Date)66 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)42 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)32 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)30 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)29 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)25 BundleJobBean (org.apache.oozie.BundleJobBean)21 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)21 BundleActionBean (org.apache.oozie.BundleActionBean)20 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)20 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)20 CommandException (org.apache.oozie.command.CommandException)18 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)16 IOException (java.io.IOException)5 CoordMaterializeTriggerRunnable (org.apache.oozie.service.CoordMaterializeTriggerService.CoordMaterializeTriggerRunnable)5 Services (org.apache.oozie.service.Services)5