Search in sources :

Example 1 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class AuthorizationService method authorizeForJobs.

/**
 * Check if the user+group is authorized to operate on the specified jobs. <p> Checks if the user is a super-user or
 * the one who started the jobs. <p> Read operations are allowed to all users.
 *
 * @param user user name.
 * @param filter filter used to select jobs
 * @param start starting index of the jobs in DB
 * @param len maximum amount of jobs to select
 * @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 authorizeForJobs(String user, Map<String, List<String>> filter, String jobType, int start, int len, boolean write) throws AuthorizationException {
    if (authorizationEnabled && write && !isAdmin(user)) {
        try {
            // handle workflow jobs
            if (jobType.equals("wf")) {
                List<WorkflowJobBean> jobBeans = new ArrayList<WorkflowJobBean>();
                JPAService jpaService = Services.get().get(JPAService.class);
                if (jpaService != null) {
                    try {
                        jobBeans = jpaService.execute(new WorkflowsJobGetJPAExecutor(filter, start, len)).getWorkflows();
                    } catch (JPAExecutorException je) {
                        throw new AuthorizationException(je);
                    }
                } else {
                    throw new AuthorizationException(ErrorCode.E0610);
                }
                for (WorkflowJobBean jobBean : jobBeans) {
                    if (jobBean != null && !jobBean.getUser().equals(user)) {
                        if (!isUserInAcl(user, jobBean.getGroup())) {
                            incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                            throw new AuthorizationException(ErrorCode.E0508, user, jobBean.getId());
                        }
                    }
                }
            } else // handle bundle jobs
            if (jobType.equals("bundle")) {
                List<BundleJobBean> jobBeans = new ArrayList<BundleJobBean>();
                JPAService jpaService = Services.get().get(JPAService.class);
                if (jpaService != null) {
                    try {
                        jobBeans = jpaService.execute(new BundleJobInfoGetJPAExecutor(filter, start, len)).getBundleJobs();
                    } catch (JPAExecutorException je) {
                        throw new AuthorizationException(je);
                    }
                } else {
                    throw new AuthorizationException(ErrorCode.E0610);
                }
                for (BundleJobBean jobBean : jobBeans) {
                    if (jobBean != null && !jobBean.getUser().equals(user)) {
                        if (!isUserInAcl(user, jobBean.getGroup())) {
                            incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                            throw new AuthorizationException(ErrorCode.E0509, user, jobBean.getId());
                        }
                    }
                }
            } else // handle coordinator jobs
            {
                List<CoordinatorJobBean> jobBeans = new ArrayList<CoordinatorJobBean>();
                JPAService jpaService = Services.get().get(JPAService.class);
                if (jpaService != null) {
                    try {
                        jobBeans = jpaService.execute(new CoordJobInfoGetJPAExecutor(filter, start, len)).getCoordJobs();
                    } catch (JPAExecutorException je) {
                        throw new AuthorizationException(je);
                    }
                } else {
                    throw new AuthorizationException(ErrorCode.E0610);
                }
                for (CoordinatorJobBean jobBean : jobBeans) {
                    if (jobBean != null && !jobBean.getUser().equals(user)) {
                        if (!isUserInAcl(user, jobBean.getGroup())) {
                            incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                            throw new AuthorizationException(ErrorCode.E0509, user, jobBean.getId());
                        }
                    }
                }
            }
        } catch (IOException ex) {
            throw new AuthorizationException(ErrorCode.E0501, ex.getMessage(), ex);
        }
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobInfoGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobInfoGetJPAExecutor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowsJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowsJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobBean(org.apache.oozie.BundleJobBean) ArrayList(java.util.ArrayList) List(java.util.List) BundleJobInfoGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobInfoGetJPAExecutor)

Example 2 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean 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 3 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestWorkflowJobsGetFromCoordParentIdJPAExecutor method testGetCoordinatorParent.

public void testGetCoordinatorParent() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordinatorJobBean coordJobA = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    CoordinatorJobBean coordJobB = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    WorkflowJobBean wfJobA1 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowJobBean wfJobA2 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowJobBean wfJobB = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowActionBean wfActionA1 = addRecordToWfActionTable(wfJobA1.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfActionA2 = addRecordToWfActionTable(wfJobA2.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfActionB = addRecordToWfActionTable(wfJobB.getId(), "1", WorkflowAction.Status.OK);
    CoordinatorActionBean coordActionA1 = addRecordToCoordActionTable(coordJobA.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJobA1.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordActionA2 = addRecordToCoordActionTable(coordJobA.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJobA2.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordActionB = addRecordToCoordActionTable(coordJobB.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJobB.getId(), "SUCCEEDED", 0);
    List<String> children = new ArrayList<String>();
    children.addAll(jpaService.execute(new WorkflowJobsGetFromCoordParentIdJPAExecutor(coordJobA.getId(), 10)));
    checkChildren(children, wfJobA1.getId(), wfJobA2.getId());
    children = new ArrayList<String>();
    children.addAll(jpaService.execute(new WorkflowJobsGetFromCoordParentIdJPAExecutor(coordJobB.getId(), 10)));
    checkChildren(children, wfJobB.getId());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 4 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestWorkflowJobsGetFromCoordParentIdJPAExecutor method testGetWorkflowParentTooMany.

public void testGetWorkflowParentTooMany() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    WorkflowJobBean wfJob1 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, coordJob.getId());
    WorkflowJobBean wfJob2 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, coordJob.getId());
    WorkflowJobBean wfJob3 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, coordJob.getId());
    WorkflowJobBean wfJob4 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, coordJob.getId());
    WorkflowJobBean wfJob5 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, coordJob.getId());
    WorkflowActionBean wfAction1 = addRecordToWfActionTable(wfJob1.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction2 = addRecordToWfActionTable(wfJob2.getId(), "2", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction3 = addRecordToWfActionTable(wfJob3.getId(), "2", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction4 = addRecordToWfActionTable(wfJob4.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction5 = addRecordToWfActionTable(wfJob5.getId(), "1", WorkflowAction.Status.OK);
    CoordinatorActionBean coordAction1 = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob1.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction2 = addRecordToCoordActionTable(coordJob.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob2.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction3 = addRecordToCoordActionTable(coordJob.getId(), 3, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob3.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction4 = addRecordToCoordActionTable(coordJob.getId(), 4, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob4.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction5 = addRecordToCoordActionTable(coordJob.getId(), 5, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob5.getId(), "SUCCEEDED", 0);
    List<String> children = new ArrayList<String>();
    // Get the first 3
    children.addAll(jpaService.execute(new WorkflowJobsGetFromCoordParentIdJPAExecutor(coordJob.getId(), 3)));
    assertEquals(3, children.size());
    // Get the next 3 (though there's only 2 more)
    children.addAll(jpaService.execute(new WorkflowJobsGetFromCoordParentIdJPAExecutor(coordJob.getId(), 3, 3)));
    assertEquals(5, children.size());
    checkChildren(children, wfJob1.getId(), wfJob2.getId(), wfJob3.getId(), wfJob4.getId(), wfJob5.getId());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 5 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean 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)

Aggregations

CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)373 Date (java.util.Date)177 JPAService (org.apache.oozie.service.JPAService)153 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)149 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)121 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)114 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)53 CommandException (org.apache.oozie.command.CommandException)49 BundleJobBean (org.apache.oozie.BundleJobBean)46 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)43 IOException (java.io.IOException)39 XConfiguration (org.apache.oozie.util.XConfiguration)38 ArrayList (java.util.ArrayList)36 BundleActionBean (org.apache.oozie.BundleActionBean)36 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)34 Configuration (org.apache.hadoop.conf.Configuration)33 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)32 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)30 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)30 Path (org.apache.hadoop.fs.Path)24