parent
0cc09fba29
commit
bdde4368c4
@ -5,7 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CompoundProcessor extends AbstractProcessor {
|
public class CompoundProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private static final long serialVersionUID = 5718623579674305929L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private List<Processor> aProcessors;
|
private List<Processor> aProcessors;
|
||||||
|
|
||||||
@ -26,5 +26,15 @@ public class CompoundProcessor extends AbstractProcessor {
|
|||||||
public void appendProcessor(Processor aProcessor) {
|
public void appendProcessor(Processor aProcessor) {
|
||||||
aProcessors.add(aProcessor);
|
aProcessors.add(aProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String logInfo() {
|
||||||
|
StringBuffer log = new StringBuffer();
|
||||||
|
for (Processor aProcessor : aProcessors) {
|
||||||
|
log.append(aProcessor.logInfo());
|
||||||
|
log.append("\n\n");
|
||||||
|
}
|
||||||
|
return log.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package de.hsadmin.core.qserv;
|
|||||||
|
|
||||||
public class CopyFileProcessor extends AbstractProcessor {
|
public class CopyFileProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1741419610410712714L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Processor internal;
|
private Processor internal;
|
||||||
|
|
||||||
@ -19,4 +19,9 @@ public class CopyFileProcessor extends AbstractProcessor {
|
|||||||
return internal.process();
|
return internal.process();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String logInfo() {
|
||||||
|
return internal.logInfo();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import de.hsadmin.mods.pac.Hive;
|
|||||||
|
|
||||||
public class CreateFileProcessor extends AbstractProcessor {
|
public class CreateFileProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private static final long serialVersionUID = -2947609532975712444L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Processor compoundProcessor;
|
private Processor compoundProcessor;
|
||||||
|
|
||||||
@ -35,4 +35,9 @@ public class CreateFileProcessor extends AbstractProcessor {
|
|||||||
return compoundProcessor.process();
|
return compoundProcessor.process();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String logInfo() {
|
||||||
|
return compoundProcessor.logInfo();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,19 +13,21 @@ import de.hsadmin.core.util.Config;
|
|||||||
|
|
||||||
public class JDBCProcessor extends AbstractProcessor {
|
public class JDBCProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private static final long serialVersionUID = 7702753017749022325L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private String driver;
|
private String driver;
|
||||||
private String url;
|
private String url;
|
||||||
private String user;
|
private String user;
|
||||||
private String password;
|
private String password;
|
||||||
private List<String> sql;
|
private List<String> sql;
|
||||||
|
private String errorMsg;
|
||||||
|
|
||||||
public JDBCProcessor(String driver, String url, String user, String password) {
|
public JDBCProcessor(String driver, String url, String user, String password) {
|
||||||
this.driver = driver;
|
this.driver = driver;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
|
this.errorMsg = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public JDBCProcessor(String driver, String url) {
|
public JDBCProcessor(String driver, String url) {
|
||||||
@ -70,11 +72,12 @@ public class JDBCProcessor extends AbstractProcessor {
|
|||||||
return s.executeBatch();
|
return s.executeBatch();
|
||||||
} catch (SQLException aSqlExc) {
|
} catch (SQLException aSqlExc) {
|
||||||
Exception exc = aSqlExc.getNextException();
|
Exception exc = aSqlExc.getNextException();
|
||||||
if (exc == null)
|
if (exc == null) {
|
||||||
exc = aSqlExc;
|
exc = aSqlExc;
|
||||||
System.out.println("ERR: " + exc.getMessage());
|
}
|
||||||
throw new ProcessorException(aSqlExc.getMessage() + ", reason: "
|
errorMsg = exc.getMessage();
|
||||||
+ exc.getMessage());
|
System.out.println("ERR: " + errorMsg);
|
||||||
|
throw new ProcessorException(aSqlExc.getMessage() + ", reason: " + errorMsg);
|
||||||
} catch (Exception aExc) {
|
} catch (Exception aExc) {
|
||||||
throw new ProcessorException(aExc.getMessage());
|
throw new ProcessorException(aExc.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
@ -86,4 +89,19 @@ public class JDBCProcessor extends AbstractProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String logInfo() {
|
||||||
|
StringBuffer log = new StringBuffer("JDBCProcessor\n");
|
||||||
|
log.append(url);
|
||||||
|
log.append("\n");
|
||||||
|
for (String s : sql) {
|
||||||
|
log.append(s);
|
||||||
|
log.append("\n");
|
||||||
|
}
|
||||||
|
log.append("Error: ");
|
||||||
|
log.append(errorMsg);
|
||||||
|
log.append("\n");
|
||||||
|
return log.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,18 @@ public interface Processor extends Serializable {
|
|||||||
*/
|
*/
|
||||||
public abstract Object process() throws ProcessorException;
|
public abstract Object process() throws ProcessorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute some code after successful execution on sending master.
|
||||||
|
* @param transaction
|
||||||
|
* @param task
|
||||||
|
* @throws ProcessorException
|
||||||
|
*/
|
||||||
public abstract void finalize(Transaction transaction, QueueTask task) throws ProcessorException;
|
public abstract void finalize(Transaction transaction, QueueTask task) throws ProcessorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct an email body to send to hostmasters on error.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract String logInfo();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,12 +24,10 @@ import javax.jms.Session;
|
|||||||
import javax.naming.Context;
|
import javax.naming.Context;
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
|
|
||||||
public class QueueServer extends QueueCommons implements
|
public class QueueServer extends QueueCommons implements MessageListener, ExceptionListener {
|
||||||
MessageListener, ExceptionListener {
|
|
||||||
|
|
||||||
private static final String VERSION_NO = "1.0";
|
private static final String VERSION_NO = "1.1";
|
||||||
|
|
||||||
private int nMessagesProcessed = 0;
|
|
||||||
private QueueConnection conn;
|
private QueueConnection conn;
|
||||||
private QueueSession queueSession;
|
private QueueSession queueSession;
|
||||||
private String jmsStatusQueue;
|
private String jmsStatusQueue;
|
||||||
@ -38,14 +36,16 @@ public class QueueServer extends QueueCommons implements
|
|||||||
private String jmsSystemQueue;
|
private String jmsSystemQueue;
|
||||||
private String jmsFactory;
|
private String jmsFactory;
|
||||||
|
|
||||||
|
private String serviceEMail;
|
||||||
|
|
||||||
/** Runs the QueueServer, using the arguments as ConnectionFactory
|
/** Runs the QueueServer, using the arguments as ConnectionFactory
|
||||||
* and Topic names.
|
* and Topic names.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
File propFile = new File(System.getProperty("user.dir"),
|
File propFile = new File(System.getProperty("user.dir"), "conf/qserv.properties");
|
||||||
"conf/qserv.properties");
|
if (args.length == 1) {
|
||||||
if (args.length == 1)
|
|
||||||
propFile = new File(args[0]);
|
propFile = new File(args[0]);
|
||||||
|
}
|
||||||
else if (args.length != 0) {
|
else if (args.length != 0) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"Wrong number of arguments.\n"
|
"Wrong number of arguments.\n"
|
||||||
@ -78,17 +78,13 @@ public class QueueServer extends QueueCommons implements
|
|||||||
qServ.setJmsStatusQueue(props.getProperty("hsadmin.jms.status-queue"));
|
qServ.setJmsStatusQueue(props.getProperty("hsadmin.jms.status-queue"));
|
||||||
qServ.setJmsUserName(props.getProperty("hsadmin.jms.username"));
|
qServ.setJmsUserName(props.getProperty("hsadmin.jms.username"));
|
||||||
qServ.setJmsPassWord(props.getProperty("hsadmin.jms.password"));
|
qServ.setJmsPassWord(props.getProperty("hsadmin.jms.password"));
|
||||||
|
qServ.setServiceEMail(props.getProperty("hsadmin.email.service"));
|
||||||
System.out.println("==================================================");
|
System.out.println("==================================================");
|
||||||
System.out.println("hsadmin-qserv " + VERSION_NO +
|
System.out.println("hsadmin-qserv " + VERSION_NO + " started using:");
|
||||||
" started using:");
|
System.out.println("queue server: " + props.getProperty("hsadmin.jms.factory"));
|
||||||
System.out.println("queue server: "
|
System.out.println("system queue: " + props.getProperty("hsadmin.jms.system-queue"));
|
||||||
+ props.getProperty("hsadmin.jms.factory"));
|
System.out.println("status queue: " + props.getProperty("hsadmin.jms.status-queue"));
|
||||||
System.out.println("system queue: "
|
System.out.println("queue user: " + props.getProperty("hsadmin.jms.username"));
|
||||||
+ props.getProperty("hsadmin.jms.system-queue"));
|
|
||||||
System.out.println("status queue: "
|
|
||||||
+ props.getProperty("hsadmin.jms.status-queue"));
|
|
||||||
System.out.println("queue user: "
|
|
||||||
+ props.getProperty("hsadmin.jms.username"));
|
|
||||||
System.out.println("==================================================");
|
System.out.println("==================================================");
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
@Override
|
@Override
|
||||||
@ -104,6 +100,14 @@ public class QueueServer extends QueueCommons implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setServiceEMail(String property) {
|
||||||
|
if (property == null) {
|
||||||
|
serviceEMail = "peter@ostwall195.de";
|
||||||
|
} else {
|
||||||
|
serviceEMail = property;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean connect() {
|
private boolean connect() {
|
||||||
// create JMS connection and session
|
// create JMS connection and session
|
||||||
try {
|
try {
|
||||||
@ -124,32 +128,31 @@ public class QueueServer extends QueueCommons implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// / Is called when a message arrives; processes Processor within message.
|
|
||||||
public synchronized void onMessage(Message jmsMessage) {
|
public synchronized void onMessage(Message jmsMessage) {
|
||||||
// TODO logging
|
// TODO logging
|
||||||
System.out.println("\nonMessage(" + jmsMessage);
|
System.out.println("\nonMessage(" + jmsMessage);
|
||||||
QueueTask task = null;
|
QueueTask task = null;
|
||||||
try {
|
try {
|
||||||
// expect ObjectMessage
|
|
||||||
ObjectMessage jmsObjectMessage = (ObjectMessage) jmsMessage;
|
ObjectMessage jmsObjectMessage = (ObjectMessage) jmsMessage;
|
||||||
|
|
||||||
// get QueueTask
|
|
||||||
task = (QueueTask) jmsObjectMessage.getObject();
|
task = (QueueTask) jmsObjectMessage.getObject();
|
||||||
|
Processor processor = task.getProcessor();
|
||||||
// TODO: logging
|
|
||||||
System.out.println("processing (" + task.getTitle() + " | started("
|
System.out.println("processing (" + task.getTitle() + " | started("
|
||||||
+ task.getStarted() + ") |" + task.getDetails() + "|"
|
+ task.getStarted() + ") |" + task.getDetails() + "|"
|
||||||
+ task.getProcessor() + ")");
|
+ processor + ")");
|
||||||
System.out.println("with " + task.getProcessor());
|
System.out.println("with " + processor);
|
||||||
// execute processor within the message
|
try {
|
||||||
task.getProcessor().process();
|
processor.process();
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
|
} catch (ProcessorException e) {
|
||||||
|
logException(e);
|
||||||
|
task.setException(e);
|
||||||
|
SmtpHelper.send("queueserv@hostsharing.net", serviceEMail, jmsSystemQueue, processor.logInfo());
|
||||||
|
}
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
logException(throwable);
|
logException(throwable);
|
||||||
task.setException(throwable);
|
task.setException(throwable);
|
||||||
} finally {
|
} finally {
|
||||||
sendStatus(task);
|
sendStatus(task);
|
||||||
setNMessagesProcessed(getNMessagesProcessed() + 1);
|
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,7 +192,6 @@ public class QueueServer extends QueueCommons implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// / send the status information back to the hsadmin server
|
|
||||||
protected void sendStatus(QueueTask queueMessage) {
|
protected void sendStatus(QueueTask queueMessage) {
|
||||||
MessageProducer producer = null;
|
MessageProducer producer = null;
|
||||||
Session statusSession = null;
|
Session statusSession = null;
|
||||||
@ -199,8 +201,7 @@ public class QueueServer extends QueueCommons implements
|
|||||||
Context ctx = new InitialContext();
|
Context ctx = new InitialContext();
|
||||||
System.out.println("Created InitialContext");
|
System.out.println("Created InitialContext");
|
||||||
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup(jmsFactory);
|
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup(jmsFactory);
|
||||||
System.out.println("connectionFactory= "
|
System.out.println("connectionFactory= " + connectionFactory.toString());
|
||||||
+ connectionFactory.toString());
|
|
||||||
Destination queue = (Destination) ctx.lookup(jmsStatusQueue);
|
Destination queue = (Destination) ctx.lookup(jmsStatusQueue);
|
||||||
statusConnection = connectionFactory.createConnection(jmsUserName, jmsPassWord);
|
statusConnection = connectionFactory.createConnection(jmsUserName, jmsPassWord);
|
||||||
statusSession = statusConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
statusSession = statusConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
@ -221,14 +222,6 @@ public class QueueServer extends QueueCommons implements
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNMessagesProcessed(int nMessagesProcessed) {
|
|
||||||
this.nMessagesProcessed = nMessagesProcessed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNMessagesProcessed() {
|
|
||||||
return nMessagesProcessed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setJmsStatusQueue(String property) {
|
public void setJmsStatusQueue(String property) {
|
||||||
jmsStatusQueue = property;
|
jmsStatusQueue = property;
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,12 @@ package de.hsadmin.core.qserv;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A ShellProcessor encapsulates a shell command as a Processor.
|
* A ShellProcessor encapsulates a shell command as a Processor.
|
||||||
*
|
|
||||||
* As such, a client can prepare shell commands to be processed on a server.
|
* As such, a client can prepare shell commands to be processed on a server.
|
||||||
*
|
|
||||||
* @author mi
|
* @author mi
|
||||||
*/
|
*/
|
||||||
public class ShellProcessor extends AbstractProcessor {
|
public class ShellProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private static final long serialVersionUID = -649045174380048818L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private String aSystemCall;
|
private String aSystemCall;
|
||||||
private String aInput;
|
private String aInput;
|
||||||
@ -27,6 +25,7 @@ public class ShellProcessor extends AbstractProcessor {
|
|||||||
this.aInput = null;
|
this.aInput = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object process() throws ProcessorException {
|
public Object process() throws ProcessorException {
|
||||||
try {
|
try {
|
||||||
aOutput = CommandShell.execute(aSystemCall, aInput);
|
aOutput = CommandShell.execute(aSystemCall, aInput);
|
||||||
@ -38,18 +37,14 @@ public class ShellProcessor extends AbstractProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @return Returns stderr as a String.
|
public String logInfo() {
|
||||||
*/
|
StringBuffer log = new StringBuffer("ShellProcessor\n");
|
||||||
public String getErrors() {
|
log.append(aSystemCall);
|
||||||
return aErrors;
|
log.append("\nError: ");
|
||||||
}
|
log.append(aErrors);
|
||||||
|
log.append("\n");
|
||||||
/**
|
return log.toString();
|
||||||
* @return Returns stdout as a String.
|
|
||||||
*/
|
|
||||||
public String getOutput() {
|
|
||||||
return aOutput;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -15,14 +14,12 @@ import org.apache.velocity.VelocityContext;
|
|||||||
import org.apache.velocity.app.Velocity;
|
import org.apache.velocity.app.Velocity;
|
||||||
|
|
||||||
import de.hsadmin.mods.dom.Domain;
|
import de.hsadmin.mods.dom.Domain;
|
||||||
import de.hsadmin.mods.pac.BasePac;
|
|
||||||
import de.hsadmin.mods.pac.Hive;
|
import de.hsadmin.mods.pac.Hive;
|
||||||
import de.hsadmin.mods.pac.INetAddress;
|
|
||||||
import de.hsadmin.mods.pac.Pac;
|
import de.hsadmin.mods.pac.Pac;
|
||||||
|
|
||||||
public class VelocityProcessor extends AbstractProcessor {
|
public class VelocityProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 2L;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
@ -34,8 +31,10 @@ public class VelocityProcessor extends AbstractProcessor {
|
|||||||
private String content;
|
private String content;
|
||||||
private String targetPath;
|
private String targetPath;
|
||||||
private boolean overwriteTarget;
|
private boolean overwriteTarget;
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
public VelocityProcessor(String templateName, Hive hive, String targetPath, boolean overwriteTarget) {
|
public VelocityProcessor(String templateName, Hive hive, String targetPath, boolean overwriteTarget) {
|
||||||
|
errorMessage = "";
|
||||||
this.targetPath = targetPath;
|
this.targetPath = targetPath;
|
||||||
this.overwriteTarget = overwriteTarget;
|
this.overwriteTarget = overwriteTarget;
|
||||||
VelocityContext context = new VelocityContext();
|
VelocityContext context = new VelocityContext();
|
||||||
@ -99,46 +98,34 @@ public class VelocityProcessor extends AbstractProcessor {
|
|||||||
try {
|
try {
|
||||||
File file = new File(targetPath);
|
File file = new File(targetPath);
|
||||||
if (file.exists() && !overwriteTarget) {
|
if (file.exists() && !overwriteTarget) {
|
||||||
return "did not overwrite existing file " + targetPath;
|
errorMessage = "did not overwrite existing file " + targetPath;
|
||||||
|
return errorMessage;
|
||||||
}
|
}
|
||||||
if (!file.exists() || file.canWrite()) {
|
if (!file.exists() || file.canWrite()) {
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
||||||
writer.append(content);
|
writer.append(content);
|
||||||
writer.close();
|
writer.close();
|
||||||
} else {
|
} else {
|
||||||
throw new ProcessorException("could not write file " + targetPath);
|
errorMessage = "could not write file " + targetPath;
|
||||||
|
throw new ProcessorException(errorMessage);
|
||||||
}
|
}
|
||||||
return "wrote file " + targetPath;
|
return "wrote file " + targetPath;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
errorMessage = e.getMessage();
|
||||||
throw new ProcessorException(e);
|
throw new ProcessorException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
@Override
|
||||||
Hive h = new Hive("h01", new INetAddress("192.168.1.100"));
|
public String logInfo() {
|
||||||
HashSet<Pac> pacsSet = new HashSet<Pac>();
|
StringBuffer log = new StringBuffer("VelocityProcessor\n");
|
||||||
h.setPacs(pacsSet);
|
log.append("Target: ");
|
||||||
Pac p1 = new Pac("pac01", null, new BasePac(), h);
|
log.append(targetPath);
|
||||||
pacsSet.add(p1);
|
log.append("\n");
|
||||||
Pac p2 = new Pac("pac02", null, new BasePac(), h);
|
log.append("Error: ");
|
||||||
pacsSet.add(p2);
|
log.append(errorMessage);
|
||||||
p1.setCurINetAddr(new INetAddress("192.168.2.11"));
|
log.append("\n");
|
||||||
p2.setCurINetAddr(new INetAddress("192.168.2.12"));
|
return log.toString();
|
||||||
VelocityProcessor procHosts = new VelocityProcessor("/de/hsadmin/mods/pac/hosts.vm", h, "/tmp/etc-hosts", true);
|
|
||||||
VelocityProcessor procVirtual = new VelocityProcessor("/de/hsadmin/mods/pac/httpd-virtual.vm", h, "/tmp/httpd-virtual.conf", true);
|
|
||||||
VelocityProcessor procInterfaces = new VelocityProcessor("/de/hsadmin/mods/pac/interfaces.vm", h, "/tmp/net-interfaces", true);
|
|
||||||
VelocityProcessor procProFtpd = new VelocityProcessor("/de/hsadmin/mods/pac/proftpd-conf.vm", h, "/tmp/proftpd.conf", true);
|
|
||||||
VelocityProcessor procSudoers = new VelocityProcessor("/de/hsadmin/mods/pac/sudoers.vm", h, "/tmp/sudoers", true);
|
|
||||||
try {
|
|
||||||
System.out.println(procHosts.process());
|
|
||||||
System.out.println(procVirtual.process());
|
|
||||||
System.out.println(procInterfaces.process());
|
|
||||||
System.out.println(procProFtpd.process());
|
|
||||||
System.out.println(procSudoers.process());
|
|
||||||
} catch (ProcessorException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import de.hsadmin.core.model.Transaction;
|
|||||||
|
|
||||||
public class WaitingTasksProcessor extends AbstractProcessor {
|
public class WaitingTasksProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1198528557513957546L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Processor main;
|
private Processor main;
|
||||||
private List<WaitingProcessor> waitingTasks;
|
private List<WaitingProcessor> waitingTasks;
|
||||||
@ -24,8 +24,7 @@ public class WaitingTasksProcessor extends AbstractProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finalize(Transaction transaction, QueueTask task)
|
public void finalize(Transaction transaction, QueueTask task) throws ProcessorException {
|
||||||
throws ProcessorException {
|
|
||||||
if (task.getException() == null) {
|
if (task.getException() == null) {
|
||||||
for (WaitingProcessor p : waitingTasks) {
|
for (WaitingProcessor p : waitingTasks) {
|
||||||
QueueTask wTask =
|
QueueTask wTask =
|
||||||
@ -61,4 +60,9 @@ public class WaitingTasksProcessor extends AbstractProcessor {
|
|||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String logInfo() {
|
||||||
|
return main.logInfo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,89 +0,0 @@
|
|||||||
package de.hsadmin.mods.db;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.hsadmin.core.qserv.AbstractProcessor;
|
|
||||||
import de.hsadmin.core.qserv.ProcessorException;
|
|
||||||
import de.hsadmin.core.util.Config;
|
|
||||||
|
|
||||||
public class JDBCProcessor extends AbstractProcessor {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 7702753017749022325L;
|
|
||||||
|
|
||||||
private String driver;
|
|
||||||
private String url;
|
|
||||||
private String user;
|
|
||||||
private String password;
|
|
||||||
private List<String> sql;
|
|
||||||
|
|
||||||
public JDBCProcessor(String driver, String url, String user, String password) {
|
|
||||||
this.driver = driver;
|
|
||||||
this.url = url;
|
|
||||||
this.user = user;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JDBCProcessor(String driver, String url) {
|
|
||||||
this.driver = driver;
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSQL(String sqlStatement) {
|
|
||||||
if (sql == null)
|
|
||||||
sql = new ArrayList<String>();
|
|
||||||
sql.add(sqlStatement);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object process() throws ProcessorException {
|
|
||||||
Connection c = null;
|
|
||||||
Config config = Config.getInstance();
|
|
||||||
if ("com.mysql.jdbc.Driver".equals(driver)) {
|
|
||||||
if (user == null)
|
|
||||||
user = config.getProperty("mysqladmin.user", "root");
|
|
||||||
if (password == null)
|
|
||||||
password = config.getProperty("mysqladmin.password");
|
|
||||||
}
|
|
||||||
if ("org.postgresql.Driver".equals(driver)) {
|
|
||||||
if (user == null)
|
|
||||||
user = config.getProperty("pgsqladmin.user", "postgres");
|
|
||||||
if (password == null)
|
|
||||||
password = config.getProperty("pgsqladmin.password");
|
|
||||||
}
|
|
||||||
if (user == null || password == null) {
|
|
||||||
throw new ProcessorException("database admin-user configuration failed");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Class.forName(driver);
|
|
||||||
c = DriverManager.getConnection(url, user, password);
|
|
||||||
if (c == null)
|
|
||||||
throw new ProcessorException("cannot connect to '" + url + "'");
|
|
||||||
Statement s = c.createStatement();
|
|
||||||
for (String sqlStatement : sql) {
|
|
||||||
s.addBatch(sqlStatement);
|
|
||||||
System.out.println("SQL: " + sqlStatement);
|
|
||||||
}
|
|
||||||
return s.executeBatch();
|
|
||||||
} catch (SQLException aSqlExc) {
|
|
||||||
Exception exc = aSqlExc.getNextException();
|
|
||||||
if (exc == null)
|
|
||||||
exc = aSqlExc;
|
|
||||||
System.out.println("ERR: " + exc.getMessage());
|
|
||||||
throw new ProcessorException(aSqlExc.getMessage() + ", reason: "
|
|
||||||
+ exc.getMessage());
|
|
||||||
} catch (Exception aExc) {
|
|
||||||
throw new ProcessorException(aExc.getMessage());
|
|
||||||
} finally {
|
|
||||||
if (c != null) {
|
|
||||||
try {
|
|
||||||
c.close();
|
|
||||||
} catch (Exception exc) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,72 +4,59 @@ import javax.persistence.EntityManager;
|
|||||||
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
|
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||||
import de.hsadmin.core.qserv.Processor;
|
import de.hsadmin.core.qserv.Processor;
|
||||||
|
|
||||||
/** Factory class which creates Processor instances for dealing with UNIX user accounts.
|
/**
|
||||||
|
* Factory class which creates Processor instances for dealing with UNIX user
|
||||||
|
* accounts.
|
||||||
*
|
*
|
||||||
* @author mi
|
* @author mi
|
||||||
*/
|
*/
|
||||||
public class MySqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
public class MySqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
||||||
/// creates a JDBCProcessor for MySQL and the given user
|
public static JDBCProcessor createMySqlProcessor(String database,
|
||||||
public static JDBCProcessor createMySqlProcessor( String database, String user, String password )
|
String user, String password) {
|
||||||
{
|
return new JDBCProcessor("com.mysql.jdbc.Driver",
|
||||||
return new JDBCProcessor( "com.mysql.jdbc.Driver",
|
"jdbc:mysql://localhost/" + database, user, password);
|
||||||
"jdbc:mysql://localhost/" + database,
|
|
||||||
user, password );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// creates a JDBCProcessor for the MySQL admin user
|
public static JDBCProcessor createMySqlAdminProcessor() {
|
||||||
public static JDBCProcessor createMySqlAdminProcessor()
|
return new JDBCProcessor("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/");
|
||||||
{
|
|
||||||
return new JDBCProcessor( "com.mysql.jdbc.Driver", "jdbc:mysql://localhost/" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return a Processor which creates a new database
|
public <T extends AbstractEntity> Processor createCreateProcessor(
|
||||||
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity)
|
EntityManager em, T entity) {
|
||||||
{
|
|
||||||
Database db = (Database) entity;
|
Database db = (Database) entity;
|
||||||
assert db.getInstance().equals("mysql");
|
assert db.getInstance().equals("mysql");
|
||||||
|
|
||||||
JDBCProcessor aJDBCP = null;
|
JDBCProcessor aJDBCP = null;
|
||||||
String aName = AbstractEntity.escapeString( db.getName() );
|
String aName = AbstractEntity.escapeString(db.getName());
|
||||||
String aOwner = AbstractEntity.escapeString( db.getOwner() );
|
String aOwner = AbstractEntity.escapeString(db.getOwner());
|
||||||
String aEncoding = AbstractEntity.escapeString( db.getSystemEncoding() );
|
String aEncoding = AbstractEntity.escapeString(db.getSystemEncoding());
|
||||||
aJDBCP = createMySqlAdminProcessor();
|
aJDBCP = createMySqlAdminProcessor();
|
||||||
aJDBCP.addSQL( "CREATE DATABASE " + aName + " " +
|
aJDBCP.addSQL("CREATE DATABASE " + aName + " DEFAULT CHARACTER SET '" + aEncoding + "'");
|
||||||
"DEFAULT CHARACTER SET '" + aEncoding + "'");
|
aJDBCP.addSQL("GRANT ALL ON " + aName + ".* TO '" + aOwner + "'@'%' WITH GRANT OPTION");
|
||||||
aJDBCP.addSQL( "GRANT ALL ON " + aName + ".* TO '" + aOwner + "'@'%' WITH GRANT OPTION" );
|
|
||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return a Processor which updates a preexisting database
|
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
|
||||||
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity)
|
|
||||||
{
|
|
||||||
Database db = (Database) entity;
|
Database db = (Database) entity;
|
||||||
assert db.getInstance().equals("mysql");
|
assert db.getInstance().equals("mysql");
|
||||||
|
String aName = AbstractEntity.escapeString(db.getName());
|
||||||
String aName = AbstractEntity.escapeString( db.getName() );
|
String aOwner = AbstractEntity.escapeString(db.getOwner());
|
||||||
String aOwner = AbstractEntity.escapeString( db.getOwner() );
|
|
||||||
// String aEncoding = AbstractEntity.escapeString( db.getSystemEncoding() );
|
|
||||||
JDBCProcessor aJDBCP = null;
|
JDBCProcessor aJDBCP = null;
|
||||||
aJDBCP = createMySqlAdminProcessor();
|
aJDBCP = createMySqlAdminProcessor();
|
||||||
// aJDBCP.addSQL( "ALTER DATABASE " + aName + " DEFAULT CHARACTER SET '" + aEncoding + "'" );
|
aJDBCP.addSQL("GRANT ALL ON " + aName + ".* TO '" + aOwner + "'@'%'");
|
||||||
aJDBCP.addSQL( "GRANT ALL ON " + aName + ".* TO '" + aOwner + "'@'%'" );
|
|
||||||
// TODO: alte Admin-Rechte entziehen
|
|
||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return a Processor which deletes an existing database
|
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
|
||||||
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity)
|
|
||||||
{
|
|
||||||
Database db = (Database) entity;
|
Database db = (Database) entity;
|
||||||
assert db.getInstance().equals("mysql");
|
assert db.getInstance().equals("mysql");
|
||||||
|
|
||||||
JDBCProcessor aJDBCP = createMySqlAdminProcessor();
|
JDBCProcessor aJDBCP = createMySqlAdminProcessor();
|
||||||
String aName = AbstractEntity.escapeString( db.getName() );
|
String aName = AbstractEntity.escapeString(db.getName());
|
||||||
String aOwner = AbstractEntity.escapeString( db.getOwner() );
|
String aOwner = AbstractEntity.escapeString(db.getOwner());
|
||||||
aJDBCP.addSQL( "REVOKE ALL ON " + aName + ".* FROM '" + aOwner + "'@'%'" );
|
aJDBCP.addSQL("REVOKE ALL ON " + aName + ".* FROM '" + aOwner + "'@'%'");
|
||||||
aJDBCP.addSQL( "DROP DATABASE " + aName );
|
aJDBCP.addSQL("DROP DATABASE " + aName);
|
||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import javax.persistence.EntityManager;
|
|||||||
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
|
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||||
import de.hsadmin.core.qserv.Processor;
|
import de.hsadmin.core.qserv.Processor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,8 +25,7 @@ public class MySqlUserProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createUpdateProcessor(
|
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
|
||||||
EntityManager em, T entity) {
|
|
||||||
DatabaseUser dbu = (DatabaseUser) entity;
|
DatabaseUser dbu = (DatabaseUser) entity;
|
||||||
assert dbu.getInstance().equals("mysql");
|
assert dbu.getInstance().equals("mysql");
|
||||||
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
||||||
@ -35,11 +35,9 @@ public class MySqlUserProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createDeleteProcessor(
|
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
|
||||||
EntityManager em, T entity) {
|
|
||||||
DatabaseUser dbu = (DatabaseUser) entity;
|
DatabaseUser dbu = (DatabaseUser) entity;
|
||||||
assert dbu.getInstance().equals("mysql");
|
assert dbu.getInstance().equals("mysql");
|
||||||
|
|
||||||
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
||||||
String aName = AbstractEntity.escapeString(dbu.getName());
|
String aName = AbstractEntity.escapeString(dbu.getName());
|
||||||
aJDBCP.addSQL("REVOKE ALL PRIVILEGES, GRANT OPTION FROM '" + aName + "'@'%'");
|
aJDBCP.addSQL("REVOKE ALL PRIVILEGES, GRANT OPTION FROM '" + aName + "'@'%'");
|
||||||
|
@ -4,6 +4,7 @@ import javax.persistence.EntityManager;
|
|||||||
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
|
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||||
import de.hsadmin.core.qserv.Processor;
|
import de.hsadmin.core.qserv.Processor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,6 +14,7 @@ import de.hsadmin.core.qserv.Processor;
|
|||||||
* @author mi
|
* @author mi
|
||||||
*/
|
*/
|
||||||
public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a JDBCProcessor for PostgreSQL and the given user
|
* creates a JDBCProcessor for PostgreSQL and the given user
|
||||||
*
|
*
|
||||||
@ -21,8 +23,7 @@ public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static JDBCProcessor createPostgreSqlProcessor(String user, String password) {
|
public static JDBCProcessor createPostgreSqlProcessor(String user, String password) {
|
||||||
return new JDBCProcessor("org.postgresql.Driver",
|
return new JDBCProcessor("org.postgresql.Driver", "jdbc:postgresql://localhost/template1", user, password);
|
||||||
"jdbc:postgresql://localhost/template1", user, password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ import javax.persistence.EntityManager;
|
|||||||
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
|
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||||
import de.hsadmin.core.qserv.Processor;
|
import de.hsadmin.core.qserv.Processor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,8 +25,7 @@ public class PgSqlUserProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createUpdateProcessor(
|
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
|
||||||
EntityManager em, T entity) {
|
|
||||||
DatabaseUser dbu = (DatabaseUser) entity;
|
DatabaseUser dbu = (DatabaseUser) entity;
|
||||||
assert dbu.getInstance().equals("pgsql");
|
assert dbu.getInstance().equals("pgsql");
|
||||||
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
||||||
@ -35,8 +35,7 @@ public class PgSqlUserProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createDeleteProcessor(
|
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
|
||||||
EntityManager em, T entity) {
|
|
||||||
DatabaseUser dbu = (DatabaseUser) entity;
|
DatabaseUser dbu = (DatabaseUser) entity;
|
||||||
assert dbu.getInstance().equals("pgsql");
|
assert dbu.getInstance().equals("pgsql");
|
||||||
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
||||||
|
Loading…
Reference in New Issue
Block a user