Skip to content
Snippets Groups Projects
Unverified Commit f8072b92 authored by Jason Tedor's avatar Jason Tedor
Browse files

[elasticsearch] require path.home in embedded mode

Today when running the Elasticsearch binding in embedded mode, a
temporary directory is used. This can be confusing for running usual
load-then-run style workflows because the temporary directory will not
be the same between runs. Instead, we should just require a directory
when running in embedded mode and this commit makes this the case.
parent 98712967
No related branches found
No related tags found
No related merge requests found
...@@ -82,20 +82,29 @@ public class ElasticsearchClient extends DB { ...@@ -82,20 +82,29 @@ public class ElasticsearchClient extends DB {
*/ */
@Override @Override
public void init() throws DBException { public void init() throws DBException {
Properties props = getProperties(); final Properties props = getProperties();
// Check if transport client needs to be used (To connect to multiple
// elasticsearch nodes)
remoteMode = Boolean.parseBoolean(props.getProperty("es.remote", "false"));
final String pathHome = props.getProperty("path.home");
// when running in embedded mode, require path.home
if (!remoteMode && (pathHome == null || pathHome.isEmpty())) {
throw new IllegalArgumentException("path.home must be specified when running in embedded mode");
}
this.indexKey = props.getProperty("es.index.key", DEFAULT_INDEX_KEY); this.indexKey = props.getProperty("es.index.key", DEFAULT_INDEX_KEY);
int numberOfShards = parseIntegerProperty(props, "es.number_of_shards", NUMBER_OF_SHARDS); int numberOfShards = parseIntegerProperty(props, "es.number_of_shards", NUMBER_OF_SHARDS);
int numberOfReplicas = parseIntegerProperty(props, "es.number_of_replicas", NUMBER_OF_REPLICAS); int numberOfReplicas = parseIntegerProperty(props, "es.number_of_replicas", NUMBER_OF_REPLICAS);
// Check if transport client needs to be used (To connect to multiple
// elasticsearch nodes)
remoteMode = Boolean.parseBoolean(props.getProperty("es.remote", "false"));
Boolean newdb = Boolean.parseBoolean(props.getProperty("es.newdb", "false")); Boolean newdb = Boolean.parseBoolean(props.getProperty("es.newdb", "false"));
Builder settings = Settings.settingsBuilder() Builder settings = Settings.settingsBuilder()
.put("cluster.name", DEFAULT_CLUSTER_NAME) .put("cluster.name", DEFAULT_CLUSTER_NAME)
.put("node.local", Boolean.toString(!remoteMode)) .put("node.local", Boolean.toString(!remoteMode))
.put("path.home", System.getProperty("java.io.tmpdir")); .put("path.home", pathHome);
// if properties file contains elasticsearch user defined properties // if properties file contains elasticsearch user defined properties
// add it to the settings file (will overwrite the defaults). // add it to the settings file (will overwrite the defaults).
......
...@@ -29,9 +29,13 @@ import org.junit.After; ...@@ -29,9 +29,13 @@ import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.util.HashMap; import java.util.HashMap;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.Vector; import java.util.Vector;
...@@ -39,6 +43,7 @@ import static org.junit.Assert.assertEquals; ...@@ -39,6 +43,7 @@ import static org.junit.Assert.assertEquals;
public class ElasticsearchClientTest { public class ElasticsearchClientTest {
@ClassRule public final static TemporaryFolder temp = new TemporaryFolder();
protected final static ElasticsearchClient instance = new ElasticsearchClient(); protected final static ElasticsearchClient instance = new ElasticsearchClient();
protected final static HashMap<String, ByteIterator> MOCK_DATA; protected final static HashMap<String, ByteIterator> MOCK_DATA;
protected final static String MOCK_TABLE = "MOCK_TABLE"; protected final static String MOCK_TABLE = "MOCK_TABLE";
...@@ -55,6 +60,9 @@ public class ElasticsearchClientTest { ...@@ -55,6 +60,9 @@ public class ElasticsearchClientTest {
@BeforeClass @BeforeClass
public static void setUpClass() throws DBException { public static void setUpClass() throws DBException {
final Properties props = new Properties();
props.put("path.home", temp.getRoot().toString());
instance.setProperties(props);
instance.init(); instance.init();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment