Commit 4e9c087f authored by Yann Mombrun's avatar Yann Mombrun

Fix #9 Addd host configuration

When a server is started to only listen to its named host, it was not
possible to connect to it. Now a new host property is available
parent efcefda2
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2017 Airbus Defence and Space
* Copyright (C) 2004 - 2018 Airbus Defence and Space SAS
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
......@@ -43,6 +43,9 @@ public class ActiveMQServer extends AbstractApplicationServer {
private String processIdentificationClue;
/**
* The default constructor
*/
public ActiveMQServer() {
this.setMandatory(true);
}
......@@ -64,7 +67,7 @@ public class ActiveMQServer extends AbstractApplicationServer {
@Override
public JMXConnector getJMXConnector() {
return ProcessUtils.createJMXclient("localhost", this.getJmxPort(), "", "", "jmxrmi", 2000, false, this.logger);
return ProcessUtils.createJMXclient(this.getHost(), this.getJmxPort(), "", "", "jmxrmi", 2000, false, this.logger);
}
......@@ -97,7 +100,7 @@ public class ActiveMQServer extends AbstractApplicationServer {
return true;
}
this.logger.info("Checking " + this.getName() + " status ... ");
if (!Utils.isPortAvailable(this.logger, this.getPort())) {
if (!Utils.isPortAvailable(this.logger, this.getHost(), this.getPort())) {
this.logger.info(this.getName() + " is started.");
if (showDetails) {
this.listQueuesStatus();
......@@ -109,10 +112,15 @@ public class ActiveMQServer extends AbstractApplicationServer {
}
/**
* @param connection
* An already opened MBean connection
* @return The list of queues
*/
public ObjectName[] listQueues(final MBeanServerConnection connection) {
final ObjectName activeMQ;
try {
activeMQ = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost");
activeMQ = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + this.getHost());
} catch (final MalformedObjectNameException mone) {
this.logger.log(Level.WARNING, "Invalid object name Broker!", mone);
return null;
......@@ -126,7 +134,7 @@ public class ActiveMQServer extends AbstractApplicationServer {
private void listQueuesStatus() {
try (final JMXConnector connector = this.getJMXConnector()) {
MBeanServerConnection connection = connector.getMBeanServerConnection();
final MBeanServerConnection connection = connector.getMBeanServerConnection();
if (connection == null) {
this.logger.info("Unable to connect to " + this.getName() + " to retrieve list of queues.");
return;
......@@ -149,7 +157,7 @@ public class ActiveMQServer extends AbstractApplicationServer {
public void purge(final String queue) {
boolean queueFound = false;
try (final JMXConnector connector = this.getJMXConnector()) {
MBeanServerConnection connection = connector.getMBeanServerConnection();
final MBeanServerConnection connection = connector.getMBeanServerConnection();
if (connection == null) {
this.logger.info("Unable to connect to " + this.getName() + " to retrieve list of queues.");
return;
......@@ -177,5 +185,4 @@ public class ActiveMQServer extends AbstractApplicationServer {
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2017 Airbus Defence and Space
* Copyright (C) 2004 - 2018 Airbus Defence and Space SAS
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
......@@ -61,11 +61,11 @@ public class Fuseki extends WebLabServer {
this.logger.info("Can not check if " + this.getName() + " is started since control is disabled.");
return true;
}
if (!Utils.isPortAvailable(this.logger, this.getPort())) {
if (!Utils.isPortAvailable(this.logger, this.getHost(), this.getPort())) {
this.logger.info(this.getName() + " is started.");
if (showDetails) {
try (final CloseableHttpClient client = HttpClients.custom().build();) {
final HttpGet httpget = new HttpGet(new URL("http", "localhost", this.getPort(), "/$/datasets").toURI());
final HttpGet httpget = new HttpGet(new URL("http", this.getHost(), this.getPort(), "/$/datasets").toURI());
final String result = client.execute(httpget, new BasicResponseHandler());
this.logger.finest(result);
final JsonObject json = new JsonParser().parse(result).getAsJsonObject();
......@@ -88,7 +88,6 @@ public class Fuseki extends WebLabServer {
/**
* Execute a command
*
......
......@@ -91,7 +91,7 @@ public class Heritrix extends WebLabServer {
this.logger.info("Can not check if " + this.getName() + " is started since control is disabled.");
return true;
}
if (!Utils.isPortAvailable(this.logger, this.getPort())) {
if (!Utils.isPortAvailable(this.logger, this.getHost(), this.getPort())) {
if (showDetails) {
try (final CloseableHttpClient client = this.createClient()) {
final HttpGet httpget = new HttpGet(new URL("https", this.getUiHost(), this.getPort(), "/engine").toURI());
......
......@@ -19,10 +19,10 @@ package org.ow2.weblab.bundle.server;
import java.io.File;
import java.util.logging.Level;
import javax.management.remote.JMXConnector;
import org.apache.commons.io.FileUtils;
import org.ow2.weblab.bundle.server.WebLabServer;
import org.apache.commons.io.FileUtils;
import org.ow2.weblab.bundle.utils.ProcessUtils;
import org.ow2.weblab.bundle.utils.Utils;
......@@ -42,6 +42,7 @@ public class JettyServer extends WebLabServer {
* Just an empty constructor that says that the manager has been created.
*/
public JettyServer() {
super();
this.logger.finest("JettyServer started.");
}
......@@ -50,9 +51,10 @@ public class JettyServer extends WebLabServer {
@Override
public int getPid() {
if (this.isLocked()) {
// Server has already been started at least one time. Checking if it is really running (file is not deleted in case of dirty stop).
if (Utils.isPortAvailable(this.logger, this.getPort())) {
if (Utils.isPortAvailable(this.logger, this.getHost(), this.getPort())) {
this.logger.severe("Port " + this.getPort() + " is available but lock file " + this.getLockFile() + " exists. Strange!");
return -1;
}
......@@ -71,6 +73,7 @@ public class JettyServer extends WebLabServer {
private File getLockFile() {
return new File(this.getHome(), JettyServer.JETTY_PID);
}
......@@ -84,6 +87,7 @@ public class JettyServer extends WebLabServer {
@Override
public String getProcessIdentificationClue() {
this.logger.finest("getProcessIdentificationClue is not implemented by JettyServer.");
return this.getHome();
}
......@@ -92,11 +96,12 @@ public class JettyServer extends WebLabServer {
@Override
public boolean isServerFullyStarted(final boolean showDetails) {
if (!this.isEnabled()) {
this.logger.info("Can not check if " + this.getName() + " is started since control is disabled.");
return true;
}
if (this.status() == State.STARTED && !Utils.isPortAvailable(this.logger, this.getPort())) {
if ((this.status() == State.STARTED) && !Utils.isPortAvailable(this.logger, this.getHome(), this.getPort())) {
this.logger.info(this.getName() + " is started.");
if (showDetails) {
// this.logger.info("showDetails is not implemented.");
......@@ -141,12 +146,14 @@ public class JettyServer extends WebLabServer {
@Override
public JMXConnector getJMXConnector() {
return null;
}
@Override
public Process start() {
// check status
if (this.status() != State.STOPPED) {
this.logger.severe(this.getName() + " is not stopped! Aborting start...");
......@@ -192,6 +199,7 @@ public class JettyServer extends WebLabServer {
@Override
public void stop() {
this.logger.info(this.getName() + " is stopping ...");
this.execute(this.getEnv(), "stop");
this.logger.info(this.getName() + " is stopped.");
......
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2017 Airbus Defence and Space
* Copyright (C) 2004 - 2018 Airbus Defence and Space SAS
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
......@@ -154,7 +154,7 @@ public class Karaf extends Bus {
}
this.logger.info("Checking " + this.getName() + " status ... ");
this.detailedStatus();
boolean running = !Utils.isPortAvailable(this.logger, this.getJmxPort());
boolean running = !Utils.isPortAvailable(this.logger, this.getHost(), this.getJmxPort());
if (showDetails && running) {
this.listChains();
}
......
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2017 Airbus Defence and Space
* Copyright (C) 2004 - 2018 Airbus Defence and Space SAS
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
......@@ -145,7 +145,7 @@ public class SolrServer extends AbstractApplicationServer {
@Override
public boolean isServerFullyStarted(final boolean showDetails) {
return !Utils.isPortAvailable(this.logger, this.getPort());
return !Utils.isPortAvailable(this.logger, this.getHost(), this.getPort());
}
......@@ -428,4 +428,5 @@ public class SolrServer extends AbstractApplicationServer {
public void setDataDirectory(final String dataDirectory) {
this.dataDirectory = dataDirectory;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2017 Airbus Defence and Space
* Copyright (C) 2004 - 2018 Airbus Defence and Space SAS
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
......@@ -61,6 +61,9 @@ public abstract class WebLabServer {
private int port, jmxPort, ajpPort, timeout;
private String host = "localhost";
protected Logger logger = Launcher.logger;
......@@ -388,4 +391,20 @@ public abstract class WebLabServer {
this.cleanablePathsAfterStop = cleanablePathsAfterStop;
}
/**
* @return the host
*/
public String getHost() {
return this.host;
}
/**
* @param host the host to set
*/
public void setHost(String host) {
this.host = host;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2017 Airbus Defence and Space
* Copyright (C) 2004 - 2018 Airbus Defence and Space SAS
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
......@@ -72,7 +72,7 @@ public class ZooKeeperServer extends AbstractApplicationServer {
@Override
public boolean isServerFullyStarted(final boolean showDetails) {
return !Utils.isPortAvailable(this.logger, this.getPort());
return !Utils.isPortAvailable(this.logger, this.getHost(), this.getPort());
}
......
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2017 Airbus Defence and Space
* Copyright (C) 2004 - 2018 Airbus Defence and Space SAS
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
......@@ -22,13 +22,10 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Field;
......@@ -41,7 +38,6 @@ import java.net.Socket;
import java.net.URL;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
......@@ -83,13 +79,15 @@ public final class Utils {
*
* @param logger
* The logger used inside
* @param host
* The host to be used to open the socket
* @param port
* a port
* @return true if the port is available, else false
*/
public static boolean isPortAvailable(final Logger logger, final int port) {
public static boolean isPortAvailable(final Logger logger, final String host, final int port) {
boolean available = true;
try (final Socket socket = new Socket("localhost", port)) {
try (final Socket socket = new Socket(host, port)) {
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Port " + port + " is listening.");
}
......@@ -113,6 +111,22 @@ public final class Utils {
}
/**
* Check if a port is available
*
* @param logger
* The logger used inside
* @param port
* a port
* @return true if the port is available, else false
* @deprecated Use instead {@link #isPortAvailable(Logger, String, int)}
*/
@Deprecated
public static boolean isPortAvailable(final Logger logger, final int port) {
return Utils.isPortAvailable(logger, "localhost", port);
}
/**
* Load default properties or those configured in weblab.properties file
*
......@@ -127,14 +141,6 @@ public final class Utils {
}
protected static void saveProperties(final File propFile, final Properties properties, final Logger logger) throws FileNotFoundException, IOException {
try (FileOutputStream fos = new FileOutputStream(propFile)) {
properties.storeToXML(fos, "WebLab Default Properties.");
}
logger.info("Default WebLab options can be customized in the following file: " + propFile.getAbsolutePath());
}
/**
* Update a file
*
......@@ -394,20 +400,4 @@ public final class Utils {
}
/**
* Ask a question and return the answer
*
* @param question
* a question
* @param logger
* a logger
* @return the user's answer to the question
* @throws IOException
* if anything wrong occurs
*/
public static String ask(final String question, final Logger logger) throws IOException {
logger.info(question);
final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
return br.readLine();
}
}
\ No newline at end of file
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