Commit eeded591 authored by Yann Mombrun's avatar Yann Mombrun

Various cleanup

Remove useless code
Update javadoc only
Add loaded properties in debug log
Minor code style update
parent 17a54316
......@@ -43,6 +43,9 @@ import com.google.gson.JsonParser;
public class Fuseki extends WebLabServer {
/**
* The default constructor
*/
public Fuseki() {
// Nothing to do
}
......
......@@ -99,7 +99,7 @@ public class ProcessUtils {
}
}
Process process;
final Process process;
try {
process = pbuilder.start();
new StreamGobbler(logger, process.getErrorStream(), true).start();
......
......@@ -28,7 +28,6 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.ow2.weblab.bundle.conf.WebLabBean;
import org.ow2.weblab.bundle.server.TomcatServer;
import org.ow2.weblab.bundle.utils.manager.ProcessManager;
public class TomcatUtils {
......@@ -43,44 +42,6 @@ public class TomcatUtils {
}
/**
* Copy a tomcat and return the file to the new Tomcat
*
* @param source
* the Tomcat to copy
* @param dest
* where the Tomcat will be copied
* @param services
* list of services to copy
* @param logger
* the logger used inside
* @return file to the new Tomcat
* @throws IOException
* If an error occurs when copying, deleting or creating various files.
*/
public static File copy(final String source, final String dest, final List<String> services, final Log logger) throws IOException {
final File newTomcat = new File(dest);
FileUtils.copyDirectory(new File(source), newTomcat);
final File webappDir = new File(PathUtils.createPath(newTomcat.getAbsolutePath(), "webapps"));
// emptying the tomcat
FileUtils.deleteDirectory(webappDir);
if ((services != null) && !services.isEmpty()) {
for (final String service : services) {
FileUtils.copyDirectory(new File(PathUtils.createPath(source, "webapps", service)), new File(PathUtils.createPath(webappDir.getAbsolutePath(), service)));
}
}
// make script executables
final ProcessManager procManager = ProcessManager.getInstance();
procManager.setPermission(newTomcat.getAbsolutePath(), "755", true, logger);
return newTomcat;
}
/**
* Update Tomcat server ports and return a tomcatServer
*
......@@ -194,171 +155,4 @@ public class TomcatUtils {
return newOne;
}
/**
* Parse saved split configuration and return loaded tomcats
*
* @param original
* @param splitConfig
* @param logger
* @param configuration
* @return a tomcat manager
*/
public static MultiTomcatServer loadConfiguration(final TomcatServer original, final String splitConfig, final Log logger, final WebLabBean configuration) {
// load tomcats
final String[] confs = splitConfig.split("\n");
final List<TomcatServer> servers = new LinkedList<>();
for (final String conf : confs) {
if (!"".equals(conf)) {
final String[] data = conf.split(":");
final String name = data[0];
final int port = Integer.parseInt(data[1]);
final int jmxPort = Integer.parseInt(data[2]);
final String home = data[3];
final int shutdownPort = port - TomcatUtils.TO_SHUTDOWN;
final int redirPort = port - TomcatUtils.TO_REDIRECT;
servers.add(TomcatUtils.buildTomcat(original, name, home, port, jmxPort, shutdownPort, redirPort, logger, configuration));
}
}
return new MultiTomcatServer(original, servers, logger);
}
/**
* To manage multiple tomcat at once
*
* @author asaval
*
*/
public static class MultiTomcatServer extends TomcatServer {
private final TomcatServer original;
private final List<TomcatServer> servers;
public MultiTomcatServer(final TomcatServer original, final List<TomcatServer> servers, final Log logger) {
this.setName(original.getName());
this.original = original;
this.servers = servers;
}
public TomcatServer getOriginal() {
return this.original;
}
@Override
public Process start(final String command) {
final Process process = this.original.start(command);
// run others servers
for (final TomcatServer server : this.servers) {
server.start(command);
}
return process;
}
@Override
public Process stop(final String command) {
final Process process = this.original.stop(command);
// run others servers
for (final TomcatServer server : this.servers) {
server.stop(command);
}
return process;
}
@Override
public boolean becomeReadyOrDieTrying() {
boolean value = this.original.becomeReadyOrDieTrying();
// run others servers
for (final TomcatServer server : this.servers) {
value = value && server.becomeReadyOrDieTrying();
}
return value;
}
@Override
public State status() {
final State state = this.original.status();
for (final TomcatServer server : this.servers) {
server.status();
}
return state;
}
@Override
public File getServiceConfigurationFile(final String service, final String cxfFileName) {
// find on which tomcat this service is deployed and update its configuration
// start with generated server
for (final TomcatServer server : this.servers) {
if (TomcatUtils.listServices(server, this.logger).contains(service)) {
// return service conf
return server.getServiceConfigurationFile(service, cxfFileName);
}
}
// if not found update default server
return this.original.getServiceConfigurationFile(service, cxfFileName);
}
@Override
public String getSubDir(final String subDir) {
return this.original.getSubDir(subDir);
}
@Override
public String getBinDirectory() {
return this.original.getBinDirectory();
}
@Override
public int getTimeout() {
return this.original.getTimeout();
}
@Override
public boolean isEnabled() {
return this.original.isEnabled();
}
@Override
public int getPort() {
return this.original.getPort();
}
@Override
public int getJmxPort() {
return this.original.getJmxPort();
}
@Override
public int getPid() {
return this.original.getPid();
}
}
}
......@@ -59,6 +59,7 @@ public final class Utils {
* Utility class
*/
private Utils() {
}
......@@ -74,6 +75,7 @@ public final class Utils {
* @return true if the port is available, else false
*/
public static boolean isPortAvailable(final Log logger, final String host, final int port) {
boolean available = true;
try (final Socket socket = new Socket(host, port)) {
logger.debug("Port " + port + " is listening.");
......@@ -92,14 +94,22 @@ public final class Utils {
return available;
}
/**
* Load default properties or those configured in weblab.properties file
*
* @param logger
* The logger used to write the system properties loaded
*
* @return a set of properties
*/
public static WebLabBean loadConfiguration() {
public static WebLabBean loadConfiguration(final Log logger) {
// load configuration
try (final FileSystemXmlApplicationContext factory = new FileSystemXmlApplicationContext("file:" + PathUtils.getWebLabHome("conf") + "configuration.xml")) {
if (logger.isDebugEnabled()) {
logger.debug("Loaded system properties: " + factory.getEnvironment().getSystemProperties());
}
return factory.getBean("WebLab", WebLabBean.class);
}
}
......@@ -140,6 +150,7 @@ public final class Utils {
* @return the logger
*/
public static Log getLogger() {
return LogFactory.getLog("weblab.launcher");
}
......@@ -154,6 +165,7 @@ public final class Utils {
* @return the Server or null
*/
public static String getServer(final Log logger, final String[] args) {
if ((args == null) || (args.length < 2) || (args[1] == null)) {
logger.debug("Server selected : all");
return null;
......@@ -175,6 +187,7 @@ public final class Utils {
* The logger used inside
*/
public static void reinit(final Log logger) {
final int size = 75;
final BufferedImage image = new BufferedImage(size, 32, BufferedImage.TYPE_INT_RGB);
final Graphics graph = image.getGraphics();
......@@ -221,6 +234,7 @@ public final class Utils {
* @return true if webdav collection has been reset.
*/
public static boolean resetWebDav(final Log logger, final String webdavURL, final String user, final String password) {
boolean success = false;
try {
......@@ -259,11 +273,13 @@ public final class Utils {
* If any wrong occurs
*/
public static String httpRequest(final Log logger, final String anurl, final String method, final String user, final String password, final boolean verbose) throws Exception {
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
});
......@@ -299,6 +315,7 @@ public final class Utils {
* @return a String describing the array
*/
public static String arrayToString(final Object array) {
if (array instanceof int[]) {
return Arrays.toString((int[]) array);
} else if (array instanceof float[]) {
......
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://localhost:8181/exposed-configuration/spring-beans-3.0.xsd">
<!-- Define a bean by service -->
<bean id="folder-listener" class="org.ow2.weblab.bundle.server.Service">
<property name="wsdl" value="http://localhost:8181/folder-listener/folder-listener?wsdl" />
</bean>
<bean id="warc-listener" class="org.ow2.weblab.bundle.server.Service">
<property name="wsdl" value="http://localhost:8181/folder-listener/warc-listener?wsdl" />
</bean>
<bean id="tika-extractor" class="org.ow2.weblab.bundle.server.Service">
<property name="wsdl" value="http://localhost:8181/tika-normaliser/analyser?wsdl" />
</bean>
<bean id="gate-extractor" class="org.ow2.weblab.bundle.server.Service">
<property name="wsdl" value="http://localhost:8181/gate-extraction/analyser?wsdl" />
</bean>
<bean id="gazetteer-extractor" class="org.ow2.weblab.bundle.server.Service">
<property name="wsdl" value="http://localhost:8181/simple-gazetteer/simple-gazetteer?wsdl" />
</bean>
<bean id="ngramj-extractor" class="org.ow2.weblab.bundle.server.Service">
<property name="wsdl" value="http://localhost:8181/ngramj-language-extraction/analyser?wsdl" />
</bean>
<bean id="simple-repository" class="org.ow2.weblab.bundle.server.Service">
<property name="wsdl" value="http://localhost:8181/simple-file-repository/resourceContainer?wsdl" />
</bean>
<bean id="solr-indexer" class="org.ow2.weblab.bundle.server.Service">
<property name="wsdl" value="http://localhost:8181/solr-engine/indexer?wsdl" />
</bean>
<bean id="solr-searcher" class="org.ow2.weblab.bundle.server.Service">
<property name="wsdl" value="http://localhost:8181/solr-engine/searcher?wsdl" />
</bean>
<bean id="solr-suggester" class="org.ow2.weblab.bundle.server.Service">
<property name="wsdl" value="http://localhost:8181/solr-engine/spellSuggestion?wsdl" />
</bean>
<!-- Set of services used in chains -->
<bean id="Services" class="java.util.HashSet">
<constructor-arg>
<set>
<ref bean="folder-listener"/>
<ref bean="warc-listener"/>
<ref bean="tika-extractor"/>
<ref bean="gate-extractor"/>
<ref bean="gazetteer-extractor"/>
<ref bean="ngramj-extractor"/>
<ref bean="simple-repository"/>
<ref bean="solr-indexer"/>
<ref bean="solr-searcher"/>
</set>
</constructor-arg>
</bean>
<!-- Set of services acting as consumers -->
<bean id="Consumers" class="java.util.HashSet">
<constructor-arg>
<set>
<bean id="solr-searcher-consumer" class="org.ow2.weblab.bundle.server.Consumer">
<property name="service"><ref bean="solr-searcher"/></property>
<property name="operationNS" value="http://weblab.ow2.org/core/1.2/services/searcher" />
<property name="operation" value="search" />
<property name="serviceName" value="weblab-demo-search" />
</bean>
<bean id="solr-suggester-consumer" class="org.ow2.weblab.bundle.server.Consumer">
<property name="service"><ref bean="solr-suggester"/></property>
<property name="operationNS" value="http://weblab.ow2.org/core/1.2/services/suggester" />
<property name="operation" value="process" />
<property name="serviceName" value="weblab-suggester" />
</bean>
<bean id="simple-repository-consumer" class="org.ow2.weblab.bundle.server.Consumer">
<property name="service"><ref bean="simple-repository"/></property>
<property name="operationNS" value="http://weblab.ow2.org/core/1.2/services/resourcecontainer" />
<property name="operation" value="loadResource" />
<property name="serviceName" value="weblab-repository" />
</bean>
</set>
</constructor-arg>
</bean>
<!-- This will split a resource through several analyser and merge results -->
<bean id="split" class="org.ow2.weblab.bundle.server.Split">
<property name="services">
<set>
<ref bean="gazetteer-extractor"/>
<ref bean="gate-sequence"/>
</set>
</property>
</bean>
<!-- This will process a resource a list of analyser in the given order -->
<bean id="gate-sequence" class="org.ow2.weblab.bundle.server.Sequence">
<property name="services">
<list>
<ref bean="ngramj-extractor"/>
<ref bean="gate-extractor"/>
</list>
</property>
</bean>
<bean id="files" class="org.ow2.weblab.bundle.server.Chain">
<property name="queuemanager"><ref bean="folder-listener"/></property>
<property name="normalizers"><ref bean="tika-extractor"/></property>
<property name="analysers"><ref bean="split"/></property>
<property name="repositories"><ref bean="simple-repository"/></property>
<property name="indexers"><ref bean="solr-indexer"/></property>
</bean>
<bean id="warcs" class="org.ow2.weblab.bundle.server.Chain">
<property name="queuemanager"><ref bean="warc-listener"/></property>
<property name="normalizers"><ref bean="tika-extractor"/></property>
<property name="analysers"><ref bean="split"/></property>
<property name="repositories"><ref bean="simple-repository"/></property>
<property name="indexers"><ref bean="solr-indexer"/></property>
</bean>
<bean id="chain-manager" class="java.util.HashMap">
<constructor-arg>
<map>
<entry key="files"><ref bean="files"/></entry>
<entry key="warcs"><ref bean="warcs"/></entry>
</map>
</constructor-arg>
</bean>
</beans>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment