org.elasticsearch.common.network.NetworkService Java Examples

The following examples show how to use org.elasticsearch.common.network.NetworkService. 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: Netty4Transport.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected void doStart() {
    boolean success = false;
    try {
        clientBootstrap = createClientBootstrap();
        if (NetworkService.NETWORK_SERVER.get(settings)) {
            for (ProfileSettings profileSettings : profileSettings) {
                createServerBootstrap(profileSettings);
                bindServer(profileSettings);
            }
        }
        super.doStart();
        success = true;
    } finally {
        if (success == false) {
            doStop();
        }
    }
}
 
Example #2
Source File: PostgresNettyPublishPortTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishAddressOverride() {
    // Check override for network.publish_host
    Settings settingsWithCustomPublish = Settings.builder().put("network.publish_host", "cantbindtothis").build();
    NetworkService networkService = new NetworkService(Collections.emptyList());
    PostgresNetty psql = new PostgresNetty(
        settingsWithCustomPublish,
        mock(SQLOperations.class),
        new StubUserManager(),
        networkService,
        new AlwaysOKNullAuthentication(),
        mock(SslContextProvider.class));
    try {
        psql.doStart();
        fail("Should have failed due to custom hostname");
    } catch (BindTransportException e) {
        // that's what we want
        assertThat(e.getCause(), instanceOf(UnknownHostException.class));
    } finally {
        psql.doStop();
    }
}
 
Example #3
Source File: PostgresNettyPublishPortTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testBindAddressOverrideSetting() {
    // Check override for network.bind_host
    Settings settingsWithCustomBind = Settings.builder().put("network.bind_host", "cantbindtothis").build();
    NetworkService networkService = new NetworkService(Collections.emptyList());
    PostgresNetty psql = new PostgresNetty(
        settingsWithCustomBind,
        mock(SQLOperations.class),
        new StubUserManager(),
        networkService,
        new AlwaysOKNullAuthentication(),
        mock(SslContextProvider.class));
    try {
        psql.doStart();
        fail("Should have failed due to custom hostname");
    } catch (BindPostgresException e) {
        // that's what we want
        assertThat(e.getCause(), instanceOf(UnknownHostException.class));
    } finally {
        psql.doStop();
    }
}
 
Example #4
Source File: PostgresNettyPublishPortTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testGeneralBindAndPublishAddressOverrideSetting() {
    // Check override for network.host
    Settings settingsWithCustomHost = Settings.builder().put("network.host", "cantbindtothis").build();
    NetworkService networkService = new NetworkService(Collections.emptyList());
    PostgresNetty psql = new PostgresNetty(
        settingsWithCustomHost,
        mock(SQLOperations.class),
        new StubUserManager(),
        networkService,
        new AlwaysOKNullAuthentication(),
        mock(SslContextProvider.class));
    try {
        psql.doStart();
        fail("Should have failed due to custom hostname");
    } catch (BindPostgresException e) {
        // that's what we want
        assertThat(e.getCause(), instanceOf(UnknownHostException.class));
    } finally {
        psql.doStop();
    }
}
 
Example #5
Source File: PostgresNettyPublishPortTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testBindAndPublishAddressDefault() {
    // First check if binding to a local works
    NetworkService networkService = new NetworkService(Collections.emptyList());
    PostgresNetty psql = new PostgresNetty(
        Settings.EMPTY,
        mock(SQLOperations.class),
        new StubUserManager(),
        networkService,
        new AlwaysOKNullAuthentication(),
        mock(SslContextProvider.class));
    try {
        psql.doStart();
    } finally {
        psql.doStop();
    }
}
 
Example #6
Source File: MockTcpTransport.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected void doStart() {
    boolean success = false;
    try {
        if (NetworkService.NETWORK_SERVER.get(settings)) {
            // loop through all profiles and start them up, special handling for default one
            for (ProfileSettings profileSettings : profileSettings) {
                bindServer(profileSettings);
            }
        }
        super.doStart();
        success = true;
    } finally {
        if (success == false) {
            doStop();
        }
    }
}
 
Example #7
Source File: MockTcpTransport.java    From crate with Apache License 2.0 6 votes vote down vote up
public MockTcpTransport(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
                        CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry,
                        NetworkService networkService, Version mockVersion) {
    super("mock-tcp-transport",
          settings,
          threadPool,
          bigArrays,
          circuitBreakerService,
          namedWriteableRegistry,
          networkService);
    // we have our own crazy cached threadpool this one is not bounded at all...
    // using the ES thread factory here is crucial for tests otherwise disruption tests won't block that thread
    executor = Executors.newCachedThreadPool(EsExecutors.daemonThreadFactory(settings,
                                                                             Transports.TEST_MOCK_TRANSPORT_THREAD_PREFIX));
    this.mockVersion = mockVersion;
}
 
Example #8
Source File: AzureDiscoveryPlugin.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Supplier<SeedHostsProvider>> getSeedHostProviders(TransportService transportService,
                                                                     NetworkService networkService) {
    return Collections.singletonMap(
        AzureConfiguration.AZURE,
        () -> {
            if (AzureConfiguration.isDiscoveryReady(settings, logger)) {
                return new AzureSeedHostsProvider(settings,
                                                  azureComputeService(),
                                                  transportService,
                                                  networkService);
            } else {
                return hostsResolver -> Collections.emptyList();
            }
        });
}
 
Example #9
Source File: Netty4Plugin.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
                                                                    CircuitBreakerService circuitBreakerService,
                                                                    NamedWriteableRegistry namedWriteableRegistry,
                                                                    NamedXContentRegistry xContentRegistry,
                                                                    NetworkService networkService,
                                                                    NodeClient nodeClient) {
    return Collections.singletonMap(
        NETTY_HTTP_TRANSPORT_NAME,
        () -> new Netty4HttpServerTransport(
            settings,
            networkService,
            bigArrays,
            threadPool,
            xContentRegistry,
            pipelineRegistry,
            nodeClient
        )
    );
}
 
Example #10
Source File: Netty4Plugin.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Supplier<Transport>> getTransports(Settings settings,
                                                      ThreadPool threadPool,
                                                      BigArrays bigArrays,
                                                      PageCacheRecycler pageCacheRecycler,
                                                      CircuitBreakerService circuitBreakerService,
                                                      NamedWriteableRegistry namedWriteableRegistry,
                                                      NetworkService networkService) {
    return Collections.singletonMap(
        NETTY_TRANSPORT_NAME,
        () -> new Netty4Transport(
            settings,
            threadPool,
            networkService,
            bigArrays,
            namedWriteableRegistry,
            circuitBreakerService
        )
    );
}
 
Example #11
Source File: TcpTransport.java    From crate with Apache License 2.0 6 votes vote down vote up
public ProfileSettings(Settings settings, String profileName) {
    this.profileName = profileName;
    isDefaultProfile = TransportSettings.DEFAULT_PROFILE.equals(profileName);
    tcpKeepAlive = TransportSettings.TCP_KEEP_ALIVE_PROFILE.getConcreteSettingForNamespace(profileName).get(settings);
    tcpNoDelay = TransportSettings.TCP_NO_DELAY_PROFILE.getConcreteSettingForNamespace(profileName).get(settings);
    reuseAddress = TransportSettings.TCP_REUSE_ADDRESS_PROFILE.getConcreteSettingForNamespace(profileName).get(settings);
    sendBufferSize = TransportSettings.TCP_SEND_BUFFER_SIZE_PROFILE.getConcreteSettingForNamespace(profileName).get(settings);
    receiveBufferSize = TransportSettings.TCP_RECEIVE_BUFFER_SIZE_PROFILE.getConcreteSettingForNamespace(profileName).get(settings);
    List<String> profileBindHosts = TransportSettings.BIND_HOST_PROFILE.getConcreteSettingForNamespace(profileName).get(settings);
    bindHosts = (profileBindHosts.isEmpty() ? NetworkService.GLOBAL_NETWORK_BIND_HOST_SETTING.get(settings)
        : profileBindHosts);
    publishHosts = TransportSettings.PUBLISH_HOST_PROFILE.getConcreteSettingForNamespace(profileName).get(settings);
    Setting<String> concretePort = TransportSettings.PORT_PROFILE.getConcreteSettingForNamespace(profileName);
    if (concretePort.exists(settings) == false && isDefaultProfile == false) {
        throw new IllegalStateException("profile [" + profileName + "] has no port configured");
    }
    portOrRange = TransportSettings.PORT_PROFILE.getConcreteSettingForNamespace(profileName).get(settings);
    publishPort = isDefaultProfile ? TransportSettings.PUBLISH_PORT.get(settings) :
        TransportSettings.PUBLISH_PORT_PROFILE.getConcreteSettingForNamespace(profileName).get(settings);
}
 
Example #12
Source File: LocalElasticSearch.java    From core-ng-project with Apache License 2.0 6 votes vote down vote up
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 #13
Source File: OpenDistroSecuritySSLPlugin.java    From deprecated-security-ssl with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
        CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry,
        NamedXContentRegistry xContentRegistry, NetworkService networkService, Dispatcher dispatcher) {
    
    final Map<String, Supplier<HttpServerTransport>> httpTransports = new HashMap<String, Supplier<HttpServerTransport>>(1);
    if (!client && httpSSLEnabled) {
        
        final ValidatingDispatcher validatingDispatcher = new ValidatingDispatcher(threadPool.getThreadContext(), dispatcher, settings, configPath, NOOP_SSL_EXCEPTION_HANDLER);
        final OpenDistroSecuritySSLNettyHttpServerTransport sgsnht = new OpenDistroSecuritySSLNettyHttpServerTransport(settings, networkService, bigArrays, threadPool, odsks, xContentRegistry, validatingDispatcher, NOOP_SSL_EXCEPTION_HANDLER);
        
        httpTransports.put("com.amazon.opendistroforelasticsearch.security.ssl.http.netty.OpenDistroSecuritySSLNettyHttpServerTransport", () -> sgsnht);
        
    }
    return httpTransports;
}
 
Example #14
Source File: NetworkPlugin.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a map of {@link HttpServerTransport} suppliers.
 * See {@link org.elasticsearch.common.network.NetworkModule#HTTP_TYPE_SETTING} to configure a specific implementation.
 */
default Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings,
                                                                     ThreadPool threadPool,
                                                                     BigArrays bigArrays,
                                                                     CircuitBreakerService circuitBreakerService,
                                                                     NamedWriteableRegistry namedWriteableRegistry,
                                                                     NamedXContentRegistry xContentRegistry,
                                                                     NetworkService networkService,
                                                                     NodeClient nodeClient) {
    return Collections.emptyMap();
}
 
Example #15
Source File: OpenDistroSecuritySSLPlugin.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
@Override
   public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, PageCacheRecycler pageCacheRecycler,
        CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) { 
    Map<String, Supplier<Transport>> transports = new HashMap<String, Supplier<Transport>>();
    if (transportSSLEnabled) {
        transports.put("com.amazon.opendistroforelasticsearch.security.ssl.http.netty.OpenDistroSecuritySSLNettyTransport", 
                () -> new OpenDistroSecuritySSLNettyTransport(settings, Version.CURRENT, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService, odsks, NOOP_SSL_EXCEPTION_HANDLER));

    }
    return transports;

}
 
Example #16
Source File: OpenDistroSecuritySSLNettyHttpServerTransport.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
public OpenDistroSecuritySSLNettyHttpServerTransport(final Settings settings, final NetworkService networkService, final BigArrays bigArrays,
        final ThreadPool threadPool, final OpenDistroSecurityKeyStore odks, final NamedXContentRegistry namedXContentRegistry, final ValidatingDispatcher dispatcher,
        final SslExceptionHandler errorHandler) {
    super(settings, networkService, bigArrays, threadPool, namedXContentRegistry, dispatcher);
    this.odks = odks;
    this.threadContext = threadPool.getThreadContext();
    this.errorHandler = errorHandler;
}
 
Example #17
Source File: OpenDistroSecuritySSLNettyTransport.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
public OpenDistroSecuritySSLNettyTransport(final Settings settings, final Version version, final ThreadPool threadPool, final NetworkService networkService,
    final PageCacheRecycler pageCacheRecycler, final NamedWriteableRegistry namedWriteableRegistry,
    final CircuitBreakerService circuitBreakerService, final OpenDistroSecurityKeyStore odks, final SslExceptionHandler errorHandler) {
    super(settings, version, threadPool, networkService, pageCacheRecycler, namedWriteableRegistry, circuitBreakerService);
    this.odks = odks;
    this.errorHandler = errorHandler;
}
 
Example #18
Source File: CrateNettyHttpServerTransport.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public CrateNettyHttpServerTransport(Settings settings,
                                     NetworkService networkService,
                                     BigArrays bigArrays,
                                     BlobService blobService,
                                     BlobIndices blobIndices,
                                     DiscoveryNodeService discoveryNodeService) {
    super(settings, networkService, bigArrays);
    this.blobService = blobService;
    this.blobIndices = blobIndices;
    this.discoveryNodeService = discoveryNodeService;
}
 
Example #19
Source File: MockTransportService.java    From crate with Apache License 2.0 5 votes vote down vote up
public static MockTcpTransport newMockTransport(Settings settings, Version version, ThreadPool threadPool) {
    // some tests use MockTransportService to do network based testing. Yet, we run tests in multiple JVMs that means
    // concurrent tests could claim port that another JVM just released and if that test tries to simulate a disconnect it might
    // be smart enough to re-connect depending on what is tested. To reduce the risk, since this is very hard to debug we use
    // a different default port range per JVM unless the incoming settings override it
    int basePort = 10300 + (JVM_ORDINAL * 100); // use a non-default port otherwise some cluster in this JVM might reuse a port
    settings = Settings.builder().put(TransportSettings.PORT.getKey(), basePort + "-" + (basePort + 100)).put(settings).build();
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables());
    return new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE,
        new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(Collections.emptyList()), version);
}
 
Example #20
Source File: TcpTransportTest.java    From crate with Apache License 2.0 5 votes vote down vote up
private void testDefaultSeedAddresses(final Settings settings, Matcher<Iterable<? extends String>> seedAddressesMatcher) {
    final TestThreadPool testThreadPool = new TestThreadPool("test");
    try {
        final TcpTransport tcpTransport = new TcpTransport("test",
                                                           settings,
                                                           testThreadPool,
                                                           BigArrays.NON_RECYCLING_INSTANCE,
                                                           new NoneCircuitBreakerService(),
                                                           writableRegistry(),
                                                           new NetworkService(Collections.emptyList())) {

            @Override
            protected TcpChannel bind(String name, InetSocketAddress address) {
                throw new UnsupportedOperationException();
            }

            @Override
            protected TcpChannel initiateChannel(DiscoveryNode node,
                                                 ActionListener<Void> connectListener) {
                throw new UnsupportedOperationException();
            }

            @Override
            protected void stopInternal() {
                throw new UnsupportedOperationException();
            }
        };

        assertThat(tcpTransport.getDefaultSeedAddresses(), seedAddressesMatcher);
    } finally {
        testThreadPool.shutdown();
    }
}
 
Example #21
Source File: MockTcpTransportPlugin.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
                                                      PageCacheRecycler pageCacheRecycler,
                                                      CircuitBreakerService circuitBreakerService,
                                                      NamedWriteableRegistry namedWriteableRegistry,
                                                      NetworkService networkService) {
    return Collections.singletonMap(MOCK_TCP_TRANSPORT_NAME,
        () -> new MockTcpTransport(settings, threadPool, bigArrays, circuitBreakerService, namedWriteableRegistry, networkService));
}
 
Example #22
Source File: OpenShiftElasticSearchPlugin.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
        CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry,
        NetworkService networkService) {
    Map<String, Supplier<Transport>> transports = sgPlugin.getTransports(settings, threadPool, bigArrays, circuitBreakerService, namedWriteableRegistry,
            networkService);
    return transports;
}
 
Example #23
Source File: PostgresNetty.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public PostgresNetty(Settings settings,
                     SQLOperations sqlOperations,
                     UserManager userManager,
                     NetworkService networkService,
                     Authentication authentication,
                     SslContextProvider sslContextProvider) {
    this.settings = settings;
    this.userManager = userManager;
    namedLogger = LogManager.getLogger("psql");
    this.sqlOperations = sqlOperations;
    this.networkService = networkService;
    this.authentication = authentication;

    if (SslConfigSettings.isPSQLSslEnabled(settings)) {
        namedLogger.info("PSQL SSL support is enabled.");
        this.sslContextProvider = sslContextProvider;
    } else {
        namedLogger.info("PSQL SSL support is disabled.");
        this.sslContextProvider = null;
    }

    enabled = PSQL_ENABLED_SETTING.setting().get(settings);
    bindHosts = NetworkService.GLOBAL_NETWORK_BIND_HOST_SETTING.get(settings).toArray(new String[0]);
    publishHosts = NetworkService.GLOBAL_NETWORK_PUBLISH_HOST_SETTING.get(settings).toArray(new String[0]);
    port = PSQL_PORT_SETTING.setting().get(settings);
}
 
Example #24
Source File: NetworkPlugin.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a map of {@link Transport} suppliers.
 * See {@link org.elasticsearch.common.network.NetworkModule#TRANSPORT_TYPE_KEY} to configure a specific implementation.
 */
default Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
                                                       PageCacheRecycler pageCacheRecycler,
                                                       CircuitBreakerService circuitBreakerService,
                                                       NamedWriteableRegistry namedWriteableRegistry,
                                                       NetworkService networkService) {
    return Collections.emptyMap();
}
 
Example #25
Source File: OpenShiftElasticSearchPlugin.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool,
        BigArrays bigArrays, CircuitBreakerService circuitBreakerService,
        NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry namedXContentRegistry,
        NetworkService networkService, Dispatcher dispatcher) {
    Map<String, Supplier<HttpServerTransport>> transports = sgPlugin.getHttpTransports(settings, threadPool, bigArrays, circuitBreakerService,
            namedWriteableRegistry, namedXContentRegistry, networkService, dispatcher);
    return transports;
}
 
Example #26
Source File: AzureSeedHostsProvider.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public AzureSeedHostsProvider(Settings settings,
                              AzureComputeService azureComputeService,
                              TransportService transportService,
                              NetworkService networkService) {
    this.azureComputeService = azureComputeService;
    this.transportService = transportService;
    this.networkService = networkService;

    refreshInterval = Discovery.REFRESH.get(settings);
    resourceGroup = AzureComputeService.Management.RESOURCE_GROUP_NAME.get(settings);
    hostType = HostType.fromString(Discovery.HOST_TYPE.get(settings));
    discoveryMethod = Discovery.DISCOVERY_METHOD.get(settings);
}
 
Example #27
Source File: Node.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Get Custom Name Resolvers list based on a Discovery Plugins list
 * @param discoveryPlugins Discovery plugins list
 */
private List<NetworkService.CustomNameResolver> getCustomNameResolvers(List<DiscoveryPlugin> discoveryPlugins) {
    List<NetworkService.CustomNameResolver> customNameResolvers = new ArrayList<>();
    for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) {
        NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings);
        if (customNameResolver != null) {
            customNameResolvers.add(customNameResolver);
        }
    }
    return customNameResolvers;
}
 
Example #28
Source File: RaigadDiscoveryPlugin.java    From Raigad with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Supplier<UnicastHostsProvider>> getZenHostsProviders(
        TransportService transportService, NetworkService networkService) {
    return Collections.singletonMap(
            "raigad",
            () -> new RaigadUnicastHostsProvider(settings, transportService));
}
 
Example #29
Source File: TcpTransport.java    From crate with Apache License 2.0 5 votes vote down vote up
private BoundTransportAddress createBoundTransportAddress(ProfileSettings profileSettings,
                                                          List<InetSocketAddress> boundAddresses) {
    String[] boundAddressesHostStrings = new String[boundAddresses.size()];
    TransportAddress[] transportBoundAddresses = new TransportAddress[boundAddresses.size()];
    for (int i = 0; i < boundAddresses.size(); i++) {
        InetSocketAddress boundAddress = boundAddresses.get(i);
        boundAddressesHostStrings[i] = boundAddress.getHostString();
        transportBoundAddresses[i] = new TransportAddress(boundAddress);
    }

    List<String> publishHosts = profileSettings.publishHosts;
    if (profileSettings.isDefaultProfile == false && publishHosts.isEmpty()) {
        publishHosts = Arrays.asList(boundAddressesHostStrings);
    }
    if (publishHosts.isEmpty()) {
        publishHosts = NetworkService.GLOBAL_NETWORK_PUBLISH_HOST_SETTING.get(settings);
    }

    final InetAddress publishInetAddress;
    try {
        publishInetAddress = networkService.resolvePublishHostAddresses(publishHosts.toArray(Strings.EMPTY_ARRAY));
    } catch (Exception e) {
        throw new BindTransportException("Failed to resolve publish address", e);
    }

    final int publishPort = resolvePublishPort(profileSettings, boundAddresses, publishInetAddress);
    final TransportAddress publishAddress = new TransportAddress(new InetSocketAddress(publishInetAddress, publishPort));
    return new BoundTransportAddress(transportBoundAddresses, publishAddress);
}
 
Example #30
Source File: TcpTransport.java    From crate with Apache License 2.0 5 votes vote down vote up
public TcpTransport(String transportName, Settings settings, ThreadPool threadPool, BigArrays bigArrays,
                    CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry,
                    NetworkService networkService) {
    this.settings = settings;
    this.profileSettings = getProfileSettings(settings);
    this.threadPool = threadPool;
    this.bigArrays = bigArrays;
    this.circuitBreakerService = circuitBreakerService;
    this.namedWriteableRegistry = namedWriteableRegistry;
    this.compress = Transport.TRANSPORT_TCP_COMPRESS.get(settings);
    this.networkService = networkService;
    this.transportName = transportName;
    this.nodeName = Node.NODE_NAME_SETTING.get(settings);
    final Settings defaultFeatures = DEFAULT_FEATURES_SETTING.get(settings);
    if (defaultFeatures == null) {
        this.features = new String[0];
    } else {
        defaultFeatures.names().forEach(key -> {
            if (Booleans.parseBoolean(defaultFeatures.get(key)) == false) {
                throw new IllegalArgumentException("feature settings must have default [true] value");
            }
        });
        // use a sorted set to present the features in a consistent order
        this.features = new TreeSet<>(defaultFeatures.names()).toArray(new String[defaultFeatures.names().size()]);
    }

    try (BytesStreamOutput out = new BytesStreamOutput()) {
        out.writeByte((byte) 'E');
        out.writeByte((byte) 'S');
        out.writeInt(TcpTransport.PING_DATA_SIZE);
        pingMessage = out.bytes();
    } catch (IOException e) {
        throw new AssertionError(e.getMessage(), e); // won't happen
    }
}