Examples of WorkflowStore


Examples of org.apache.oozie.store.WorkflowStore

    public void authorizeForJob(String user, String jobId, boolean write) throws AuthorizationException {
        if (securityEnabled && write && !isAdmin(user)) {
            // handle workflow jobs
            if (jobId.endsWith("-W")) {
                WorkflowJobBean jobBean = null;
                WorkflowStore store = null;
                try {
                    store = Services.get().get(WorkflowStoreService.class).create();
                    store.beginTrx();
                    jobBean = store.getWorkflow(jobId, false);
                    store.commitTrx();
                }
                catch (StoreException ex) {
                    incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                    if (store != null) {
                        store.rollbackTrx();
                    }
                    throw new AuthorizationException(ex);
                }
                catch (Exception ex) {
                    incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                    log.error("Exception, {0}", ex.getMessage(), ex);
                    if (store != null && store.isActive()) {
                        try {
                            store.rollbackTrx();
                        }
                        catch (RuntimeException rex) {
                            log.warn("openjpa error, {0}", rex.getMessage(), rex);
                        }
                    }
                    throw new AuthorizationException(ErrorCode.E0501, ex);
                }
                finally {
                    if (store != null) {
                        if (!store.isActive()) {
                            try {
                                store.closeTrx();
                            }
                            catch (RuntimeException rex) {
                                log.warn("Exception while attempting to close store", rex);
                            }
                        }
                        else {
                            log.warn("transaction is not committed or rolled back before closing entitymanager.");
                        }
                    }
                }
                if (jobBean != null && !jobBean.getUser().equals(user)) {
                    if (!isUserInGroup(user, jobBean.getGroup())) {
                        incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                        throw new AuthorizationException(ErrorCode.E0508, user, jobId);
                    }
                }
            }
            // handle coordinator jobs
            else {
                CoordinatorJobBean jobBean = null;
                CoordinatorStore store = null;
                try {
                    store = Services.get().get(CoordinatorStoreService.class).create();
                    store.beginTrx();
                    jobBean = store.getCoordinatorJob(jobId, false);
                    store.commitTrx();
                }
                catch (StoreException ex) {
                    incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                    if (store != null) {
                        store.rollbackTrx();
                    }
                    throw new AuthorizationException(ex);
                }
                catch (Exception ex) {
                    incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
                    log.error("Exception, {0}", ex.getMessage(), ex);
                    if (store != null && store.isActive()) {
                        try {
                            store.rollbackTrx();
                        }
                        catch (RuntimeException rex) {
                            log.warn("openjpa error, {0}", rex.getMessage(), rex);
                        }
                    }
                    throw new AuthorizationException(ErrorCode.E0501, ex);
                }
                finally {
                    if (store != null) {
                        if (!store.isActive()) {
                            try {
                                store.closeTrx();
                            }
                            catch (RuntimeException rex) {
                                log.warn("Exception while attempting to close store", rex);
                            }
                        }
View Full Code Here

Examples of org.apache.oozie.store.WorkflowStore

                return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.RUNNING);
            }
        });

        Thread.sleep(1000);
        final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
        store.beginTrx();
        List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, false);
        WorkflowActionBean action = actions.get(0);
        final String actionId = action.getId();
        assertEquals(WorkflowActionBean.Status.RUNNING, action.getStatus());
        String actionConf = action.getConf();
        String fixedActionConf = actionConf.replaceAll("async", "sync");
        action.setConf(fixedActionConf);
        action.setPending();
        store.updateAction(action);
        store.commitTrx();
        store.closeTrx();

        Runnable recoveryRunnable = new RecoveryRunnable(0, 60);
        recoveryRunnable.run();
        Thread.sleep(3000);

        final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
        assertEquals(WorkflowJob.Status.RUNNING, engine.getJob(jobId).getStatus());
        store2.beginTrx();
        WorkflowActionBean action2 = store2.getAction(actionId, false);
        assertEquals(WorkflowActionBean.Status.RUNNING, action2.getStatus());
        action2.setStatus(WorkflowActionBean.Status.PREP);
        action2.setPending();
        store2.updateAction(action2);
        store2.commitTrx();
        store2.closeTrx();

        Thread.sleep(1000);
        recoveryRunnable.run();
        Thread.sleep(3000);

        waitFor(10000, new Predicate() {
            public boolean evaluate() throws Exception {
                return (engine.getWorkflowAction(actionId).getStatus() == WorkflowActionBean.Status.OK);
            }
        });

        // getPendingActions works correctly only with MYSQL - following assertsfail with hsql - to be investigated
        // assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());
        final WorkflowStore store3 = Services.get().get(WorkflowStoreService.class).create();
        store3.beginTrx();
        WorkflowActionBean action3 = store3.getAction(actionId, false);
        assertEquals(WorkflowActionBean.Status.OK, action3.getStatus());
        store3.commitTrx();
        store3.closeTrx();
    }
View Full Code Here

Examples of org.apache.oozie.store.WorkflowStore

                return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.RUNNING);
            }
        });
        Thread.sleep(2000);

        final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
        store.beginTrx();
        List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, false);
        WorkflowActionBean action = actions.get(0);
        assertEquals(WorkflowActionBean.Status.RUNNING, action.getStatus());
        store.commitTrx();
        store.closeTrx();

        Thread.sleep(2000);
        Runnable actionCheckRunnable = new ActionCheckRunnable(0);
        actionCheckRunnable.run();

        waitFor(20000, new Predicate() {
            public boolean evaluate() throws Exception {
                return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED);
            }
        });

        final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
        store2.beginTrx();
        List<WorkflowActionBean> actions2 = store2.getActionsForWorkflow(jobId, false);
        WorkflowActionBean action2 = actions2.get(0);
        assertEquals(WorkflowActionBean.Status.OK, action2.getStatus());
        store2.commitTrx();
        store2.closeTrx();
    }
View Full Code Here

Examples of org.apache.oozie.store.WorkflowStore

                return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.RUNNING);
            }
        });

        Thread.sleep(100);
        final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
        store.beginTrx();
        List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, true);
        WorkflowActionBean action = actions.get(0);
        assertEquals(WorkflowActionBean.Status.RUNNING, action.getStatus());

        action.setLastCheckTime(new Date());
        store.updateAction(action);
        store.commitTrx();
        store.closeTrx();

        int actionCheckDelay = 20;

        Runnable actionCheckRunnable = new ActionCheckRunnable(actionCheckDelay);
        actionCheckRunnable.run();

        Thread.sleep(3000);
        final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
        store2.beginTrx();
        List<WorkflowActionBean> actions2 = store2.getActionsForWorkflow(jobId, false);
        WorkflowActionBean action2 = actions2.get(0);
        assertEquals(WorkflowActionBean.Status.RUNNING, action2.getStatus());
        store2.commitTrx();
        store2.closeTrx();
        assertEquals(WorkflowJob.Status.RUNNING, engine.getJob(jobId).getStatus());
    }
View Full Code Here

Examples of org.apache.oozie.store.WorkflowStore

         */
        private void runWFRecovery() {
            XLog.Info.get().clear();
            XLog log = XLog.getLog(getClass());
            // queue command for action recovery
            WorkflowStore store = null;
            try {
                store = Services.get().get(StoreService.class).getStore(WorkflowStore.class);
                store.beginTrx();
                List<WorkflowActionBean> actions = null;
                try {
                    actions = store.getPendingActions(olderThan);
                }
                catch (StoreException ex) {
                    log.warn("Exception while reading pending actions from storage", ex);
                }
                //log.debug("QUEUING[{0}] pending wf actions for potential recovery", actions.size());
                msg.append(" WF_ACTIONS " + actions.size());

                for (WorkflowActionBean action : actions) {
                    Services.get().get(InstrumentationService.class).get().incr(INSTRUMENTATION_GROUP,
                                                                                INSTR_RECOVERED_ACTIONS_COUNTER, 1);
                    if (action.getStatus() == WorkflowActionBean.Status.PREP
                            || action.getStatus() == WorkflowActionBean.Status.START_MANUAL) {
                        queueCallable(new ActionStartCommand(action.getId(), action.getType()));
                    }
                    else {
                        if (action.getStatus() == WorkflowActionBean.Status.START_RETRY) {
                            Date nextRunTime = action.getPendingAge();
                            queueCallable(new ActionStartCommand(action.getId(), action.getType()), nextRunTime.getTime()
                                    - System.currentTimeMillis());
                        }
                        else {
                            if (action.getStatus() == WorkflowActionBean.Status.DONE
                                    || action.getStatus() == WorkflowActionBean.Status.END_MANUAL) {
                                queueCallable(new ActionEndCommand(action.getId(), action.getType()));
                            }
                            else {
                                if (action.getStatus() == WorkflowActionBean.Status.END_RETRY) {
                                    Date nextRunTime = action.getPendingAge();
                                    queueCallable(new ActionEndCommand(action.getId(), action.getType()), nextRunTime.getTime()
                                            - System.currentTimeMillis());
                                }
                                else {
                                    if (action.getStatus() == WorkflowActionBean.Status.OK
                                            || action.getStatus() == WorkflowActionBean.Status.ERROR) {
                                        queueCallable(new SignalCommand(action.getJobId(), action.getId()));
                                    }
                                }
                            }
                        }
                    }
                }
                store.commitTrx();
            }
            catch (StoreException ex) {
                if (store != null) {
                    store.rollbackTrx();
                }
                log.warn("Exception while getting store to get pending actions", ex);
            }
            catch (Exception ex) {
                log.error("Exception, {0}", ex.getMessage(), ex);
                if (store != null && store.isActive()) {
                    try {
                        store.rollbackTrx();
                    }
                    catch (RuntimeException rex) {
                        log.warn("openjpa error, {0}", rex.getMessage(), rex);
                    }
                }
            }
            finally {
                if (store != null) {
                    if (!store.isActive()) {
                        try {
                            store.closeTrx();
                        }
                        catch (RuntimeException rex) {
                            log.warn("Exception while attempting to close store", rex);
                        }
                    }
View Full Code Here

Examples of org.apache.oozie.store.WorkflowStore

        final int actionNum = 1;
        final String actionId = jobId + "@" + actionNum;
        final String wfId = "0000000-" + new Date().getTime() + "-testCoordRecoveryService-W";
        final CoordinatorEngine ce = new CoordinatorEngine(getTestUser(), "UNIT_TESTING");
        CoordinatorStore cStore = Services.get().get(StoreService.class).getStore(CoordinatorStore.class);
        WorkflowStore wStore = Services.get().get(StoreService.class).getStore(WorkflowStore.class, cStore);
        try {
            addRecordToCoordJobTable(jobId, cStore);
            addRecordToCoordActionTable(jobId, actionNum, actionId, wfId, cStore);
            addRecordToWfJobTable(wfId, wStore);
        }
View Full Code Here

Examples of org.apache.oozie.store.WorkflowStore

    }

    @Override
    public WorkflowStore create() throws StoreException {
        try {
            return new WorkflowStore(selectForUpdate);
        }
        catch (Exception ex) {
            throw new StoreException(ErrorCode.E0600, ex.getMessage(), ex);
        }
    }
View Full Code Here

Examples of org.apache.oozie.store.WorkflowStore

    }

    @Override
    public <S extends Store> WorkflowStore create(S store) throws StoreException {
        try {
            return new WorkflowStore(store, selectForUpdate);
        }
        catch (Exception ex) {
            throw new StoreException(ErrorCode.E0600, ex.getMessage(), ex);
        }
    }
View Full Code Here

Examples of org.apache.oozie.store.WorkflowStore

     * Gets the number of workflows for each status and populates the hash.
     */
    class JobStatusCountCallable implements Runnable {
        @Override
        public void run() {
            WorkflowStore store = null;
            try {
                store = Services.get().get(WorkflowStoreService.class).create();
                store.beginTrx();
                WorkflowJob.Status[] wfStatusArr = WorkflowJob.Status.values();
                for (WorkflowJob.Status aWfStatusArr : wfStatusArr) {
                    statusCounts.put(aWfStatusArr.name(), store.getWorkflowCountWithStatus(aWfStatusArr.name()));
                    statusWindowCounts.put(aWfStatusArr.name(), store.getWorkflowCountWithStatusInLastNSeconds(
                            aWfStatusArr.name(), statusWindow));
                }
                store.commitTrx();
            }
            catch (StoreException e) {
                if (store != null) {
                    store.rollbackTrx();
                }
                log.warn("Exception while accessing the store", e);
            }
            catch (Exception ex) {
                log.error("Exception, {0}", ex.getMessage(), ex);
                if (store != null && store.isActive()) {
                    try {
                        store.rollbackTrx();
                    }
                    catch (RuntimeException rex) {
                        log.warn("openjpa error, {0}", rex.getMessage(), rex);
                    }
                }
            }
            finally {
                if (store != null) {
                    if (!store.isActive()) {
                        try {
                            store.closeTrx();
                        }
                        catch (RuntimeException rex) {
                            log.warn("Exception while attempting to close store", rex);
                        }
                    }
View Full Code Here

Examples of org.apache.oozie.store.WorkflowStore

                return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.RUNNING);
            }
        });

        sleep(1000);
        final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
        store.beginTrx();
        List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, false);
        WorkflowActionBean action = null;
        for (WorkflowActionBean bean : actions) {
            if (bean.getType().equals("test")) {
                action = bean;
                break;
            }
        }
        assertNotNull(action);
        final String actionId = action.getId();
        assertEquals(WorkflowActionBean.Status.RUNNING, action.getStatus());
        String actionConf = action.getConf();
        String fixedActionConf = actionConf.replaceAll("async", "sync");
        action.setConf(fixedActionConf);
        action.setPending();
        store.updateAction(action);
        store.commitTrx();
        store.closeTrx();

        Runnable recoveryRunnable = new RecoveryRunnable(0, 60, 60);
        recoveryRunnable.run();
        sleep(3000);

        final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
        assertEquals(WorkflowJob.Status.RUNNING, engine.getJob(jobId).getStatus());
        store2.beginTrx();
        WorkflowActionBean action2 = store2.getAction(actionId, false);
        assertEquals(WorkflowActionBean.Status.RUNNING, action2.getStatus());
        action2.setStatus(WorkflowActionBean.Status.PREP);
        action2.setPending();
        store2.updateAction(action2);
        store2.commitTrx();
        store2.closeTrx();

        sleep(1000);
        recoveryRunnable.run();
        sleep(3000);

        waitFor(10000, new Predicate() {
            public boolean evaluate() throws Exception {
                return (engine.getWorkflowAction(actionId).getStatus() == WorkflowActionBean.Status.OK);
            }
        });

        // getPendingActions works correctly only with MYSQL - following assertsfail with hsql - to be investigated
        // assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());
        final WorkflowStore store3 = Services.get().get(WorkflowStoreService.class).create();
        store3.beginTrx();
        WorkflowActionBean action3 = store3.getAction(actionId, false);
        assertEquals(WorkflowActionBean.Status.OK, action3.getStatus());
        store3.commitTrx();
        store3.closeTrx();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.