Commit 19376a9c authored by Fabien Viale's avatar Fabien Viale
Browse files

Add server public url configuration

Allows to adapt PASchedulerProperties.SCHEDULER_REST_URL and PASchedulerProperties.CATALOG_REST_URL when the ProActive server has a public url (for example, behind a reverse proxy or resolved with a domain name)
parent 96ec7c0c
......@@ -14,9 +14,14 @@ pa.scheduler.home=.
# When the server has a public endpoint, different from the hostname available on the machine, this property should be used to correctly set the url
#pa.scheduler.rest.url=
#Catalog rest url. If not defined, it is set automatically when starting the server. Same as scheduler rest url
# Catalog rest url. If not defined, it is set automatically when starting the server. Same as scheduler rest url
#pa.catalog.rest.url=
# Set this property to define the public url of the server (e.g. if behind a reverse proxy or accessed through a domain)
# the pa.scheduler.rest.url and pa.catalog.rest.url properties will be updated accordingly
# Example https://myserver.mydomain.com
#pa.server.public.url=
# Timeout for the scheduling loop (in millisecond)
pa.scheduler.core.timeout=10000
......
......@@ -328,6 +328,12 @@ public enum PASchedulerProperties implements PACommonProperties {
*/
CATALOG_REST_URL("pa.catalog.rest.url", PropertyType.STRING),
/**
* Set this property to define the public url of the server (e.g. if behind a reverse proxy or accessed through a domain)
* the SCHEDULER_REST_URL and CATALOG_REST_URL properties will be updated accordingly
*/
SERVER_PUBLIC_URL("pa.server.public.url", PropertyType.STRING),
/* ***************************************************************** */
/* ************************** RM PROPERTIES ************************ */
/* ***************************************************************** */
......
......@@ -36,6 +36,7 @@ import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.UnknownHostException;
import java.rmi.AlreadyBoundException;
import java.security.KeyException;
......@@ -242,15 +243,32 @@ public class SchedulerStarter {
if (applicationUrls != null) {
for (String applicationUrl : applicationUrls) {
if (applicationUrl.endsWith("/rest") && !PASchedulerProperties.SCHEDULER_REST_URL.isSet()) {
PASchedulerProperties.SCHEDULER_REST_URL.updateProperty(applicationUrl);
PASchedulerProperties.SCHEDULER_REST_URL.updateProperty(getPublicUrl(applicationUrl));
}
if (applicationUrl.endsWith("/catalog") && !PASchedulerProperties.CATALOG_REST_URL.isSet()) {
PASchedulerProperties.CATALOG_REST_URL.updateProperty(applicationUrl);
PASchedulerProperties.CATALOG_REST_URL.updateProperty(getPublicUrl(applicationUrl));
}
}
}
}
private static String getPublicUrl(String url) {
if (PASchedulerProperties.SERVER_PUBLIC_URL.isSet()) {
try {
URL publicUrl = new URL(PASchedulerProperties.SERVER_PUBLIC_URL.getValueAsString());
URL applicationUrl = new URL(url);
URL resolvedUrl = new URL(publicUrl, applicationUrl.getPath().substring(1));
return resolvedUrl.toExternalForm();
} catch (Exception e) {
LOGGER.warn("Error when resolving public url for " + url, e);
return url;
}
} else {
return url;
}
}
private static void startRouter() throws Exception {
if (needToStartRouter()) {
RouterConfig config = new RouterConfig();
......
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