use of org.elasticsearch.node.NodeBuilder in project titan by thinkaurelius.
the class ElasticSearchConfigTest method testIndexCreationOptions.
@Test
public void testIndexCreationOptions() throws InterruptedException, BackendException {
final int shards = 77;
ElasticsearchRunner esr = new ElasticsearchRunner(".", "indexCreationOptions.yml");
esr.start();
CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
cc.set("index." + INDEX_NAME + ".elasticsearch.create.ext.number_of_shards", String.valueOf(shards));
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.cluster.name", "indexCreationOptions");
ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE);
config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
Configuration indexConfig = config.restrictTo(INDEX_NAME);
IndexProvider idx = new ElasticSearchIndex(indexConfig);
simpleWriteAndQuery(idx);
ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
settingsBuilder.put("discovery.zen.ping.multicast.enabled", "false");
settingsBuilder.put("discovery.zen.ping.unicast.hosts", "localhost,127.0.0.1:9300");
settingsBuilder.put("cluster.name", "indexCreationOptions");
NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build());
nodeBuilder.client(true).data(false).local(false);
Node n = nodeBuilder.build().start();
GetSettingsResponse response = n.client().admin().indices().getSettings(new GetSettingsRequest().indices("titan")).actionGet();
assertEquals(String.valueOf(shards), response.getSetting("titan", "index.number_of_shards"));
idx.close();
n.stop();
esr.stop();
}
use of org.elasticsearch.node.NodeBuilder in project spring-boot by spring-projects.
the class ElasticsearchAutoConfiguration method createNodeClient.
private Client createNodeClient() throws Exception {
Settings.Builder settings = Settings.settingsBuilder();
for (Map.Entry<String, String> entry : DEFAULTS.entrySet()) {
if (!this.properties.getProperties().containsKey(entry.getKey())) {
settings.put(entry.getKey(), entry.getValue());
}
}
settings.put(this.properties.getProperties());
Node node = new NodeBuilder().settings(settings).clusterName(this.properties.getClusterName()).node();
this.releasable = node;
return node.client();
}
use of org.elasticsearch.node.NodeBuilder in project titan by thinkaurelius.
the class ElasticSearchIndex method legacyConfiguration.
/**
* Configure ElasticSearchIndex's ES client according to 0.4.x - 0.5.0 semantics.
* This checks local-mode first. If local-mode is true, then it creates a Node that
* uses JVM local transport and can't talk over the network. If local-mode is
* false, then it creates a TransportClient that can talk over the network and
* uses {@link com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration#INDEX_HOSTS}
* as the server addresses. Note that this configuration method
* does not allow creating a Node that talks over the network.
* <p>
* This is activated by <b>not</b> setting an explicit value for {@link #INTERFACE} in the
* Titan configuration.
*
* @see #interfaceConfiguration(com.thinkaurelius.titan.diskstorage.configuration.Configuration)
* @param config a config passed to ElasticSearchIndex's constructor
* @return a node and client object open and ready for use
*/
private ElasticSearchSetup.Connection legacyConfiguration(Configuration config) {
Node node;
Client client;
if (config.get(LOCAL_MODE)) {
log.debug("Configuring ES for JVM local transport");
boolean clientOnly = config.get(CLIENT_ONLY);
boolean local = config.get(LOCAL_MODE);
NodeBuilder builder = NodeBuilder.nodeBuilder();
Preconditions.checkArgument(config.has(INDEX_CONF_FILE) || config.has(INDEX_DIRECTORY), "Must either configure configuration file or base directory");
if (config.has(INDEX_CONF_FILE)) {
String configFile = config.get(INDEX_CONF_FILE);
ImmutableSettings.Builder sb = ImmutableSettings.settingsBuilder();
log.debug("Configuring ES from YML file [{}]", configFile);
FileInputStream fis = null;
try {
fis = new FileInputStream(configFile);
sb.loadFromStream(configFile, fis);
builder.settings(sb.build());
} catch (FileNotFoundException e) {
throw new TitanException(e);
} finally {
IOUtils.closeQuietly(fis);
}
} else {
String dataDirectory = config.get(INDEX_DIRECTORY);
log.debug("Configuring ES with data directory [{}]", dataDirectory);
File f = new File(dataDirectory);
if (!f.exists())
f.mkdirs();
ImmutableSettings.Builder b = ImmutableSettings.settingsBuilder();
for (String sub : DATA_SUBDIRS) {
String subdir = dataDirectory + File.separator + sub;
f = new File(subdir);
if (!f.exists())
f.mkdirs();
b.put("path." + sub, subdir);
}
b.put("script.disable_dynamic", false);
b.put("indices.ttl.interval", "5s");
builder.settings(b.build());
String clustername = config.get(CLUSTER_NAME);
Preconditions.checkArgument(StringUtils.isNotBlank(clustername), "Invalid cluster name: %s", clustername);
builder.clusterName(clustername);
}
node = builder.client(clientOnly).data(!clientOnly).local(local).node();
client = node.client();
} else {
log.debug("Configuring ES for network transport");
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
if (config.has(CLUSTER_NAME)) {
String clustername = config.get(CLUSTER_NAME);
Preconditions.checkArgument(StringUtils.isNotBlank(clustername), "Invalid cluster name: %s", clustername);
settings.put("cluster.name", clustername);
} else {
settings.put("client.transport.ignore_cluster_name", true);
}
log.debug("Transport sniffing enabled: {}", config.get(CLIENT_SNIFF));
settings.put("client.transport.sniff", config.get(CLIENT_SNIFF));
settings.put("script.disable_dynamic", false);
TransportClient tc = new TransportClient(settings.build());
int defaultPort = config.has(INDEX_PORT) ? config.get(INDEX_PORT) : HOST_PORT_DEFAULT;
for (String host : config.get(INDEX_HOSTS)) {
String[] hostparts = host.split(":");
String hostname = hostparts[0];
int hostport = defaultPort;
if (hostparts.length == 2)
hostport = Integer.parseInt(hostparts[1]);
log.info("Configured remote host: {} : {}", hostname, hostport);
tc.addTransportAddress(new InetSocketTransportAddress(hostname, hostport));
}
client = tc;
node = null;
}
return new ElasticSearchSetup.Connection(node, client);
}
use of org.elasticsearch.node.NodeBuilder in project play2-elasticsearch by cleverage.
the class IndexClient method start.
public void start() throws Exception {
// Load Elasticsearch Settings
Settings.Builder settings = loadSettings();
// Check Model
if (this.isLocalMode()) {
Logger.info("ElasticSearch : Starting in Local Mode");
NodeBuilder nb = nodeBuilder().settings(settings).local(true).client(false).data(true);
node = nb.node();
client = node.client();
Logger.info("ElasticSearch : Started in Local Mode");
} else {
Logger.info("ElasticSearch : Starting in Client Mode");
TransportClient c = TransportClient.builder().settings(settings).build();
if (config.client == null) {
throw new Exception("Configuration required - elasticsearch.client when local model is disabled!");
}
String[] hosts = config.client.trim().split(",");
boolean done = false;
for (String host : hosts) {
String[] parts = host.split(":");
if (parts.length != 2) {
throw new Exception("Invalid Host: " + host);
}
Logger.info("ElasticSearch : Client - Host: " + parts[0] + " Port: " + parts[1]);
c.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(parts[0]), Integer.valueOf(parts[1])));
done = true;
}
if (!done) {
throw new Exception("No Hosts Provided for ElasticSearch!");
}
client = c;
Logger.info("ElasticSearch : Started in Client Mode");
}
// Check Client
if (client == null) {
throw new Exception("ElasticSearch Client cannot be null - please check the configuration provided and the health of your ElasticSearch instances.");
}
}
Aggregations