Search in sources :

Example 16 with Configuration

use of nl.nn.adapterframework.configuration.Configuration 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 17 with Configuration

use of nl.nn.adapterframework.configuration.Configuration in project iaf by ibissource.

the class JobDef method checkReload.

private void checkReload(IbisManager ibisManager) {
    String configJmsRealm = JmsRealmFactory.getInstance().getFirstDatasourceJmsRealm();
    List<String> configsToReload = new ArrayList<String>();
    if (StringUtils.isNotEmpty(configJmsRealm)) {
        Connection conn = null;
        ResultSet rs = null;
        FixedQuerySender qs = (FixedQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(FixedQuerySender.class);
        qs.setJmsRealm(configJmsRealm);
        qs.setQuery("SELECT COUNT(*) FROM IBISCONFIG");
        String selectQuery = "SELECT VERSION FROM IBISCONFIG WHERE NAME=? AND ACTIVECONFIG = 'TRUE' and AUTORELOAD = 'TRUE'";
        try {
            qs.configure();
            qs.open();
            conn = qs.getConnection();
            PreparedStatement stmt = conn.prepareStatement(selectQuery);
            for (Configuration configuration : ibisManager.getConfigurations()) {
                if ("DatabaseClassLoader".equals(configuration.getClassLoaderType())) {
                    String configName = configuration.getName();
                    stmt.setString(1, configName);
                    rs = stmt.executeQuery();
                    if (rs.next()) {
                        String ibisConfigVersion = rs.getString(1);
                        String configVersion = configuration.getVersion();
                        if (!StringUtils.equalsIgnoreCase(ibisConfigVersion, configVersion)) {
                            configsToReload.add(configName);
                        }
                    }
                }
            }
        } catch (Exception e) {
            String msg = "error while executing query [" + selectQuery + "] (as part of scheduled job execution): " + e.getMessage();
            getMessageKeeper().add(msg, MessageKeeperMessage.ERROR_LEVEL);
            log.error(getLogPrefix() + msg);
        } finally {
            qs.close();
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    log.warn("Could not close resultset", e);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    log.warn("Could not close connection", e);
                }
            }
        }
    }
    if (!configsToReload.isEmpty()) {
        for (String configToReload : configsToReload) {
            ibisManager.getIbisContext().reload(configToReload);
        }
    }
}
Also used : Configuration(nl.nn.adapterframework.configuration.Configuration) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender) SQLException(java.sql.SQLException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 18 with Configuration

use of nl.nn.adapterframework.configuration.Configuration in project iaf by ibissource.

the class SchedulerAdapter method getJobGroupNamesWithJobsToXml.

/**
 * Get all jobgroups, jobs within this group, the jobdetail and the
 * associated triggers in XML format.
 */
public XmlBuilder getJobGroupNamesWithJobsToXml(Scheduler theScheduler, IbisManager ibisManager) {
    XmlBuilder xbRoot = new XmlBuilder("jobGroups");
    try {
        // process groups
        String[] jgnames = theScheduler.getJobGroupNames();
        for (int i = 0; i < jgnames.length; i++) {
            XmlBuilder el = new XmlBuilder("jobGroup");
            el.addAttribute("name", jgnames[i]);
            // process jobs within group
            XmlBuilder jb = new XmlBuilder("jobs");
            String[] jobNames = theScheduler.getJobNames(jgnames[i]);
            for (int j = 0; j < jobNames.length; j++) {
                XmlBuilder jn = new XmlBuilder("job");
                jn.addAttribute("name", jobNames[j]);
                // details for job
                XmlBuilder jd = jobDetailToXmlBuilder(theScheduler, jobNames[j], jgnames[i]);
                jn.addSubElement(jd);
                // get the triggers for this job
                XmlBuilder tr = getJobTriggers(theScheduler, jobNames[j], jgnames[i]);
                jn.addSubElement(tr);
                XmlBuilder datamap = jobDataMapToXmlBuilder(theScheduler, jobNames[j], jgnames[i]);
                jn.addSubElement(datamap);
                jb.addSubElement(jn);
                JobDef jobDef = null;
                for (Configuration configuration : ibisManager.getConfigurations()) {
                    jobDef = configuration.getScheduledJob(jobNames[j]);
                    if (jobDef != null) {
                        break;
                    }
                }
                XmlBuilder ms = getJobMessages(jobDef);
                jn.addSubElement(ms);
                XmlBuilder jrs = getJobRunStatistics(jobDef);
                jn.addSubElement(jrs);
            }
            el.addSubElement(jb);
            xbRoot.addSubElement(el);
        }
    } catch (org.quartz.SchedulerException se) {
        log.error(se);
    }
    return xbRoot;
}
Also used : Configuration(nl.nn.adapterframework.configuration.Configuration) SchedulerException(org.quartz.SchedulerException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Example 19 with Configuration

use of nl.nn.adapterframework.configuration.Configuration in project iaf by ibissource.

the class ReloadSender method sendMessage.

@Override
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws TimeOutException, SenderException {
    String configName = null;
    String activeVersion = null;
    ParameterValueList pvl = null;
    try {
        if (prc != null && paramList != null) {
            pvl = prc.getValues(paramList);
            if (pvl.getParameterValue("name") != null)
                configName = (String) pvl.getParameterValue("name").getValue();
            if (pvl.getParameterValue("forceReload") != null)
                setForceReload((Boolean) pvl.getParameterValue("forceReload").getValue());
        }
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
    }
    try {
        if (configName == null)
            configName = XmlUtils.evaluateXPathNodeSetFirstElement(message, "row/field[@name='NAME']");
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "error evaluating Xpath expression configName", e);
    }
    try {
        if (!getForceReload())
            activeVersion = XmlUtils.evaluateXPathNodeSetFirstElement(message, "row/field[@name='VERSION']");
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "error evaluating Xpath expression activeVersion", e);
    }
    Configuration configuration = getPipe().getAdapter().getConfiguration().getIbisManager().getConfiguration(configName);
    if (configuration != null) {
        String latestVersion = configuration.getVersion();
        if (getForceReload() || (latestVersion != null && !activeVersion.equals(latestVersion))) {
            IbisContext ibisContext = configuration.getIbisManager().getIbisContext();
            ibisContext.reload(configName);
            return "Reload " + configName + " succeeded";
        } else {
            return "Reload " + configName + " skipped";
        }
    } else {
        log.warn("Configuration [" + configName + "] not loaded yet");
        return "Reload " + configName + " skipped";
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Configuration(nl.nn.adapterframework.configuration.Configuration) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Example 20 with Configuration

use of nl.nn.adapterframework.configuration.Configuration in project iaf by ibissource.

the class EsbJmsListenerChecker method doCheck.

public static void doCheck(IbisManager ibisManager, PlatformTransactionManager txManager, String logPrefix) {
    long idleTimeout = AppConstants.getInstance().getInt("check.esbJmsListeners.idleTimeout", 300) * 1000;
    for (Configuration configuration : ibisManager.getConfigurations()) {
        String msg;
        List<String> jmsRealmNames = new ArrayList<String>();
        for (IAdapter adapter : configuration.getRegisteredAdapters()) {
            if (adapter instanceof Adapter) {
                for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
                    IReceiver receiver = (IReceiver) receiverIt.next();
                    if (receiver instanceof ReceiverBase) {
                        ReceiverBase rb = (ReceiverBase) receiver;
                        if (rb.getRunState().equals(RunStateEnum.STARTED)) {
                            // if (true) {
                            long lastMessageDate = rb.getLastMessageDate();
                            if (lastMessageDate == 0 || System.currentTimeMillis() - lastMessageDate > idleTimeout) {
                                IListener listener = rb.getListener();
                                if (listener instanceof EsbJmsListener) {
                                    EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
                                    if (esbJmsListener.getMessageProtocol().equals("FF")) {
                                        Object managedConnectionFactory = null;
                                        try {
                                            managedConnectionFactory = esbJmsListener.getManagedConnectionFactory();
                                            if (managedConnectionFactory == null) {
                                                msg = logPrefix + "could not get managed connection factory";
                                                warn(adapter, msg);
                                            } else {
                                                String contextFactoryClassname = getContextFactoryClassname(managedConnectionFactory);
                                                String providerURL = getProviderURL(managedConnectionFactory);
                                                String authDataAlias = getAuthDataAlias(managedConnectionFactory);
                                                String username = null;
                                                String password = null;
                                                msg = logPrefix + "found esbJmsListener [" + esbJmsListener.getName() + "] with managedConnectionFactoryClassname [" + managedConnectionFactory.getClass().getName() + "] having contextFactoryClassname [" + contextFactoryClassname + "] providerURL [" + providerURL + "] authDataAlias [" + authDataAlias + "]";
                                                if (authDataAlias != null) {
                                                    CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
                                                    username = cf.getUsername();
                                                    password = cf.getPassword();
                                                }
                                                if (contextFactoryClassname != null && contextFactoryClassname.equals("com.tibco.tibjms.naming.TibjmsInitialContextFactory")) {
                                                    log.debug(msg + ", checking...");
                                                    long age = getTibcoQueueFirstMessageAge(providerURL, authDataAlias, username, password, esbJmsListener.getPhysicalDestinationShortName(), esbJmsListener.getMessageSelector());
                                                    if (age > idleTimeout) {
                                                        msg = logPrefix + "most probably esbJmsListener [" + esbJmsListener.getName() + "] has lost connection with queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
                                                        warn(adapter, msg);
                                                    }
                                                } else {
                                                    log.debug(msg + ", ignoring...");
                                                }
                                            }
                                        } catch (Throwable t) {
                                            msg = logPrefix + "exception on checking queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
                                            warn(adapter, msg, t);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) Configuration(nl.nn.adapterframework.configuration.Configuration) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) IReceiver(nl.nn.adapterframework.core.IReceiver) Iterator(java.util.Iterator) IAdapter(nl.nn.adapterframework.core.IAdapter)

Aggregations

Configuration (nl.nn.adapterframework.configuration.Configuration)31 ArrayList (java.util.ArrayList)12 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)9 IAdapter (nl.nn.adapterframework.core.IAdapter)8 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 Adapter (nl.nn.adapterframework.core.Adapter)7 HashMap (java.util.HashMap)6 GET (javax.ws.rs.GET)6 Iterator (java.util.Iterator)5 LinkedHashMap (java.util.LinkedHashMap)5 RolesAllowed (javax.annotation.security.RolesAllowed)5 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)4 IbisManager (nl.nn.adapterframework.configuration.IbisManager)4 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)4 IOException (java.io.IOException)3 URL (java.net.URL)3 Date (java.util.Date)3 Transformer (javax.xml.transform.Transformer)3 IReceiver (nl.nn.adapterframework.core.IReceiver)3