parent
0cc09fba29
commit
bdde4368c4
@ -5,7 +5,7 @@ import java.util.List;
|
||||
|
||||
public class CompoundProcessor extends AbstractProcessor {
|
||||
|
||||
private static final long serialVersionUID = 5718623579674305929L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private List<Processor> aProcessors;
|
||||
|
||||
@ -26,5 +26,15 @@ public class CompoundProcessor extends AbstractProcessor {
|
||||
public void appendProcessor(Processor 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 {
|
||||
|
||||
private static final long serialVersionUID = 1741419610410712714L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Processor internal;
|
||||
|
||||
@ -19,4 +19,9 @@ public class CopyFileProcessor extends AbstractProcessor {
|
||||
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 {
|
||||
|
||||
private static final long serialVersionUID = -2947609532975712444L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Processor compoundProcessor;
|
||||
|
||||
@ -35,4 +35,9 @@ public class CreateFileProcessor extends AbstractProcessor {
|
||||
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 {
|
||||
|
||||
private static final long serialVersionUID = 7702753017749022325L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String driver;
|
||||
private String url;
|
||||
private String user;
|
||||
private String password;
|
||||
private List<String> sql;
|
||||
private String errorMsg;
|
||||
|
||||
public JDBCProcessor(String driver, String url, String user, String password) {
|
||||
this.driver = driver;
|
||||
this.url = url;
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
this.errorMsg = "";
|
||||
}
|
||||
|
||||
public JDBCProcessor(String driver, String url) {
|
||||
@ -70,11 +72,12 @@ public class JDBCProcessor extends AbstractProcessor {
|
||||
return s.executeBatch();
|
||||
} catch (SQLException aSqlExc) {
|
||||
Exception exc = aSqlExc.getNextException();
|
||||
if (exc == null)
|
||||
if (exc == null) {
|
||||
exc = aSqlExc;
|
||||
System.out.println("ERR: " + exc.getMessage());
|
||||
throw new ProcessorException(aSqlExc.getMessage() + ", reason: "
|
||||
+ exc.getMessage());
|
||||
}
|
||||
errorMsg = exc.getMessage();
|
||||
System.out.println("ERR: " + errorMsg);
|
||||
throw new ProcessorException(aSqlExc.getMessage() + ", reason: " + errorMsg);
|
||||
} catch (Exception aExc) {
|
||||
throw new ProcessorException(aExc.getMessage());
|
||||
} 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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.InitialContext;
|
||||
|
||||
public class QueueServer extends QueueCommons implements
|
||||
MessageListener, ExceptionListener {
|
||||
public class QueueServer extends QueueCommons implements 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 QueueSession queueSession;
|
||||
private String jmsStatusQueue;
|
||||
@ -38,14 +36,16 @@ public class QueueServer extends QueueCommons implements
|
||||
private String jmsSystemQueue;
|
||||
private String jmsFactory;
|
||||
|
||||
private String serviceEMail;
|
||||
|
||||
/** 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)
|
||||
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(
|
||||
"Wrong number of arguments.\n"
|
||||
@ -78,17 +78,13 @@ public class QueueServer extends QueueCommons implements
|
||||
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.email.service"));
|
||||
System.out.println("==================================================");
|
||||
System.out.println("hsadmin-qserv " + VERSION_NO +
|
||||
" started using:");
|
||||
System.out.println("queue server: "
|
||||
+ props.getProperty("hsadmin.jms.factory"));
|
||||
System.out.println("system queue: "
|
||||
+ 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("hsadmin-qserv " + VERSION_NO + " started using:");
|
||||
System.out.println("queue server: " + props.getProperty("hsadmin.jms.factory"));
|
||||
System.out.println("system queue: " + 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("==================================================");
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@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() {
|
||||
// create JMS connection and session
|
||||
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) {
|
||||
// TODO logging
|
||||
System.out.println("\nonMessage(" + jmsMessage);
|
||||
QueueTask task = null;
|
||||
try {
|
||||
// expect ObjectMessage
|
||||
ObjectMessage jmsObjectMessage = (ObjectMessage) jmsMessage;
|
||||
|
||||
// get QueueTask
|
||||
task = (QueueTask) jmsObjectMessage.getObject();
|
||||
|
||||
// TODO: logging
|
||||
Processor processor = task.getProcessor();
|
||||
System.out.println("processing (" + task.getTitle() + " | started("
|
||||
+ task.getStarted() + ") |" + task.getDetails() + "|"
|
||||
+ task.getProcessor() + ")");
|
||||
System.out.println("with " + task.getProcessor());
|
||||
// execute processor within the message
|
||||
task.getProcessor().process();
|
||||
System.out.println("done");
|
||||
+ processor + ")");
|
||||
System.out.println("with " + processor);
|
||||
try {
|
||||
processor.process();
|
||||
System.out.println("done");
|
||||
} catch (ProcessorException e) {
|
||||
logException(e);
|
||||
task.setException(e);
|
||||
SmtpHelper.send("queueserv@hostsharing.net", serviceEMail, jmsSystemQueue, processor.logInfo());
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
logException(throwable);
|
||||
task.setException(throwable);
|
||||
} finally {
|
||||
sendStatus(task);
|
||||
setNMessagesProcessed(getNMessagesProcessed() + 1);
|
||||
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) {
|
||||
MessageProducer producer = null;
|
||||
Session statusSession = null;
|
||||
@ -199,8 +201,7 @@ public class QueueServer extends QueueCommons implements
|
||||
Context ctx = new InitialContext();
|
||||
System.out.println("Created InitialContext");
|
||||
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup(jmsFactory);
|
||||
System.out.println("connectionFactory= "
|
||||
+ connectionFactory.toString());
|
||||
System.out.println("connectionFactory= " + connectionFactory.toString());
|
||||
Destination queue = (Destination) ctx.lookup(jmsStatusQueue);
|
||||
statusConnection = connectionFactory.createConnection(jmsUserName, jmsPassWord);
|
||||
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) {
|
||||
jmsStatusQueue = property;
|
||||
}
|
||||
|
@ -3,14 +3,12 @@ package de.hsadmin.core.qserv;
|
||||
|
||||
/**
|
||||
* A ShellProcessor encapsulates a shell command as a Processor.
|
||||
*
|
||||
* As such, a client can prepare shell commands to be processed on a server.
|
||||
*
|
||||
* @author mi
|
||||
*/
|
||||
public class ShellProcessor extends AbstractProcessor {
|
||||
|
||||
private static final long serialVersionUID = -649045174380048818L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String aSystemCall;
|
||||
private String aInput;
|
||||
@ -27,6 +25,7 @@ public class ShellProcessor extends AbstractProcessor {
|
||||
this.aInput = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object process() throws ProcessorException {
|
||||
try {
|
||||
aOutput = CommandShell.execute(aSystemCall, aInput);
|
||||
@ -38,18 +37,14 @@ public class ShellProcessor extends AbstractProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns stderr as a String.
|
||||
*/
|
||||
public String getErrors() {
|
||||
return aErrors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns stdout as a String.
|
||||
*/
|
||||
public String getOutput() {
|
||||
return aOutput;
|
||||
@Override
|
||||
public String logInfo() {
|
||||
StringBuffer log = new StringBuffer("ShellProcessor\n");
|
||||
log.append(aSystemCall);
|
||||
log.append("\nError: ");
|
||||
log.append(aErrors);
|
||||
log.append("\n");
|
||||
return log.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@ -15,14 +14,12 @@ import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
|
||||
import de.hsadmin.mods.dom.Domain;
|
||||
import de.hsadmin.mods.pac.BasePac;
|
||||
import de.hsadmin.mods.pac.Hive;
|
||||
import de.hsadmin.mods.pac.INetAddress;
|
||||
import de.hsadmin.mods.pac.Pac;
|
||||
|
||||
public class VelocityProcessor extends AbstractProcessor {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
static {
|
||||
Properties props = new Properties();
|
||||
@ -34,8 +31,10 @@ public class VelocityProcessor extends AbstractProcessor {
|
||||
private String content;
|
||||
private String targetPath;
|
||||
private boolean overwriteTarget;
|
||||
private String errorMessage;
|
||||
|
||||
public VelocityProcessor(String templateName, Hive hive, String targetPath, boolean overwriteTarget) {
|
||||
errorMessage = "";
|
||||
this.targetPath = targetPath;
|
||||
this.overwriteTarget = overwriteTarget;
|
||||
VelocityContext context = new VelocityContext();
|
||||
@ -99,46 +98,34 @@ public class VelocityProcessor extends AbstractProcessor {
|
||||
try {
|
||||
File file = new File(targetPath);
|
||||
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()) {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
||||
writer.append(content);
|
||||
writer.close();
|
||||
} else {
|
||||
throw new ProcessorException("could not write file " + targetPath);
|
||||
errorMessage = "could not write file " + targetPath;
|
||||
throw new ProcessorException(errorMessage);
|
||||
}
|
||||
return "wrote file " + targetPath;
|
||||
} catch (IOException e) {
|
||||
errorMessage = e.getMessage();
|
||||
throw new ProcessorException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Hive h = new Hive("h01", new INetAddress("192.168.1.100"));
|
||||
HashSet<Pac> pacsSet = new HashSet<Pac>();
|
||||
h.setPacs(pacsSet);
|
||||
Pac p1 = new Pac("pac01", null, new BasePac(), h);
|
||||
pacsSet.add(p1);
|
||||
Pac p2 = new Pac("pac02", null, new BasePac(), h);
|
||||
pacsSet.add(p2);
|
||||
p1.setCurINetAddr(new INetAddress("192.168.2.11"));
|
||||
p2.setCurINetAddr(new INetAddress("192.168.2.12"));
|
||||
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();
|
||||
}
|
||||
@Override
|
||||
public String logInfo() {
|
||||
StringBuffer log = new StringBuffer("VelocityProcessor\n");
|
||||
log.append("Target: ");
|
||||
log.append(targetPath);
|
||||
log.append("\n");
|
||||
log.append("Error: ");
|
||||
log.append(errorMessage);
|
||||
log.append("\n");
|
||||
return log.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import de.hsadmin.core.model.Transaction;
|
||||
|
||||
public class WaitingTasksProcessor extends AbstractProcessor {
|
||||
|
||||
private static final long serialVersionUID = 1198528557513957546L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Processor main;
|
||||
private List<WaitingProcessor> waitingTasks;
|
||||
@ -24,8 +24,7 @@ public class WaitingTasksProcessor extends AbstractProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finalize(Transaction transaction, QueueTask task)
|
||||
throws ProcessorException {
|
||||
public void finalize(Transaction transaction, QueueTask task) throws ProcessorException {
|
||||
if (task.getException() == null) {
|
||||
for (WaitingProcessor p : waitingTasks) {
|
||||
QueueTask wTask =
|
||||
@ -61,4 +60,9 @@ public class WaitingTasksProcessor extends AbstractProcessor {
|
||||
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.qserv.EntityProcessorFactory;
|
||||
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||
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
|
||||
*/
|
||||
*/
|
||||
public class MySqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
||||
/// creates a JDBCProcessor for MySQL and the given user
|
||||
public static JDBCProcessor createMySqlProcessor( String database, String user, String password )
|
||||
{
|
||||
return new JDBCProcessor( "com.mysql.jdbc.Driver",
|
||||
"jdbc:mysql://localhost/" + database,
|
||||
user, password );
|
||||
public static JDBCProcessor createMySqlProcessor(String database,
|
||||
String user, String password) {
|
||||
return new JDBCProcessor("com.mysql.jdbc.Driver",
|
||||
"jdbc:mysql://localhost/" + database, user, password);
|
||||
}
|
||||
|
||||
/// creates a JDBCProcessor for the MySQL admin user
|
||||
public static JDBCProcessor createMySqlAdminProcessor()
|
||||
{
|
||||
return new JDBCProcessor( "com.mysql.jdbc.Driver", "jdbc:mysql://localhost/" );
|
||||
public static JDBCProcessor createMySqlAdminProcessor() {
|
||||
return new JDBCProcessor("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/");
|
||||
}
|
||||
|
||||
/// @return a Processor which creates a new database
|
||||
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity)
|
||||
{
|
||||
|
||||
public <T extends AbstractEntity> Processor createCreateProcessor(
|
||||
EntityManager em, T entity) {
|
||||
Database db = (Database) entity;
|
||||
assert db.getInstance().equals("mysql");
|
||||
|
||||
JDBCProcessor aJDBCP = null;
|
||||
String aName = AbstractEntity.escapeString( db.getName() );
|
||||
String aOwner = AbstractEntity.escapeString( db.getOwner() );
|
||||
String aEncoding = AbstractEntity.escapeString( db.getSystemEncoding() );
|
||||
String aName = AbstractEntity.escapeString(db.getName());
|
||||
String aOwner = AbstractEntity.escapeString(db.getOwner());
|
||||
String aEncoding = AbstractEntity.escapeString(db.getSystemEncoding());
|
||||
aJDBCP = createMySqlAdminProcessor();
|
||||
aJDBCP.addSQL( "CREATE DATABASE " + aName + " " +
|
||||
"DEFAULT CHARACTER SET '" + aEncoding + "'");
|
||||
aJDBCP.addSQL( "GRANT ALL ON " + aName + ".* TO '" + aOwner + "'@'%' WITH GRANT OPTION" );
|
||||
aJDBCP.addSQL("CREATE DATABASE " + aName + " DEFAULT CHARACTER SET '" + aEncoding + "'");
|
||||
aJDBCP.addSQL("GRANT ALL ON " + aName + ".* TO '" + aOwner + "'@'%' WITH GRANT OPTION");
|
||||
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;
|
||||
assert db.getInstance().equals("mysql");
|
||||
|
||||
String aName = AbstractEntity.escapeString( db.getName() );
|
||||
String aOwner = AbstractEntity.escapeString( db.getOwner() );
|
||||
// String aEncoding = AbstractEntity.escapeString( db.getSystemEncoding() );
|
||||
String aName = AbstractEntity.escapeString(db.getName());
|
||||
String aOwner = AbstractEntity.escapeString(db.getOwner());
|
||||
JDBCProcessor aJDBCP = null;
|
||||
aJDBCP = createMySqlAdminProcessor();
|
||||
// aJDBCP.addSQL( "ALTER DATABASE " + aName + " DEFAULT CHARACTER SET '" + aEncoding + "'" );
|
||||
aJDBCP.addSQL( "GRANT ALL ON " + aName + ".* TO '" + aOwner + "'@'%'" );
|
||||
// TODO: alte Admin-Rechte entziehen
|
||||
aJDBCP.addSQL("GRANT ALL ON " + aName + ".* TO '" + aOwner + "'@'%'");
|
||||
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;
|
||||
assert db.getInstance().equals("mysql");
|
||||
|
||||
JDBCProcessor aJDBCP = createMySqlAdminProcessor();
|
||||
String aName = AbstractEntity.escapeString( db.getName() );
|
||||
String aOwner = AbstractEntity.escapeString( db.getOwner() );
|
||||
aJDBCP.addSQL( "REVOKE ALL ON " + aName + ".* FROM '" + aOwner + "'@'%'" );
|
||||
aJDBCP.addSQL( "DROP DATABASE " + aName );
|
||||
String aName = AbstractEntity.escapeString(db.getName());
|
||||
String aOwner = AbstractEntity.escapeString(db.getOwner());
|
||||
aJDBCP.addSQL("REVOKE ALL ON " + aName + ".* FROM '" + aOwner + "'@'%'");
|
||||
aJDBCP.addSQL("DROP DATABASE " + aName);
|
||||
return aJDBCP;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import javax.persistence.EntityManager;
|
||||
|
||||
import de.hsadmin.core.model.AbstractEntity;
|
||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||
import de.hsadmin.core.qserv.Processor;
|
||||
|
||||
/**
|
||||
@ -24,8 +25,7 @@ public class MySqlUserProcessorFactory implements EntityProcessorFactory {
|
||||
return aJDBCP;
|
||||
}
|
||||
|
||||
public <T extends AbstractEntity> Processor createUpdateProcessor(
|
||||
EntityManager em, T entity) {
|
||||
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
|
||||
DatabaseUser dbu = (DatabaseUser) entity;
|
||||
assert dbu.getInstance().equals("mysql");
|
||||
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
||||
@ -35,11 +35,9 @@ public class MySqlUserProcessorFactory implements EntityProcessorFactory {
|
||||
return aJDBCP;
|
||||
}
|
||||
|
||||
public <T extends AbstractEntity> Processor createDeleteProcessor(
|
||||
EntityManager em, T entity) {
|
||||
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
|
||||
DatabaseUser dbu = (DatabaseUser) entity;
|
||||
assert dbu.getInstance().equals("mysql");
|
||||
|
||||
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
||||
String aName = AbstractEntity.escapeString(dbu.getName());
|
||||
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.qserv.EntityProcessorFactory;
|
||||
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||
import de.hsadmin.core.qserv.Processor;
|
||||
|
||||
/**
|
||||
@ -13,6 +14,7 @@ import de.hsadmin.core.qserv.Processor;
|
||||
* @author mi
|
||||
*/
|
||||
public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
||||
|
||||
/**
|
||||
* creates a JDBCProcessor for PostgreSQL and the given user
|
||||
*
|
||||
@ -21,8 +23,7 @@ public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
||||
* @return
|
||||
*/
|
||||
public static JDBCProcessor createPostgreSqlProcessor(String user, String password) {
|
||||
return new JDBCProcessor("org.postgresql.Driver",
|
||||
"jdbc:postgresql://localhost/template1", user, password);
|
||||
return new JDBCProcessor("org.postgresql.Driver", "jdbc:postgresql://localhost/template1", user, password);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@ import javax.persistence.EntityManager;
|
||||
|
||||
import de.hsadmin.core.model.AbstractEntity;
|
||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||
import de.hsadmin.core.qserv.Processor;
|
||||
|
||||
/**
|
||||
@ -24,8 +25,7 @@ public class PgSqlUserProcessorFactory implements EntityProcessorFactory {
|
||||
return aJDBCP;
|
||||
}
|
||||
|
||||
public <T extends AbstractEntity> Processor createUpdateProcessor(
|
||||
EntityManager em, T entity) {
|
||||
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
|
||||
DatabaseUser dbu = (DatabaseUser) entity;
|
||||
assert dbu.getInstance().equals("pgsql");
|
||||
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
||||
@ -35,8 +35,7 @@ public class PgSqlUserProcessorFactory implements EntityProcessorFactory {
|
||||
return aJDBCP;
|
||||
}
|
||||
|
||||
public <T extends AbstractEntity> Processor createDeleteProcessor(
|
||||
EntityManager em, T entity) {
|
||||
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
|
||||
DatabaseUser dbu = (DatabaseUser) entity;
|
||||
assert dbu.getInstance().equals("pgsql");
|
||||
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
||||
|
Loading…
Reference in New Issue
Block a user