From a85f0d1bec1cb4f38d6375c6326248ebbe3d417b Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 14 Aug 2023 20:16:47 +0200 Subject: [PATCH 01/16] remove jndi config, new ValueObject TaskTransfer, v4.0.16 --- hsarback/pom.xml | 23 +-- .../servlets/QueueStatusReceiverServlet.java | 106 ++++------- hsarback/src/main/webapp/META-INF/context.xml | 25 --- hsarback/src/main/webapp/WEB-INF/web.xml | 35 +--- qserv/.gitignore | 2 +- qserv/pom.xml | 4 +- .../core/model/AbstractModuleImpl.java | 7 +- .../de/hsadmin/core/model/Transaction.java | 64 +++---- .../hsadmin/core/qserv/AbstractProcessor.java | 5 + .../de/hsadmin/core/qserv/NullProcessor.java | 2 +- .../de/hsadmin/core/qserv/QueueClient.java | 6 +- .../de/hsadmin/core/qserv/QueueCommons.java | 14 -- .../de/hsadmin/core/qserv/QueueServer.java | 177 ++++++------------ .../java/de/hsadmin/core/qserv/QueueTask.java | 15 +- .../de/hsadmin/core/qserv/ShellProcessor.java | 4 +- .../de/hsadmin/core/qserv/TaskTransfer.java | 130 +++++++++++++ .../core/qserv/WaitingTasksProcessor.java | 8 +- util/pom.xml | 2 +- 18 files changed, 299 insertions(+), 330 deletions(-) delete mode 100644 qserv/src/main/java/de/hsadmin/core/qserv/QueueCommons.java create mode 100644 qserv/src/main/java/de/hsadmin/core/qserv/TaskTransfer.java diff --git a/hsarback/pom.xml b/hsarback/pom.xml index 89331f5..739d21f 100644 --- a/hsarback/pom.xml +++ b/hsarback/pom.xml @@ -5,7 +5,7 @@ de.hsadmin hsar war - 4.0.15 + 4.0.16 HSAdmin Stable Backend Webapp http://maven.apache.org @@ -36,12 +36,12 @@ de.hsadmin.core hsadmin-util - 4.0.15 + 4.0.16 de.hsadmin.core hsadmin-qserv - 4.0.15 + 4.0.16 commons-httpclient @@ -78,6 +78,11 @@ openjpa 3.2.2 + + org.apache.activemq + activemq-client + 5.17.5 + junit junit @@ -90,18 +95,6 @@ 4.0.1 provided - - org.apache.activemq - activemq-all - 5.18.1 - provided - - - org.apache.geronimo.specs - geronimo-jms_1.1_spec - 1.1.1 - provided - hsar diff --git a/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java b/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java index 3c72b77..91395f1 100644 --- a/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java +++ b/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java @@ -2,6 +2,8 @@ package de.hsadmin.servlets; import java.io.IOException; import java.io.PrintWriter; +import java.io.Serializable; +import java.util.Date; import javax.jms.ExceptionListener; import javax.jms.JMSException; @@ -10,15 +12,9 @@ import javax.jms.MessageListener; import javax.jms.ObjectMessage; import javax.jms.Queue; import javax.jms.QueueConnection; -import javax.jms.QueueConnectionFactory; import javax.jms.QueueReceiver; import javax.jms.QueueSession; import javax.jms.Session; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NameClassPair; -import javax.naming.NamingEnumeration; -import javax.naming.NamingException; import javax.persistence.EntityManager; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -31,21 +27,20 @@ import org.apache.activemq.ActiveMQConnectionFactory; import de.hsadmin.core.model.TechnicalException; import de.hsadmin.core.model.TicketValidator; import de.hsadmin.core.model.Transaction; -import de.hsadmin.core.qserv.NullProcessor; import de.hsadmin.core.qserv.Processor; import de.hsadmin.core.qserv.QueueTask; +import de.hsadmin.core.qserv.TaskTransfer; import de.hsadmin.core.util.Config; public class QueueStatusReceiverServlet extends HttpServlet implements MessageListener, ExceptionListener { private static final long serialVersionUID = -5701350884034782083L; - - private static boolean initQueuesDone = false; - + + private String jmsUrl; private String jmsUser; private String jmsPass; - private QueueConnectionFactory queueConnectionFactory; + private String jmsStatusQueue; private QueueConnection queueConnection; private QueueSession queueSession; private boolean isConnected; @@ -61,39 +56,24 @@ public class QueueStatusReceiverServlet extends HttpServlet isConnected = false; messageCount = 0; errorCount = 0; - try { - if (!initQueuesDone) { - initQueues(); - } - initQueuesDone = true; - } catch (NamingException e) { - throw new ServletException(e); - } - try { - connect(); - } catch (NamingException e) { - throw new ServletException(e); - } + connect(); } - private void connect() throws NamingException { + private void connect() { Config config = Config.getInstance(); + jmsUrl = config.getProperty("hsadmin.jms.url", "tcp://localhost:61616"); jmsUser = config.getProperty("hsadmin.jms.username", "hsadmin"); jmsPass = config.getProperty("hsadmin.jms.password", "hsadmin-pw"); - InitialContext ctx = new InitialContext(); - Context env = (Context) ctx.lookup("java:comp/env"); - queueConnectionFactory = (QueueConnectionFactory) env.lookup("jms/QueueCF"); - if (queueConnectionFactory instanceof ActiveMQConnectionFactory) { - ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) queueConnectionFactory; - activeMQConnectionFactory.setTrustAllPackages(true); - } + jmsStatusQueue = config.getProperty("hsadmin.jms.status-queue", "queue.Status"); + final ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory(jmsUrl); + mqConnectionFactory.setTrustAllPackages(true); int timeoutCounter = 10; while (!isConnected && (timeoutCounter > 0)) { try { - queueConnection = queueConnectionFactory.createQueueConnection(jmsUser, jmsPass); + queueConnection = mqConnectionFactory.createQueueConnection(jmsUser, jmsPass); queueConnection.setExceptionListener(this); queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - Queue queue = (Queue) env.lookup("jms/hsadminStatus"); + Queue queue = queueSession.createQueue(jmsStatusQueue); queueConnection.start(); QueueReceiver receiver = queueSession.createReceiver(queue); receiver.setMessageListener(this); @@ -108,29 +88,6 @@ public class QueueStatusReceiverServlet extends HttpServlet } } - private void initQueues() throws NamingException { - InitialContext ctx = new InitialContext(); - NamingEnumeration list = ctx.list("java:comp/env/jms"); - Transaction transaction = new Transaction("anonymous"); - transaction.beginTransaction(); - EntityManager entityManager = transaction.getEntityManager(); - while (list.hasMore()) { - NameClassPair pair = list.next(); - String jndiName = pair.getName(); - if (jndiName != null && jndiName.startsWith("hsadminSystem-")) { - QueueTask task = new QueueTask(); - task.setProcessor(new NullProcessor()); - entityManager.persist(task); - entityManager.flush(); - String hive = jndiName.substring(14); - transaction.enqueue(hive, task); - } - } - transaction.commitTransaction(); - transaction.close(); - ctx.close(); - } - @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -159,20 +116,27 @@ public class QueueStatusReceiverServlet extends HttpServlet messageCount++; try { ObjectMessage objMessage = (ObjectMessage) jmsMessage; - QueueTask detachedQT = (QueueTask) objMessage.getObject(); - transaction = new Transaction("statusreceiver"); - transaction.beginTransaction(); - EntityManager em = transaction.getEntityManager(); - em.clear(); - QueueTask persistentQT = em.find(QueueTask.class, detachedQT.getId()); - persistentQT.assign(detachedQT); - Processor processor = persistentQT.getProcessor(); - if (processor != null) { - processor.finalize(transaction, persistentQT); + final Serializable object = objMessage.getObject(); + if (object != null) { + TaskTransfer detachedQT = (TaskTransfer) object; + transaction = new Transaction("statusreceiver"); + transaction.beginTransaction(); + EntityManager em = transaction.getEntityManager(); + em.clear(); + QueueTask persistentQT = em.find(QueueTask.class, detachedQT.getId()); + persistentQT.assign(detachedQT); + Processor processor = persistentQT.getProcessor(); + if (processor != null) { + processor.finalize(transaction, persistentQT); + } + em.persist(persistentQT); + em.flush(); + transaction.commitTransaction(); + } else { + final String err = "Deserialization failed " + new Date(); + System.out.println(err); + throw new TechnicalException(err); } - em.persist(persistentQT); - em.flush(); - transaction.commitTransaction(); } catch (Exception e) { errorCount++; if (transaction != null) transaction.rollbackTransaction(); @@ -186,7 +150,7 @@ public class QueueStatusReceiverServlet extends HttpServlet public void onException(JMSException exception) { close(); try { Thread.sleep(10000); } catch (InterruptedException e) { } - try { connect(); } catch (NamingException e) { } + connect(); } } diff --git a/hsarback/src/main/webapp/META-INF/context.xml b/hsarback/src/main/webapp/META-INF/context.xml index 808ab2b..5690171 100644 --- a/hsarback/src/main/webapp/META-INF/context.xml +++ b/hsarback/src/main/webapp/META-INF/context.xml @@ -5,29 +5,4 @@ global="jdbc/HSAdminDB" type="javax.sql.DataSource"/> - - - - - - - - - - diff --git a/hsarback/src/main/webapp/WEB-INF/web.xml b/hsarback/src/main/webapp/WEB-INF/web.xml index 7b91d45..1c2f6f3 100644 --- a/hsarback/src/main/webapp/WEB-INF/web.xml +++ b/hsarback/src/main/webapp/WEB-INF/web.xml @@ -57,36 +57,5 @@ Container - - jms/QueueCF - javax.jms.QueueConnectionFactory - Container - Shareable - - - - jms/hsadminSystem-h99 - javax.jms.Queue - Container - Shareable - - - jms/hsadminSystem-testdns - javax.jms.Queue - Container - Shareable - - - jms/hsadminSystem-testmail - javax.jms.Queue - Container - Shareable - - - jms/hsadminStatus - javax.jms.Queue - Container - Shareable - - - \ No newline at end of file + + diff --git a/qserv/.gitignore b/qserv/.gitignore index 21d4321..424bb27 100644 --- a/qserv/.gitignore +++ b/qserv/.gitignore @@ -4,4 +4,4 @@ .classpath .project .settings/ - +hsadmin.properties diff --git a/qserv/pom.xml b/qserv/pom.xml index d2694d6..785d36d 100644 --- a/qserv/pom.xml +++ b/qserv/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin.core hsadmin-qserv - 4.0.15 + 4.0.16 UTF-8 11 @@ -13,7 +13,7 @@ de.hsadmin.core hsadmin-util - 4.0.15 + 4.0.16 commons-lang diff --git a/qserv/src/main/java/de/hsadmin/core/model/AbstractModuleImpl.java b/qserv/src/main/java/de/hsadmin/core/model/AbstractModuleImpl.java index eadb74a..663e683 100644 --- a/qserv/src/main/java/de/hsadmin/core/model/AbstractModuleImpl.java +++ b/qserv/src/main/java/de/hsadmin/core/model/AbstractModuleImpl.java @@ -14,6 +14,7 @@ import de.hsadmin.core.qserv.EntityProcessorFactory; import de.hsadmin.core.qserv.NullProcessor; import de.hsadmin.core.qserv.Processor; import de.hsadmin.core.qserv.QueueTask; +import de.hsadmin.core.qserv.TaskTransfer; import de.hsadmin.core.util.HSAdminException; import de.hsadmin.mods.user.UnixUser; @@ -199,8 +200,10 @@ public abstract class AbstractModuleImpl implements ModuleInterface { StringBuilder details = new StringBuilder(); String title = entityTypeName + " (" + entity.createStringKey() + ") " + action; QueueTask task = new QueueTask(user, title, details.toString(), proc); - transaction.getEntityManager().persist(task); - transaction.enqueue(entity.getHiveName(), task); + final EntityManager entityManager = transaction.getEntityManager(); + entityManager.persist(task); + entityManager.refresh(task); + transaction.enqueue(entity.getHiveName(), TaskTransfer.getTransferObject(task)); } public String toString(StackTraceElement[] stackTrace) { diff --git a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java index 4e7f890..2ee331d 100644 --- a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java +++ b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java @@ -6,11 +6,11 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.jms.JMSException; import javax.jms.Queue; +import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; +import javax.jms.QueueSession; import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; import javax.persistence.Query; @@ -19,7 +19,7 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.openjpa.persistence.OpenJPAEntityManager; import de.hsadmin.core.qserv.QueueClient; -import de.hsadmin.core.qserv.QueueTask; +import de.hsadmin.core.qserv.TaskTransfer; import de.hsadmin.core.util.Config; import de.hsadmin.mods.cust.Customer; import de.hsadmin.mods.pac.Pac; @@ -32,24 +32,23 @@ public class Transaction { private String loginName; private Map taskStores; private boolean transactionActive; - private InitialContext ctx; + private Config config; + private String jmsServerUrl; + private String jmsUsername; + private String jmsPassword; public Transaction(String loginName) { + this.config = Config.getInstance(); + this.jmsServerUrl = config.getProperty("hsadmin.jms.url", "tcp://localhost:61616"); + this.jmsUsername = config.getProperty("hsadmin.jms.username", "hsar"); + this.jmsPassword = config.getProperty("hsadmin.jms.password", "default"); this.transactionActive = false; this.entityManager = PersistenceManager.getEntityManager("hsadmin"); this.loginName = loginName; this.taskStores = new HashMap(); - try { - ctx = new InitialContext(); - Context env = (Context) ctx.lookup("java:comp/env"); - queueConnectionFactory = (QueueConnectionFactory) env.lookup("jms/QueueCF"); - if (queueConnectionFactory instanceof ActiveMQConnectionFactory) { - ActiveMQConnectionFactory activeMQconnectionFatory = (ActiveMQConnectionFactory) queueConnectionFactory; - activeMQconnectionFatory.setTrustAllPackages(true); - } - } catch (NamingException e) { - throw new TechnicalException("no jms queue: jms/QueueCF", e); - } + final ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory(jmsServerUrl); + mqConnectionFactory.setTrustAllPackages(true); + this.queueConnectionFactory = mqConnectionFactory; } public EntityManager getEntityManager() { @@ -61,15 +60,14 @@ public class Transaction { } public Queue lookupJMSQueue(String queueName) { - if (ctx != null) { - try { - Context env = (Context) ctx.lookup("java:comp/env"); - return (Queue) env.lookup("jms/" + queueName); - } catch (NamingException e) { - throw new TechnicalException("no jms queue: jms/" + queueName, e); - } + try { + final QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); + final QueueSession session = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); + final Queue queue = session.createQueue(queueName); + return queue; + } catch (JMSException e) { + throw new TechnicalException("no jms queue: jms/" + queueName, e); } - return null; } public String getLoginName() { @@ -79,7 +77,7 @@ public class Transaction { throw new TechnicalException("no login"); } - public void enqueue(String hiveName, QueueTask task) { + public void enqueue(String hiveName, TaskTransfer task) { QueueTaskStore taskStore = taskStores.get(hiveName); if (taskStore == null) { taskStore = new QueueTaskStore(); @@ -96,8 +94,8 @@ public class Transaction { QueueClient qClient = null; try { qClient = new QueueClient(queueConnectionFactory, jmsSystemQueue); - for (QueueTask task : store.getTasks()) { - qClient.send(task); + for (TaskTransfer taskTransfer : store.getTasks()) { + qClient.send(taskTransfer); } } catch (Exception e) { throw new TechnicalException(e); @@ -151,7 +149,7 @@ public class Transaction { } /** - * Detach entities from hibernate session. + * Detach entities from JPA session. * Used to detach entities before update. Makes it possible to compare * old and new attribute values. */ @@ -163,17 +161,17 @@ public class Transaction { } class QueueTaskStore { - private List taskList; + private List taskList; QueueTaskStore() { - taskList = new ArrayList(); + taskList = new ArrayList(); } public void clear() { - taskList = new ArrayList(); + taskList = new ArrayList(); } - void add(QueueTask t) { + void add(TaskTransfer t) { taskList.add(t); } - Iterable getTasks() { + Iterable getTasks() { return taskList; } } diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/AbstractProcessor.java b/qserv/src/main/java/de/hsadmin/core/qserv/AbstractProcessor.java index f88bcc7..693f662 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/AbstractProcessor.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/AbstractProcessor.java @@ -14,4 +14,9 @@ abstract public class AbstractProcessor implements Processor { task.done(); } + @Override + public String toString() { + return "a Processor of class " + this.getClass().getCanonicalName(); + } + } diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/NullProcessor.java b/qserv/src/main/java/de/hsadmin/core/qserv/NullProcessor.java index 6d42f2f..6d741e1 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/NullProcessor.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/NullProcessor.java @@ -3,7 +3,7 @@ package de.hsadmin.core.qserv; public class NullProcessor extends AbstractProcessor { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = -3667951484545665538L; @Override public Object process() throws ProcessorException { diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java index 449faee..ff8ef1a 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java @@ -18,7 +18,7 @@ import de.hsadmin.core.util.Config; * * @author mi */ -public class QueueClient extends QueueCommons { +public class QueueClient { private QueueConnectionFactory jmsConnectionFactory; private Queue jmsSystemQueue; @@ -36,11 +36,11 @@ public class QueueClient extends QueueCommons { String jmsUser = config.getProperty("hsadmin.jms.username", "hsadmin"); String jmsPass = config.getProperty("hsadmin.jms.password", "hsadmin-pw"); jmsConnection = jmsConnectionFactory.createQueueConnection(jmsUser, jmsPass); - jmsSession = jmsConnection.createQueueSession(DEFAULT, Session.AUTO_ACKNOWLEDGE); + jmsSession = jmsConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); jmsSender = jmsSession.createSender(jmsSystemQueue); } - public void send(QueueTask task) throws ProcessorException { + public void send(TaskTransfer task) throws ProcessorException { try { ObjectMessage jmsMessage = jmsSession.createObjectMessage(task); jmsSender.send(jmsMessage); diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueCommons.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueCommons.java deleted file mode 100644 index 41305af..0000000 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueCommons.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.hsadmin.core.qserv; - -public class QueueCommons -{ - protected static final boolean TRANSACTED = true; - protected static final boolean IMMEDIATE = false; - protected static final boolean DEFAULT = IMMEDIATE; - - public QueueCommons() - { - super(); - } - -} \ No newline at end of file diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java index f997a7b..f98596e 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java @@ -1,13 +1,8 @@ package de.hsadmin.core.qserv; -import java.io.File; -import java.io.FileInputStream; -import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; -import javax.jms.Connection; -import javax.jms.Destination; import javax.jms.ExceptionListener; import javax.jms.JMSException; import javax.jms.Message; @@ -16,68 +11,49 @@ import javax.jms.MessageProducer; import javax.jms.ObjectMessage; import javax.jms.Queue; import javax.jms.QueueConnection; -import javax.jms.QueueConnectionFactory; import javax.jms.QueueReceiver; import javax.jms.QueueSession; -import javax.jms.Session; -import javax.naming.Context; -import javax.naming.InitialContext; import org.apache.activemq.ActiveMQConnectionFactory; -public class QueueServer extends QueueCommons implements MessageListener, ExceptionListener { +import de.hsadmin.core.util.Config; + +public class QueueServer implements MessageListener, ExceptionListener { - private static final String VERSION_NO = "4.0.11"; + private static final String VERSION_NO = "4.0.16"; private Logger logger; - private QueueConnection conn; - private QueueSession queueSession; - private String jmsStatusQueue; - private String jmsPassWord; - private String jmsUserName; + + private String jmsUrl; + private String jmsUsername; + private String jmsPassword; private String jmsSystemQueue; - private String jmsFactory; + private String jmsStatusQueue; private String serviceEMail; private String fromEMail; + private QueueConnection queueConnection; + /** * Runs the QueueServer, using the arguments as ConnectionFactory * and Topic names. */ public static void main(String[] args) throws Exception { - File propFile = new File(System.getProperty("user.dir"), "conf/qserv.properties"); - if (args.length == 1) { - propFile = new File(args[0]); - } else { - if (args.length != 0) { - throw new Exception(userHelp(propFile)); - } - } - FileInputStream propStream = null; - try { - propStream = new FileInputStream(propFile); - } catch (Exception e) { - System.out.println("couldn't read config file " + propFile.getAbsolutePath()); - System.exit(1); - } - Properties props = new Properties(System.getProperties()); - props.load(propStream); - propStream.close(); - System.setProperty("java.util.logging.config.file", props.getProperty("hsadmin.log.config", System.getProperty("user.home") + "/.hsadmin.log.properties")); + final Config config = Config.getInstance(); + System.setProperty("java.util.logging.config.file", config.getProperty("hsadmin.log.config", System.getProperty("user.home") + "/.hsadmin.log.properties")); final QueueServer qServ = new QueueServer(); - qServ.setJmsFactory(props.getProperty("hsadmin.jms.factory")); - qServ.setJmsSystemQueue(props.getProperty("hsadmin.jms.system-queue")); - qServ.setJmsStatusQueue(props.getProperty("hsadmin.jms.status-queue")); - qServ.setJmsUserName(props.getProperty("hsadmin.jms.username")); - qServ.setJmsPassWord(props.getProperty("hsadmin.jms.password")); - qServ.setServiceEMail(props.getProperty("hsadmin.log.email")); - qServ.setFromEMail(props.getProperty("hsadmin.log.from")); + qServ.setJmsURL(config.getProperty("hsadmin.jms.url")); + qServ.setJmsSystemQueue(config.getProperty("hsadmin.jms.system-queue")); + qServ.setJmsStatusQueue(config.getProperty("hsadmin.jms.status-queue")); + qServ.setJmsUserName(config.getProperty("hsadmin.jms.username")); + qServ.setJmsPassWord(config.getProperty("hsadmin.jms.password")); + qServ.setServiceEMail(config.getProperty("hsadmin.log.email")); + qServ.setFromEMail(config.getProperty("hsadmin.log.from")); Logger logger = Logger.getLogger("de.hsadmin.core.qserv"); logger.log(Level.CONFIG, "hsadmin-qserv " + VERSION_NO + " started using:" - + "\nqueue server: " + props.getProperty("hsadmin.jms.factory") - + "\nsystem queue: " + props.getProperty("hsadmin.jms.system-queue") - + "\nstatus queue: " + props.getProperty("hsadmin.jms.status-queue") - + "\nqueue user: " + props.getProperty("hsadmin.jms.username")); + + "\nsystem queue: " + config.getProperty("hsadmin.jms.system-queue") + + "\nstatus queue: " + config.getProperty("hsadmin.jms.status-queue") + + "\nqueue user: " + config.getProperty("hsadmin.jms.username")); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { @@ -92,18 +68,14 @@ public class QueueServer extends QueueCommons implements MessageListener, Except } } - private static String userHelp(File propFile) { - return "Wrong number of arguments.\n" - + "With no arguments '" - + propFile - + "' will be used as config file.\n" - + "Or give a properties file as single argument.\n\n" - + "Example config file:\n\n" - + "hsadmin.jms.factory=QueueCF\n" - + "hsadmin.jms.system-queue=hive-h01\n" - + "hsadmin.jms.status-queue=queue/hsadminStatus\n" - + "hsadmin.jms.username=hive-h01\n" - + "hsadmin.jms.password=geheimeskennwort\n"; + protected void close() { + if (queueConnection != null) { + try { + queueConnection.close(); + } catch (JMSException e) { + logger.log(Level.SEVERE, e.getMessage()); + } + } } public QueueServer() { @@ -127,20 +99,15 @@ public class QueueServer extends QueueCommons implements MessageListener, Except } private boolean connect() { - // create JMS connection and session try { - Context ctx = new InitialContext(); - QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx.lookup(jmsFactory); - if (connectionFactory instanceof ActiveMQConnectionFactory) { - ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) connectionFactory; - activeMQConnectionFactory.setTrustAllPackages(true); - } - conn = connectionFactory.createQueueConnection(jmsUserName, jmsPassWord); - conn.setExceptionListener(this); - queueSession = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - Queue queue = (Queue) ctx.lookup(jmsSystemQueue); - conn.start(); - QueueReceiver receiver = queueSession.createReceiver(queue); + final ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory(jmsUrl); + mqConnectionFactory.setTrustAllPackages(true); + queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); + queueConnection.setExceptionListener(this); + final QueueSession session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); + Queue queue = session.createQueue(jmsSystemQueue); + queueConnection.start(); + final QueueReceiver receiver = session.createReceiver(queue); receiver.setMessageListener(this); return true; } catch (Exception e) { @@ -151,10 +118,10 @@ public class QueueServer extends QueueCommons implements MessageListener, Except public synchronized void onMessage(Message jmsMessage) { logger.log(Level.INFO, jmsMessage.toString()); - QueueTask task = null; + TaskTransfer task = null; try { ObjectMessage jmsObjectMessage = (ObjectMessage) jmsMessage; - task = (QueueTask) jmsObjectMessage.getObject(); + task = (TaskTransfer) jmsObjectMessage.getObject(); Processor processor = task.getProcessor(); logger.log(Level.INFO, "processing (" + task.getTitle() + " | started(" + task.getStarted() + ") |" + task.getDetails() + "|" @@ -164,12 +131,12 @@ public class QueueServer extends QueueCommons implements MessageListener, Except logger.log(Level.INFO, "done"); } catch (ProcessorException e) { logException(e); - task.setException(e); + task.setException(e.getMessage()); SmtpHelper.send(fromEMail, serviceEMail, jmsSystemQueue, processor.logInfo()); } } catch (Throwable throwable) { logException(throwable); - task.setException(throwable); + task.setException(throwable.getMessage()); } finally { sendStatus(task); notifyAll(); @@ -187,7 +154,6 @@ public class QueueServer extends QueueCommons implements MessageListener, Except @Override public void onException(JMSException e) { logger.log(Level.WARNING, e.getMessage(), e); - close(); while (!connect()) { try { Thread.sleep(10000); @@ -195,67 +161,44 @@ public class QueueServer extends QueueCommons implements MessageListener, Except } } - public void close() { - if (queueSession != null) { - try { - queueSession.close(); - } catch (JMSException e1) { } - } - if (conn != null) { - try { - conn.close(); - } catch (JMSException e1) { } - } - } - - protected void sendStatus(QueueTask queueMessage) { + protected void sendStatus(TaskTransfer queueMessage) { + final ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory(jmsUrl); + mqConnectionFactory.setTrustAllPackages(true); MessageProducer producer = null; - Session statusSession = null; - Connection statusConnection = null; - try { - logger.log(Level.INFO, "sendStatus(" + queueMessage + ")"); - Context ctx = new InitialContext(); - QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx.lookup(jmsFactory); - if (connectionFactory instanceof ActiveMQConnectionFactory) { - ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) connectionFactory; - activeMQConnectionFactory.setTrustAllPackages(true); - } - Destination queue = (Destination) ctx.lookup(jmsStatusQueue); - statusConnection = connectionFactory.createConnection(jmsUserName, jmsPassWord); - statusSession = statusConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); - producer = statusSession.createProducer(queue); - ObjectMessage statusMessage = statusSession.createObjectMessage(queueMessage); + QueueSession session = null; + try (QueueConnection queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword)) { + queueConnection.setExceptionListener(this); + session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); + final Queue queue = session.createQueue(jmsStatusQueue); + queueConnection.start(); + producer = session.createProducer(queue); + final ObjectMessage statusMessage = session.createObjectMessage(queueMessage); logger.log(Level.INFO, "send(" + statusMessage + ")"); producer.send(statusMessage); } catch (Exception statusException) { logger.log(Level.SEVERE, statusException.getMessage(), statusException); - } finally { - // close JMS - try { producer.close(); } catch (Exception exc) { } - try { statusSession.close(); } catch (Exception exc) { } - try { statusConnection.close(); } catch (Exception exc) { } } } - public void setJmsStatusQueue(String property) { - jmsStatusQueue = property; + private void setJmsURL(String property) { + jmsUrl = property; } public void setJmsPassWord(String property) { - jmsPassWord = property; + jmsPassword = property; } public void setJmsUserName(String property) { - jmsUserName = property; + jmsUsername = property; } public void setJmsSystemQueue(String property) { jmsSystemQueue = property; } - public void setJmsFactory(String property) { - jmsFactory = property; + public void setJmsStatusQueue(String property) { + jmsStatusQueue = property; } } diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueTask.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueTask.java index 6ef6086..d6c2387 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueTask.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueTask.java @@ -223,14 +223,13 @@ public class QueueTask extends AbstractEntity implements Serializable { * assigns all data field of qt to this instance, with * the exception of the id */ - public void assign(QueueTask qt) { - this.user = qt.user; - this.title = qt.title; - this.details = qt.details; - this.started = qt.started; - this.finished = qt.finished; - this.proc = qt.proc; - this.exception = qt.exception; + public void assign(TaskTransfer qt) { + this.title = qt.getTitle(); + this.details = qt.getDetails(); + this.started = qt.getStarted(); + this.finished = qt.getFinished(); + this.proc = qt.getProcessor(); + this.exception = qt.getException(); } @Override diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/ShellProcessor.java b/qserv/src/main/java/de/hsadmin/core/qserv/ShellProcessor.java index df545e0..6360cec 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/ShellProcessor.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/ShellProcessor.java @@ -8,8 +8,8 @@ package de.hsadmin.core.qserv; */ public class ShellProcessor extends AbstractProcessor { - private static final long serialVersionUID = 1L; - + private static final long serialVersionUID = -8340381162948081669L; + private String aSystemCall; private String aInput; private String aOutput; diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/TaskTransfer.java b/qserv/src/main/java/de/hsadmin/core/qserv/TaskTransfer.java new file mode 100644 index 0000000..b6a383f --- /dev/null +++ b/qserv/src/main/java/de/hsadmin/core/qserv/TaskTransfer.java @@ -0,0 +1,130 @@ +package de.hsadmin.core.qserv; + +import java.io.Serializable; +import java.util.Date; + +import de.hsadmin.mods.user.UnixUser; + +public class TaskTransfer implements Serializable { + + private static final long serialVersionUID = -2120247737335542484L; + + private long id; + private String unixuser; + private Date started; + private Date finished; + private String title; + private String details; + private Processor proc; + private String exception; + + public TaskTransfer() { + id = 0L; + unixuser = "anonymous"; + started = new Date(); + finished = null; + title = "untitled"; + details = "none"; + setProcessor(new NullProcessor()); + setException(""); + } + + public TaskTransfer(long id, String unixuser, Date started, Date finished, String title, String details, Processor proc, String exception) { + this.id = id; + this.unixuser = unixuser; + this.started = started; + this.finished = finished; + this.title = title; + this.details = details; + this.setProcessor(proc); + this.setException(exception); + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getUnixuser() { + return unixuser; + } + + public void setUnixuser(String unixuser) { + this.unixuser = unixuser; + } + + public Date getStarted() { + return started; + } + + public void setStarted(Date started) { + this.started = started; + } + + public Date getFinished() { + return finished; + } + + public void setFinished(Date finished) { + this.finished = finished; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } + + public Processor getProcessor() { + return proc; + } + + public void setProcessor(Processor proc) { + this.proc = proc; + } + + public String getException() { + return exception; + } + + public void setException(String exception) { + this.exception = exception; + } + + @Override + public String toString() { + return Long.toString(id) + "|" + title + "|" + started.toString(); + } + + public static TaskTransfer getTransferObject(QueueTask task) { + long id = task.getId(); + final UnixUser user = task.getUser(); + String username = "anonymous"; + if (user == null) { + username = "anonymous"; + } else { + username = user.getName(); + } + Date started = task.getStarted(); + Date finished = task.getFinished(); + String title = task.getTitle(); + String details = task.getDetails(); + Processor proc = task.getProcessor(); + String exception = task.getException(); + return new TaskTransfer(id, username, started, finished, title, details, proc, exception); + } + +} diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/WaitingTasksProcessor.java b/qserv/src/main/java/de/hsadmin/core/qserv/WaitingTasksProcessor.java index 54b6539..01ec018 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/WaitingTasksProcessor.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/WaitingTasksProcessor.java @@ -4,6 +4,8 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import javax.persistence.EntityManager; + import de.hsadmin.core.model.Transaction; public class WaitingTasksProcessor extends AbstractProcessor { @@ -29,8 +31,10 @@ public class WaitingTasksProcessor extends AbstractProcessor { for (WaitingProcessor p : waitingTasks) { QueueTask wTask = new QueueTask(task.getUser(), task.getTitle() + " / " + p.getTitle(), task.getTitle() + " / " + p.getTitle(), p.getProc()); - transaction.getEntityManager().persist(wTask); - transaction.enqueue(p.getHost(), wTask); + final EntityManager entityManager = transaction.getEntityManager(); + entityManager.persist(wTask); + entityManager.refresh(wTask); + transaction.enqueue(p.getHost(), TaskTransfer.getTransferObject(wTask)); } } super.finalize(transaction, task); diff --git a/util/pom.xml b/util/pom.xml index 9a3de76..5539f63 100644 --- a/util/pom.xml +++ b/util/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin.core hsadmin-util - 4.0.15 + 4.0.16 UTF-8 11 From 9d09d43f3dfd44279735838d8179f583b3b0ea82 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 14 Aug 2023 20:25:36 +0200 Subject: [PATCH 02/16] some cleaning --- hsarback/pom.xml | 19 +--------- .../PersistenceManagerContextListener.java | 25 ------------- .../META-INF/persistence-with-sql-logging.xml | 36 ------------------- hsarback/src/main/webapp/WEB-INF/web.xml | 4 --- 4 files changed, 1 insertion(+), 83 deletions(-) delete mode 100644 hsarback/src/main/java/de/hsadmin/servlets/PersistenceManagerContextListener.java delete mode 100644 hsarback/src/main/webapp/META-INF/persistence-with-sql-logging.xml diff --git a/hsarback/pom.xml b/hsarback/pom.xml index 739d21f..1d17e87 100644 --- a/hsarback/pom.xml +++ b/hsarback/pom.xml @@ -13,25 +13,8 @@ UTF-8 11 11 + true - - - local - - true - - - - - src/main/resources - - - src/main/local-resources - - - - - de.hsadmin.core diff --git a/hsarback/src/main/java/de/hsadmin/servlets/PersistenceManagerContextListener.java b/hsarback/src/main/java/de/hsadmin/servlets/PersistenceManagerContextListener.java deleted file mode 100644 index 7807196..0000000 --- a/hsarback/src/main/java/de/hsadmin/servlets/PersistenceManagerContextListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.hsadmin.servlets; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import de.hsadmin.core.model.PersistenceManager; - -public class PersistenceManagerContextListener implements ServletContextListener { - - public PersistenceManagerContextListener() { - } - - @Override - public void contextDestroyed(ServletContextEvent contextEvent) { - System.out.println("PersistenceManager.contextDestroyed()"); - PersistenceManager.close(); - } - - @Override - public void contextInitialized(ServletContextEvent contextEvent) { - // do nothing - } - - -} diff --git a/hsarback/src/main/webapp/META-INF/persistence-with-sql-logging.xml b/hsarback/src/main/webapp/META-INF/persistence-with-sql-logging.xml deleted file mode 100644 index cbbe3f5..0000000 --- a/hsarback/src/main/webapp/META-INF/persistence-with-sql-logging.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - org.apache.openjpa.persistence.PersistenceProviderImpl - java:/comp/env/jdbc/HSAdminDB - de.hsadmin.core.qserv.QueueTask - de.hsadmin.mods.cust.Customer - de.hsadmin.mods.cust.Contact - de.hsadmin.mods.pac.Pac - de.hsadmin.mods.pac.BasePac - de.hsadmin.mods.pac.BaseComponent - de.hsadmin.mods.pac.Component - de.hsadmin.mods.pac.PacComponent - de.hsadmin.mods.pac.Hive - de.hsadmin.mods.pac.INetAddress - de.hsadmin.mods.user.UnixUser - de.hsadmin.mods.dom.Domain - de.hsadmin.mods.dom.DomainOption - de.hsadmin.mods.email.EMailAddress - de.hsadmin.mods.email.EMailAlias - de.hsadmin.mods.db.DatabaseUser - de.hsadmin.mods.db.MySqlUser - de.hsadmin.mods.db.PgSqlUser - de.hsadmin.mods.db.Database - de.hsadmin.mods.db.MySqlDatabase - de.hsadmin.mods.db.PgSqlDatabase - - - - - - - - - - diff --git a/hsarback/src/main/webapp/WEB-INF/web.xml b/hsarback/src/main/webapp/WEB-INF/web.xml index 1c2f6f3..e48ee29 100644 --- a/hsarback/src/main/webapp/WEB-INF/web.xml +++ b/hsarback/src/main/webapp/WEB-INF/web.xml @@ -4,10 +4,6 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> - - de.hsadmin.servlets.PersistenceManagerContextListener - - Queue Status Servlet de.hsadmin.servlets.QueueStatusReceiverServlet From 87efe77c787b487393bfb95fc75b3d4da87925e2 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 14 Aug 2023 20:41:24 +0200 Subject: [PATCH 03/16] revert activemq to v5.17.x --- qserv/pom.xml | 11 ++--------- .../main/java/de/hsadmin/core/qserv/QueueServer.java | 8 +++++++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/qserv/pom.xml b/qserv/pom.xml index 785d36d..d756d7f 100644 --- a/qserv/pom.xml +++ b/qserv/pom.xml @@ -43,15 +43,8 @@ org.apache.activemq - activemq-all - 5.18.1 - provided - - - org.apache.geronimo.specs - geronimo-jms_1.1_spec - 1.1.1 - provided + activemq-client + 5.17.5 diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java index f98596e..34660d4 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java @@ -164,9 +164,11 @@ public class QueueServer implements MessageListener, ExceptionListener { protected void sendStatus(TaskTransfer queueMessage) { final ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory(jmsUrl); mqConnectionFactory.setTrustAllPackages(true); + QueueConnection queueConnection = null; MessageProducer producer = null; QueueSession session = null; - try (QueueConnection queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword)) { + try { + queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); queueConnection.setExceptionListener(this); session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); final Queue queue = session.createQueue(jmsStatusQueue); @@ -177,6 +179,10 @@ public class QueueServer implements MessageListener, ExceptionListener { producer.send(statusMessage); } catch (Exception statusException) { logger.log(Level.SEVERE, statusException.getMessage(), statusException); + } finally { + if (producer != null) try { producer.close(); } catch (Exception e) { } + if (session != null) try { session.close(); } catch (Exception e) { } + if (queueConnection != null) try { queueConnection.close(); } catch (Exception e) { } } } From 6e39b2e883f46a1c93c26f371fe3ddae89fded9d Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 15 Aug 2023 20:09:02 +0200 Subject: [PATCH 04/16] refactoring logging, config, error handling --- .../core/model/PersistenceManager.java | 13 ++++-- .../de/hsadmin/core/model/Transaction.java | 10 ++--- .../de/hsadmin/core/qserv/JDBCProcessor.java | 4 +- .../de/hsadmin/core/qserv/QueueServer.java | 45 +++++++++++-------- .../de/hsadmin/core/qserv/SmtpHelper.java | 17 ++++--- .../java/de/hsadmin/core/util/Config.java | 36 ++++++++++++--- 6 files changed, 81 insertions(+), 44 deletions(-) diff --git a/qserv/src/main/java/de/hsadmin/core/model/PersistenceManager.java b/qserv/src/main/java/de/hsadmin/core/model/PersistenceManager.java index ae102dc..928488a 100644 --- a/qserv/src/main/java/de/hsadmin/core/model/PersistenceManager.java +++ b/qserv/src/main/java/de/hsadmin/core/model/PersistenceManager.java @@ -1,5 +1,7 @@ package de.hsadmin.core.model; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.HashMap; import java.util.Map; @@ -13,6 +15,8 @@ public class PersistenceManager { private Map persistenceUnits; + private Logger logger; + public static EntityManager getEntityManager(String persistUnitName) { EntityManagerFactory emf = PersistenceManager.getInstance().getEMF(persistUnitName); return emf.createEntityManager(); @@ -31,6 +35,7 @@ public class PersistenceManager { if (emf == null) { emf = Persistence.createEntityManagerFactory(persistUnitName); persistenceUnits.put(persistUnitName, emf); + logger.log(Level.INFO, "Create Persistence Unit: " + persistUnitName); } return emf; } @@ -43,11 +48,11 @@ public class PersistenceManager { } private void closeFactories() { - for (String puName : persistenceUnits.keySet()) { - System.out.println("Persistence Unit: " + puName); - EntityManagerFactory emf = persistenceUnits.get(puName); + for (String persistUnitName : persistenceUnits.keySet()) { + logger.log(Level.INFO, "Close Persistence Unit: " + persistUnitName); + EntityManagerFactory emf = persistenceUnits.get(persistUnitName); emf.close(); - persistenceUnits.remove(puName); + persistenceUnits.remove(persistUnitName); } } } diff --git a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java index 2ee331d..9930ac9 100644 --- a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java +++ b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java @@ -89,7 +89,7 @@ public class Transaction { private void sendAll() { for (String hive : taskStores.keySet()) { QueueTaskStore store = taskStores.get(hive); - String queueName = "hsadminSystem-" + hive; + String queueName = "queue.hsadminSystem-" + hive; Queue jmsSystemQueue = lookupJMSQueue(queueName); QueueClient qClient = null; try { @@ -179,10 +179,10 @@ public class Transaction { public UnixUser getLoginUser() { String loginName = getLoginName(); if (loginName != null && loginName.length() == 2) { - loginName = Config.getInstance().getProperty("accountprefix.hostmaster", "hsh01") + "-" + loginName; + loginName = config.getProperty("accountprefix.hostmaster", "hsh01") + "-" + loginName; } if (loginName != null && loginName.length() == 3) { - loginName = Config.getInstance().getProperty("accountprefix.customer", "hsh00") + "-" + loginName; + loginName = config.getProperty("accountprefix.customer", "hsh00") + "-" + loginName; } Query userQuery = getEntityManager().createQuery("SELECT u FROM UnixUsers u WHERE u.name = :username"); userQuery.setParameter("username", loginName); @@ -198,7 +198,7 @@ public class Transaction { if (ticketUser != null && ticketUser.length() == 2) { return true; // 2-letter hostmaster } - String hostmasterAccountPrefix = Config.getInstance().getProperty("accountprefix.hostmaster", "hsh01") + "-"; + String hostmasterAccountPrefix = config.getProperty("accountprefix.hostmaster", "hsh01") + "-"; if (ticketUser != null && ticketUser.startsWith(hostmasterAccountPrefix) && ticketUser.length() == 8) { return true; // hsh01 hostmaster } @@ -209,7 +209,7 @@ public class Transaction { String pacName = unixUser.getPac().getName(); return ticketUser.equals(pacName); // pac-admin } - String memberAccountPrefix = Config.getInstance().getProperty("accountprefix.customer", "hsh00") + "-"; + String memberAccountPrefix = config.getProperty("accountprefix.customer", "hsh00") + "-"; if (ticketUser != null && (ticketUser.length() == 3 || (ticketUser.length() >= 9 && ticketUser.startsWith(memberAccountPrefix)))) { Query memberQuery = getEntityManager().createQuery("SELECT c FROM Customers c WHERE c.name = :membername"); memberQuery.setParameter("membername", ticketUser.length() == 3 ? (memberAccountPrefix + ticketUser) : ticketUser); diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/JDBCProcessor.java b/qserv/src/main/java/de/hsadmin/core/qserv/JDBCProcessor.java index 2827562..49b3c64 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/JDBCProcessor.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/JDBCProcessor.java @@ -57,7 +57,7 @@ public class JDBCProcessor extends AbstractProcessor { throw new ProcessorException("cannot connect to '" + url + "'"); Statement s = c.createStatement(); for (String sqlStatement : sql) { - System.out.println("SQL: " + sqlStatement); + LOG.fine("SQL: " + sqlStatement); s.execute(sqlStatement); } return 0; @@ -67,7 +67,7 @@ public class JDBCProcessor extends AbstractProcessor { exc = aSqlExc; } errorMsg = exc.getMessage(); - System.out.println("ERR: " + errorMsg); + LOG.severe("ERR: " + errorMsg); throw new ProcessorException(aSqlExc.getMessage() + ", reason: " + errorMsg); } catch (Exception aExc) { throw new ProcessorException(aExc.getMessage()); diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java index 34660d4..3ea0f60 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java @@ -33,6 +33,8 @@ public class QueueServer implements MessageListener, ExceptionListener { private String fromEMail; private QueueConnection queueConnection; + private boolean isConnected; + /** * Runs the QueueServer, using the arguments as ConnectionFactory @@ -60,11 +62,11 @@ public class QueueServer implements MessageListener, ExceptionListener { qServ.close(); } }); - while (!qServ.connect()) { - Thread.sleep(30000); - } while (true) { - Thread.sleep(10000); + if (!qServ.isConnected()) { + qServ.connect(); + } + Thread.sleep(30000); } } @@ -80,6 +82,12 @@ public class QueueServer implements MessageListener, ExceptionListener { public QueueServer() { logger = Logger.getLogger("de.hsadmin.core.qserv"); + queueConnection = null; + isConnected = false; + } + + private boolean isConnected() { + return isConnected; } private void setServiceEMail(String emailAddress) { @@ -97,26 +105,27 @@ public class QueueServer implements MessageListener, ExceptionListener { fromEMail = emailAddress; } } - - private boolean connect() { + + private void connect() { try { final ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory(jmsUrl); mqConnectionFactory.setTrustAllPackages(true); queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); queueConnection.setExceptionListener(this); final QueueSession session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); - Queue queue = session.createQueue(jmsSystemQueue); - queueConnection.start(); + Queue queue = session.createQueue(jmsSystemQueue); + queueConnection.start(); final QueueReceiver receiver = session.createReceiver(queue); - receiver.setMessageListener(this); - return true; + receiver.setMessageListener(this); + isConnected = true; } catch (Exception e) { logger.log(Level.WARNING, e.getMessage(), e); - return false; + isConnected = false; } } - public synchronized void onMessage(Message jmsMessage) { + public synchronized void onMessage(final Message jmsMessage) { + assert jmsMessage != null; logger.log(Level.INFO, jmsMessage.toString()); TaskTransfer task = null; try { @@ -138,6 +147,7 @@ public class QueueServer implements MessageListener, ExceptionListener { logException(throwable); task.setException(throwable.getMessage()); } finally { + try { jmsMessage.acknowledge(); } catch (JMSException e) { } sendStatus(task); notifyAll(); } @@ -154,11 +164,8 @@ public class QueueServer implements MessageListener, ExceptionListener { @Override public void onException(JMSException e) { logger.log(Level.WARNING, e.getMessage(), e); - while (!connect()) { - try { - Thread.sleep(10000); - } catch (InterruptedException e1) { } - } + close(); + isConnected = false; } protected void sendStatus(TaskTransfer queueMessage) { @@ -170,7 +177,7 @@ public class QueueServer implements MessageListener, ExceptionListener { try { queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); queueConnection.setExceptionListener(this); - session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); + session = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); final Queue queue = session.createQueue(jmsStatusQueue); queueConnection.start(); producer = session.createProducer(queue); @@ -182,7 +189,7 @@ public class QueueServer implements MessageListener, ExceptionListener { } finally { if (producer != null) try { producer.close(); } catch (Exception e) { } if (session != null) try { session.close(); } catch (Exception e) { } - if (queueConnection != null) try { queueConnection.close(); } catch (Exception e) { } +// if (queueConnection != null) try { queueConnection.close(); } catch (Exception e) { } } } diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/SmtpHelper.java b/qserv/src/main/java/de/hsadmin/core/qserv/SmtpHelper.java index 94b40b6..2d0f66a 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/SmtpHelper.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/SmtpHelper.java @@ -6,6 +6,7 @@ import java.io.Writer; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; +import java.util.logging.Logger; import org.apache.commons.net.smtp.SMTPClient; import org.apache.commons.net.smtp.SMTPReply; @@ -16,6 +17,8 @@ import de.hsadmin.core.util.HSAdminException; public class SmtpHelper { + private static final Logger LOG = Logger.getLogger(SmtpHelper.class.getName()); + public static void send(String fromAddress, String toAddress, String subject, String text) throws HSAdminException { send(fromAddress, toAddress, null, subject, text); @@ -24,9 +27,10 @@ public class SmtpHelper { public static void send(String fromAddress, String toAddress, String ccAddress, String subject, String text) throws HSAdminException { try { - SMTPClient client = new SMTPClient(); + final SMTPClient client = new SMTPClient(); String canonicalHostName = InetAddress.getLocalHost().getCanonicalHostName(); - String smtpHost = Config.getInstance().getProperty("smtp.host"); + final Config config = Config.getInstance(); + String smtpHost = config.getProperty("smtp.host"); if (smtpHost == null || smtpHost.trim().isEmpty()) { smtpHost = "localhost"; } @@ -34,11 +38,10 @@ public class SmtpHelper { if (subject.toLowerCase().contains("error")) { throw new HSAdminException("Konnte Mail nicht senden"); } - System.out.println("------------------------"); - System.out.println("From: " + fromAddress); - System.out.println("To: " + toAddress); - System.out.println("Subject: " + subject); - System.out.println("\n" + text); + LOG.finer("From: " + fromAddress); + LOG.finer("To: " + toAddress); + LOG.finer("Subject: " + subject); + LOG.finer(text); return; } client.connect(smtpHost, 25); diff --git a/util/src/main/java/de/hsadmin/core/util/Config.java b/util/src/main/java/de/hsadmin/core/util/Config.java index 30e58bf..efe4328 100644 --- a/util/src/main/java/de/hsadmin/core/util/Config.java +++ b/util/src/main/java/de/hsadmin/core/util/Config.java @@ -11,31 +11,46 @@ public class Config { private static Logger LOG = Logger.getLogger(Config.class.getName()); - private Properties props; + private static final String userDir = System.getProperty("user.dir"); + private static final String userHome = System.getProperty("user.home"); + + private final Properties props; private Config() { props = new Properties(); - File file = new File(System.getProperty("user.dir") + "/hsadmin.properties"); + final String baseName = "hsadmin"; + initPropertiesFromFile(baseName); + } + + private Config(String baseName) { + props = new Properties(); + initPropertiesFromFile(baseName); + } + + private void initPropertiesFromFile(final String baseName) { + File file = new File(userDir + "/" + baseName + ".properties"); if (!file.canRead()) { - file = new File(System.getProperty("user.dir") + "/conf/hsadmin.properties"); + file = new File(userDir + "/conf/" + baseName + ".properties"); } if (!file.canRead()) { - file = new File(System.getProperty("user.home") + "/.hsadmin.properties"); + file = new File(userHome + "/." + baseName + ".properties"); } if (!file.canRead()) { - file = new File("/etc/hsadmin/hsadmin.properties"); + file = new File("/etc/hsadmin/" + baseName + ".properties"); } if (!file.canRead()) { - file = new File("/etc/hsadmin.properties"); + file = new File("/etc/" + baseName + ".properties"); } if (file.canRead()) { try { LOG.info("Constructor - Properties-File: " + file.getAbsolutePath()); props.load(new FileReader(file)); } catch (Exception e) { - // should not happen + LOG.severe("reading properties failed: " + e.getMessage()); e.printStackTrace(); } + } else { + LOG.severe("reading properties failed: No properties file found"); } } @@ -46,6 +61,13 @@ public class Config { return instance; } + public static Config getInstance(String baseName) { + if (instance == null) { + instance = new Config(baseName); + } + return instance; + } + public String getProperty(String propertyName) { String property = props.getProperty(propertyName); return property; From 35862c1c06ca5699eba20ac8ab7a11d1801846db Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 5 Sep 2023 12:12:13 +0200 Subject: [PATCH 05/16] null handling --- .../servlets/QueueStatusReceiverServlet.java | 10 ++- qserv-test/.classpath | 27 +++++++ qserv-test/.gitignore | 1 + qserv-test/.project | 23 ++++++ .../org.eclipse.core.resources.prefs | 3 + .../.settings/org.eclipse.jdt.core.prefs | 8 +++ .../.settings/org.eclipse.m2e.core.prefs | 4 ++ qserv-test/pom.xml | 68 ++++++++++++++++++ .../main/java/de/hsadmin/qserv/test/Pull.java | 71 +++++++++++++++++++ .../main/java/de/hsadmin/qserv/test/Push.java | 37 ++++++++++ .../de/hsadmin/core/model/Transaction.java | 4 +- 11 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 qserv-test/.classpath create mode 100644 qserv-test/.gitignore create mode 100644 qserv-test/.project create mode 100644 qserv-test/.settings/org.eclipse.core.resources.prefs create mode 100644 qserv-test/.settings/org.eclipse.jdt.core.prefs create mode 100644 qserv-test/.settings/org.eclipse.m2e.core.prefs create mode 100644 qserv-test/pom.xml create mode 100644 qserv-test/src/main/java/de/hsadmin/qserv/test/Pull.java create mode 100644 qserv-test/src/main/java/de/hsadmin/qserv/test/Push.java diff --git a/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java b/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java index 91395f1..9cd33bb 100644 --- a/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java +++ b/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java @@ -112,6 +112,7 @@ public class QueueStatusReceiverServlet extends HttpServlet @Override public void onMessage(Message jmsMessage) { + assert jmsMessage != null; Transaction transaction = null; messageCount++; try { @@ -123,7 +124,13 @@ public class QueueStatusReceiverServlet extends HttpServlet transaction.beginTransaction(); EntityManager em = transaction.getEntityManager(); em.clear(); - QueueTask persistentQT = em.find(QueueTask.class, detachedQT.getId()); + final long queueTaskId = detachedQT.getId(); + QueueTask persistentQT = em.find(QueueTask.class, queueTaskId); + if (persistentQT == null) { + jmsMessage.acknowledge(); + errorCount++; + throw new TechnicalException("QueueTask not found, id: " + queueTaskId); + } persistentQT.assign(detachedQT); Processor processor = persistentQT.getProcessor(); if (processor != null) { @@ -133,6 +140,7 @@ public class QueueStatusReceiverServlet extends HttpServlet em.flush(); transaction.commitTransaction(); } else { + errorCount++; final String err = "Deserialization failed " + new Date(); System.out.println(err); throw new TechnicalException(err); diff --git a/qserv-test/.classpath b/qserv-test/.classpath new file mode 100644 index 0000000..4559ca0 --- /dev/null +++ b/qserv-test/.classpath @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/qserv-test/.gitignore b/qserv-test/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/qserv-test/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/qserv-test/.project b/qserv-test/.project new file mode 100644 index 0000000..d1d24d6 --- /dev/null +++ b/qserv-test/.project @@ -0,0 +1,23 @@ + + + hsadmin-qserv-test + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/qserv-test/.settings/org.eclipse.core.resources.prefs b/qserv-test/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..e9441bb --- /dev/null +++ b/qserv-test/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding/=UTF-8 diff --git a/qserv-test/.settings/org.eclipse.jdt.core.prefs b/qserv-test/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2af1e7b --- /dev/null +++ b/qserv-test/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/qserv-test/.settings/org.eclipse.m2e.core.prefs b/qserv-test/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/qserv-test/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/qserv-test/pom.xml b/qserv-test/pom.xml new file mode 100644 index 0000000..cd1c9d3 --- /dev/null +++ b/qserv-test/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + de.hsadmin.core + hsadmin-qserv-test + 4.0.16 + + UTF-8 + 11 + + + + de.hsadmin.core + hsadmin-util + 4.0.16 + + + de.hsadmin.core + hsadmin-qserv + 4.0.16 + + + commons-lang + commons-lang + 2.6 + + + commons-net + commons-net + 3.9.0 + + + org.apache.velocity + velocity-engine-core + 2.3 + + + org.apache.openjpa + openjpa + 3.2.2 + + + org.apache.activemq + activemq-client + 5.17.5 + + + junit + junit + 4.13.2 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 11 + 11 + + + + + diff --git a/qserv-test/src/main/java/de/hsadmin/qserv/test/Pull.java b/qserv-test/src/main/java/de/hsadmin/qserv/test/Pull.java new file mode 100644 index 0000000..7dbd06f --- /dev/null +++ b/qserv-test/src/main/java/de/hsadmin/qserv/test/Pull.java @@ -0,0 +1,71 @@ +package de.hsadmin.qserv.test; + +import java.io.Serializable; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.ObjectMessage; +import javax.jms.Queue; +import javax.jms.QueueConnection; +import javax.jms.QueueReceiver; +import javax.jms.QueueSession; + +import org.apache.activemq.ActiveMQConnectionFactory; + +import de.hsadmin.core.qserv.ProcessorException; +import de.hsadmin.core.qserv.TaskTransfer; + +public class Pull implements MessageListener { + + public static void main(String[] args) { + ActiveMQConnectionFactory cxFact = new ActiveMQConnectionFactory("ssl://hsh02.hostsharing.net:61619"); + try { +// QueueConnection qCx = cxFact.createQueueConnection("hsar", ""); + QueueConnection queueConnect = cxFact.createQueueConnection("user-h98", ""); + QueueSession session = queueConnect.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); + Queue queue = session.createQueue("queue.hsadminSystem-h98"); + QueueReceiver receiver = session.createReceiver(queue); + receiver.setMessageListener(new Pull()); + queueConnect.start(); + boolean doContinue = true; + while (doContinue) { + try { + Thread.sleep(2000L); + } catch (InterruptedException e) { + doContinue = false; + } + } + queueConnect.stop(); + session.close(); + queueConnect.close(); + } catch (JMSException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + public void onMessage(Message message) { + if (message instanceof ObjectMessage) { + try { + ObjectMessage objMesg = (ObjectMessage) message; + Serializable serializable = objMesg.getObject(); + if (serializable instanceof TaskTransfer) { + TaskTransfer task = (TaskTransfer) serializable; + task.getProcessor().process(); + } + } catch (ProcessorException | JMSException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + try { + message.acknowledge(); + } catch (JMSException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/qserv-test/src/main/java/de/hsadmin/qserv/test/Push.java b/qserv-test/src/main/java/de/hsadmin/qserv/test/Push.java new file mode 100644 index 0000000..6e07e71 --- /dev/null +++ b/qserv-test/src/main/java/de/hsadmin/qserv/test/Push.java @@ -0,0 +1,37 @@ +package de.hsadmin.qserv.test; + +import java.util.Date; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.QueueConnection; +import javax.jms.QueueSession; + +import org.apache.activemq.ActiveMQConnectionFactory; + +import de.hsadmin.core.qserv.NullProcessor; +import de.hsadmin.core.qserv.TaskTransfer; + +public class Push { + + public static void main(String[] args) { + ActiveMQConnectionFactory cxFact = new ActiveMQConnectionFactory("ssl://hsh02.hostsharing.net:61619"); + try { +// QueueConnection qCx = cxFact.createQueueConnection("user-h98", ""); + QueueConnection qCx = cxFact.createQueueConnection("hsar", "Eix4Baijee2ae1aighetaik8"); + QueueSession session = qCx.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); + Queue queue = session.createQueue("queue.hsadminSystem-h98"); + MessageProducer producer = session.createProducer(queue); + Message message = session.createObjectMessage(new TaskTransfer(1L, "anonymous", new Date(), null, "hello world", "hello world detail", new NullProcessor(), null)); + producer.send(queue, message); + session.close(); + qCx.close(); + } catch (JMSException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java index 9930ac9..4685a49 100644 --- a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java +++ b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java @@ -145,7 +145,9 @@ public class Transaction { if (transactionActive) { rollbackTransaction(); } - entityManager.close(); + if (entityManager != null) { + entityManager.close(); + } } /** From 0b3385a3e00a3205e8797e17ab465b0c5fb76707 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 5 Sep 2023 12:12:57 +0200 Subject: [PATCH 06/16] null handling --- qserv-test/.classpath | 27 ------- qserv-test/.gitignore | 1 - qserv-test/.project | 23 ------ .../org.eclipse.core.resources.prefs | 3 - .../.settings/org.eclipse.jdt.core.prefs | 8 --- .../.settings/org.eclipse.m2e.core.prefs | 4 -- qserv-test/pom.xml | 68 ------------------ .../main/java/de/hsadmin/qserv/test/Pull.java | 71 ------------------- .../main/java/de/hsadmin/qserv/test/Push.java | 37 ---------- 9 files changed, 242 deletions(-) delete mode 100644 qserv-test/.classpath delete mode 100644 qserv-test/.gitignore delete mode 100644 qserv-test/.project delete mode 100644 qserv-test/.settings/org.eclipse.core.resources.prefs delete mode 100644 qserv-test/.settings/org.eclipse.jdt.core.prefs delete mode 100644 qserv-test/.settings/org.eclipse.m2e.core.prefs delete mode 100644 qserv-test/pom.xml delete mode 100644 qserv-test/src/main/java/de/hsadmin/qserv/test/Pull.java delete mode 100644 qserv-test/src/main/java/de/hsadmin/qserv/test/Push.java diff --git a/qserv-test/.classpath b/qserv-test/.classpath deleted file mode 100644 index 4559ca0..0000000 --- a/qserv-test/.classpath +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qserv-test/.gitignore b/qserv-test/.gitignore deleted file mode 100644 index b83d222..0000000 --- a/qserv-test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target/ diff --git a/qserv-test/.project b/qserv-test/.project deleted file mode 100644 index d1d24d6..0000000 --- a/qserv-test/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - hsadmin-qserv-test - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/qserv-test/.settings/org.eclipse.core.resources.prefs b/qserv-test/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index e9441bb..0000000 --- a/qserv-test/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 -encoding/=UTF-8 diff --git a/qserv-test/.settings/org.eclipse.jdt.core.prefs b/qserv-test/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 2af1e7b..0000000 --- a/qserv-test/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 -org.eclipse.jdt.core.compiler.compliance=11 -org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore -org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=11 diff --git a/qserv-test/.settings/org.eclipse.m2e.core.prefs b/qserv-test/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f..0000000 --- a/qserv-test/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/qserv-test/pom.xml b/qserv-test/pom.xml deleted file mode 100644 index cd1c9d3..0000000 --- a/qserv-test/pom.xml +++ /dev/null @@ -1,68 +0,0 @@ - - 4.0.0 - de.hsadmin.core - hsadmin-qserv-test - 4.0.16 - - UTF-8 - 11 - - - - de.hsadmin.core - hsadmin-util - 4.0.16 - - - de.hsadmin.core - hsadmin-qserv - 4.0.16 - - - commons-lang - commons-lang - 2.6 - - - commons-net - commons-net - 3.9.0 - - - org.apache.velocity - velocity-engine-core - 2.3 - - - org.apache.openjpa - openjpa - 3.2.2 - - - org.apache.activemq - activemq-client - 5.17.5 - - - junit - junit - 4.13.2 - test - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.11.0 - - 11 - 11 - - - - - diff --git a/qserv-test/src/main/java/de/hsadmin/qserv/test/Pull.java b/qserv-test/src/main/java/de/hsadmin/qserv/test/Pull.java deleted file mode 100644 index 7dbd06f..0000000 --- a/qserv-test/src/main/java/de/hsadmin/qserv/test/Pull.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.hsadmin.qserv.test; - -import java.io.Serializable; - -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.ObjectMessage; -import javax.jms.Queue; -import javax.jms.QueueConnection; -import javax.jms.QueueReceiver; -import javax.jms.QueueSession; - -import org.apache.activemq.ActiveMQConnectionFactory; - -import de.hsadmin.core.qserv.ProcessorException; -import de.hsadmin.core.qserv.TaskTransfer; - -public class Pull implements MessageListener { - - public static void main(String[] args) { - ActiveMQConnectionFactory cxFact = new ActiveMQConnectionFactory("ssl://hsh02.hostsharing.net:61619"); - try { -// QueueConnection qCx = cxFact.createQueueConnection("hsar", ""); - QueueConnection queueConnect = cxFact.createQueueConnection("user-h98", ""); - QueueSession session = queueConnect.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); - Queue queue = session.createQueue("queue.hsadminSystem-h98"); - QueueReceiver receiver = session.createReceiver(queue); - receiver.setMessageListener(new Pull()); - queueConnect.start(); - boolean doContinue = true; - while (doContinue) { - try { - Thread.sleep(2000L); - } catch (InterruptedException e) { - doContinue = false; - } - } - queueConnect.stop(); - session.close(); - queueConnect.close(); - } catch (JMSException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Override - public void onMessage(Message message) { - if (message instanceof ObjectMessage) { - try { - ObjectMessage objMesg = (ObjectMessage) message; - Serializable serializable = objMesg.getObject(); - if (serializable instanceof TaskTransfer) { - TaskTransfer task = (TaskTransfer) serializable; - task.getProcessor().process(); - } - } catch (ProcessorException | JMSException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - try { - message.acknowledge(); - } catch (JMSException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - -} diff --git a/qserv-test/src/main/java/de/hsadmin/qserv/test/Push.java b/qserv-test/src/main/java/de/hsadmin/qserv/test/Push.java deleted file mode 100644 index 6e07e71..0000000 --- a/qserv-test/src/main/java/de/hsadmin/qserv/test/Push.java +++ /dev/null @@ -1,37 +0,0 @@ -package de.hsadmin.qserv.test; - -import java.util.Date; - -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.QueueConnection; -import javax.jms.QueueSession; - -import org.apache.activemq.ActiveMQConnectionFactory; - -import de.hsadmin.core.qserv.NullProcessor; -import de.hsadmin.core.qserv.TaskTransfer; - -public class Push { - - public static void main(String[] args) { - ActiveMQConnectionFactory cxFact = new ActiveMQConnectionFactory("ssl://hsh02.hostsharing.net:61619"); - try { -// QueueConnection qCx = cxFact.createQueueConnection("user-h98", ""); - QueueConnection qCx = cxFact.createQueueConnection("hsar", "Eix4Baijee2ae1aighetaik8"); - QueueSession session = qCx.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); - Queue queue = session.createQueue("queue.hsadminSystem-h98"); - MessageProducer producer = session.createProducer(queue); - Message message = session.createObjectMessage(new TaskTransfer(1L, "anonymous", new Date(), null, "hello world", "hello world detail", new NullProcessor(), null)); - producer.send(queue, message); - session.close(); - qCx.close(); - } catch (JMSException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - -} From 4791781eeba47475edd571d31d342eaaef897d88 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 5 Sep 2023 12:14:22 +0200 Subject: [PATCH 07/16] null handling --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e9bb5bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/qserv-test/ From 221aea252064a4772e5bb420365bfbd73f14d3cf Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 5 Sep 2023 12:17:38 +0200 Subject: [PATCH 08/16] release 4.0.16 --- qserv-deploy/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qserv-deploy/pom.xml b/qserv-deploy/pom.xml index 55c215c..e75abde 100644 --- a/qserv-deploy/pom.xml +++ b/qserv-deploy/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin hsadmin-qserv - 4.0.15 + 4.0.16 jar HSAdmin-QServ @@ -20,7 +20,7 @@ de.hsadmin.core hsadmin-qserv - 4.0.15 + 4.0.16 org.apache.activemq From f4457d515930c6286ee9403018eccee760098381 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Tue, 5 Sep 2023 17:42:53 +0200 Subject: [PATCH 09/16] refactoring qserv config --- hsarback/pom.xml | 6 +-- .../java/de/hsadmin/remote/RoleRemote.java | 5 +- qserv-deploy/pom.xml | 18 ++++++- .../src/deb/init/init_hive_mysqldb.sh | 50 +++++++++++++++++++ .../src/deb/systemd/hsadmin-qserv.service | 4 +- qserv/pom.xml | 4 +- .../de/hsadmin/core/qserv/QueueServer.java | 3 +- util/pom.xml | 2 +- .../java/de/hsadmin/core/util/Config.java | 23 +++------ 9 files changed, 85 insertions(+), 30 deletions(-) create mode 100644 qserv-deploy/src/deb/init/init_hive_mysqldb.sh diff --git a/hsarback/pom.xml b/hsarback/pom.xml index 1d17e87..d13d420 100644 --- a/hsarback/pom.xml +++ b/hsarback/pom.xml @@ -5,7 +5,7 @@ de.hsadmin hsar war - 4.0.16 + 4.0.17 HSAdmin Stable Backend Webapp http://maven.apache.org @@ -19,12 +19,12 @@ de.hsadmin.core hsadmin-util - 4.0.16 + 4.0.17 de.hsadmin.core hsadmin-qserv - 4.0.16 + 4.0.17 commons-httpclient diff --git a/hsarback/src/main/java/de/hsadmin/remote/RoleRemote.java b/hsarback/src/main/java/de/hsadmin/remote/RoleRemote.java index 41349d4..2f82b6c 100644 --- a/hsarback/src/main/java/de/hsadmin/remote/RoleRemote.java +++ b/hsarback/src/main/java/de/hsadmin/remote/RoleRemote.java @@ -23,8 +23,9 @@ public class RoleRemote implements IRemote { Transaction transaction = new Transaction(user); if (transaction.login(user, ticket)) { String role = "USER"; - String accoutPrefixCustomer = Config.getInstance().getProperty("accountprefix.customer"); - String accoutPrefixHostmaster = Config.getInstance().getProperty("accountprefix.hostmaster"); + Config config = Config.getInstance(); + String accoutPrefixCustomer = config.getProperty("accountprefix.customer"); + String accoutPrefixHostmaster = config.getProperty("accountprefix.hostmaster"); Pac pac = transaction.getLoginUser().getPac(); String pacName = pac.getName(); if (accoutPrefixCustomer.equals(pacName)) { diff --git a/qserv-deploy/pom.xml b/qserv-deploy/pom.xml index e75abde..275e776 100644 --- a/qserv-deploy/pom.xml +++ b/qserv-deploy/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin hsadmin-qserv - 4.0.16 + 4.0.17 jar HSAdmin-QServ @@ -17,10 +17,15 @@ + + de.hsadmin.core + hsadmin-util + 4.0.17 + de.hsadmin.core hsadmin-qserv - 4.0.16 + 4.0.17 org.apache.activemq @@ -79,6 +84,15 @@ /usr/local/lib/hostsharing/hsadmin + + src/deb/init/init_hive_mysqldb.sh + file + + perm + /usr/local/lib/hostsharing/hsadmin/tools/ + 754 + + src/deb/systemd/hsadmin-qserv.service file diff --git a/qserv-deploy/src/deb/init/init_hive_mysqldb.sh b/qserv-deploy/src/deb/init/init_hive_mysqldb.sh new file mode 100644 index 0000000..2375bc0 --- /dev/null +++ b/qserv-deploy/src/deb/init/init_hive_mysqldb.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +mysql --defaults-file=/root/.my.cnf mysql <4.0.0 de.hsadmin.core hsadmin-qserv - 4.0.16 + 4.0.17 UTF-8 11 @@ -13,7 +13,7 @@ de.hsadmin.core hsadmin-util - 4.0.16 + 4.0.17 commons-lang diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java index 3ea0f60..add34b1 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java @@ -37,8 +37,7 @@ public class QueueServer implements MessageListener, ExceptionListener { /** - * Runs the QueueServer, using the arguments as ConnectionFactory - * and Topic names. + * Runs the QueueServer. */ public static void main(String[] args) throws Exception { final Config config = Config.getInstance(); diff --git a/util/pom.xml b/util/pom.xml index 5539f63..f10de1a 100644 --- a/util/pom.xml +++ b/util/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin.core hsadmin-util - 4.0.16 + 4.0.17 UTF-8 11 diff --git a/util/src/main/java/de/hsadmin/core/util/Config.java b/util/src/main/java/de/hsadmin/core/util/Config.java index efe4328..8e78bc9 100644 --- a/util/src/main/java/de/hsadmin/core/util/Config.java +++ b/util/src/main/java/de/hsadmin/core/util/Config.java @@ -18,16 +18,11 @@ public class Config { private Config() { props = new Properties(); + initPropertiesFromFile(); + } + + private void initPropertiesFromFile() { final String baseName = "hsadmin"; - initPropertiesFromFile(baseName); - } - - private Config(String baseName) { - props = new Properties(); - initPropertiesFromFile(baseName); - } - - private void initPropertiesFromFile(final String baseName) { File file = new File(userDir + "/" + baseName + ".properties"); if (!file.canRead()) { file = new File(userDir + "/conf/" + baseName + ".properties"); @@ -50,7 +45,8 @@ public class Config { e.printStackTrace(); } } else { - LOG.severe("reading properties failed: No properties file found"); + final String errormsg = "reading properties failed: No properties file found"; + LOG.severe(errormsg); } } @@ -61,13 +57,6 @@ public class Config { return instance; } - public static Config getInstance(String baseName) { - if (instance == null) { - instance = new Config(baseName); - } - return instance; - } - public String getProperty(String propertyName) { String property = props.getProperty(propertyName); return property; From 3733c4916579f42b6548ff8e2e2195b32c2af5d1 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 7 Sep 2023 13:13:15 +0200 Subject: [PATCH 10/16] release v4.0.18 --- hsarback/pom.xml | 6 +++--- qserv-deploy/pom.xml | 6 +++--- qserv/pom.xml | 4 ++-- util/pom.xml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hsarback/pom.xml b/hsarback/pom.xml index d13d420..155c793 100644 --- a/hsarback/pom.xml +++ b/hsarback/pom.xml @@ -5,7 +5,7 @@ de.hsadmin hsar war - 4.0.17 + 4.0.18 HSAdmin Stable Backend Webapp http://maven.apache.org @@ -19,12 +19,12 @@ de.hsadmin.core hsadmin-util - 4.0.17 + 4.0.18 de.hsadmin.core hsadmin-qserv - 4.0.17 + 4.0.18 commons-httpclient diff --git a/qserv-deploy/pom.xml b/qserv-deploy/pom.xml index 275e776..0d596d9 100644 --- a/qserv-deploy/pom.xml +++ b/qserv-deploy/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin hsadmin-qserv - 4.0.17 + 4.0.18 jar HSAdmin-QServ @@ -20,12 +20,12 @@ de.hsadmin.core hsadmin-util - 4.0.17 + 4.0.18 de.hsadmin.core hsadmin-qserv - 4.0.17 + 4.0.18 org.apache.activemq diff --git a/qserv/pom.xml b/qserv/pom.xml index 94d8556..7da9877 100644 --- a/qserv/pom.xml +++ b/qserv/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin.core hsadmin-qserv - 4.0.17 + 4.0.18 UTF-8 11 @@ -13,7 +13,7 @@ de.hsadmin.core hsadmin-util - 4.0.17 + 4.0.18 commons-lang diff --git a/util/pom.xml b/util/pom.xml index f10de1a..ec5283e 100644 --- a/util/pom.xml +++ b/util/pom.xml @@ -4,7 +4,7 @@ 4.0.0 de.hsadmin.core hsadmin-util - 4.0.17 + 4.0.18 UTF-8 11 From ad42d235453ea73e369f259752f1680cf73c9cc0 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Wed, 13 Sep 2023 18:58:51 +0200 Subject: [PATCH 11/16] fix nullpointer, initialize logger --- .../main/java/de/hsadmin/core/model/PersistenceManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qserv/src/main/java/de/hsadmin/core/model/PersistenceManager.java b/qserv/src/main/java/de/hsadmin/core/model/PersistenceManager.java index 928488a..dae38b0 100644 --- a/qserv/src/main/java/de/hsadmin/core/model/PersistenceManager.java +++ b/qserv/src/main/java/de/hsadmin/core/model/PersistenceManager.java @@ -1,9 +1,9 @@ package de.hsadmin.core.model; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; @@ -15,7 +15,7 @@ public class PersistenceManager { private Map persistenceUnits; - private Logger logger; + private Logger logger = Logger.getLogger(PersistenceManager.class.getName()); public static EntityManager getEntityManager(String persistUnitName) { EntityManagerFactory emf = PersistenceManager.getInstance().getEMF(persistUnitName); From c530a654610e040d6dec6d56ec4acc4f9c154e7f Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Wed, 13 Sep 2023 19:43:17 +0200 Subject: [PATCH 12/16] client_ack --- .../java/de/hsadmin/servlets/QueueStatusReceiverServlet.java | 2 +- qserv/src/main/java/de/hsadmin/core/model/Transaction.java | 2 +- qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java | 5 +++-- qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java b/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java index 9cd33bb..8399887 100644 --- a/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java +++ b/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java @@ -72,7 +72,7 @@ public class QueueStatusReceiverServlet extends HttpServlet try { queueConnection = mqConnectionFactory.createQueueConnection(jmsUser, jmsPass); queueConnection.setExceptionListener(this); - queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); + queueSession = queueConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); Queue queue = queueSession.createQueue(jmsStatusQueue); queueConnection.start(); QueueReceiver receiver = queueSession.createReceiver(queue); diff --git a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java index 4685a49..e02820c 100644 --- a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java +++ b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java @@ -62,7 +62,7 @@ public class Transaction { public Queue lookupJMSQueue(String queueName) { try { final QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); - final QueueSession session = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); + final QueueSession session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); final Queue queue = session.createQueue(queueName); return queue; } catch (JMSException e) { diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java index ff8ef1a..d989ed1 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java @@ -36,7 +36,7 @@ public class QueueClient { String jmsUser = config.getProperty("hsadmin.jms.username", "hsadmin"); String jmsPass = config.getProperty("hsadmin.jms.password", "hsadmin-pw"); jmsConnection = jmsConnectionFactory.createQueueConnection(jmsUser, jmsPass); - jmsSession = jmsConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); + jmsSession = jmsConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); jmsSender = jmsSession.createSender(jmsSystemQueue); } @@ -44,6 +44,7 @@ public class QueueClient { try { ObjectMessage jmsMessage = jmsSession.createObjectMessage(task); jmsSender.send(jmsMessage); + jmsMessage.acknowledge(); } catch (JMSSecurityException secExc) { secExc.printStackTrace(); throw new ProcessorException("Not allowed to send to queue " @@ -55,7 +56,7 @@ public class QueueClient { } } - private String queueName(Queue jmsSystemQueue2) { + private String queueName(Queue jmsSystemQueue) { try { return jmsSystemQueue.getQueueName(); } catch (Exception exc) { diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java index add34b1..6431211 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java @@ -176,7 +176,7 @@ public class QueueServer implements MessageListener, ExceptionListener { try { queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); queueConnection.setExceptionListener(this); - session = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); + session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); final Queue queue = session.createQueue(jmsStatusQueue); queueConnection.start(); producer = session.createProducer(queue); From 99f33b5b4b895410a3ca20f4dd5769f08d65b9f8 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Wed, 13 Sep 2023 19:54:05 +0200 Subject: [PATCH 13/16] client_ack --- qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java index 6431211..5974492 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java @@ -183,6 +183,7 @@ public class QueueServer implements MessageListener, ExceptionListener { final ObjectMessage statusMessage = session.createObjectMessage(queueMessage); logger.log(Level.INFO, "send(" + statusMessage + ")"); producer.send(statusMessage); + statusMessage.acknowledge(); } catch (Exception statusException) { logger.log(Level.SEVERE, statusException.getMessage(), statusException); } finally { From a8857091f9d10300f35558f3c39edc0eef3ec5a5 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Wed, 13 Sep 2023 20:15:04 +0200 Subject: [PATCH 14/16] auto_ack --- .../de/hsadmin/servlets/QueueStatusReceiverServlet.java | 3 +-- .../src/main/java/de/hsadmin/core/model/Transaction.java | 2 +- .../src/main/java/de/hsadmin/core/qserv/QueueClient.java | 3 +-- .../src/main/java/de/hsadmin/core/qserv/QueueServer.java | 8 +++----- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java b/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java index 8399887..3248c5f 100644 --- a/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java +++ b/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java @@ -72,7 +72,7 @@ public class QueueStatusReceiverServlet extends HttpServlet try { queueConnection = mqConnectionFactory.createQueueConnection(jmsUser, jmsPass); queueConnection.setExceptionListener(this); - queueSession = queueConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); + queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = queueSession.createQueue(jmsStatusQueue); queueConnection.start(); QueueReceiver receiver = queueSession.createReceiver(queue); @@ -127,7 +127,6 @@ public class QueueStatusReceiverServlet extends HttpServlet final long queueTaskId = detachedQT.getId(); QueueTask persistentQT = em.find(QueueTask.class, queueTaskId); if (persistentQT == null) { - jmsMessage.acknowledge(); errorCount++; throw new TechnicalException("QueueTask not found, id: " + queueTaskId); } diff --git a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java index e02820c..4685a49 100644 --- a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java +++ b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java @@ -62,7 +62,7 @@ public class Transaction { public Queue lookupJMSQueue(String queueName) { try { final QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); - final QueueSession session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); + final QueueSession session = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); final Queue queue = session.createQueue(queueName); return queue; } catch (JMSException e) { diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java index d989ed1..d40769d 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueClient.java @@ -36,7 +36,7 @@ public class QueueClient { String jmsUser = config.getProperty("hsadmin.jms.username", "hsadmin"); String jmsPass = config.getProperty("hsadmin.jms.password", "hsadmin-pw"); jmsConnection = jmsConnectionFactory.createQueueConnection(jmsUser, jmsPass); - jmsSession = jmsConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); + jmsSession = jmsConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); jmsSender = jmsSession.createSender(jmsSystemQueue); } @@ -44,7 +44,6 @@ public class QueueClient { try { ObjectMessage jmsMessage = jmsSession.createObjectMessage(task); jmsSender.send(jmsMessage); - jmsMessage.acknowledge(); } catch (JMSSecurityException secExc) { secExc.printStackTrace(); throw new ProcessorException("Not allowed to send to queue " diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java index 5974492..1d7f771 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java @@ -111,7 +111,7 @@ public class QueueServer implements MessageListener, ExceptionListener { mqConnectionFactory.setTrustAllPackages(true); queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); queueConnection.setExceptionListener(this); - final QueueSession session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); + final QueueSession session = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(jmsSystemQueue); queueConnection.start(); final QueueReceiver receiver = session.createReceiver(queue); @@ -146,7 +146,6 @@ public class QueueServer implements MessageListener, ExceptionListener { logException(throwable); task.setException(throwable.getMessage()); } finally { - try { jmsMessage.acknowledge(); } catch (JMSException e) { } sendStatus(task); notifyAll(); } @@ -176,14 +175,13 @@ public class QueueServer implements MessageListener, ExceptionListener { try { queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); queueConnection.setExceptionListener(this); - session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); + session = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); final Queue queue = session.createQueue(jmsStatusQueue); queueConnection.start(); producer = session.createProducer(queue); final ObjectMessage statusMessage = session.createObjectMessage(queueMessage); - logger.log(Level.INFO, "send(" + statusMessage + ")"); producer.send(statusMessage); - statusMessage.acknowledge(); + logger.log(Level.INFO, "send(" + statusMessage + ")"); } catch (Exception statusException) { logger.log(Level.SEVERE, statusException.getMessage(), statusException); } finally { From 96611786871881b3c0e160e6d9003db9c46c9ff4 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Wed, 13 Sep 2023 20:42:36 +0200 Subject: [PATCH 15/16] auto_ack --- qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java index 1d7f771..834abab 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java @@ -187,7 +187,7 @@ public class QueueServer implements MessageListener, ExceptionListener { } finally { if (producer != null) try { producer.close(); } catch (Exception e) { } if (session != null) try { session.close(); } catch (Exception e) { } -// if (queueConnection != null) try { queueConnection.close(); } catch (Exception e) { } + if (queueConnection != null) try { queueConnection.close(); } catch (Exception e) { } } } From 5004cab8148361190a4d184f1f31c706f042c3f4 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 27 Nov 2023 13:40:39 +0100 Subject: [PATCH 16/16] commit changes --- .../servlets/QueueStatusReceiverServlet.java | 3 +- .../de/hsadmin/core/model/Transaction.java | 4 +-- .../de/hsadmin/core/qserv/QueueServer.java | 35 +++++++++++-------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java b/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java index 3248c5f..4dc54ec 100644 --- a/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java +++ b/hsarback/src/main/java/de/hsadmin/servlets/QueueStatusReceiverServlet.java @@ -74,9 +74,9 @@ public class QueueStatusReceiverServlet extends HttpServlet queueConnection.setExceptionListener(this); queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = queueSession.createQueue(jmsStatusQueue); - queueConnection.start(); QueueReceiver receiver = queueSession.createReceiver(queue); receiver.setMessageListener(this); + queueConnection.start(); isConnected = true; } catch (JMSException e) { close(); @@ -150,6 +150,7 @@ public class QueueStatusReceiverServlet extends HttpServlet throw new TechnicalException(e); } finally { if (transaction != null) transaction.close(); + notifyAll(); } } diff --git a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java index 4685a49..ab0b12b 100644 --- a/qserv/src/main/java/de/hsadmin/core/model/Transaction.java +++ b/qserv/src/main/java/de/hsadmin/core/model/Transaction.java @@ -59,7 +59,7 @@ public class Transaction { return queueConnectionFactory; } - public Queue lookupJMSQueue(String queueName) { + public Queue createQueueSession(String queueName) { try { final QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); final QueueSession session = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); @@ -90,7 +90,7 @@ public class Transaction { for (String hive : taskStores.keySet()) { QueueTaskStore store = taskStores.get(hive); String queueName = "queue.hsadminSystem-" + hive; - Queue jmsSystemQueue = lookupJMSQueue(queueName); + Queue jmsSystemQueue = createQueueSession(queueName); QueueClient qClient = null; try { qClient = new QueueClient(queueConnectionFactory, jmsSystemQueue); diff --git a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java index 834abab..e5326a9 100644 --- a/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java +++ b/qserv/src/main/java/de/hsadmin/core/qserv/QueueServer.java @@ -3,15 +3,16 @@ package de.hsadmin.core.qserv; import java.util.logging.Level; import java.util.logging.Logger; +import javax.jms.ConnectionMetaData; import javax.jms.ExceptionListener; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageListener; -import javax.jms.MessageProducer; import javax.jms.ObjectMessage; import javax.jms.Queue; import javax.jms.QueueConnection; import javax.jms.QueueReceiver; +import javax.jms.QueueSender; import javax.jms.QueueSession; import org.apache.activemq.ActiveMQConnectionFactory; @@ -20,7 +21,7 @@ import de.hsadmin.core.util.Config; public class QueueServer implements MessageListener, ExceptionListener { - private static final String VERSION_NO = "4.0.16"; + private static final String VERSION_NO = "4.0.19"; private Logger logger; @@ -50,7 +51,7 @@ public class QueueServer implements MessageListener, ExceptionListener { qServ.setJmsPassWord(config.getProperty("hsadmin.jms.password")); qServ.setServiceEMail(config.getProperty("hsadmin.log.email")); qServ.setFromEMail(config.getProperty("hsadmin.log.from")); - Logger logger = Logger.getLogger("de.hsadmin.core.qserv"); + Logger logger = Logger.getLogger(QueueServer.class.getName()); logger.log(Level.CONFIG, "hsadmin-qserv " + VERSION_NO + " started using:" + "\nsystem queue: " + config.getProperty("hsadmin.jms.system-queue") + "\nstatus queue: " + config.getProperty("hsadmin.jms.status-queue") @@ -80,7 +81,7 @@ public class QueueServer implements MessageListener, ExceptionListener { } public QueueServer() { - logger = Logger.getLogger("de.hsadmin.core.qserv"); + logger = Logger.getLogger(QueueServer.class.getName()); queueConnection = null; isConnected = false; } @@ -111,11 +112,11 @@ public class QueueServer implements MessageListener, ExceptionListener { mqConnectionFactory.setTrustAllPackages(true); queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); queueConnection.setExceptionListener(this); - final QueueSession session = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); + final QueueSession session = queueConnection.createQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE); Queue queue = session.createQueue(jmsSystemQueue); - queueConnection.start(); final QueueReceiver receiver = session.createReceiver(queue); receiver.setMessageListener(this); + queueConnection.start(); isConnected = true; } catch (Exception e) { logger.log(Level.WARNING, e.getMessage(), e); @@ -131,12 +132,12 @@ public class QueueServer implements MessageListener, ExceptionListener { ObjectMessage jmsObjectMessage = (ObjectMessage) jmsMessage; task = (TaskTransfer) jmsObjectMessage.getObject(); Processor processor = task.getProcessor(); - logger.log(Level.INFO, "processing (" + task.getTitle() + " | started(" + logger.log(Level.FINE, "processing (" + task.getTitle() + " | started(" + task.getStarted() + ") |" + task.getDetails() + "|" + processor + ")"); try { processor.process(); - logger.log(Level.INFO, "done"); + logger.log(Level.FINE, "done"); } catch (ProcessorException e) { logException(e); task.setException(e.getMessage()); @@ -146,6 +147,9 @@ public class QueueServer implements MessageListener, ExceptionListener { logException(throwable); task.setException(throwable.getMessage()); } finally { + try { jmsMessage.acknowledge(); } catch (JMSException e) { + logger.log(Level.INFO, e.getMessage()); + } sendStatus(task); notifyAll(); } @@ -167,25 +171,28 @@ public class QueueServer implements MessageListener, ExceptionListener { } protected void sendStatus(TaskTransfer queueMessage) { + logger.log(Level.INFO, "sendStatus|" + queueMessage.getTitle()); final ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory(jmsUrl); mqConnectionFactory.setTrustAllPackages(true); QueueConnection queueConnection = null; - MessageProducer producer = null; + QueueSender sender = null; QueueSession session = null; try { queueConnection = mqConnectionFactory.createQueueConnection(jmsUsername, jmsPassword); - queueConnection.setExceptionListener(this); + final ConnectionMetaData connectionMetaData = queueConnection.getMetaData(); + logger.log(Level.INFO, "sendStatus|" + connectionMetaData.getJMSProviderName()); session = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); final Queue queue = session.createQueue(jmsStatusQueue); - queueConnection.start(); - producer = session.createProducer(queue); + logger.log(Level.INFO, "sendStatus|" + queue.getQueueName()); + sender = session.createSender(queue); final ObjectMessage statusMessage = session.createObjectMessage(queueMessage); - producer.send(statusMessage); + logger.log(Level.INFO, "sendStatus|" + statusMessage.getJMSMessageID()); + sender.send(statusMessage); logger.log(Level.INFO, "send(" + statusMessage + ")"); } catch (Exception statusException) { logger.log(Level.SEVERE, statusException.getMessage(), statusException); } finally { - if (producer != null) try { producer.close(); } catch (Exception e) { } + if (sender != null) try { sender.close(); } catch (Exception e) { } if (session != null) try { session.close(); } catch (Exception e) { } if (queueConnection != null) try { queueConnection.close(); } catch (Exception e) { } }