Skip to content

Commit

Permalink
Merge pull request #10923 from elastic/die_cwd_die
Browse files Browse the repository at this point in the history
Remove CWD access in tests and don't implicitly use CWD/user.dir for configuration.
  • Loading branch information
rmuir committed May 4, 2015
2 parents f042b8f + 4b3672b commit 02da246
Show file tree
Hide file tree
Showing 49 changed files with 290 additions and 156 deletions.
Expand Up @@ -3,7 +3,7 @@

Basic support for hunspell stemming. Hunspell dictionaries will be
picked up from a dedicated hunspell directory on the filesystem
(defaults to `<path.conf>/hunspell`). Each dictionary is expected to
(`<path.conf>/hunspell`). Each dictionary is expected to
have its own directory named after its associated locale (language).
This dictionary directory is expected to hold a single `*.aff` and
one or more `*.dic` files (all of which will automatically be picked up).
Expand All @@ -19,10 +19,6 @@ following directory layout will define the `en_US` dictionary:
| | |-- en_US.aff
--------------------------------------------------

The location of the hunspell directory can be configured using the
`indices.analysis.hunspell.dictionary.location` settings in
_elasticsearch.yml_.

Each dictionary can be configured with one setting:

`ignore_case`::
Expand Down Expand Up @@ -91,9 +87,9 @@ the stemming is determined by the quality of the dictionary.
[float]
==== Dictionary loading

By default, the configured (`indices.analysis.hunspell.dictionary.location`)
or default Hunspell directory (`config/hunspell/`) is checked for dictionaries
when the node starts up, and any dictionaries are automatically loaded.
By default, the default Hunspell directory (`config/hunspell/`) is checked
for dictionaries when the node starts up, and any dictionaries are
automatically loaded.

Dictionary loading can be deferred until they are actually used by setting
`indices.analysis.hunspell.dictionary.lazy` to `true`in the config file.
Expand Down
5 changes: 5 additions & 0 deletions docs/reference/migration/migrate_2_0.asciidoc
Expand Up @@ -458,3 +458,8 @@ there is not enough disk space to complete this migration, the upgrade will be
cancelled and can only be resumed once enough disk space is made available.

The `index.store.distributor` setting has also been removed.

=== Hunspell dictionary configuration

The parameter `indices.analysis.hunspell.dictionary.location` has been removed,
and `<path.conf>/hunspell` is always used.
Expand Up @@ -103,14 +103,6 @@ public class TransportClient extends AbstractClient {
private final TransportClientNodesService nodesService;
private final InternalTransportClient internalClient;

/**
* Constructs a new transport client with settings loaded either from the classpath or the file system (the
* <tt>elasticsearch.(yml|json)</tt> files optionally prefixed with <tt>config/</tt>).
*/
public TransportClient() {
this(ImmutableSettings.Builder.EMPTY_SETTINGS, true);
}

/**
* Constructs a new transport client with explicit settings and settings loaded either from the classpath or the file
* system (the <tt>elasticsearch.(yml|json)</tt> files optionally prefixed with <tt>config/</tt>).
Expand Down
32 changes: 7 additions & 25 deletions src/main/java/org/elasticsearch/env/Environment.java
Expand Up @@ -32,7 +32,6 @@
import java.util.ArrayList;

import static org.elasticsearch.common.Strings.cleanPath;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;

/**
* The environment of where things exists.
Expand Down Expand Up @@ -69,16 +68,12 @@ public class Environment {
fileStores = allStores.toArray(new ESFileStore[allStores.size()]);
}

public Environment() {
this(EMPTY_SETTINGS);
}

public Environment(Settings settings) {
this.settings = settings;
if (settings.get("path.home") != null) {
homeFile = PathUtils.get(cleanPath(settings.get("path.home")));
} else {
homeFile = PathUtils.get(System.getProperty("user.dir"));
throw new IllegalStateException("path.home is not configured");
}

if (settings.get("path.conf") != null) {
Expand Down Expand Up @@ -175,26 +170,13 @@ public FileStore getFileStore(Path path) throws IOException {
}

public URL resolveConfig(String path) throws FailedToResolveConfigException {
String origPath = path;
// first, try it as a path on the file system
Path f1 = PathUtils.get(path);
if (Files.exists(f1)) {
try {
return f1.toUri().toURL();
} catch (MalformedURLException e) {
throw new FailedToResolveConfigException("Failed to resolve path [" + f1 + "]", e);
}
}
if (path.startsWith("/")) {
path = path.substring(1);
}
// next, try it relative to the config location
Path f2 = configFile.resolve(path);
if (Files.exists(f2)) {
// first, try it as a path in the config directory
Path f = configFile.resolve(path);
if (Files.exists(f)) {
try {
return f2.toUri().toURL();
return f.toUri().toURL();
} catch (MalformedURLException e) {
throw new FailedToResolveConfigException("Failed to resolve path [" + f1 + "]", e);
throw new FailedToResolveConfigException("Failed to resolve path [" + f + "]", e);
}
}
// try and load it from the classpath directly
Expand All @@ -209,6 +191,6 @@ public URL resolveConfig(String path) throws FailedToResolveConfigException {
return resource;
}
}
throw new FailedToResolveConfigException("Failed to resolve config path [" + origPath + "], tried file path [" + f1 + "], path file [" + f2 + "], and classpath");
throw new FailedToResolveConfigException("Failed to resolve config path [" + path + "], tried config path [" + f + "] and classpath");
}
}
Expand Up @@ -74,7 +74,7 @@ public class HunspellService extends AbstractComponent {

public final static String HUNSPELL_LAZY_LOAD = "indices.analysis.hunspell.dictionary.lazy";
public final static String HUNSPELL_IGNORE_CASE = "indices.analysis.hunspell.dictionary.ignore_case";
public final static String HUNSPELL_LOCATION = "indices.analysis.hunspell.dictionary.location";
private final static String OLD_HUNSPELL_LOCATION = "indices.analysis.hunspell.dictionary.location";
private final LoadingCache<String, Dictionary> dictionaries;
private final Map<String, Dictionary> knownDictionaries;

Expand Down Expand Up @@ -116,9 +116,9 @@ public Dictionary getDictionary(String locale) {
}

private Path resolveHunspellDirectory(Settings settings, Environment env) {
String location = settings.get(HUNSPELL_LOCATION, null);
String location = settings.get(OLD_HUNSPELL_LOCATION, null);
if (location != null) {
return PathUtils.get(location);
throw new IllegalArgumentException("please, put your hunspell dictionaries under config/hunspell !");
}
return env.configFile().resolve("hunspell");
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/elasticsearch/tribe/TribeService.java
Expand Up @@ -127,6 +127,7 @@ public TribeService(Settings settings, ClusterService clusterService, DiscoveryS
for (Map.Entry<String, Settings> entry : nodesSettings.entrySet()) {
ImmutableSettings.Builder sb = ImmutableSettings.builder().put(entry.getValue());
sb.put("node.name", settings.get("name") + "/" + entry.getKey());
sb.put("path.home", settings.get("path.home")); // pass through ES home dir
sb.put(TRIBE_NAME, entry.getKey());
sb.put("config.ignore_system_properties", true);
if (sb.get("http.enabled") == null) {
Expand Down
Expand Up @@ -31,8 +31,9 @@ grant {
permission java.io.FilePermission "${java.io.tmpdir}${/}-", "read,write,delete";

// paths used for running tests
// project base directory
permission java.io.FilePermission "${project.basedir}${/}target${/}-", "read";
// compiled classes
permission java.io.FilePermission "${project.basedir}${/}target${/}classes${/}-", "read";
permission java.io.FilePermission "${project.basedir}${/}target${/}test-classes${/}-", "read";
// read permission for lib sigar
permission java.io.FilePermission "${project.basedir}${/}lib${/}sigar${/}-", "read";
// mvn custom ./m2/repository for dependency jars
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
Expand Down Expand Up @@ -157,7 +158,10 @@ public void testBulkProcessorConcurrentRequests() throws Exception {
//https://github.com/elasticsearch/elasticsearch/issues/5038
public void testBulkProcessorConcurrentRequestsNoNodeAvailableException() throws Exception {
//we create a transport client with no nodes to make sure it throws NoNodeAvailableException
Client transportClient = new TransportClient();
Settings settings = ImmutableSettings.builder()
.put("path.home", createTempDir().toString())
.build();
Client transportClient = new TransportClient(settings);

int bulkActions = randomIntBetween(10, 100);
int numDocs = randomIntBetween(bulkActions, bulkActions + 100);
Expand Down
Expand Up @@ -23,6 +23,8 @@
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
Expand All @@ -46,7 +48,10 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase {
public static void initClient() {
//this client will not be hit by any request, but it needs to be a non null proper client
//that is why we create it but we don't add any transport address to it
client = new TransportClient();
Settings settings = ImmutableSettings.builder()
.put("path.home", createTempDir().toString())
.build();
client = new TransportClient(settings);
}

@AfterClass
Expand Down
Expand Up @@ -21,6 +21,8 @@

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
Expand All @@ -45,7 +47,10 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase {
public static void initClient() {
//this client will not be hit by any request, but it needs to be a non null proper client
//that is why we create it but we don't add any transport address to it
client = new TransportClient();
Settings settings = ImmutableSettings.builder()
.put("path.home", createTempDir().toString())
.build();
client = new TransportClient(settings);
}

@AfterClass
Expand Down
Expand Up @@ -90,8 +90,12 @@ public abstract class AbstractClientHeadersTests extends ElasticsearchTestCase {

@Before
public void initClient() {
Settings settings = ImmutableSettings.builder()
.put(HEADER_SETTINGS)
.put("path.home", createTempDir().toString())
.build();
threadPool = new ThreadPool("test-" + getTestName());
client = buildClient(HEADER_SETTINGS, ACTIONS);
client = buildClient(settings, ACTIONS);
}

@After
Expand Down
Expand Up @@ -59,7 +59,7 @@ protected Client buildClient(Settings headersSettings, GenericAction[] testedAct
.put("client.transport.sniff", false)
.put("node.name", "transport_client_" + this.getTestName())
.put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName())
.put(HEADER_SETTINGS)
.put(headersSettings)
.build());

client.addTransportAddress(address);
Expand All @@ -75,6 +75,7 @@ public void testWithSniffing() throws Exception {
.put("client.transport.nodes_sampler_interval", "1s")
.put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName())
.put(HEADER_SETTINGS)
.put("path.home", createTempDir().toString())
.build());
try {
client.addTransportAddress(address);
Expand Down
Expand Up @@ -62,7 +62,8 @@ public void testRetry() throws IOException, ExecutionException, InterruptedExcep
.put("node.mode", InternalTestCluster.nodeMode())
.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false)
.put(ClusterName.SETTING, internalCluster().getClusterName())
.put("config.ignore_system_properties", true);
.put("config.ignore_system_properties", true)
.put("path.home", createTempDir());

try (TransportClient transportClient = new TransportClient(builder.build())) {
transportClient.addTransportAddresses(addresses);
Expand Down
Expand Up @@ -25,7 +25,6 @@
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.index.store.IndexStoreModule;
import org.elasticsearch.node.Node;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
Expand All @@ -35,7 +34,10 @@
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;

@ClusterScope(scope = Scope.TEST, numDataNodes = 0, transportClientRatio = 1.0)
public class TransportClientTests extends ElasticsearchIntegrationTest {
Expand Down Expand Up @@ -92,7 +94,8 @@ public void testThatTransportClientSettingIsSet() {

@Test
public void testThatTransportClientSettingCannotBeChanged() {
try (TransportClient client = new TransportClient(settingsBuilder().put(Client.CLIENT_TYPE_SETTING, "anything"))) {
Settings baseSettings = settingsBuilder().put(Client.CLIENT_TYPE_SETTING, "anything").put("path.home", createTempDir()).build();
try (TransportClient client = new TransportClient(baseSettings)) {
Settings settings = client.injector.getInstance(Settings.class);
assertThat(settings.get(Client.CLIENT_TYPE_SETTING), is("transport"));
}
Expand Down

0 comments on commit 02da246

Please sign in to comment.