Skip to content

Commit

Permalink
Merge pull request #470 from mesos/configuration/464-LoadFromURL
Browse files Browse the repository at this point in the history
Configuration/464 load from url
  • Loading branch information
Phil Winder committed Jan 25, 2016
2 parents 0f66756 + fafc623 commit bde3f7b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions executor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
compile "log4j:log4j:1.2.16"
compile "com.beust:jcommander:1.48"
compile 'com.jayway.awaitility:awaitility:1.6.3'
compile "commons-validator:commons-validator:1.5.0"

testCompile 'com.mashape.unirest:unirest-java:1.4.5'
testCompile 'com.jayway.awaitility:awaitility:1.6.3'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package org.apache.mesos.elasticsearch.executor;

import com.beust.jcommander.JCommander;
import org.apache.commons.validator.routines.UrlValidator;
import org.apache.log4j.Logger;
import org.apache.mesos.elasticsearch.common.cli.ElasticsearchCLIParameter;
import org.apache.mesos.elasticsearch.common.cli.HostsCLIParameter;
import org.apache.mesos.elasticsearch.common.cli.ZookeeperCLIParameter;
import org.elasticsearch.common.settings.Settings;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.nio.file.Paths;
import java.util.List;

Expand All @@ -17,6 +22,7 @@ public class Configuration {
private static final Logger LOGGER = Logger.getLogger(Configuration.class);
public static final String ELASTICSEARCH_YML = "elasticsearch.yml";
private final ElasticsearchCLIParameter elasticsearchCLI = new ElasticsearchCLIParameter();
UrlValidator urlValidator = new UrlValidator();

// **** ZOOKEEPER
private final ZookeeperCLIParameter zookeeperCLI = new ZookeeperCLIParameter();
Expand All @@ -42,7 +48,19 @@ public Settings.Builder getUserESSettings() {
String settingsLocation = getElasticsearchCLI().getElasticsearchSettingsLocation();
if (settingsLocation.isEmpty()) {
return Settings.builder();
} else {
} else if (urlValidator.isValid(settingsLocation)) { // If url
final InputStream is;
try {
final URL url = URI.create(settingsLocation).toURL();
LOGGER.debug("Loading settings from url: " + url.toExternalForm());
is = url.openStream();
return Settings.builder().loadFromStream(settingsLocation, is);
} catch (IOException e) {
LOGGER.error("Tried to load from URL: " + settingsLocation + ", but failed.", e);
throw new IllegalStateException("Unable to load user specified settings file. Please check the URL");
}
} else { // If file
LOGGER.debug("Loading settings from file: " + settingsLocation);
return Settings.builder().loadFromPath(Paths.get(settingsLocation));
}
}
Expand Down

0 comments on commit bde3f7b

Please sign in to comment.