Refine search
static Settings.Builder defaults() { Settings.Builder builder = Settings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put("index.refresh_interval", "30s") .put("index.mapper.dynamic", false); Arrays.stream(DefaultIndexSettingsElement.values()) .map(DefaultIndexSettingsElement::settings) .forEach(builder::put); return builder; } }
@Override public TransportClient createClient(Map<String, String> clientConfig) { Settings settings = Settings.settingsBuilder().put(clientConfig).build(); TransportClient transportClient = TransportClient.builder().settings(settings).build(); for (TransportAddress address : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) { transportClient.addTransportAddress(address); } // verify that we actually are connected to a cluster if (transportClient.connectedNodes().isEmpty()) { // close the transportClient here IOUtils.closeQuietly(transportClient); throw new RuntimeException("Elasticsearch client is not connected to any Elasticsearch nodes!"); } if (LOG.isInfoEnabled()) { LOG.info("Created Elasticsearch TransportClient with connected nodes {}", transportClient.connectedNodes()); } return transportClient; }
private Settings getSettings(String clusterName, String host, int port) throws IOException { dataDir = Files.createTempDirectory(clusterName + "_" + System.currentTimeMillis() + "data").toFile(); File homeDir = Files.createTempDirectory(clusterName + "_" + System.currentTimeMillis() + "-home").toFile(); Settings.Builder settingsBuilder = Settings.builder() .put("cluster.name", clusterName) .put("http.host", host) .put("http.port", port) .put("transport.tcp.port", port + 100) .put(ElasticSearchConfiguration.EMBEDDED_DATA_PATH_DEFAULT_VALUE, dataDir.getAbsolutePath()) .put(ElasticSearchConfiguration.EMBEDDED_HOME_PATH_DEFAULT_VALUE, homeDir.getAbsolutePath()) .put("http.enabled", true) .put("script.inline", true) .put("script.stored", true) .put("node.data", true) .put("http.enabled", true) .put("http.type", "netty4") .put("transport.type", "netty4"); return settingsBuilder.build(); }
private TransportClient buildTransportClient() { Settings.Builder esSettings = Settings.builder(); // mandatory property defined by bootstrap process esSettings.put("cluster.name", clusterName); TransportClient nativeClient = new MinimalTransportClient(esSettings.build(), hostAndPorts); if (LOG.isDebugEnabled()) { LOG.debug("Connected to Elasticsearch node: [{}]", displayedAddresses(nativeClient)); } return nativeClient; }
@Override public Settings additionalSettings() { if(disabled) { return Settings.EMPTY; } final Settings.Builder builder = Settings.builder(); builder.put(super.additionalSettings()); if(!sslOnly){ builder.put(NetworkModule.TRANSPORT_TYPE_KEY, "com.floragunn.searchguard.ssl.http.netty.SearchGuardSSLNettyTransport"); builder.put(NetworkModule.HTTP_TYPE_KEY, "com.floragunn.searchguard.http.SearchGuardHttpServerTransport"); } return builder.build(); } @Override
private TransportClient createTransportClient(Config config) throws UnknownHostException { TransportClient transportClient; // Set TransportClient settings Settings.Builder settingsBuilder = Settings.builder(); if (config.hasPath(ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_SETTINGS)) { settingsBuilder.put(ConfigUtils.configToProperties(config, ElasticsearchWriterConfigurationKeys.ELASTICSEARCH_WRITER_SETTINGS)); } settingsBuilder.put("client.transport.ignore_cluster_name",true); settingsBuilder.put("client.transport.sniff", true); transportClient = new PreBuiltTransportClient(settingsBuilder.build()); this.hostAddresses.forEach(transportClient::addTransportAddress); return transportClient; } }
@Override public Connection createPhysicalConnection(String url, Properties info) throws SQLException { if (client == null) { synchronized (this) { if (client == null) { Settings.Builder builder = Settings.builder(); info.forEach((k, v) -> builder.put(k.toString(), v.toString())); String[] hostAndPortArray = url.split("/")[2].split(","); int length = hostAndPortArray.length; TransportAddress[] addresses = new TransportAddress[length]; try { String[] hostAndPortArr; for (int i = 0; i < length; ++i) { hostAndPortArr = hostAndPortArray[i].split(":"); addresses[i] = new TransportAddress(InetAddress.getByName(hostAndPortArr[0]), Integer.parseInt(hostAndPortArr[1])); } } catch (UnknownHostException e) { throw new SQLException(e); } client = new PreBuiltXPackTransportClient(builder.build()).addTransportAddresses(addresses); } } } Connection conn = new ElasticSearchConnection(client); createCount.incrementAndGet(); return conn; }
@Override public TransportClient createClient(Map<String, String> clientConfig) { Settings settings = Settings.builder().put(clientConfig) .put(NetworkModule.HTTP_TYPE_KEY, Netty3Plugin.NETTY_HTTP_TRANSPORT_NAME) .put(NetworkModule.TRANSPORT_TYPE_KEY, Netty3Plugin.NETTY_TRANSPORT_NAME) .build(); TransportClient transportClient = new PreBuiltTransportClient(settings); for (TransportAddress transport : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) { transportClient.addTransportAddress(transport); } // verify that we actually are connected to a cluster if (transportClient.connectedNodes().isEmpty()) { // close the transportClient here IOUtils.closeQuietly(transportClient); throw new RuntimeException("Elasticsearch client is not connected to any Elasticsearch nodes!"); } if (LOG.isInfoEnabled()) { LOG.info("Created Elasticsearch TransportClient with connected nodes {}", transportClient.connectedNodes()); } return transportClient; }
@Override public Client get() { Settings settings = Settings.builder() .put("client.transport.ignore_cluster_name", true) .put("client.transport.sniff", true) .build(); TransportClient tc = new PreBuiltTransportClient(settings); List<URI> clusterAddresses = configuration.getURIs(); if (clusterAddresses.isEmpty()) { logger.warn(ElasticSearchConfiguration.ELASTIC_SEARCH_URL_PROPERTY_NAME + " is not set. Indexing will remain DISABLED."); } for (URI hostAddress : clusterAddresses) { int port = Optional.ofNullable(hostAddress.getPort()).orElse(9200); try { tc.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAddress.getHost()), port)); } catch (UnknownHostException uhe){ throw new ProvisionException("Invalid host" + hostAddress.getHost(), uhe); } } return tc; } }
public void createIndexIfNotExists(String indexName, final int shards, final int replicas) { // create an index if not existent if (!this.elasticsearchClient.admin().indices().prepareExists(indexName).execute().actionGet().isExists()) { Settings.Builder settings = Settings.builder() .put("number_of_shards", shards) .put("number_of_replicas", replicas); this.elasticsearchClient.admin().indices().prepareCreate(indexName) .setSettings(settings) .setUpdateAllTypes(true) .execute().actionGet(); } else { //LOGGER.debug("Index with name {} already exists", indexName); } }
EmbeddedElasticsearchNode() { try { elasticsearchDirectory = File.createTempFile("elasticsearch", "test"); elasticsearchDirectory.delete(); elasticsearchDirectory.mkdir(); } catch (IOException e) { throw new UncheckedIOException(e); } Settings setting = Settings.builder() .put("cluster.name", "test") .put("path.home", elasticsearchDirectory.getPath()) .put("path.data", new File(elasticsearchDirectory, "data").getAbsolutePath()) .put("path.logs", new File(elasticsearchDirectory, "logs").getAbsolutePath()) .put("transport.type.default", "local") .put("transport.type", "netty4") .put("http.type", "netty4") .put("http.enabled", "true") .put("path.home", "elasticsearch-test-data") .build(); node = new ElasticsearchNode(setting, ImmutableList.of(Netty4Plugin.class)); }
@Inject public ElasticsearchClient(ElasticsearchTableDescriptionProvider descriptions, ElasticsearchConnectorConfig config) throws IOException { tableDescriptions = requireNonNull(descriptions, "description is null"); ElasticsearchConnectorConfig configuration = requireNonNull(config, "config is null"); requestTimeout = configuration.getRequestTimeout(); maxAttempts = configuration.getMaxRequestRetries(); maxRetryTime = configuration.getMaxRetryTime(); for (ElasticsearchTableDescription tableDescription : tableDescriptions.getAllTableDescriptions()) { if (!clients.containsKey(tableDescription.getClusterName())) { Settings settings = Settings.builder().put("cluster.name", tableDescription.getClusterName()).build(); TransportAddress address = new TransportAddress(InetAddress.getByName(tableDescription.getHost()), tableDescription.getPort()); TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(address); clients.put(tableDescription.getClusterName(), client); } } this.columnMetadataCache = CacheBuilder.newBuilder() .expireAfterWrite(30, MINUTES) .refreshAfterWrite(15, MINUTES) .maximumSize(500) .build(asyncReloading(CacheLoader.from(this::loadColumns), executor)); }
private void initClient() throws UnknownHostException { Settings.Builder settingsBuilder = Settings.builder(); settingsBuilder.put( Settings.Builder.EMPTY_SETTINGS ); meta.getSettingsMap().entrySet().stream().forEach( ( s ) -> settingsBuilder.put( s.getKey(), environmentSubstitute( s.getValue() ) ) ); PreBuiltTransportClient tClient = new PreBuiltTransportClient( settingsBuilder.build() ); for ( Server server : meta.getServers() ) { tClient.addTransportAddress( new TransportAddress( InetAddress.getByName( environmentSubstitute( server.getAddress() ) ), server.getPort() ) ); } client = tClient; /** With the upgrade to elasticsearch 6.3.0, removed the NodeBuilder, * which was removed from the elasticsearch 5.0 API, see: * https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_java_api_changes * .html#_nodebuilder_removed */ }
/** * create a elasticsearch transport client (remote elasticsearch) * @param addresses an array of host:port addresses * @param clusterName */ public ElasticsearchClient(final String[] addresses, final String clusterName) { // create default settings and add cluster name Settings.Builder settings = Settings.builder() .put("cluster.name", clusterName) .put("cluster.routing.allocation.enable", "all") .put("cluster.routing.allocation.allow_rebalance", "true"); // create a client TransportClient tc = TransportClient.builder() .settings(settings.build()) .build(); for (String address: addresses) { String a = address.trim(); int p = a.indexOf(':'); if (p >= 0) try { InetAddress i = InetAddress.getByName(a.substring(0, p)); int port = Integer.parseInt(a.substring(p + 1)); tc.addTransportAddress(new InetSocketTransportAddress(i, port)); } catch (UnknownHostException e) { DAO.severe(e); } } this.elasticsearchClient = tc; }
private Settings.Builder getMinimumNonSgNodeSettingsBuilder(final int nodenum, final boolean masterNode, final boolean dataNode, final boolean tribeNode, int nodeCount, int masterCount, SortedSet<Integer> tcpPorts, int tcpPort, int httpPort) { return Settings.builder() .put("node.name", "node_"+clustername+ "_num" + nodenum) .put("node.data", dataNode) .put("node.master", masterNode) .put("cluster.name", clustername) .put("path.data", "data/"+clustername+"/data") .put("path.logs", "data/"+clustername+"/logs") .put("node.max_local_storage_nodes", nodeCount) .put("discovery.zen.minimum_master_nodes", minMasterNodes(masterCount)) .put("discovery.zen.no_master_block", "all") .put("discovery.zen.fd.ping_timeout", "5s") .put("discovery.initial_state_timeout","8s") .putList("discovery.zen.ping.unicast.hosts", tcpPorts.stream().map(s->"127.0.0.1:"+s).collect(Collectors.toList())) .put("transport.tcp.port", tcpPort) .put("http.port", httpPort) .put("http.enabled", true) .put("cluster.routing.allocation.disk.threshold_enabled", false) .put("http.cors.enabled", true) .put("path.home", "."); } // @formatter:on