Package org.apache.oozie.store

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


     * 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

            public boolean evaluate() throws Exception {
                return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUSPENDED);
            }
        });

        final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
        store.beginTrx();
        List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, true);
        int n = actions.size();
        WorkflowActionBean action = actions.get(n - 1);
        assertEquals("TEST_ERROR", action.getErrorCode());
        assertEquals(expErrorMsg, action.getErrorMessage());
        assertEquals(expStatus1, action.getStatus());
        assertTrue(action.getPending() == false);

        assertTrue(engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUSPENDED);

        String actionConf = action.getConf();
        String fixedActionConf = actionConf.replaceAll(errorType, "none");
        action.setConf(fixedActionConf);
        store.updateAction(action);
        store.commitTrx();
        store.closeTrx();

        engine.resume(jobId);

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

        assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());

        final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
        store2.beginTrx();
        actions = store2.getActionsForWorkflow(jobId, false);
        action = actions.get(0);
        assertEquals(null, action.getErrorCode());
        assertEquals(null, action.getErrorMessage());
        assertEquals(WorkflowActionBean.Status.OK, action.getStatus());
        store2.commitTrx();
        store2.closeTrx();
    }
View Full Code Here

        WorkflowActionBean.Status expectedStatus = expStatus1;
        int expectedRetryCount = 2;

        Thread.sleep(20000);
        String aId = null;
        final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
        store.beginTrx();
        while (retryCount <= maxRetries) {
            List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, false);
            WorkflowActionBean action = actions.get(0);
            aId = action.getId();
            assertEquals(expectedStatus, action.getStatus());
            assertEquals(expectedRetryCount, action.getRetries());
            assertEquals("TEST_ERROR", action.getErrorCode());
            assertEquals(expErrorMsg, action.getErrorMessage());
            if (action.getRetries() == maxRetries) {
                expectedRetryCount = 0;
                expectedStatus = expStatus2;
                break;
            }
            else {
                expectedRetryCount++;
            }
            Thread.sleep(retryInterval * 1000);
            retryCount++;
        }
        store.commitTrx();
        store.closeTrx();
        Thread.sleep(5000);

        final String actionId = aId;

        waitFor(5000, new Predicate() {
            public boolean evaluate() throws Exception {
                return (engine.getWorkflowAction(actionId).getStatus() == expStatus2);
            }
        });

        final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
        store2.beginTrx();
        WorkflowActionBean action = engine.getWorkflowAction(actionId);
        assertEquals("TEST_ERROR", action.getErrorCode());
        assertEquals(expErrorMsg, action.getErrorMessage());
        assertEquals(expStatus2, action.getStatus());
        assertTrue(action.getPending() == false);
        assertEquals(WorkflowJob.Status.SUSPENDED, engine.getJob(jobId).getStatus());
        store2.commitTrx();
        store2.closeTrx();
    }
View Full Code Here

        conf.set("external-status", externalStatus);
        conf.set("signal-value", signalValue);

        final String jobId = engine.submitJob(conf, true);

        final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
        store.beginTrx();
        waitFor(5000, new Predicate() {
            public boolean evaluate() throws Exception {
                WorkflowJobBean bean = store.getWorkflow(jobId, false);
                return (bean.getWorkflowInstance().getStatus() == WorkflowInstance.Status.KILLED);
            }
        });
        assertEquals(WorkflowJob.Status.KILLED, engine.getJob(jobId).getStatus());
        store.commitTrx();
        store.closeTrx();
    }
View Full Code Here

        conf.set("signal-value", "based_on_action_status");
        conf.set(avoidParam, "true");

        final String jobId = engine.submitJob(conf, true);

        final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
        store.beginTrx();
        Thread.sleep(2000);

        waitFor(5000, new Predicate() {
            public boolean evaluate() throws Exception {
                WorkflowJobBean bean = store.getWorkflow(jobId, false);
                return (bean.getWorkflowInstance().getStatus() == WorkflowInstance.Status.FAILED);
            }
        });
        store.commitTrx();
        store.closeTrx();

        final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
        store2.beginTrx();
        assertEquals(WorkflowInstance.Status.FAILED, store2.getWorkflow(jobId, false).getWorkflowInstance().getStatus());
        assertEquals(WorkflowJob.Status.FAILED, engine.getJob(jobId).getStatus());

        List<WorkflowActionBean> actions = store2.getActionsForWorkflow(jobId, false);
        WorkflowActionBean action = actions.get(0);
        assertEquals(expActionErrorCode, action.getErrorCode());
        store2.commitTrx();
        store2.closeTrx();
    }
View Full Code Here

         */
        private void runWFActionCheck() {
            XLog.Info.get().clear();
            XLog log = XLog.getLog(getClass());

            WorkflowStore store = null;
            try {
                store = (WorkflowStore) Services.get().get(StoreService.class).getStore(WorkflowStore.class);
                store.beginTrx();
                List<WorkflowActionBean> actions = store.getRunningActions(actionCheckDelay);
                msg.append(" WF_ACTIONS : " + actions.size());
                for (WorkflowActionBean action : actions) {
                    Services.get().get(InstrumentationService.class).get().incr(INSTRUMENTATION_GROUP,
                                                                                INSTR_CHECK_ACTIONS_COUNTER, 1);
                    queueCallable(new ActionCheckCommand(action.getId()));
                }
                store.commitTrx();
            }
            catch (StoreException ex) {
                if (store != null) {
                    store.rollbackTrx();
                }
                log.warn("Exception while accessing the store", 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

        assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId)
                .getStatus());
        new PurgeCommand(1, 10000).call();
        Thread.sleep(1000);

        final WorkflowStore store = Services.get().get(
                WorkflowStoreService.class).create();
        store.beginTrx();
        WorkflowJobBean wfBean = store.getWorkflow(jobId, true);
        Date endDate = new Date(System.currentTimeMillis() - 2 * 24 * 60 * 60
                * 1000);
        wfBean.setEndTime(endDate);
        store.updateWorkflow(wfBean);
        store.commitTrx();
        store.closeTrx();

        Runnable purgeRunnable = new PurgeRunnable(1, 1, 100);
        purgeRunnable.run();

        waitFor(10000, new Predicate() {
View Full Code Here

    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

                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

TOP

Related Classes of org.apache.oozie.store.WorkflowStore

Copyright © 2018 www.massapicom. 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.