remove jndi config, new ValueObject TaskTransfer, v4.0.16
This commit is contained in:
parent
8409ede74b
commit
a85f0d1bec
@ -5,7 +5,7 @@
|
||||
<groupId>de.hsadmin</groupId>
|
||||
<artifactId>hsar</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>4.0.15</version>
|
||||
<version>4.0.16</version>
|
||||
<name>HSAdmin Stable Backend Webapp</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
@ -36,12 +36,12 @@
|
||||
<dependency>
|
||||
<groupId>de.hsadmin.core</groupId>
|
||||
<artifactId>hsadmin-util</artifactId>
|
||||
<version>4.0.15</version>
|
||||
<version>4.0.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.hsadmin.core</groupId>
|
||||
<artifactId>hsadmin-qserv</artifactId>
|
||||
<version>4.0.15</version>
|
||||
<version>4.0.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-httpclient</groupId>
|
||||
@ -78,6 +78,11 @@
|
||||
<artifactId>openjpa</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-client</artifactId>
|
||||
<version>5.17.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@ -90,18 +95,6 @@
|
||||
<version>4.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-all</artifactId>
|
||||
<version>5.18.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-jms_1.1_spec</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>hsar</finalName>
|
||||
|
@ -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<NameClassPair> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,29 +5,4 @@
|
||||
global="jdbc/HSAdminDB"
|
||||
type="javax.sql.DataSource"/>
|
||||
|
||||
<ResourceLink
|
||||
name="jms/QueueCF"
|
||||
global="jms/QueueCF"
|
||||
type="javax.jms.QueueConnectionFactory"/>
|
||||
|
||||
<ResourceLink
|
||||
name="jms/hsadminSystem-h99"
|
||||
global="jms/hsadminSystem-h99"
|
||||
type="javax.jms.Queue"/>
|
||||
|
||||
<ResourceLink
|
||||
name="jms/hsadminSystem-testmail"
|
||||
global="jms/hsadminSystem-testmail"
|
||||
type="javax.jms.Queue"/>
|
||||
|
||||
<ResourceLink
|
||||
name="jms/hsadminSystem-testdns"
|
||||
global="jms/hsadminSystem-testdns"
|
||||
type="javax.jms.Queue"/>
|
||||
|
||||
<ResourceLink
|
||||
name="jms/hsadminStatus"
|
||||
global="jms/hsadminStatus"
|
||||
type="javax.jms.Queue"/>
|
||||
|
||||
</Context>
|
||||
|
@ -57,36 +57,5 @@
|
||||
<res-auth>Container</res-auth>
|
||||
</resource-ref>
|
||||
|
||||
<resource-ref>
|
||||
<res-ref-name>jms/QueueCF</res-ref-name>
|
||||
<res-type>javax.jms.QueueConnectionFactory</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
</resource-ref>
|
||||
|
||||
<resource-ref>
|
||||
<res-ref-name>jms/hsadminSystem-h99</res-ref-name>
|
||||
<res-type>javax.jms.Queue</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
</resource-ref>
|
||||
<resource-ref>
|
||||
<res-ref-name>jms/hsadminSystem-testdns</res-ref-name>
|
||||
<res-type>javax.jms.Queue</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
</resource-ref>
|
||||
<resource-ref>
|
||||
<res-ref-name>jms/hsadminSystem-testmail</res-ref-name>
|
||||
<res-type>javax.jms.Queue</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
</resource-ref>
|
||||
<resource-ref>
|
||||
<res-ref-name>jms/hsadminStatus</res-ref-name>
|
||||
<res-type>javax.jms.Queue</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<res-sharing-scope>Shareable</res-sharing-scope>
|
||||
</resource-ref>
|
||||
|
||||
</web-app>
|
||||
</web-app>
|
||||
|
||||
|
2
qserv/.gitignore
vendored
2
qserv/.gitignore
vendored
@ -4,4 +4,4 @@
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
|
||||
hsadmin.properties
|
||||
|
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.hsadmin.core</groupId>
|
||||
<artifactId>hsadmin-qserv</artifactId>
|
||||
<version>4.0.15</version>
|
||||
<version>4.0.16</version>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>11</java.version>
|
||||
@ -13,7 +13,7 @@
|
||||
<dependency>
|
||||
<groupId>de.hsadmin.core</groupId>
|
||||
<artifactId>hsadmin-util</artifactId>
|
||||
<version>4.0.15</version>
|
||||
<version>4.0.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
|
@ -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) {
|
||||
|
@ -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<String, QueueTaskStore> 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<String, QueueTaskStore>();
|
||||
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<QueueTask> taskList;
|
||||
private List<TaskTransfer> taskList;
|
||||
QueueTaskStore() {
|
||||
taskList = new ArrayList<QueueTask>();
|
||||
taskList = new ArrayList<TaskTransfer>();
|
||||
}
|
||||
public void clear() {
|
||||
taskList = new ArrayList<QueueTask>();
|
||||
taskList = new ArrayList<TaskTransfer>();
|
||||
}
|
||||
void add(QueueTask t) {
|
||||
void add(TaskTransfer t) {
|
||||
taskList.add(t);
|
||||
}
|
||||
Iterable<QueueTask> getTasks() {
|
||||
Iterable<TaskTransfer> getTasks() {
|
||||
return taskList;
|
||||
}
|
||||
}
|
||||
|
@ -14,4 +14,9 @@ abstract public class AbstractProcessor implements Processor {
|
||||
task.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "a Processor of class " + this.getClass().getCanonicalName();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
130
qserv/src/main/java/de/hsadmin/core/qserv/TaskTransfer.java
Normal file
130
qserv/src/main/java/de/hsadmin/core/qserv/TaskTransfer.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
|
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.hsadmin.core</groupId>
|
||||
<artifactId>hsadmin-util</artifactId>
|
||||
<version>4.0.15</version>
|
||||
<version>4.0.16</version>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>11</java.version>
|
||||
|
Loading…
Reference in New Issue
Block a user