Package org.apache.oozie.util

Examples of org.apache.oozie.util.XLog


        /**
         * Recover wf actions
         */
        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);
                        }
                    }
                    else {
                        log.warn("transaction is not committed or rolled back before closing entitymanager.");
                    }
                }
            }
        }
View Full Code Here


     * without committing, thus doing a rollback.
     */
    @SuppressWarnings({"ThrowFromFinallyBlock", "unchecked"})
    public final T call() throws CommandException {
        XLog.Info.get().setParameters(logInfo);
        XLog log = XLog.getLog(getClass());
        log.trace(logMask, "Start");
        Instrumentation.Cron cron = new Instrumentation.Cron();
        cron.start();
        callables = new ArrayList<XCallable<Void>>();
        delayedCallables = new ArrayList<XCallable<Void>>();
        exceptionCallables = new ArrayList<XCallable<Void>>();
        delay = 0;
        S store = null;
        boolean exception = false;

        try {
            if (withStore) {
                store = (S) Services.get().get(StoreService.class).getStore(getStoreClass());
                store.beginTrx();
            }
            T result = execute(store);
            /*
             *
             * if (store != null && log != null) { log.info(XLog.STD,
             * "connection log from store Flush Mode {0} ",
             * store.getFlushMode()); }
             */
            if (withStore) {
                if (store == null) {
                    throw new IllegalStateException("WorkflowStore should not be null");
                }
                if (FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection")) {
                    throw new RuntimeException("Skipping Commit for Failover Testing");
                }
                store.commitTrx();
            }

            // TODO figure out the reject due to concurrency problems and remove
            // the delayed queuing for callables.
            boolean ret = Services.get().get(CallableQueueService.class).queueSerial(callables, 10);
            if (ret == false) {
                logQueueCallableFalse(callables);
            }

            ret = Services.get().get(CallableQueueService.class).queueSerial(delayedCallables, delay);
            if (ret == false) {
                logQueueCallableFalse(delayedCallables);
            }

            return result;
        }
        catch (XException ex) {
            log.error(logMask | XLog.OPS, "XException, {0}", ex);
            if (store != null) {
                log.info(XLog.STD, "XException - connection logs from store {0}, {1}", store.getConnection(), store
                        .isClosed());
            }
            exception = true;
            if (store != null && store.isActive()) {
                try {
                    store.rollbackTrx();
                }
                catch (RuntimeException rex) {
                    log.warn(logMask | XLog.OPS, "openjpa error, {0}, {1}", name, rex.getMessage(), rex);
                }
            }

            // TODO figure out the reject due to concurrency problems and remove
            // the delayed queuing for callables.
            boolean ret = Services.get().get(CallableQueueService.class).queueSerial(exceptionCallables, 10);
            if (ret == false) {
                logQueueCallableFalse(exceptionCallables);
            }
            if (ex instanceof CommandException) {
                throw (CommandException) ex;
            }
            else {
                throw new CommandException(ex);
            }
        }
        catch (Exception ex) {
            log.error(logMask | XLog.OPS, "Exception, {0}", ex);
            exception = true;
            if (store != null && store.isActive()) {
                try {
                    store.rollbackTrx();
                }
                catch (RuntimeException rex) {
                    log.warn(logMask | XLog.OPS, "openjpa error, {0}, {1}", name, rex.getMessage(), rex);
                }
            }
            throw new CommandException(ErrorCode.E0607, ex);
        }
        catch (Error er) {
            log.error(logMask | XLog.OPS, "Error, {0}", er);
            exception = true;
            if (store != null && store.isActive()) {
                try {
                    store.rollbackTrx();
                }
                catch (RuntimeException rex) {
                    log.warn(logMask | XLog.OPS, "openjpa error, {0}, {1}", name, rex.getMessage(), rex);
                }
            }
            throw er;
        }
        finally {
            FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
            cron.stop();
            instrumentation.addCron(INSTRUMENTATION_GROUP, name, cron);
            incrCommandCounter(1);
            log.trace(logMask, "End");
            if (locks != null) {
                for (LockToken lock : locks) {
                    lock.release();
                }
                locks.clear();
            }
            if (store != null) {
                if (!store.isActive()) {
                    try {
                        store.closeTrx();
                    }
                    catch (RuntimeException rex) {
                        if (exception) {
                            log.warn(logMask | XLog.OPS, "openjpa error, {0}, {1}", name, rex.getMessage(), rex);
                        }
                        else {
                            throw rex;
                        }
                    }
                }
                else {
                    log.warn(logMask | XLog.OPS, "transaction is not committed or rolled back before closing entitymanager.");
                }
            }
        }
    }
View Full Code Here

            this.actionCheckDelay = actionCheckDelay;
        }

        public void run() {
            XLog.Info.get().clear();
            XLog log = XLog.getLog(getClass());
            msg = new StringBuilder();
            runWFActionCheck();
            runCoordActionCheck();
            log.debug("QUEUING [{0}] for potential checking", msg.toString());
            if (null != callables) {
                boolean ret = Services.get().get(CallableQueueService.class).queueSerial(callables);
                if (ret == false) {
                    log.warn("Unable to queue the callables commands for CheckerService. "
                            + "Most possibly command queue is full. Queue size is :"
                            + Services.get().get(CallableQueueService.class).queueSize());
                }
                callables = null;
            }
View Full Code Here

        /**
         * check workflow actions
         */
        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);
                        }
                    }
                    else {
                        log.warn("transaction is not committed or rolled back before closing entitymanager.");
                    }
                }
            }
        }
View Full Code Here

        /**
         * check coordinator actions
         */
        private void runCoordActionCheck() {
            XLog.Info.get().clear();
            XLog log = XLog.getLog(getClass());

            CoordinatorStore store = null;
            try {
                store = Services.get().get(StoreService.class).getStore(CoordinatorStore.class);
                store.beginTrx();
                List<CoordinatorActionBean> cactions = store.getRunningActionsOlderThan(actionCheckDelay, false);
                msg.append(" COORD_ACTIONS : " + cactions.size());
                for (CoordinatorActionBean caction : cactions) {
                    Services.get().get(InstrumentationService.class).get().incr(INSTRUMENTATION_GROUP,
                                                                                INSTR_CHECK_COORD_ACTIONS_COUNTER, 1);
                    queueCallable(new CoordActionCheckCommand(caction.getId(), actionCheckDelay));
                }
                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);
                        }
                    }
                    else {
                        log.warn("transaction is not committed or rolled back before closing entitymanager.");
                    }
                }
            }
        }
View Full Code Here

            else {
                interval = Long.parseLong(System.getProperty(LOG4J_RELOAD, DEFAULT_RELOAD_INTERVAL));
                PropertyConfigurator.configureAndWatch(log4jFile.toString(), interval * 1000);
            }

            log = new XLog(LogFactory.getLog(getClass()));

            log.info(XLog.OPS, STARTUP_MESSAGE, BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VERSION),
                     BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_USER_NAME), BuildInfo.getBuildInfo()
                    .getProperty(BuildInfo.BUILD_TIME), BuildInfo.getBuildInfo().getProperty(
                    BuildInfo.BUILD_VC_REVISION), BuildInfo.getBuildInfo()
View Full Code Here

            this.coordOlderThan = coordOlderThan;
        }

        public void run() {
            XLog.Info.get().clear();
            XLog log = XLog.getLog(getClass());
            msg = new StringBuilder();
            runWFRecovery();
            runCoordJobRecovery();
            runCoordActionRecovery();
            runCoordActionRecoveryForReady();
            log.debug("QUEUING [{0}] for potential recovery", msg.toString());
            boolean ret = false;
            if (null != callables) {
                ret = Services.get().get(CallableQueueService.class).queueSerial(callables);
                if (ret == false) {
                    log.warn("Unable to queue the callables commands for RecoveryService. "
                            + "Most possibly command queue is full. Queue size is :"
                            + Services.get().get(CallableQueueService.class).queueSize());
                }
                callables = null;
            }
            if (null != delayedCallables) {
                ret = Services.get().get(CallableQueueService.class).queueSerial(delayedCallables, this.delay);
                if (ret == false) {
                    log.warn("Unable to queue the delayedCallables commands for RecoveryService. "
                            + "Most possibly Callable queue is full. Queue size is :"
                            + Services.get().get(CallableQueueService.class).queueSize());
                }
                delayedCallables = null;
                this.delay = 0;
View Full Code Here

     * @param predicate predicate waiting on.
     * @return the waited time.
     */
    protected long waitFor(int timeout, Predicate predicate) {
        ParamChecker.notNull(predicate, "predicate");
        XLog log = new XLog(LogFactory.getLog(getClass()));
        long started = System.currentTimeMillis();
        long mustEnd = System.currentTimeMillis() + (long)(WAITFOR_RATIO * timeout);
        long lastEcho = 0;
        try {
            long waiting = mustEnd - System.currentTimeMillis();
            log.info("Waiting up to [{0}] msec", waiting);
            boolean eval;
            while (!(eval = predicate.evaluate()) && System.currentTimeMillis() < mustEnd) {
                if ((System.currentTimeMillis() - lastEcho) > 1000) {
                    waiting = mustEnd - System.currentTimeMillis();
                    log.info("Waiting up to [{0}] msec", waiting);
                    lastEcho = System.currentTimeMillis();
                }
                Thread.sleep(1000);
            }
            if (!eval) {
                log.info("Waiting timed out after [{0}] msec", timeout);
            }
            return System.currentTimeMillis() - started;
        }
        catch (Exception ex) {
            throw new RuntimeException(ex);
View Full Code Here

            this.nameIndex = id + ":" + nameIndex;
            this.sb = buffer;
        }

        public void run() {
            XLog log = XLog.getLog(getClass());
            try {
                WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
                log.info("Get [{0}]", nameIndex);
                store.beginTrx();
                store.getWorkflow(id, false);
                log.info("Got [{0}]", nameIndex);
                sb.append(nameIndex + "-L ");
                synchronized (this) {
                    wait();
                }
                sb.append(nameIndex + "-U ");
                store.commitTrx();
                store.closeTrx();
                log.info("Release [{0}]", nameIndex);
            }
            catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
View Full Code Here

            try {
                if (callableBegin(callable)) {
                    cron.stop();
                    addInQueueCron(cron);
                    XLog.Info.get().clear();
                    XLog log = XLog.getLog(getClass());
                    log.trace("executing callable [{0}]", callable.getName());

                    removeFromUniqueCallables();
                    try {
                        callable.call();
                        incrCounter(INSTR_EXECUTED_COUNTER, 1);
                        log.trace("executed callable [{0}]", callable.getName());
                    }
                    catch (Exception ex) {
                        incrCounter(INSTR_FAILED_COUNTER, 1);
                        log.warn("exception callable [{0}], {1}", callable.getName(), ex.getMessage(), ex);
                    }
                    finally {
                        XLog.Info.get().clear();
                    }
                }
                else {
                    log.warn("max concurrency for callable [{0}] exceeded, requeueing with [{1}]ms delay", callable
                            .getType(), CONCURRENCY_DELAY);
                    setDelay(CONCURRENCY_DELAY, TimeUnit.MILLISECONDS);
                    removeFromUniqueCallables();
                    queue(this, true);
                    incrCounter(callable.getType() + "#exceeded.concurrency", 1);
View Full Code Here

TOP

Related Classes of org.apache.oozie.util.XLog

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.