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();
}
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;
}
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);
}
}
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");
}
}
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();
}
Aggregations