Search in sources :

Example 6 with RunState

use of nl.nn.adapterframework.util.RunState in project iaf by ibissource.

the class ShowConfigurationStatus method getIbisHealth.

@GET
@PermitAll
@Path("/adapters/{name}/health")
@Produces(MediaType.APPLICATION_JSON)
public Response getIbisHealth(@PathParam("name") String name) throws ApiException {
    Adapter adapter = getAdapter(name);
    Map<String, Object> response = new HashMap<String, Object>();
    List<String> errors = new ArrayList<String>();
    // Let's not make it difficult for ourselves and only use STARTED/ERROR enums
    RunState state = adapter.getRunState();
    if (state == RunState.STARTED) {
        for (Receiver<?> receiver : adapter.getReceivers()) {
            RunState rState = receiver.getRunState();
            if (rState != RunState.STARTED) {
                errors.add("receiver[" + receiver.getName() + "] of adapter[" + adapter.getName() + "] is in state[" + rState.toString() + "]");
                state = RunState.ERROR;
            }
        }
    } else {
        errors.add("adapter[" + adapter.getName() + "] is in state[" + state.toString() + "]");
        state = RunState.ERROR;
    }
    Status status = Response.Status.OK;
    if (state == RunState.ERROR) {
        status = Response.Status.SERVICE_UNAVAILABLE;
    }
    if (errors.size() > 0)
        response.put("errors", errors);
    response.put("status", status);
    return Response.status(status).entity(response).build();
}
Also used : RunState(nl.nn.adapterframework.util.RunState) Status(javax.ws.rs.core.Response.Status) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Example 7 with RunState

use of nl.nn.adapterframework.util.RunState in project iaf by ibissource.

the class ShowConfigurationStatus method mapAdapter.

private Map<String, Object> mapAdapter(Adapter adapter) {
    Map<String, Object> adapterInfo = new HashMap<String, Object>();
    Configuration config = adapter.getConfiguration();
    String adapterName = adapter.getName();
    adapterInfo.put("name", adapterName);
    adapterInfo.put("description", adapter.getDescription());
    adapterInfo.put("configuration", config.getName());
    // replace low line (x'5f') by asterisk (x'2a) so it's sorted before any digit and letter
    String nameUC = StringUtils.upperCase(StringUtils.replace(adapterName, "_", "*"));
    adapterInfo.put("nameUC", nameUC);
    RunState adapterRunState = adapter.getRunState();
    adapterInfo.put("started", adapterRunState == RunState.STARTED);
    String state = adapterRunState.toString().toLowerCase().replace("*", "");
    adapterInfo.put("state", state);
    adapterInfo.put("configured", adapter.configurationSucceeded());
    adapterInfo.put("upSince", adapter.getStatsUpSinceDate().getTime());
    Date lastMessage = adapter.getLastMessageDateDate();
    if (lastMessage != null) {
        adapterInfo.put("lastMessage", lastMessage.getTime());
        adapterInfo.put("messagesInProcess", adapter.getNumOfMessagesInProcess());
        adapterInfo.put("messagesProcessed", adapter.getNumOfMessagesProcessed());
        adapterInfo.put("messagesInError", adapter.getNumOfMessagesInError());
    }
    Iterator<Receiver<?>> it = adapter.getReceivers().iterator();
    int errorStoreMessageCount = 0;
    int messageLogMessageCount = 0;
    while (it.hasNext()) {
        Receiver rcv = it.next();
        if (rcv.isNumberOfExceptionsCaughtWithoutMessageBeingReceivedThresholdReached()) {
            adapterInfo.put("receiverReachedMaxExceptions", "true");
        }
        IMessageBrowser esmb = rcv.getMessageBrowser(ProcessState.ERROR);
        if (esmb != null) {
            try {
                errorStoreMessageCount += esmb.getMessageCount();
            } catch (ListenerException e) {
                log.warn("Cannot determine number of messages in errorstore of [" + rcv.getName() + "]", e);
            }
        }
        IMessageBrowser mlmb = rcv.getMessageBrowser(ProcessState.DONE);
        if (mlmb != null) {
            try {
                messageLogMessageCount += mlmb.getMessageCount();
            } catch (ListenerException e) {
                log.warn("Cannot determine number of messages in messagelog of [" + rcv.getName() + "]", e);
            }
        }
    }
    if (errorStoreMessageCount != 0) {
        adapterInfo.put("errorStoreMessageCount", errorStoreMessageCount);
    }
    if (messageLogMessageCount != 0) {
        adapterInfo.put("messageLogMessageCount", messageLogMessageCount);
    }
    return adapterInfo;
}
Also used : RunState(nl.nn.adapterframework.util.RunState) ListenerException(nl.nn.adapterframework.core.ListenerException) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IMessageBrowser(nl.nn.adapterframework.core.IMessageBrowser) Receiver(nl.nn.adapterframework.receivers.Receiver) Date(java.util.Date)

Example 8 with RunState

use of nl.nn.adapterframework.util.RunState in project iaf by ibissource.

the class IbisTester method testStartAdapters.

/**
 * returns a string containing the error, if any
 */
public String testStartAdapters() {
    // Log4J2 will automatically create a console appender and basic pattern layout.
    Configurator.setLevel(LogUtil.getRootLogger().getName(), Level.INFO);
    // remove AppConstants because it can be present from another JUnit test
    AppConstants.removeInstance();
    appConstants = AppConstants.getInstance();
    webAppPath = getWebContentDirectory();
    String projectBaseDir = Misc.getProjectBaseDir();
    appConstants.put("project.basedir", projectBaseDir);
    debug("***set property with name [project.basedir] and value [" + projectBaseDir + "]***");
    System.setProperty("jdbc.migrator.active", "true");
    // appConstants.put("validators.disabled", "true");
    // appConstants.put("xmlValidator.lazyInit", "true");
    // appConstants.put("xmlValidator.maxInitialised", "200");
    ibisContext = new IbisContext();
    long configLoadStartTime = System.currentTimeMillis();
    ibisContext.init(false);
    long configLoadEndTime = System.currentTimeMillis();
    debug("***configuration loaded in [" + (configLoadEndTime - configLoadStartTime) + "] msec***");
    List<Configuration> configurations = ibisContext.getIbisManager().getConfigurations();
    for (Configuration configuration : configurations) {
        if (configuration.getConfigurationException() != null) {
            error("error loading configuration [" + configuration.getName() + "]: " + configuration.getConfigurationException().getMessage());
        } else {
            debug("loading configuration [" + configuration.getName() + "] with [" + configuration.getRegisteredAdapters().size() + "] adapters");
        }
    }
    debug("***starting adapters***");
    int adaptersStarted = 0;
    int adaptersCount = 0;
    for (Adapter adapter : ibisContext.getIbisManager().getRegisteredAdapters()) {
        adaptersCount++;
        RunState runState = adapter.getRunState();
        if (!(RunState.STARTED).equals(runState)) {
            debug("adapter [" + adapter.getName() + "] has state [" + runState + "], will retry...");
            int count = 30;
            while (count-- > 0 && !(RunState.STARTED).equals(runState)) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                runState = adapter.getRunState();
                if (!(RunState.STARTED).equals(runState)) {
                    debug("adapter [" + adapter.getName() + "] has state [" + runState + "], retries left [" + count + "]");
                } else {
                    debug("adapter [" + adapter.getName() + "] has state [" + runState + "]");
                }
            }
        } else {
            debug("adapter [" + adapter.getName() + "] has state [" + runState + "]");
        }
        if ((RunState.STARTED).equals(runState)) {
            adaptersStarted++;
        } else {
            error("adapter [" + adapter.getName() + "] has state [" + runState + "]");
        }
    }
    String msg = "adapters started [" + adaptersStarted + "] from [" + adaptersCount + "]";
    if (adaptersCount == adaptersStarted) {
        debug(msg);
        // null == good
        return null;
    } else {
        return error(msg);
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) RunState(nl.nn.adapterframework.util.RunState) Configuration(nl.nn.adapterframework.configuration.Configuration) Adapter(nl.nn.adapterframework.core.Adapter)

Example 9 with RunState

use of nl.nn.adapterframework.util.RunState in project iaf by ibissource.

the class DefaultIbisManager method handleAction.

@Override
public void handleAction(IbisAction action, String configurationName, String adapterName, String receiverName, String commandIssuedBy, boolean isAdmin) {
    switch(action) {
        case 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();
                    }
                }
            }
            break;
        case 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()));
                }
            }
            break;
        case STOPRECEIVER:
            for (Configuration configuration : configurations) {
                if (configuration.getRegisteredAdapter(adapterName) != null) {
                    Adapter adapter = configuration.getRegisteredAdapter(adapterName);
                    Receiver<?> receiver = adapter.getReceiverByName(receiverName);
                    RunState receiverRunState = receiver.getRunState();
                    switch(receiverRunState) {
                        case STOPPING:
                        case STOPPED:
                            adapter.getMessageKeeper().info(receiver, "already in state [" + receiverRunState + "]");
                            break;
                        case STARTED:
                        case EXCEPTION_STARTING:
                        case EXCEPTION_STOPPING:
                            receiver.stopRunning();
                            log.info("receiver [" + receiverName + "] stopped by webcontrol on request of " + commandIssuedBy);
                            break;
                        default:
                            log.warn("receiver [" + receiverName + "] currently in state [" + receiverRunState + "], ignoring stop() command");
                            break;
                    }
                }
            }
            break;
        case STARTRECEIVER:
            for (Configuration configuration : configurations) {
                if (configuration.getRegisteredAdapter(adapterName) != null) {
                    Adapter adapter = configuration.getRegisteredAdapter(adapterName);
                    Receiver<?> receiver = adapter.getReceiverByName(receiverName);
                    RunState receiverRunState = receiver.getRunState();
                    switch(receiverRunState) {
                        case STARTING:
                        case STARTED:
                            adapter.getMessageKeeper().info(receiver, "already in state [" + receiverRunState + "]");
                            break;
                        case STOPPED:
                            receiver.startRunning();
                            log.info("receiver [" + receiverName + "] started by " + commandIssuedBy);
                            break;
                        default:
                            log.warn("receiver [" + receiverName + "] currently in state [" + receiverRunState + "], ignoring start() command");
                            break;
                    }
                }
            }
            break;
        case RELOAD:
            String msg = "Reload configuration [" + configurationName + "] on request of [" + commandIssuedBy + "]";
            log.info(msg);
            secLog.info(msg);
            ibisContext.reload(configurationName);
            break;
        case FULLRELOAD:
            if (isAdmin) {
                String msg2 = "Full reload on request of [" + commandIssuedBy + "]";
                log.info(msg2);
                secLog.info(msg2);
                ibisContext.fullReload();
            } else {
                log.warn("Full reload not allowed for [" + commandIssuedBy + "]");
            }
            break;
        case INCTHREADS:
            for (Configuration configuration : configurations) {
                if (configuration.getRegisteredAdapter(adapterName) != null) {
                    Adapter adapter = configuration.getRegisteredAdapter(adapterName);
                    Receiver<?> receiver = adapter.getReceiverByName(receiverName);
                    if (receiver.isThreadCountControllable()) {
                        receiver.increaseThreadCount();
                    }
                    log.info("receiver [" + receiverName + "] increased threadcount on request of " + commandIssuedBy);
                }
            }
            break;
        case DECTHREADS:
            for (Configuration configuration : configurations) {
                if (configuration.getRegisteredAdapter(adapterName) != null) {
                    Adapter adapter = configuration.getRegisteredAdapter(adapterName);
                    Receiver<?> receiver = adapter.getReceiverByName(receiverName);
                    if (receiver.isThreadCountControllable()) {
                        receiver.decreaseThreadCount();
                    }
                    log.info("receiver [" + receiverName + "] decreased threadcount on request of " + commandIssuedBy);
                }
            }
            break;
        default:
            throw new NotImplementedException("action [" + action.name() + "] not implemented");
    }
}
Also used : RunState(nl.nn.adapterframework.util.RunState) Configuration(nl.nn.adapterframework.configuration.Configuration) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Adapter(nl.nn.adapterframework.core.Adapter) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 10 with RunState

use of nl.nn.adapterframework.util.RunState in project iaf by ibissource.

the class ShowConfiguration method getConfigurationHealth.

@GET
@PermitAll
@Path("/configurations/{configuration}/health")
@Produces(MediaType.APPLICATION_JSON)
public Response getConfigurationHealth(@PathParam("configuration") String configurationName) throws ApiException {
    Configuration configuration = getIbisManager().getConfiguration(configurationName);
    if (configuration == null) {
        throw new ApiException("Configuration not found!");
    }
    if (!configuration.isActive()) {
        throw new ApiException("Configuration not active", configuration.getConfigurationException());
    }
    Map<String, Object> response = new HashMap<>();
    Map<RunState, Integer> stateCount = new HashMap<>();
    List<String> errors = new ArrayList<>();
    for (IAdapter adapter : configuration.getRegisteredAdapters()) {
        // Let's not make it difficult for ourselves and only use STARTED/ERROR enums
        RunState state = adapter.getRunState();
        if (state == RunState.STARTED) {
            for (Receiver<?> receiver : adapter.getReceivers()) {
                RunState rState = receiver.getRunState();
                if (rState != RunState.STARTED) {
                    errors.add("receiver[" + receiver.getName() + "] of adapter[" + adapter.getName() + "] is in state[" + rState.toString() + "]");
                    state = RunState.ERROR;
                }
            }
        } else {
            errors.add("adapter[" + adapter.getName() + "] is in state[" + state.toString() + "]");
            state = RunState.ERROR;
        }
        int count;
        if (stateCount.containsKey(state))
            count = stateCount.get(state);
        else
            count = 0;
        stateCount.put(state, ++count);
    }
    Status status = Response.Status.OK;
    if (stateCount.containsKey(RunState.ERROR))
        status = Response.Status.SERVICE_UNAVAILABLE;
    if (!errors.isEmpty())
        response.put("errors", errors);
    response.put("status", status);
    return Response.status(status).entity(response).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) RunState(nl.nn.adapterframework.util.RunState) IAdapter(nl.nn.adapterframework.core.IAdapter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Aggregations

RunState (nl.nn.adapterframework.util.RunState)12 HashMap (java.util.HashMap)5 Configuration (nl.nn.adapterframework.configuration.Configuration)5 Adapter (nl.nn.adapterframework.core.Adapter)5 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 PermitAll (javax.annotation.security.PermitAll)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Status (javax.ws.rs.core.Response.Status)3 Date (java.util.Date)2 ListenerException (nl.nn.adapterframework.core.ListenerException)2 IOException (java.io.IOException)1 StringTokenizer (java.util.StringTokenizer)1 TransformerException (javax.xml.transform.TransformerException)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 IbisContext (nl.nn.adapterframework.configuration.IbisContext)1 HasPhysicalDestination (nl.nn.adapterframework.core.HasPhysicalDestination)1 HasSender (nl.nn.adapterframework.core.HasSender)1