org.elasticsearch.common.network.NetworkModule Java Examples

The following examples show how to use org.elasticsearch.common.network.NetworkModule. 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: EmbeddedElasticsearchNodeEnvironmentImpl.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void start(File tmpDataFolder, String clusterName) throws Exception {
	if (node == null) {
		Settings settings = Settings.builder()
			.put("cluster.name", clusterName)
			.put("http.enabled", false)
			.put("path.home", tmpDataFolder.getParent())
			.put("path.data", tmpDataFolder.getAbsolutePath())
			.put(NetworkModule.HTTP_TYPE_KEY, Netty3Plugin.NETTY_HTTP_TRANSPORT_NAME)
			.put(NetworkModule.TRANSPORT_TYPE_KEY, Netty3Plugin.NETTY_TRANSPORT_NAME)
			.build();

		node = new PluginNode(settings);
		node.start();
	}
}
 
Example #2
Source File: EmbeddedElasticsearchNodeEnvironmentImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void start(File tmpDataFolder, String clusterName) throws Exception {
	if (node == null) {
		Settings settings = Settings.builder()
			.put("cluster.name", clusterName)
			.put("http.enabled", false)
			.put("path.home", tmpDataFolder.getParent())
			.put("path.data", tmpDataFolder.getAbsolutePath())
			.put(NetworkModule.HTTP_TYPE_KEY, Netty3Plugin.NETTY_HTTP_TRANSPORT_NAME)
			.put(NetworkModule.TRANSPORT_TYPE_KEY, Netty3Plugin.NETTY_TRANSPORT_NAME)
			.build();

		node = new PluginNode(settings);
		node.start();
	}
}
 
Example #3
Source File: OpenDistroSecuritySSLPlugin.java    From deprecated-security-ssl with Apache License 2.0 6 votes vote down vote up
@Override
public Settings additionalSettings() {
   final Settings.Builder builder = Settings.builder();
    
   if(!client && httpSSLEnabled) {
       
       if(settings.get("http.compression") == null) {
           builder.put("http.compression", false);
           log.info("Disabled https compression by default to mitigate BREACH attacks. You can enable it by setting 'http.compression: true' in elasticsearch.yml");
       }
       
       builder.put(NetworkModule.HTTP_TYPE_KEY, "com.amazon.opendistroforelasticsearch.security.ssl.http.netty.OpenDistroSecuritySSLNettyHttpServerTransport");
   }
    
   if (transportSSLEnabled) {
       builder.put(NetworkModule.TRANSPORT_TYPE_KEY, "com.amazon.opendistroforelasticsearch.security.ssl.http.netty.OpenDistroSecuritySSLNettyTransport");
   }
    
    return builder.build();
}
 
Example #4
Source File: NodeTestConfig.java    From elastic-crud with Apache License 2.0 6 votes vote down vote up
@Bean(destroyMethod="close")
Node newNode() throws NodeValidationException {
  final Path tempDir = createTempDir().toPath();
  final Settings settings = Settings.builder()
    .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), new ClusterName("single-node-cluster" + System.nanoTime()))
    .put(Environment.PATH_HOME_SETTING.getKey(), tempDir)
    .put(Environment.PATH_REPO_SETTING.getKey(), tempDir.resolve("repo"))
    .put(Environment.PATH_SHARED_DATA_SETTING.getKey(), createTempDir().getParent())
    .put("node.name", "single-node")
    .put("script.inline", "true")
    .put("script.stored", "true")
    .put(ScriptService.SCRIPT_MAX_COMPILATIONS_PER_MINUTE.getKey(), 1000)
    .put(EsExecutors.PROCESSORS_SETTING.getKey(), 1)
    .put(NetworkModule.HTTP_ENABLED.getKey(), false)
    .put("discovery.type", "zen")
    .put("transport.type", "local")
    .put(Node.NODE_DATA_SETTING.getKey(), true)
    .put(NODE_ID_SEED_SETTING.getKey(), System.nanoTime())
    .build();
  return new Node(settings).start(); // NOSONAR
}
 
Example #5
Source File: PreBuiltTransportClient.java    From sql4es with Apache License 2.0 6 votes vote down vote up
public void close() {
    super.close();
    if (!NetworkModule.TRANSPORT_TYPE_SETTING.exists(this.settings) || ((String)NetworkModule.TRANSPORT_TYPE_SETTING.get(this.settings)).equals("netty4")) {
        try {
            GlobalEventExecutor.INSTANCE.awaitInactivity(5L, TimeUnit.SECONDS);
        } catch (InterruptedException var3) {
            Thread.currentThread().interrupt();
        }

        try {
            ThreadDeathWatcher.awaitInactivity(5L, TimeUnit.SECONDS);
        } catch (InterruptedException var2) {
            Thread.currentThread().interrupt();
        }
    }

}
 
Example #6
Source File: EmbeddedElasticsearchNodeEnvironmentImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void start(File tmpDataFolder, String clusterName) throws Exception {
	if (node == null) {
		Settings settings = Settings.builder()
			.put("cluster.name", clusterName)
			.put("http.enabled", false)
			.put("path.home", tmpDataFolder.getParent())
			.put("path.data", tmpDataFolder.getAbsolutePath())
			.put(NetworkModule.HTTP_TYPE_KEY, Netty3Plugin.NETTY_HTTP_TRANSPORT_NAME)
			.put(NetworkModule.TRANSPORT_TYPE_KEY, Netty3Plugin.NETTY_TRANSPORT_NAME)
			.build();

		node = new PluginNode(settings);
		node.start();
	}
}
 
Example #7
Source File: ElasticsearchCollectorTest.java    From karaf-decanter with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    Collection plugins = Arrays.asList(Netty4Plugin.class);
    Settings settings = Settings.builder()
            .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), CLUSTER_NAME)
            .put(Node.NODE_NAME_SETTING.getKey(), "test")
            .put(NetworkModule.HTTP_TYPE_KEY, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME)
            .put(Environment.PATH_HOME_SETTING.getKey(), "target/data")
            .put(Environment.PATH_DATA_SETTING.getKey(), "target/data")
            .put("network.host", HOST)
            .put("http.port", HTTP_PORT)
            .put(NetworkModule.TRANSPORT_TYPE_KEY, Netty4Plugin.NETTY_TRANSPORT_NAME)
            .put("transport.port", TRANSPORT_PORT)
            .build();
    node = new MockNode(settings, plugins);
    node.start();
}
 
Example #8
Source File: TestElasticsearchAppender.java    From karaf-decanter with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    Collection plugins = Arrays.asList(Netty4Plugin.class);
    Settings settings = Settings.builder()
            .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), CLUSTER_NAME)
            .put(Node.NODE_NAME_SETTING.getKey(), "test")
            .put(NetworkModule.HTTP_TYPE_KEY, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME)
            .put(Environment.PATH_HOME_SETTING.getKey(), "target/data")
            .put(Environment.PATH_DATA_SETTING.getKey(), "target/data")
            .put("network.host", HOST)
            .put("http.port", HTTP_PORT)
            .put(NetworkModule.TRANSPORT_TYPE_KEY, Netty4Plugin.NETTY_TRANSPORT_NAME)
            .put("transport.port", TRANSPORT_PORT)
            .build();
    node = new MockNode(settings, plugins);
    node.start();
}
 
Example #9
Source File: Elasticsearch5ApiCallBridge.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #10
Source File: Elasticsearch5ApiCallBridge.java    From flink with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #11
Source File: Elasticsearch5ApiCallBridge.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public TransportClient createClient(Map<String, String> clientConfig) {
	Settings settings = Settings.builder()
		.put(NetworkModule.HTTP_TYPE_KEY, Netty3Plugin.NETTY_HTTP_TRANSPORT_NAME)
		.put(NetworkModule.TRANSPORT_TYPE_KEY, Netty3Plugin.NETTY_TRANSPORT_NAME)
		.put(clientConfig)
		.build();

	TransportClient transportClient = new PreBuiltTransportClient(settings);
	for (TransportAddress transport : ElasticsearchUtils.convertInetSocketAddresses(transportAddresses)) {
		transportClient.addTransportAddress(transport);
	}

	return transportClient;
}
 
Example #12
Source File: Netty4Plugin.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public Settings additionalSettings() {
    return Settings.builder()
        // here we set the netty4 transport and http transport as the default. This is a set once setting
        // ie. if another plugin does that as well the server will fail - only one default network can exist!
        .put(NetworkModule.HTTP_DEFAULT_TYPE_SETTING.getKey(), NETTY_HTTP_TRANSPORT_NAME)
        .put(NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.getKey(), NETTY_TRANSPORT_NAME)
        .put(HttpTransportSettings.SETTING_HTTP_COMPRESSION.getKey(), false)
        .build();
}
 
Example #13
Source File: MockNode.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected HttpServerTransport newHttpTransport(NetworkModule networkModule) {
    if (getPluginsService().filterPlugins(MockHttpTransport.TestPlugin.class).isEmpty()) {
        return super.newHttpTransport(networkModule);
    } else {
        return new MockHttpTransport();
    }
}
 
Example #14
Source File: TransportClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a new instance of the transport client.
 */
public TransportClient build() {
    Settings settings = InternalSettingsPreparer.prepareSettings(this.settings);
    settings = settingsBuilder()
            .put(NettyTransport.PING_SCHEDULE, "5s") // enable by default the transport schedule ping interval
            .put(settings)
            .put("network.server", false)
            .put("node.client", true)
            .put(CLIENT_TYPE_SETTING, CLIENT_TYPE)
            .build();

    PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses);
    this.settings = pluginsService.updatedSettings();

    Version version = Version.CURRENT;

    final ThreadPool threadPool = new ThreadPool(settings);
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();

    boolean success = false;
    try {
        ModulesBuilder modules = new ModulesBuilder();
        modules.add(new Version.Module(version));
        // plugin modules must be added here, before others or we can get crazy injection errors...
        for (Module pluginModule : pluginsService.nodeModules()) {
            modules.add(pluginModule);
        }
        modules.add(new PluginsModule(pluginsService));
        modules.add(new SettingsModule(this.settings));
        modules.add(new NetworkModule(namedWriteableRegistry));
        modules.add(new ClusterNameModule(this.settings));
        modules.add(new ThreadPoolModule(threadPool));
        modules.add(new TransportModule(this.settings, namedWriteableRegistry));
        modules.add(new SearchModule() {
            @Override
            protected void configure() {
                // noop
            }
        });
        modules.add(new ActionModule(true));
        modules.add(new ClientTransportModule());
        modules.add(new CircuitBreakerModule(this.settings));

        pluginsService.processModules(modules);

        Injector injector = modules.createInjector();
        final TransportService transportService = injector.getInstance(TransportService.class);
        transportService.start();
        transportService.acceptIncomingRequests();

        TransportClient transportClient = new TransportClient(injector);
        success = true;
        return transportClient;
    } finally {
        if (!success) {
            ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
        }
    }
}
 
Example #15
Source File: TransportClient.java    From elasticsearch-helper with Apache License 2.0 4 votes vote down vote up
public TransportClient build() {
    Settings settings = InternalSettingsPreparer.prepareSettings(this.settings);
    settings = settingsBuilder()
            .put("transport.ping.schedule", this.settings.get("ping.interval", "30s"))
            .put(settings)
            .put("network.server", false)
            .put("node.client", true)
            .put(CLIENT_TYPE_SETTING, CLIENT_TYPE)
            .build();
    PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses);
    this.settings = pluginsService.updatedSettings();
    Version version = Version.CURRENT;
    final ThreadPool threadPool = new ThreadPool(settings);
    final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();

    boolean success = false;
    try {
        ModulesBuilder modules = new ModulesBuilder();
        modules.add(new Version.Module(version));
        // plugin modules must be added here, before others or we can get crazy injection errors...
        for (Module pluginModule : pluginsService.nodeModules()) {
            modules.add(pluginModule);
        }
        modules.add(new PluginsModule(pluginsService));
        modules.add(new SettingsModule(this.settings));
        modules.add(new NetworkModule(namedWriteableRegistry));
        modules.add(new ClusterNameModule(this.settings));
        modules.add(new ThreadPoolModule(threadPool));
        modules.add(new TransportModule(this.settings, namedWriteableRegistry));
        modules.add(new SearchModule() {
            @Override
            protected void configure() {
                // noop
            }
        });
        modules.add(new ActionModule(true));
        modules.add(new ClientTransportModule(hostFailedListener));
        modules.add(new CircuitBreakerModule(this.settings));
        pluginsService.processModules(modules);
        Injector injector = modules.createInjector();
        injector.getInstance(TransportService.class).start();
        TransportClient transportClient = new TransportClient(injector);
        success = true;
        return transportClient;
    } finally {
        if (!success) {
            ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
        }
    }
}
 
Example #16
Source File: Node.java    From crate with Apache License 2.0 4 votes vote down vote up
/** Constructs a {@link org.elasticsearch.http.HttpServerTransport} which may be mocked for tests. */
protected HttpServerTransport newHttpTransport(NetworkModule networkModule) {
    return networkModule.getHttpServerTransportSupplier().get();
}