Search in sources :

Example 21 with Configuration

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

the class RestListenerUtils method doRestartShowConfigurationStatus.

private static boolean doRestartShowConfigurationStatus(ServletContext servletContext) {
    String attributeKey = AppConstants.getInstance().getProperty(ConfigurationServlet.KEY_CONTEXT);
    IbisContext ibisContext = (IbisContext) servletContext.getAttribute(attributeKey);
    IAdapter adapter = null;
    IReceiver receiver = null;
    if (ibisContext != null) {
        IbisManager ibisManager = ibisContext.getIbisManager();
        if (ibisManager != null) {
            Configuration configuration = ibisManager.getConfiguration(SHOW_CONFIG_STATUS_CONFIGURATION);
            if (configuration != null) {
                adapter = configuration.getRegisteredAdapter(SHOW_CONFIG_STATUS_ADAPTER);
                if (adapter instanceof Adapter) {
                    receiver = ((Adapter) adapter).getReceiverByNameAndListener(SHOW_CONFIG_STATUS_RECEIVER, RestListener.class);
                }
            }
        }
    }
    if (adapter == null) {
        log.info("could not restart ShowConfigurationStatus, adapter [" + SHOW_CONFIG_STATUS_ADAPTER + "] not found");
        return false;
    }
    if (receiver == null) {
        log.info("could not restart ShowConfigurationStatus, receiver [" + SHOW_CONFIG_STATUS_RECEIVER + "] not found");
        return false;
    }
    RunStateEnum adapterStatus = adapter.getRunState();
    RunStateEnum receiverStatus = receiver.getRunState();
    if (RunStateEnum.STARTED.equals(adapterStatus) && RunStateEnum.STARTED.equals(receiverStatus)) {
        log.info("ShowConfigurationStatus is already running, will restart it");
        ibisContext.getIbisManager().handleAdapter("stopadapter", SHOW_CONFIG_STATUS_CONFIGURATION, SHOW_CONFIG_STATUS_ADAPTER, SHOW_CONFIG_STATUS_RECEIVER, "system", true);
    }
    if (RunStateEnum.STOPPED.equals(adapterStatus)) {
        log.info("starting adapter of ShowConfigurationStatus");
        ibisContext.getIbisManager().handleAdapter("startadapter", SHOW_CONFIG_STATUS_CONFIGURATION, SHOW_CONFIG_STATUS_ADAPTER, SHOW_CONFIG_STATUS_RECEIVER, "system", true);
        return true;
    } else {
        if (RunStateEnum.STARTED.equals(adapterStatus) && RunStateEnum.STOPPED.equals(receiverStatus)) {
            log.info("starting receiver of ShowConfigurationStatus");
            ibisContext.getIbisManager().handleAdapter("startreceiver", SHOW_CONFIG_STATUS_CONFIGURATION, SHOW_CONFIG_STATUS_ADAPTER, SHOW_CONFIG_STATUS_RECEIVER, "system", true);
            return true;
        }
    }
    log.info("could not restart ShowConfigurationStatus with adapter status [" + adapterStatus + "] and receiver status [" + receiverStatus + "]");
    return false;
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) IReceiver(nl.nn.adapterframework.core.IReceiver) IbisManager(nl.nn.adapterframework.configuration.IbisManager) Configuration(nl.nn.adapterframework.configuration.Configuration) RunStateEnum(nl.nn.adapterframework.util.RunStateEnum) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 22 with Configuration

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

Example 23 with Configuration

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

the class JobDef method executeSendMessageJob.

private void executeSendMessageJob(IbisManager ibisManager) {
    try {
        // send job
        IbisLocalSender localSender = new IbisLocalSender();
        localSender.setJavaListener(receiverName);
        localSender.setIsolated(false);
        localSender.setName("AdapterJob");
        if (getInterval() == 0) {
            localSender.setDependencyTimeOut(-1);
        }
        if (StringUtils.isNotEmpty(adapterName)) {
            IAdapter iAdapter = ibisManager.getRegisteredAdapter(adapterName);
            Configuration configuration = iAdapter.getConfiguration();
            localSender.setConfiguration(configuration);
        }
        localSender.configure();
        localSender.open();
        try {
            localSender.sendMessage(null, "");
        } finally {
            localSender.close();
        }
    } catch (Exception e) {
        String msg = "Error while sending message (as part of scheduled job execution): " + e.getMessage();
        getMessageKeeper().add(msg, MessageKeeperMessage.ERROR_LEVEL);
        log.error(getLogPrefix() + msg, e);
    }
}
Also used : IbisLocalSender(nl.nn.adapterframework.senders.IbisLocalSender) Configuration(nl.nn.adapterframework.configuration.Configuration) IAdapter(nl.nn.adapterframework.core.IAdapter) SQLException(java.sql.SQLException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 24 with Configuration

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

the class FlowDiagram method generate.

public void generate(List<Configuration> configurations) throws IOException, DomBuilderException, TransformerException, ConfigurationException, SenderException, TimeOutException {
    File destFile = retrieveAllConfigurationsFlowFile();
    destFile.delete();
    String dotInput = "<configs>";
    for (Configuration configuration : configurations) {
        dotInput = dotInput + XmlUtils.skipXmlDeclaration(configuration.getLoadedConfiguration());
    }
    dotInput = dotInput + "</configs>";
    URL xsltSource = ClassUtils.getResourceURL(this, IBIS2DOT_XSLT);
    Transformer transformer = XmlUtils.createTransformer(xsltSource);
    String dotOutput = XmlUtils.transformXml(transformer, dotInput);
    String name = "configurations [*ALL*]";
    generateFlowDiagram(name, dotOutput, destFile);
}
Also used : Transformer(javax.xml.transform.Transformer) Configuration(nl.nn.adapterframework.configuration.Configuration) File(java.io.File) URL(java.net.URL)

Example 25 with Configuration

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

the class ShowConfiguration method getConfigurationDetailsByName.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/configurations/manage/{configuration}")
@Produces(MediaType.APPLICATION_JSON)
public Response getConfigurationDetailsByName(@PathParam("configuration") String configurationName, @QueryParam("realm") String jmsRealm) throws ApiException {
    initBase(servletConfig);
    Configuration configuration = ibisManager.getConfiguration(configurationName);
    if (configuration == null) {
        throw new ApiException("Configuration not found!");
    }
    if (configuration.getClassLoader().getParent() instanceof DatabaseClassLoader) {
        List<Map<String, Object>> configs = getConfigsFromDatabase(configurationName, jmsRealm);
        if (configs == null)
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
        for (Map<String, Object> config : configs) {
            if (config.get("version").toString().equals(configuration.getVersion()))
                config.put("loaded", true);
            else
                config.put("loaded", false);
        }
        return Response.status(Response.Status.CREATED).entity(configs).build();
    }
    return Response.status(Response.Status.NO_CONTENT).build();
}
Also used : DatabaseClassLoader(nl.nn.adapterframework.configuration.classloaders.DatabaseClassLoader) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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