/** * Starts an ElasticSearch node. * @return the started node. */ public static Node startEsNode() { Node node = NodeBuilder.nodeBuilder().data(true).settings( Settings.settingsBuilder() .put(ClusterName.SETTING, EsConstants.CLUSTER_NAME) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(EsExecutors.PROCESSORS, 1) .put("http.enabled", true) .put("index.percolator.map_unmapped_fields_as_string", true) .put("index.store.type", "mmapfs") .put("path.home", "./data") ).build(); node.start(); return node; }
public synchronized void start(String clusterName, String host, int port) throws Exception { if (instance != null) { String msg = String.format( "An instance of this Embedded Elastic Search server is already running on port: %d. " + "It must be stopped before you can call start again.", getPort() ); logger.error(msg); throw new IllegalStateException(msg); } final Settings settings = getSettings(clusterName, host, port); dataDir = setupDataDir(settings.get(ElasticSearchConfiguration.EMBEDDED_DATA_PATH_DEFAULT_VALUE)); logger.info("Starting ElasticSearch for cluster {} ", settings.get("cluster.name")); instance = new PluginConfigurableNode(settings, singletonList(Netty4Plugin.class)); instance.start(); Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { if (instance != null) { instance.close(); } } catch (IOException e) { logger.error("Error closing ElasticSearch"); } })); logger.info("ElasticSearch cluster {} started in local mode on port {}", instance.settings().get("cluster.name"), getPort()); }
} else { // Start node only if transport client mode is disabled node = nodeBuilder().clusterName(clusterName).settings(settings).node(); node.start(); client = node.client();
private static void startElasticsearch() throws Exception { try { FileUtils.deleteDirectory(new File("build/elasticsearch")); } catch (IOException e) { // ignore } final Settings settings = Settings.builder() .put("path.home", "build/elasticsearch") .put("node.name", "junit-es-node") .put("path.logs", "build/elasticsearch/logs") .put("path.data", "build/elasticsearch/data") .put("transport.type", "local") .put("http.type", "netty4") .build(); node = new TestNode(settings, Collections.singletonList(Netty4Plugin.class)); node.start(); node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get(); }
private static Node createNode() { try { Path tempDir = Files.createTempDirectory("EsTester"); tempDir.toFile().deleteOnExit(); Settings settings = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), tempDir) .put("node.name", "EsTester") .put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), Integer.MAX_VALUE) .put("logger.level", "INFO") .put("action.auto_create_index", false) // Default the watermarks to absurdly low to prevent the tests // from failing on nodes without enough disk space .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1b") .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "1b") // always reduce this - it can make tests really slow .put(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_STATE_SYNC_SETTING.getKey(), TimeValue.timeValueMillis(20)) .put(NetworkModule.TRANSPORT_TYPE_KEY, "local") .put(NetworkModule.HTTP_ENABLED.getKey(), false) .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "single-node") .build(); Node node = new Node(settings); return node.start(); } catch (Exception e) { throw new IllegalStateException("Fail to start embedded Elasticsearch", e); } } }
node.start(); node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get();
private void start() throws NodeValidationException { node.start(); keepAliveThread.start(); }
@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(); }
lList.add(Netty4Plugin.class); esNode = new MyNode(settings, lList); esNode.start();
client = node.client(); try { node.start(); } catch (NodeValidationException e) { throw new UnableToStartException("Error starting ES node.", e);
private Node startNode() { if (null != node) { return node.start(); } return null; }
/** * Starts current node */ public void start() { Preconditions.checkState(!isStarted, "already started"); try { node.start(); this.isStarted = true; } catch (NodeValidationException e) { throw new RuntimeException(e); } }
@Override public void start(Context context) { for (Entry<String, Node> entry : elasticSearchLocalNodes.entrySet()) { LOGGER.info("Starting ElasticSearch local node {}", entry.getKey()); entry.getValue().start(); } }
@Override public void start() { try { elasticsearch.start(); proxy = elasticsearch.client(); } catch (final Exception exception) { throw new RuntimeException(exception); } }
/** * Starts current node */ public void start() { Preconditions.checkState(!isStarted, "already started"); try { node.start(); this.isStarted = true; } catch (NodeValidationException e) { throw new RuntimeException(e); } }
/** * Starts current node. */ public void start() { Preconditions.checkState(! isStarted, "already started"); try { node.start(); this.isStarted = true; } catch (NodeValidationException ex) { throw new RuntimeException(ex); } }
BasicConfigurator.configure(); Node node = NodeBuilder.nodeBuilder().local(true).node(); node.start(); while (!node.isClosed()) { try { Thread.sleep(60*1000); } catch (InterruptedException e) { node.close(); } } node.stop();
protected org.elasticsearch.node.Node createLocalNode(String clusterName) { return org.elasticsearch.node.NodeBuilder.nodeBuilder() .clusterName(clusterName).local(true).build().start(); } }
public final void startES(final Settings settings) throws Exception { FileUtils.deleteDirectory(new File("data")); esNode1 = new PluginAwareNode(getDefaultSettingsBuilder(1, false, true).put( settings == null ? Settings.Builder.EMPTY_SETTINGS : settings).build(), Netty4Plugin.class, SearchGuardSSLPlugin.class); esNode2 = new PluginAwareNode(getDefaultSettingsBuilder(2, true, true).put( settings == null ? Settings.Builder.EMPTY_SETTINGS : settings).build(), Netty4Plugin.class, SearchGuardSSLPlugin.class); esNode3 = new PluginAwareNode(getDefaultSettingsBuilder(3, true, false).put( settings == null ? Settings.Builder.EMPTY_SETTINGS : settings).build(), Netty4Plugin.class, SearchGuardSSLPlugin.class); esNode1.start(); esNode2.start(); esNode3.start(); waitForGreenClusterState(esNode1.client()); }
public static Node createNode(String clusterName, boolean client, int port) { Settings settings = NodeBuilder.nodeBuilder().settings() .put("script.groovy.sandbox.enabled", true) .put("script.disable_dynamic", false) .put("transport.tcp.port", port).build(); Node node = NodeBuilder.nodeBuilder().client(client).data(!client).clusterName(clusterName).settings(settings).build(); node.start(); return node; } }