Search in sources :

Example 6 with JPAService

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

the class TestBulkMonitorWebServiceAPI method testBundleIdWithCoordId.

public void testBundleIdWithCoordId() throws Exception {
    // fetching coord Ids
    JPAService jpaService = Services.get().get(JPAService.class);
    List<String> coordIds = jpaService.execute(new CoordJobsGetFromParentIdJPAExecutor(bundleId, 10));
    // there are 3 coordinators but giving range as only two of them
    final String coordIdsStr = coordIds.get(0) + "," + coordIds.get(1);
    runTest("/v1/jobs", V1JobsServlet.class, false, new Callable<Void>() {

        public Void call() throws Exception {
            // giving range as 2 of the total 3 coordinators
            String bulkRequest = "bundle=" + bundleId + ";coordinators=" + coordIdsStr + ";actionstatus=KILLED";
            JSONArray array = _requestToServer(bulkRequest);
            assertEquals(2, array.size());
            JSONObject jbundle = (JSONObject) ((JSONObject) array.get(0)).get(JsonTags.BULK_RESPONSE_BUNDLE);
            JSONObject jaction1 = (JSONObject) ((JSONObject) array.get(0)).get(JsonTags.BULK_RESPONSE_ACTION);
            JSONObject jaction2 = (JSONObject) ((JSONObject) array.get(1)).get(JsonTags.BULK_RESPONSE_ACTION);
            assertEquals(jaction1.get(JsonTags.COORDINATOR_ACTION_ID), "Coord1@2");
            assertEquals(jaction2.get(JsonTags.COORDINATOR_ACTION_ID), "Coord2@1");
            return null;
        }
    });
}
Also used : JSONObject(org.json.simple.JSONObject) CoordJobsGetFromParentIdJPAExecutor(org.apache.oozie.executor.jpa.CoordJobsGetFromParentIdJPAExecutor) JSONArray(org.json.simple.JSONArray) JPAService(org.apache.oozie.service.JPAService)

Example 7 with JPAService

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

the class TestBulkMonitorWebServiceAPI method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    services = new Services();
    services.init();
    LocalOozie.start();
    jpaService = Services.get().get(JPAService.class);
    addRecordsForBulkMonitor();
}
Also used : Services(org.apache.oozie.service.Services) JPAService(org.apache.oozie.service.JPAService)

Example 8 with JPAService

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

the class TestPauseTransitService method testUnpauseBundleAndCoordinator.

/**
 * Test : Unpause a PAUSED bundle, then check bundle action has been updated to RUNNING by BundleStatusUpdateXCommand
 *
 * @throws Exception
 */
public void testUnpauseBundleAndCoordinator() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PAUSED, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    job.setPauseTime(null);
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_PAUSE_KICKOFF, job);
    BundleActionBean bundleAction1 = this.addRecordToBundleActionTable(job.getId(), "action1", 0, Job.Status.PAUSED);
    BundleActionBean bundleAction2 = this.addRecordToBundleActionTable(job.getId(), "action2", 0, Job.Status.PAUSED);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob1 = addRecordToCoordJobTable("action1", CoordinatorJob.Status.PAUSED, start, end, false);
    CoordinatorJobBean coordJob2 = addRecordToCoordJobTable("action2", CoordinatorJob.Status.PAUSED, start, end, false);
    coordJob1.setPauseTime(null);
    coordJob1.setBundleId(job.getId());
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_BUNDLEID_APPNAMESPACE_PAUSETIME, coordJob1);
    coordJob2.setPauseTime(null);
    coordJob2.setBundleId(job.getId());
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_BUNDLEID_APPNAMESPACE_PAUSETIME, coordJob2);
    BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetExecutor);
    assertEquals(Job.Status.PAUSED, job.getStatus());
    Runnable pauseStartRunnable = new PauseTransitRunnable();
    pauseStartRunnable.run();
    final String jobId = job.getId();
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean bJob1 = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
            return bJob1.getStatus() == Job.Status.RUNNING;
        }
    });
    final String coordJobId1 = coordJob1.getId();
    final String coordJobId2 = coordJob2.getId();
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean cJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId1));
            CoordinatorJobBean cJob2 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId2));
            return cJob1.getStatus() == Job.Status.RUNNING && cJob2.getStatus() == Job.Status.RUNNING;
        }
    });
    job = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
    assertEquals(Job.Status.RUNNING, job.getStatus());
    coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId1));
    assertEquals(Job.Status.RUNNING, coordJob1.getStatus());
    coordJob2 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId2));
    assertEquals(Job.Status.RUNNING, coordJob2.getStatus());
    bundleAction1 = jpaService.execute(new BundleActionGetJPAExecutor(job.getId(), "action1"));
    assertEquals(Job.Status.RUNNING, bundleAction1.getStatus());
    bundleAction2 = jpaService.execute(new BundleActionGetJPAExecutor(job.getId(), "action2"));
    assertEquals(Job.Status.RUNNING, bundleAction2.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 9 with JPAService

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

the class TestPauseTransitService method testPauseCoordinatorForBackwardSupport.

/**
 * Test : Pause a RUNNING coordinator, but set oozie.service.StatusTransitService.backward.support.for.coord.status=true
 * and use uri:oozie:coordinator:0.1 namespace, the status should not be changed to PAUSED
 *
 * @throws Exception
 */
public void testPauseCoordinatorForBackwardSupport() throws Exception {
    Services.get().destroy();
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_COORD_STATUS, "true");
    services = new Services();
    setClassesToBeExcluded(services.getConf(), excludedServices);
    services.init();
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    Date pauseTime = new Date(new Date().getTime() - 30 * 1000);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob1 = addRecordToCoordJobTable("action1", CoordinatorJob.Status.RUNNING, start, end, false);
    CoordinatorJobBean coordJob2 = addRecordToCoordJobTable("action2", CoordinatorJob.Status.RUNNING, start, end, false);
    coordJob1.setAppNamespace(SchemaService.COORDINATOR_NAMESPACE_URI_1);
    coordJob1.setPauseTime(pauseTime);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_BUNDLEID_APPNAMESPACE_PAUSETIME, coordJob1);
    coordJob2.setAppNamespace(SchemaService.COORDINATOR_NAMESPACE_URI_1);
    coordJob2.setPauseTime(pauseTime);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_BUNDLEID_APPNAMESPACE_PAUSETIME, coordJob2);
    Runnable pauseStartRunnable = new PauseTransitRunnable();
    pauseStartRunnable.run();
    final String coordJobId1 = coordJob1.getId();
    final String coordJobId2 = coordJob2.getId();
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean cJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId1));
            return cJob1.getStatus() == Job.Status.RUNNING;
        }
    });
    coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId1));
    assertEquals(Job.Status.RUNNING, coordJob1.getStatus());
    coordJob2 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId2));
    assertEquals(Job.Status.RUNNING, coordJob2.getStatus());
}
Also used : Services(org.apache.oozie.service.Services) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Example 10 with JPAService

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

the class TestPauseTransitService method testPauseUnpause2.

/**
 * Test : Pause a PREP bundle, then reset its pausetime to null to unpause it.
 *
 * @throws Exception
 */
public void testPauseUnpause2() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    job.setPauseTime(new Date(new Date().getTime() - 30 * 1000));
    job.setKickoffTime(new Date(new Date().getTime() + 3600 * 1000));
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_PAUSE_KICKOFF, job);
    Runnable pauseStartRunnable = new PauseTransitRunnable();
    pauseStartRunnable.run();
    final String jobId = job.getId();
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean job1 = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
            return job1.getStatus() == Job.Status.PREPPAUSED;
        }
    });
    job = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
    assertEquals(Job.Status.PREPPAUSED, job.getStatus());
    job.setPauseTime(null);
    BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_PAUSE_KICKOFF, job);
    pauseStartRunnable.run();
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean job1 = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
            return job1.getStatus() == Job.Status.PREP;
        }
    });
    job = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
    assertEquals(Job.Status.PREP, job.getStatus());
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) PauseTransitRunnable(org.apache.oozie.service.PauseTransitService.PauseTransitRunnable) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

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