Search in sources :

Example 1 with JdbcTransactionalStorage

use of nl.nn.adapterframework.jdbc.JdbcTransactionalStorage in project iaf by ibissource.

the class DefaultIbisManager method handleAdapter.

/**
 * Utility function to give commands to Adapters and Receivers
 */
public void handleAdapter(String action, String configurationName, String adapterName, String receiverName, String commandIssuedBy, boolean isAdmin) {
    if (action.equalsIgnoreCase("STOPADAPTER")) {
        if (adapterName.equals("*ALL*")) {
            if (configurationName.equals("*ALL*")) {
                log.info("Stopping all adapters on request of [" + commandIssuedBy + "]");
                for (Configuration configuration : configurations) {
                    stopAdapters(configuration);
                }
            } else {
                log.info("Stopping all adapters for configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]");
                stopAdapters(getConfiguration(configurationName));
            }
        } else {
            for (Configuration configuration : configurations) {
                if (configuration.getRegisteredAdapter(adapterName) != null) {
                    log.info("Stopping adapter [" + adapterName + "], on request of [" + commandIssuedBy + "]");
                    configuration.getRegisteredAdapter(adapterName).stopRunning();
                }
            }
        }
    } else if (action.equalsIgnoreCase("STARTADAPTER")) {
        if (adapterName.equals("*ALL*")) {
            if (configurationName.equals("*ALL*")) {
                log.info("Starting all adapters on request of [" + commandIssuedBy + "]");
                for (Configuration configuration : configurations) {
                    startAdapters(configuration);
                }
            } else {
                log.info("Starting all adapters for configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]");
                startAdapters(getConfiguration(configurationName));
            }
        } else {
            try {
                for (Configuration configuration : configurations) {
                    if (configuration.getRegisteredAdapter(adapterName) != null) {
                        log.info("Starting adapter [" + adapterName + "] on request of [" + commandIssuedBy + "]");
                        configuration.getRegisteredAdapter(adapterName).startRunning();
                    }
                }
            } catch (Exception e) {
                log.error("error in execution of command [" + action + "] for adapter [" + adapterName + "]", e);
            // errors.add("", new ActionError("errors.generic", e.toString()));
            }
        }
    } else if (action.equalsIgnoreCase("STOPRECEIVER")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                receiver.stopRunning();
                log.info("receiver [" + receiverName + "] stopped by webcontrol on request of " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("STARTRECEIVER")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                receiver.startRunning();
                log.info("receiver [" + receiverName + "] started by " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("RELOAD")) {
        String msg = "Reload configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]";
        log.info(msg);
        secLog.info(msg);
        ibisContext.reload(configurationName);
    } else if (action.equalsIgnoreCase("FULLRELOAD")) {
        if (isAdmin) {
            String msg = "Full reload on request of [" + commandIssuedBy + "]";
            log.info(msg);
            secLog.info(msg);
            ibisContext.fullReload();
        } else {
            log.warn("Full reload not allowed for [" + commandIssuedBy + "]");
        }
    } else if (action.equalsIgnoreCase("INCTHREADS")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                if (receiver instanceof IThreadCountControllable) {
                    IThreadCountControllable tcc = (IThreadCountControllable) receiver;
                    if (tcc.isThreadCountControllable()) {
                        tcc.increaseThreadCount();
                    }
                }
                log.info("receiver [" + receiverName + "] increased threadcount on request of " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("DECTHREADS")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                if (receiver instanceof IThreadCountControllable) {
                    IThreadCountControllable tcc = (IThreadCountControllable) receiver;
                    if (tcc.isThreadCountControllable()) {
                        tcc.decreaseThreadCount();
                    }
                }
                log.info("receiver [" + receiverName + "] decreased threadcount on request of " + commandIssuedBy);
            }
        }
    } else if (action.equalsIgnoreCase("SENDMESSAGE")) {
        try {
            // send job
            IbisLocalSender localSender = new IbisLocalSender();
            localSender.setJavaListener(receiverName);
            localSender.setIsolated(false);
            localSender.setName("AdapterJob");
            localSender.configure();
            localSender.open();
            try {
                localSender.sendMessage(null, "");
            } finally {
                localSender.close();
            }
        } catch (Exception e) {
            log.error("Error while sending message (as part of scheduled job execution)", e);
        }
    } else if (action.equalsIgnoreCase("MOVEMESSAGE")) {
        for (Configuration configuration : configurations) {
            if (configuration.getRegisteredAdapter(adapterName) != null) {
                IAdapter adapter = configuration.getRegisteredAdapter(adapterName);
                IReceiver receiver = adapter.getReceiverByName(receiverName);
                if (receiver instanceof ReceiverBase) {
                    ReceiverBase rb = (ReceiverBase) receiver;
                    ITransactionalStorage errorStorage = rb.getErrorStorage();
                    if (errorStorage == null) {
                        log.error("action [" + action + "] is only allowed for receivers with an ErrorStorage");
                    } else {
                        if (errorStorage instanceof JdbcTransactionalStorage) {
                            JdbcTransactionalStorage jdbcErrorStorage = (JdbcTransactionalStorage) rb.getErrorStorage();
                            IListener listener = rb.getListener();
                            if (listener instanceof EsbJmsListener) {
                                EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
                                EsbUtils.receiveMessageAndMoveToErrorStorage(esbJmsListener, jdbcErrorStorage);
                            } else {
                                log.error("action [" + action + "] is currently only allowed for EsbJmsListener, not for type [" + listener.getClass().getName() + "]");
                            }
                        } else {
                            log.error("action [" + action + "] is currently only allowed for JdbcTransactionalStorage, not for type [" + errorStorage.getClass().getName() + "]");
                        }
                    }
                }
            }
        }
    }
}
Also used : IReceiver(nl.nn.adapterframework.core.IReceiver) IbisLocalSender(nl.nn.adapterframework.senders.IbisLocalSender) ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) Configuration(nl.nn.adapterframework.configuration.Configuration) IThreadCountControllable(nl.nn.adapterframework.core.IThreadCountControllable) IListener(nl.nn.adapterframework.core.IListener) EsbJmsListener(nl.nn.adapterframework.extensions.esb.EsbJmsListener) IAdapter(nl.nn.adapterframework.core.IAdapter) SchedulerException(org.quartz.SchedulerException) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) JdbcTransactionalStorage(nl.nn.adapterframework.jdbc.JdbcTransactionalStorage)

Example 2 with JdbcTransactionalStorage

use of nl.nn.adapterframework.jdbc.JdbcTransactionalStorage in project iaf by ibissource.

the class JobDef method cleanupDatabase.

private void cleanupDatabase(IbisManager ibisManager) {
    Date date = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String formattedDate = formatter.format(date);
    List<String> jmsRealmNames = new ArrayList<String>();
    for (Configuration configuration : ibisManager.getConfigurations()) {
        List<JobDef> scheduledJobs = configuration.getScheduledJobs();
        for (JobDef jobdef : configuration.getScheduledJobs()) {
            if (jobdef.getLocker() != null) {
                String jmsRealmName = jobdef.getLocker().getJmsRealName();
                if (!jmsRealmNames.contains(jmsRealmName)) {
                    jmsRealmNames.add(jmsRealmName);
                }
            }
        }
    }
    for (IAdapter adapter : ibisManager.getRegisteredAdapters()) {
        if (adapter instanceof Adapter) {
            PipeLine pipeLine = ((Adapter) adapter).getPipeLine();
            if (pipeLine != null) {
                for (IPipe pipe : pipeLine.getPipes()) {
                    if (pipe instanceof IExtendedPipe) {
                        IExtendedPipe extendedPipe = (IExtendedPipe) pipe;
                        if (extendedPipe.getLocker() != null) {
                            String jmsRealmName = extendedPipe.getLocker().getJmsRealName();
                            if (!jmsRealmNames.contains(jmsRealmName)) {
                                jmsRealmNames.add(jmsRealmName);
                            }
                        }
                    }
                }
            }
        }
    }
    for (Iterator iter = jmsRealmNames.iterator(); iter.hasNext(); ) {
        String jmsRealmName = (String) iter.next();
        setJmsRealm(jmsRealmName);
        DirectQuerySender qs;
        qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(jmsRealmName);
        String deleteQuery;
        if (qs.getDatabaseType() == DbmsSupportFactory.DBMS_MSSQLSERVER) {
            deleteQuery = "DELETE FROM IBISLOCK WHERE EXPIRYDATE < CONVERT(datetime, '" + formattedDate + "', 120)";
        } else {
            deleteQuery = "DELETE FROM IBISLOCK WHERE EXPIRYDATE < TO_TIMESTAMP('" + formattedDate + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        setQuery(deleteQuery);
        qs = null;
        executeQueryJob(ibisManager);
    }
    List messageLogs = new ArrayList();
    for (IAdapter iadapter : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) iadapter;
        PipeLine pipeline = adapter.getPipeLine();
        for (int i = 0; i < pipeline.getPipes().size(); i++) {
            IPipe pipe = pipeline.getPipe(i);
            if (pipe instanceof MessageSendingPipe) {
                MessageSendingPipe msp = (MessageSendingPipe) pipe;
                if (msp.getMessageLog() != null) {
                    ITransactionalStorage transactionStorage = msp.getMessageLog();
                    if (transactionStorage instanceof JdbcTransactionalStorage) {
                        JdbcTransactionalStorage messageLog = (JdbcTransactionalStorage) transactionStorage;
                        String jmsRealmName = messageLog.getJmsRealName();
                        String expiryDateField = messageLog.getExpiryDateField();
                        String tableName = messageLog.getTableName();
                        String keyField = messageLog.getKeyField();
                        String typeField = messageLog.getTypeField();
                        MessageLogObject mlo = new MessageLogObject(jmsRealmName, tableName, expiryDateField, keyField, typeField);
                        if (!messageLogs.contains(mlo)) {
                            messageLogs.add(mlo);
                        }
                    }
                }
            }
        }
    }
    for (Iterator iter = messageLogs.iterator(); iter.hasNext(); ) {
        MessageLogObject mlo = (MessageLogObject) iter.next();
        setJmsRealm(mlo.getJmsRealmName());
        DirectQuerySender qs;
        qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
        qs.setJmsRealm(mlo.getJmsRealmName());
        String deleteQuery;
        if (qs.getDatabaseType() == DbmsSupportFactory.DBMS_MSSQLSERVER) {
            deleteQuery = "DELETE FROM " + mlo.getTableName() + " WHERE " + mlo.getKeyField() + " IN (SELECT " + mlo.getKeyField() + " FROM " + mlo.getTableName() + " WITH (rowlock,updlock,readpast) WHERE " + mlo.getTypeField() + " IN ('" + JdbcTransactionalStorage.TYPE_MESSAGELOG_PIPE + "','" + JdbcTransactionalStorage.TYPE_MESSAGELOG_RECEIVER + "') AND " + mlo.getExpiryDateField() + " < CONVERT(datetime, '" + formattedDate + "', 120))";
        } else {
            deleteQuery = "DELETE FROM " + mlo.getTableName() + " WHERE " + mlo.getTypeField() + " IN ('" + JdbcTransactionalStorage.TYPE_MESSAGELOG_PIPE + "','" + JdbcTransactionalStorage.TYPE_MESSAGELOG_RECEIVER + "') AND " + mlo.getExpiryDateField() + " < TO_TIMESTAMP('" + formattedDate + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        qs = null;
        setQuery(deleteQuery);
        setQueryTimeout(900);
        executeQueryJob(ibisManager);
    }
}
Also used : Configuration(nl.nn.adapterframework.configuration.Configuration) MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) ArrayList(java.util.ArrayList) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) Date(java.util.Date) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) JdbcTransactionalStorage(nl.nn.adapterframework.jdbc.JdbcTransactionalStorage) Iterator(java.util.Iterator) IExtendedPipe(nl.nn.adapterframework.core.IExtendedPipe) ArrayList(java.util.ArrayList) List(java.util.List) PipeLine(nl.nn.adapterframework.core.PipeLine) SimpleDateFormat(java.text.SimpleDateFormat) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipe(nl.nn.adapterframework.core.IPipe)

Aggregations

Configuration (nl.nn.adapterframework.configuration.Configuration)2 IAdapter (nl.nn.adapterframework.core.IAdapter)2 ITransactionalStorage (nl.nn.adapterframework.core.ITransactionalStorage)2 JdbcTransactionalStorage (nl.nn.adapterframework.jdbc.JdbcTransactionalStorage)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Adapter (nl.nn.adapterframework.core.Adapter)1 IExtendedPipe (nl.nn.adapterframework.core.IExtendedPipe)1 IListener (nl.nn.adapterframework.core.IListener)1 IPipe (nl.nn.adapterframework.core.IPipe)1 IReceiver (nl.nn.adapterframework.core.IReceiver)1 IThreadCountControllable (nl.nn.adapterframework.core.IThreadCountControllable)1 PipeLine (nl.nn.adapterframework.core.PipeLine)1 EsbJmsListener (nl.nn.adapterframework.extensions.esb.EsbJmsListener)1 DirectQuerySender (nl.nn.adapterframework.jdbc.DirectQuerySender)1 MessageSendingPipe (nl.nn.adapterframework.pipes.MessageSendingPipe)1 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)1