org.elasticsearch.node.Node Java Examples
The following examples show how to use
org.elasticsearch.node.Node.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockTransportService.java From crate with Apache License 2.0 | 6 votes |
/** * Build the service. * * @param clusterSettings if non null the {@linkplain TransportService} will register with the {@link ClusterSettings} for settings * updates for {@link TransportSettings#TRACE_LOG_EXCLUDE_SETTING} and {@link TransportSettings#TRACE_LOG_INCLUDE_SETTING}. */ public MockTransportService(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor, @Nullable ClusterSettings clusterSettings) { this( settings, transport, threadPool, interceptor, (boundAddress) -> DiscoveryNode.createLocal( settings, boundAddress.publishAddress(), settings.get(Node.NODE_NAME_SETTING.getKey(), UUIDs.randomBase64UUID()) ), clusterSettings ); }
Example #2
Source File: InternalTestCluster.java From crate with Apache License 2.0 | 6 votes |
synchronized String routingKeyForShard(Index index, int shard, Random random) { assertThat(shard, greaterThanOrEqualTo(0)); assertThat(shard, greaterThanOrEqualTo(0)); for (NodeAndClient n : nodes.values()) { Node node = n.node; IndicesService indicesService = getInstanceFromNode(IndicesService.class, node); ClusterService clusterService = getInstanceFromNode(ClusterService.class, node); IndexService indexService = indicesService.indexService(index); if (indexService != null) { assertThat(indexService.getIndexSettings().getSettings().getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), greaterThan(shard)); OperationRouting operationRouting = clusterService.operationRouting(); while (true) { String routing = RandomStrings.randomAsciiOfLength(random, 10); final int targetShard = operationRouting .indexShards(clusterService.state(), index.getName(), null, routing) .shardId().getId(); if (shard == targetShard) { return routing; } } } } fail("Could not find a node that holds " + index); return null; }
Example #3
Source File: MockTransportService.java From crate with Apache License 2.0 | 6 votes |
public static MockTransportService createNewService(Settings settings, Transport transport, Version version, ThreadPool threadPool, @Nullable ClusterSettings clusterSettings) { return new MockTransportService( settings, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> new DiscoveryNode( Node.NODE_NAME_SETTING.get(settings), UUIDs.randomBase64UUID(), boundAddress.publishAddress(), Node.NODE_ATTRIBUTES.getAsMap(settings), DiscoveryNode.getRolesFromSettings(settings), version ), clusterSettings ); }
Example #4
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 6 votes |
/** * Start a closed node. * * @param i the number of nodes * @return true if the node is started. */ @SuppressWarnings("resource") public boolean startNode(final int i) { if (i >= nodeList.size()) { return false; } if (!nodeList.get(i).isClosed()) { return false; } final Node node = new ClusterRunnerNode(envList.get(i), pluginList); try { node.start(); nodeList.set(i, node); return true; } catch (final NodeValidationException e) { print(e.getLocalizedMessage()); } return false; }
Example #5
Source File: ElasticsearchITest.java From java-specialagent with Apache License 2.0 | 6 votes |
public static void main(final String[] args) throws Exception { final Settings settings = Settings.builder() .put("path.home", ES_WORKING_DIR) .put("path.data", ES_WORKING_DIR + "/data") .put("path.logs", ES_WORKING_DIR + "/logs") .put("transport.type", "netty4") .put("http.type", "netty4") .put("cluster.name", clusterName) .put("http.port", HTTP_PORT) .put("transport.tcp.port", HTTP_TRANSPORT_PORT) .put("network.host", "127.0.0.1") .build(); final Collection<Class<? extends Plugin>> classpathPlugins = Collections.singletonList(Netty4Plugin.class); try (final Node node = NodeFactory.makeNode(settings, classpathPlugins)) { node.start(); runRestClient(); runTransportClient(); } TestUtil.checkSpan(new ComponentSpanCount("java-elasticsearch", 4)); }
Example #6
Source File: LocalElasticSearch.java From core-ng-project with Apache License 2.0 | 6 votes |
public HttpHost start() { var watch = new StopWatch(); this.dataPath = Files.tempDir(); try { Settings.Builder settings = Settings.builder(); settings.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), "test") .put(Node.NODE_NAME_SETTING.getKey(), "test") .put(Environment.PATH_HOME_SETTING.getKey(), dataPath) .put(NetworkService.GLOBAL_NETWORK_BIND_HOST_SETTING.getKey(), "_local_") .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE); node = new LocalNode(settings.build()); node.start(); // on same local server, there may be multiple es started, e.g. multiple test jobs on shared build server, this is to retrieve actual http port return new HttpHost("localhost", node.injector().getInstance(HttpServerTransport.class).boundAddress().publishAddress().getPort()); } catch (NodeValidationException e) { throw new Error(e); } finally { logger.info("create local elasticsearch node, dataPath={}, elapsed={}", dataPath, watch.elapsed()); } }
Example #7
Source File: AbstractNodeTest.java From elasticsearch-gatherer with Apache License 2.0 | 6 votes |
public Node buildNode(String id, Settings settings) { String settingsSource = getClass().getName().replace('.', '/') + ".yml"; Settings finalSettings = settingsBuilder() .loadFromClasspath(settingsSource) .put(defaultSettings) .put(settings) .put("name", id) .build(); if (finalSettings.get("gateway.type") == null) { finalSettings = settingsBuilder().put(finalSettings).put("gateway.type", "none").build(); } if (finalSettings.get("cluster.routing.schedule") != null) { finalSettings = settingsBuilder().put(finalSettings).put("cluster.routing.schedule", "50ms").build(); } Node node = nodeBuilder().settings(finalSettings).build(); Client client = node.client(); nodes.put(id, node); clients.put(id, client); return node; }
Example #8
Source File: BulkProcessorObjectFactoryTest.java From log4j2-elasticsearch with Apache License 2.0 | 6 votes |
public EmbeddedElasticsearchServer(String storagePath) { this.storagePath = storagePath; try { tempFile = File.createTempFile("elasticsearch", "test"); this.storagePath = tempFile.getParent(); tempFile.deleteOnExit(); } catch (IOException e) { e.printStackTrace(); } Settings.Builder elasticsearchSettings = Settings.builder() .put("http.enabled", "false") .put("path.data", this.storagePath) .put("path.home", System.getProperty("user.dir")) .put("transport.type", "local"); node = new Node(elasticsearchSettings.build()); client = node.client(); }
Example #9
Source File: ElasticSearchTransportClient.java From ingestion with Apache License 2.0 | 5 votes |
private void openLocalDiscoveryClient() { logger.info("Using ElasticSearch AutoDiscovery mode"); Node node = NodeBuilder.nodeBuilder().client(true).local(true).node(); if (client != null) { client.close(); } client = node.client(); }
Example #10
Source File: AbstractNodeTestHelper.java From elasticsearch-csv with Apache License 2.0 | 5 votes |
public void closeAllNodes() throws IOException { for (AbstractClient client : clients.values()) { client.close(); } clients.clear(); for (Node node : nodes.values()) { if (node != null) { node.close(); } } nodes.clear(); }
Example #11
Source File: MockElasticsearchServer.java From foxtrot with Apache License 2.0 | 5 votes |
public MockElasticsearchServer(String directory) throws NodeValidationException { this.DATA_DIRECTORY = UUID.randomUUID() .toString() + "/" + directory; Settings settings = Settings.builder() .put("http.enabled", "false") .put("path.home", "target/" + DATA_DIRECTORY) .put("transport.type", "local") .build(); Stopwatch stopwatch = Stopwatch.createStarted(); node = new Node(settings).start(); System.out.printf("TimeTakenForEstart: %d%n", stopwatch.elapsed(TimeUnit.MILLISECONDS)); }
Example #12
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 5 votes |
/** * Return a non-master node. * * @return non-master node */ public synchronized Node nonMasterNode() { final ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState(); final String name = state.nodes().getMasterNode().getName(); for (final Node node : nodeList) { if (!node.isClosed() && !name.equals(node.settings().get(NODE_NAME))) { return node; } } return null; }
Example #13
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 5 votes |
/** * Return a node index. * * @param node node to check an index * @return -1 if the node does not exist. */ public int getNodeIndex(final Node node) { for (int i = 0; i < nodeList.size(); i++) { if (nodeList.get(i).equals(node)) { return i; } } return -1; }
Example #14
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 5 votes |
/** * Return a node by the name. * * @param name A node name * @return null if the node is not found by the name */ public Node getNode(final String name) { if (name == null) { return null; } for (final Node node : nodeList) { if (name.equals(node.settings().get(NODE_NAME))) { return node; } } return null; }
Example #15
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 5 votes |
/** * Return a node by the node index. * * @param i A node index * @return null if the node is not found */ public Node getNode(final int i) { if (i < 0 || i >= nodeList.size()) { return null; } return nodeList.get(i); }
Example #16
Source File: ElasticsearchClusterRunner.java From elasticsearch-cluster-runner with Apache License 2.0 | 5 votes |
/** * Check if a cluster runner is closed. * * @return true if a runner is closed. */ public boolean isClosed() { for (final Node node : nodeList) { if (!node.isClosed()) { return false; } } return true; }
Example #17
Source File: NodeTestUtils.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
private void closeNodes() throws IOException { logger.info("closing all clients"); for (AbstractClient client : clients.values()) { client.close(); } clients.clear(); logger.info("closing all nodes"); for (Node node : nodes.values()) { if (node != null) { node.close(); } } nodes.clear(); logger.info("all nodes closed"); }
Example #18
Source File: ReindexingPluginTest.java From elasticsearch-reindexing with Apache License 2.0 | 5 votes |
private void test_index_type_to_remote_newIndex(Node node, String index, String type) throws IOException { String newIndex = "dataset2"; String newType = type; try (CurlResponse curlResponse = Curl .post(node, "/" + index + "/" + type + "/_reindex/" + newIndex) .param("wait_for_completion", "true") .param("url", "http://localhost:" + node.settings().get("http.port")) .execute()) { Map<String, Object> map = curlResponse.getContentAsMap(); assertTrue(map.containsKey("acknowledged")); assertNull(map.get("name")); } runner.flush(); assertTrue(runner.indexExists(index)); assertTrue(runner.indexExists(newIndex)); // search documents { final SearchResponse searchResponse = runner.search(newIndex, newType, null, null, 0, 10); assertEquals(docNumber, searchResponse.getHits().getTotalHits()); } runner.deleteIndex(newIndex); }
Example #19
Source File: ReindexingPluginTest.java From elasticsearch-reindexing with Apache License 2.0 | 5 votes |
private void test_index_type_to_remote_newIndex_newType(Node node, String index, String type) throws IOException { String newIndex = "dataset2"; String newType = "item2"; try (CurlResponse curlResponse = Curl .post(node, "/" + index + "/" + type + "/_reindex/" + newIndex + "/" + newType) .param("wait_for_completion", "true") .param("url", "http://localhost:" + node.settings().get("http.port")) .execute()) { Map<String, Object> map = curlResponse.getContentAsMap(); assertTrue(map.containsKey("acknowledged")); assertNull(map.get("name")); } runner.flush(); assertTrue(runner.indexExists(index)); assertTrue(runner.indexExists(newIndex)); // search documents { final SearchResponse searchResponse = runner.search(newIndex, newType, null, null, 0, 10); assertEquals(docNumber, searchResponse.getHits().getTotalHits()); } runner.deleteIndex(newIndex); }
Example #20
Source File: ClientFactory.java From storm-trident-elasticsearch with Apache License 2.0 | 5 votes |
private void registerShutdownHook(final Node node) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { node.close(); } }); }
Example #21
Source File: ReindexingPluginTest.java From elasticsearch-reindexing with Apache License 2.0 | 5 votes |
private void test_index_to_newIndex(Node node, String index) throws IOException { String newIndex = "dataset2"; try (CurlResponse curlResponse = Curl .post(node, "/" + index + "/_reindex/" + newIndex) .param("wait_for_completion", "true") .execute()) { Map<String, Object> map = curlResponse.getContentAsMap(); assertTrue(map.containsKey("acknowledged")); assertNull(map.get("name")); } // causes a lucene commit, more expensive than refresh runner.flush(); assertTrue(runner.indexExists(index)); assertTrue(runner.indexExists(newIndex)); // search documents { final SearchResponse searchResponse = runner.search(newIndex, // BuilderCallback对象用于加工SearchRequestBuilder对象 new BuilderCallback<SearchRequestBuilder>() { @Override public SearchRequestBuilder apply(SearchRequestBuilder builder) { return builder; } }); assertEquals(docNumber, searchResponse.getHits().getTotalHits()); } runner.deleteIndex(newIndex); }
Example #22
Source File: ElasticsearchBaseIT.java From datacollector with Apache License 2.0 | 5 votes |
private static Node createTestNode(Map<String, Object> configs) { Settings.Builder settings = Settings.builder(); for (Map.Entry<String, Object> config : configs.entrySet()) { settings.put(config.getKey(), config.getValue()); } return new TestNode(settings.build()); }
Example #23
Source File: AbstractNodeTestHelper.java From elasticsearch-csv with Apache License 2.0 | 5 votes |
private Node buildNode(String id) { Settings finalSettings = settingsBuilder() .put(getNodeSettings()) .put("name", id) .build(); Node node = nodeBuilder() .settings(finalSettings).build(); AbstractClient client = (AbstractClient)node.client(); nodes.put(id, node); clients.put(id, client); return node; }
Example #24
Source File: DiscoveryNode.java From crate with Apache License 2.0 | 5 votes |
public static boolean nodeRequiresLocalStorage(Settings settings) { boolean localStorageEnable = Node.NODE_LOCAL_STORAGE_SETTING.get(settings); if (localStorageEnable == false && (Node.NODE_DATA_SETTING.get(settings) || Node.NODE_MASTER_SETTING.get(settings)) ) { // TODO: make this a proper setting validation logic, requiring multi-settings validation throw new IllegalArgumentException("storage can not be disabled for master and data nodes"); } return localStorageEnable; }
Example #25
Source File: SearchClientServiceMockImpl.java From elasticsearch-tutorial with MIT License | 5 votes |
public void closeAllNodes() { for (Client client : clients.values()) { client.close(); } clients.clear(); for (Node node : nodes.values()) { node.close(); } nodes.clear(); }
Example #26
Source File: ScalingExecutorBuilder.java From crate with Apache License 2.0 | 5 votes |
@Override ScalingExecutorSettings getSettings(Settings settings) { final String nodeName = Node.NODE_NAME_SETTING.get(settings); final int coreThreads = coreSetting.get(settings); final int maxThreads = maxSetting.get(settings); final TimeValue keepAlive = keepAliveSetting.get(settings); return new ScalingExecutorSettings(nodeName, coreThreads, maxThreads, keepAlive); }
Example #27
Source File: NodeEnvironment.java From crate with Apache License 2.0 | 5 votes |
private void ensureNoIndexMetaData(final NodePath[] nodePaths) throws IOException { List<Path> indexMetaDataPaths = collectIndexMetaDataPaths(nodePaths); if (indexMetaDataPaths.isEmpty() == false) { throw new IllegalStateException("Node is started with " + Node.NODE_DATA_SETTING.getKey() + "=false and " + Node.NODE_MASTER_SETTING.getKey() + "=false, but has index metadata: " + indexMetaDataPaths + "." ); } }
Example #28
Source File: DiscoveryNode.java From crate with Apache License 2.0 | 5 votes |
/** extract node roles from the given settings */ public static Set<Role> getRolesFromSettings(Settings settings) { Set<Role> roles = EnumSet.noneOf(Role.class); if (Node.NODE_MASTER_SETTING.get(settings)) { roles.add(Role.MASTER); } if (Node.NODE_DATA_SETTING.get(settings)) { roles.add(Role.DATA); } return roles; }
Example #29
Source File: NodeTestUtils.java From elasticsearch-xml with Apache License 2.0 | 5 votes |
private void closeNodes() throws IOException { logger.info("closing all clients"); for (AbstractClient client : clients.values()) { client.close(); } clients.clear(); logger.info("closing all nodes"); for (Node node : nodes.values()) { if (node != null) { node.close(); } } nodes.clear(); logger.info("all nodes closed"); }
Example #30
Source File: InternalTestCluster.java From crate with Apache License 2.0 | 5 votes |
public String startMasterOnlyNode(Settings settings) { Settings settings1 = Settings.builder() .put(settings) .put(Node.NODE_MASTER_SETTING.getKey(), true) .put(Node.NODE_DATA_SETTING.getKey(), false) .build(); return startNode(settings1); }