Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added support for configurable and default node name, resolves #135

  • Loading branch information...
commit b240a40a6582651ef226f2b92eeac0f542e3e28c 1 parent 0f535c2
@ddossot ddossot authored
View
5 src/main/java/eu/openanalytics/rsb/Constants.java
@@ -84,6 +84,7 @@
public static final MimeType ZIP_MIME_TYPE;
public static final MimeType DEFAULT_MIME_TYPE;
+ public static final String HOST_NAME;
public static final String RSERVI_CLIENT_ID;
static {
@@ -95,8 +96,8 @@
ZIP_MIME_TYPE = new MimeType(ZIP_CONTENT_TYPE);
DEFAULT_MIME_TYPE = new MimeType("application/octet-stream");
- RSERVI_CLIENT_ID = "rsb@" + InetAddress.getLocalHost().getHostName();
-
+ HOST_NAME = InetAddress.getLocalHost().getHostName();
+ RSERVI_CLIENT_ID = "rsb@" + HOST_NAME;
} catch (final Exception mtpe) {
throw new IllegalStateException(mtpe);
}
View
5 src/main/java/eu/openanalytics/rsb/config/Configuration.java
@@ -179,6 +179,11 @@ public String getSubDir() {
URL getConfigurationUrl();
/**
+ * Logical name of the RSB node.
+ */
+ String getNodeName();
+
+ /**
* Directory where a catalog of R scripts are stored.
*/
File getRScriptsCatalogDirectory();
View
13 src/main/java/eu/openanalytics/rsb/config/PersistedConfiguration.java
@@ -268,6 +268,7 @@ public void setJobConfigurationFileName(final String jobConfigurationFileName) {
}
private static final long serialVersionUID = 1L;
+ private String nodeName;
private File activeMqWorkDirectory;
private URI defaultRserviPoolUri;
private int jobTimeOut;
@@ -301,6 +302,7 @@ public PersistedConfiguration(final Configuration configuration) {
setJobStatisticsHandlerConfiguration((PersistedJobStatisticsHandlerConfiguration) configuration
.getJobStatisticsHandlerConfiguration());
setJobTimeOut(configuration.getJobTimeOut());
+ setNodeName(configuration.getNodeName());
setNumberOfConcurrentJobWorkersPerQueue(configuration.getNumberOfConcurrentJobWorkersPerQueue());
setResultsDirectory(configuration.getResultsDirectory());
setSmtpConfiguration((PersistedSmtpConfiguration) configuration.getSmtpConfiguration());
@@ -312,6 +314,17 @@ public String toString() {
}
/**
+ * Logical name of the RSB node.
+ */
+ public String getNodeName() {
+ return nodeName;
+ }
+
+ public void setNodeName(final String nodeName) {
+ this.nodeName = nodeName;
+ }
+
+ /**
* Directory under which RSB catalogs are located. The catalogs are:
* <ul>
* <li>{@link eu.openanalytics.rsb.config.Configuration#R_SCRIPTS_CATALOG_SUBDIR}: catalog of R scripts</li>
View
20 src/main/java/eu/openanalytics/rsb/config/PersistedConfigurationAdapter.java
@@ -27,9 +27,11 @@
import java.util.List;
import java.util.Map;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
+import eu.openanalytics.rsb.Constants;
import eu.openanalytics.rsb.Util;
import eu.openanalytics.rsb.config.PersistedConfiguration.PersistedJobStatisticsHandlerConfiguration;
@@ -45,15 +47,18 @@
8889);
private final PersistedConfiguration persistedConfiguration;
private final URL configurationUrl;
-
+ private final String nodeName;
private final File rScriptsCatalogDirectory;
private final File sweaveFilesCatalogDirectory;
private final File jobConfigurationCatalogDirectory;
private final File emailRepliesCatalogDirectory;
public PersistedConfigurationAdapter(final URL configurationUrl, final PersistedConfiguration persistedConfiguration) {
- this.configurationUrl = configurationUrl;
this.persistedConfiguration = persistedConfiguration;
+ this.configurationUrl = configurationUrl;
+
+ nodeName = StringUtils.isNotBlank(persistedConfiguration.getNodeName()) ? persistedConfiguration.getNodeName()
+ : getDefaultNodeName();
rScriptsCatalogDirectory = new File(persistedConfiguration.getCatalogRootDirectory(), Configuration.Catalog.R_SCRIPTS.getSubDir());
sweaveFilesCatalogDirectory = new File(persistedConfiguration.getCatalogRootDirectory(),
@@ -64,6 +69,13 @@ public PersistedConfigurationAdapter(final URL configurationUrl, final Persisted
Configuration.Catalog.EMAIL_REPLIES.getSubDir());
}
+ private String getDefaultNodeName() {
+ // find something unique about the running node like the location of resource
+ final URL resourceUrl = getClass().getResource("/META-INF/spring/core-beans.xml");
+ final String uniqueId = Long.toHexString(Math.abs((long) resourceUrl.toExternalForm().hashCode()));
+ return StringUtils.lowerCase(Constants.HOST_NAME + "-" + uniqueId);
+ }
+
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE) + "\n" + persistedConfiguration.toString();
@@ -83,6 +95,10 @@ public URL getConfigurationUrl() {
return configurationUrl;
}
+ public String getNodeName() {
+ return nodeName;
+ }
+
public File getActiveMqWorkDirectory() {
return persistedConfiguration.getActiveMqWorkDirectory();
}
View
1  src/test/resources/rsb-configuration-full.json
@@ -1,4 +1,5 @@
{
+ "nodeName": "testNodeName",
"administratorEmail": "fake@nohost.com",
"catalogRootDirectory": "/tmp/.rsb/catalog",
"activeMqWorkDirectory": "/tmp/.rsb/activemq",
Please sign in to comment.
Something went wrong with that request. Please try again.