Search in sources :

Example 1 with BundleJobBean

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

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

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

the class TestPurgeService method addRecordToBundleJobTable.

protected BundleJobBean addRecordToBundleJobTable(Job.Status jobStatus, Date lastModifiedTime) throws Exception {
    BundleJobBean bundle = createBundleJob(jobStatus, false);
    bundle.setLastModifiedTime(lastModifiedTime);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        BundleJobInsertJPAExecutor bundleInsertjpa = new BundleJobInsertJPAExecutor(bundle);
        jpaService.execute(bundleInsertjpa);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test bundle job record to table");
        throw je;
    }
    return bundle;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobBean(org.apache.oozie.BundleJobBean) BundleJobInsertJPAExecutor(org.apache.oozie.executor.jpa.BundleJobInsertJPAExecutor)

Example 4 with BundleJobBean

use of org.apache.oozie.BundleJobBean 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 5 with BundleJobBean

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

the class ZKUUIDServiceWithException method testBulkJobForZKUUIDService.

public void testBulkJobForZKUUIDService() throws Exception {
    Services service = Services.get();
    ZKUUIDService uuid = new ZKUUIDService();
    try {
        setSystemProperty(UUIDService.CONF_GENERATOR, "counter");
        uuid.init(service);
        String bundleId = uuid.generateId(ApplicationType.BUNDLE);
        BundleJobBean bundle = createBundleJob(bundleId, Job.Status.SUCCEEDED, false);
        JPAService jpaService = Services.get().get(JPAService.class);
        BundleJobInsertJPAExecutor bundleInsertjpa = new BundleJobInsertJPAExecutor(bundle);
        jpaService.execute(bundleInsertjpa);
        addCoordForBulkMonitor(bundleId);
        String request = "bundle=" + bundleId;
        BulkJPAExecutor bulkjpa = new BulkJPAExecutor(BundleEngine.parseBulkFilter(request), 1, 1);
        try {
            BulkResponseInfo response = jpaService.execute(bulkjpa);
            assertEquals(response.getResponses().get(0).getBundle().getId(), bundleId);
        } catch (JPAExecutorException jex) {
            // should not throw exception as this case is now supported
            fail();
        }
    } finally {
        uuid.destroy();
    }
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobBean(org.apache.oozie.BundleJobBean) BulkResponseInfo(org.apache.oozie.BulkResponseInfo) BulkJPAExecutor(org.apache.oozie.executor.jpa.BulkJPAExecutor) BundleJobInsertJPAExecutor(org.apache.oozie.executor.jpa.BundleJobInsertJPAExecutor)

Aggregations

BundleJobBean (org.apache.oozie.BundleJobBean)159 JPAService (org.apache.oozie.service.JPAService)78 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)69 BundleActionBean (org.apache.oozie.BundleActionBean)58 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)46 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)44 Date (java.util.Date)35 ArrayList (java.util.ArrayList)24 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)24 List (java.util.List)21 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)21 HashMap (java.util.HashMap)20 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)20 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)18 IOException (java.io.IOException)16 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)16 XConfiguration (org.apache.oozie.util.XConfiguration)16 Query (javax.persistence.Query)14 CommandException (org.apache.oozie.command.CommandException)14