Search in sources :

Example 1 with CoordJobGetJPAExecutor

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

the class AuthorizationService method authorizeForJob.

/**
 * Check if the user+group is authorized to operate on the specified job. <p> Checks if the user is a super-user or
 * the one who started the job. <p> Read operations are allowed to all users.
 *
 * @param user user name.
 * @param jobId job id.
 * @param write indicates if the check is for read or write job tasks.
 * @throws AuthorizationException thrown if the user is not authorized for the job.
 */
public void authorizeForJob(String user, String jobId, boolean write) throws AuthorizationException {
    if (authorizationEnabled && write && !isAdmin(user)) {
        try {
            // handle workflow jobs
            if (jobId.endsWith("-W")) {
                WorkflowJobBean jobBean = null;
                JPAService jpaService = Services.get().get(JPAService.class);
                if (jpaService != null) {
                    try {
                        jobBean = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_USER_GROUP, jobId);
                    } catch (JPAExecutorException je) {
                        throw new AuthorizationException(je);
                    }
                } else {
                    throw new AuthorizationException(ErrorCode.E0610);
                }
                if (jobBean != null && !jobBean.getUser().equals(user)) {
                    if (!isUserInAcl(user, jobBean.getGroup())) {
                        incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                        throw new AuthorizationException(ErrorCode.E0508, user, jobId);
                    }
                }
            } else // handle bundle jobs
            if (jobId.endsWith("-B")) {
                BundleJobBean jobBean = null;
                JPAService jpaService = Services.get().get(JPAService.class);
                if (jpaService != null) {
                    try {
                        jobBean = jpaService.execute(new BundleJobGetJPAExecutor(jobId));
                    } catch (JPAExecutorException je) {
                        throw new AuthorizationException(je);
                    }
                } else {
                    throw new AuthorizationException(ErrorCode.E0610);
                }
                if (jobBean != null && !jobBean.getUser().equals(user)) {
                    if (!isUserInAcl(user, jobBean.getGroup())) {
                        incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                        throw new AuthorizationException(ErrorCode.E0509, user, jobId);
                    }
                }
            } else // handle coordinator jobs
            {
                CoordinatorJobBean jobBean = null;
                JPAService jpaService = Services.get().get(JPAService.class);
                if (jpaService != null) {
                    try {
                        jobBean = jpaService.execute(new CoordJobGetJPAExecutor(jobId));
                    } catch (JPAExecutorException je) {
                        throw new AuthorizationException(je);
                    }
                } else {
                    throw new AuthorizationException(ErrorCode.E0610);
                }
                if (jobBean != null && !jobBean.getUser().equals(user)) {
                    if (!isUserInAcl(user, jobBean.getGroup())) {
                        incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                        throw new AuthorizationException(ErrorCode.E0509, user, jobId);
                    }
                }
            }
        } catch (IOException ex) {
            throw new AuthorizationException(ErrorCode.E0501, ex.getMessage(), ex);
        }
    }
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) IOException(java.io.IOException) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 2 with CoordJobGetJPAExecutor

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

the class TestPurgeService method testPurgeServiceForCoordinator.

/**
 * Tests the {@link org.apache.oozie.service.PurgeService}.
 * </p>
 * Creates a new coordinator job. Attempts to purge jobs older than a day.
 * Verifies the presence of the job in the system.
 * </p>
 * Sets the end date for the same job to make it qualify for the purge criteria.
 * Calls the purge service, and ensure the job does not exist in the system.
 */
public void testPurgeServiceForCoordinator() throws Exception {
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, start, end, false, false, 0);
    final String jobId = job.getId();
    CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordJobGetJPAExecutor coordJobGetExecutor = new CoordJobGetJPAExecutor(job.getId());
    CoordActionGetJPAExecutor coordActionGetExecutor = new CoordActionGetJPAExecutor(action.getId());
    job = jpaService.execute(coordJobGetExecutor);
    action = jpaService.execute(coordActionGetExecutor);
    assertEquals(job.getStatus(), CoordinatorJob.Status.SUCCEEDED);
    assertEquals(action.getStatus(), CoordinatorAction.Status.SUCCEEDED);
    Runnable purgeRunnable = new PurgeRunnable(1, 1, 1, 100);
    purgeRunnable.run();
    final CoordinatorEngine engine = new CoordinatorEngine("u");
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            try {
                engine.getCoordJob(jobId).getStatus();
            } catch (Exception ex) {
                return true;
            }
            return false;
        }
    });
    try {
        job = jpaService.execute(coordJobGetExecutor);
        fail("Job should be purged. Should fail.");
    } catch (JPAExecutorException je) {
    // Job doesn't exist. Exception is expected.
    }
    try {
        jpaService.execute(coordActionGetExecutor);
        fail("Action should be purged. Should fail.");
    } catch (JPAExecutorException je) {
    // Job doesn't exist. Exception is expected.
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) DagEngineException(org.apache.oozie.DagEngineException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordinatorEngine(org.apache.oozie.CoordinatorEngine) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable) PurgeRunnable(org.apache.oozie.service.PurgeService.PurgeRunnable)

Example 3 with CoordJobGetJPAExecutor

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

the class TestRecoveryService method testBundleRecoveryCoordCreate.

/**
 * If the bundle action is in PREP state and coord is not yet created, recovery should submit new coord
 * @throws Exception
 */
public void testBundleRecoveryCoordCreate() throws Exception {
    final BundleJobBean bundle = addRecordToBundleJobTable(Job.Status.RUNNING, false);
    addRecordToBundleActionTable(bundle.getId(), "coord1", 1, Job.Status.PREP);
    final JPAService jpaService = Services.get().get(JPAService.class);
    sleep(3000);
    Runnable recoveryRunnable = new RecoveryRunnable(0, 1, 1);
    recoveryRunnable.run();
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleActionBean mybundleAction = jpaService.execute(new BundleActionGetJPAExecutor(bundle.getId(), "coord1"));
            try {
                if (mybundleAction.getCoordId() != null) {
                    jpaService.execute(new CoordJobGetJPAExecutor(mybundleAction.getCoordId()));
                    return true;
                }
            } catch (Exception e) {
            }
            return false;
        }
    });
    BundleActionBean mybundleAction = jpaService.execute(new BundleActionGetJPAExecutor(bundle.getId(), "coord1"));
    assertNotNull(mybundleAction.getCoordId());
    try {
        jpaService.execute(new CoordJobGetJPAExecutor(mybundleAction.getCoordId()));
    } catch (Exception e) {
        e.printStackTrace();
        fail("Expected coord " + mybundleAction.getCoordId() + " to be created");
    }
}
Also used : RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) BundleJobBean(org.apache.oozie.BundleJobBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) RecoveryRunnable(org.apache.oozie.service.RecoveryService.RecoveryRunnable) BundleActionBean(org.apache.oozie.BundleActionBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException)

Example 4 with CoordJobGetJPAExecutor

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

the class TestStatusTransitService method testCoordStatusTransitServiceDoneWithError.

/**
 * Tests functionality of the StatusTransitService Runnable command. </p> Insert a coordinator job with RUNNING and
 * pending true and coordinator actions with pending false, but one of action is KILLED.
 * Then, runs the StatusTransitService runnable and ensures the job status changes to DONEWITHERROR.
 *
 * @throws Exception
 */
public void testCoordStatusTransitServiceDoneWithError() throws Exception {
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, true, true, 3);
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.KILLED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    sleep(1000);
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorJob.Status.DONEWITHERROR, coordJob.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) Date(java.util.Date)

Example 5 with CoordJobGetJPAExecutor

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

the class TestStatusTransitService method testBundleStatusTransitServiceForTerminalStates.

/**
 * Insert a coordinator job in KILLED state with one coordinator action as
 * SUCCEEDED. Make sure the status of the job changes to DONEWITHERROR.
 * Also, the status of bundle action and bundle job should change to
 * DONEWITHERROR
 *
 * @throws Exception
 */
public void testBundleStatusTransitServiceForTerminalStates() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.RUNNING, false);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final String bundleId = job.getId();
    CoordinatorJobBean coord1 = addRecordToCoordJobTable(CoordinatorJob.Status.KILLED, false, false);
    addRecordToBundleActionTable(bundleId, coord1.getId(), "action1", 0, Job.Status.KILLED);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    addRecordToCoordJobTableWithBundle(bundleId, "action1", CoordinatorJob.Status.KILLED, start, end, true, true, 2);
    addRecordToCoordActionTable("action1", 1, CoordinatorAction.Status.KILLED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable("action1", 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor("action1"));
            return coordJob.getStatus().equals(Job.Status.DONEWITHERROR);
        }
    });
    CoordinatorJobBean coordJob = jpaService.execute(new CoordJobGetJPAExecutor("action1"));
    assertEquals(Job.Status.KILLED, coordJob.getStatus());
    BundleActionBean bab = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action1"));
    assertEquals(Job.Status.KILLED, bab.getStatus());
    job = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertEquals(Job.Status.KILLED, job.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) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) BundleActionBean(org.apache.oozie.BundleActionBean)

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