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