org.elasticsearch.common.transport.BoundTransportAddress Java Examples

The following examples show how to use org.elasticsearch.common.transport.BoundTransportAddress. 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: TransportService.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
    * 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 TransportService(Settings settings,
                           Transport transport,
                           ThreadPool threadPool,
                           TransportInterceptor transportInterceptor,
                           Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                           @Nullable ClusterSettings clusterSettings) {
       this(
           settings,
           transport,
           threadPool,
           transportInterceptor,
           localNodeFactory,
           clusterSettings,
           new ConnectionManager(settings, transport, threadPool)
       );
   }
 
Example #2
Source File: TransportInfo.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.TRANSPORT);
    builder.array(Fields.BOUND_ADDRESS, (Object[]) address.boundAddresses());
    builder.field(Fields.PUBLISH_ADDRESS, address.publishAddress().toString());
    builder.startObject(Fields.PROFILES);
    if (profileAddresses != null && profileAddresses.size() > 0) {
        for (Map.Entry<String, BoundTransportAddress> entry : profileAddresses.entrySet()) {
            builder.startObject(entry.getKey());
            builder.array(Fields.BOUND_ADDRESS, (Object[]) entry.getValue().boundAddresses());
            builder.field(Fields.PUBLISH_ADDRESS, entry.getValue().publishAddress().toString());
            builder.endObject();
        }
    }
    builder.endObject();
    builder.endObject();
    return builder;
}
 
Example #3
Source File: MockTransportService.java    From crate with Apache License 2.0 6 votes vote down vote up
private MockTransportService(Settings settings,
                             StubbableTransport transport,
                             ThreadPool threadPool,
                             TransportInterceptor interceptor,
                             Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                             @Nullable ClusterSettings clusterSettings) {
    super(
        settings,
        transport,
        threadPool,
        interceptor,
        localNodeFactory,
        clusterSettings,
        new StubbableConnectionManager(new ConnectionManager(settings, transport, threadPool), settings, transport, threadPool)
    );
    this.original = transport.getDelegate();
}
 
Example #4
Source File: MockTransport.java    From crate with Apache License 2.0 6 votes vote down vote up
public TransportService createTransportService(Settings settings,
                                               ThreadPool threadPool,
                                               TransportInterceptor interceptor,
                                               Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                                               @Nullable ClusterSettings clusterSettings) {
    StubbableConnectionManager connectionManager = new StubbableConnectionManager(new ConnectionManager(settings, this, threadPool),
        settings, this, threadPool);
    connectionManager.setDefaultNodeConnectedBehavior((cm, discoveryNode) -> nodeConnected(discoveryNode));
    connectionManager.setDefaultGetConnectionBehavior((cm, discoveryNode) -> openConnection(discoveryNode, null));
    return new TransportService(
        settings,
        this,
        threadPool,
        interceptor,
        localNodeFactory,
        clusterSettings,
        connectionManager
    );
}
 
Example #5
Source File: MockNode.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected TransportService newTransportService(Settings settings,
                                               Transport transport,
                                               ThreadPool threadPool,
                                               TransportInterceptor interceptor,
                                               Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                                               ClusterSettings clusterSettings) {
    // we use the MockTransportService.TestPlugin class as a marker to create a network
    // module with this MockNetworkService. NetworkService is such an integral part of the systme
    // we don't allow to plug it in from plugins or anything. this is a test-only override and
    // can't be done in a production env.
    if (getPluginsService().filterPlugins(MockTransportService.TestPlugin.class).isEmpty()) {
        return super.newTransportService(settings, transport, threadPool, interceptor, localNodeFactory, clusterSettings);
    } else {
        return new MockTransportService(settings, transport, threadPool, interceptor, localNodeFactory, clusterSettings);
    }
}
 
Example #6
Source File: SQLTransportIntegrationTest.java    From crate with Apache License 2.0 6 votes vote down vote up
public SQLTransportIntegrationTest(boolean useSSL) {
    this(new SQLTransportExecutor(
        new SQLTransportExecutor.ClientProvider() {
            @Override
            public Client client() {
                return ESIntegTestCase.client();
            }

            @Override
            public String pgUrl() {
                PostgresNetty postgresNetty = internalCluster().getDataNodeInstance(PostgresNetty.class);
                BoundTransportAddress boundTransportAddress = postgresNetty.boundAddress();
                if (boundTransportAddress != null) {
                    InetSocketAddress address = boundTransportAddress.publishAddress().address();
                    return String.format(Locale.ENGLISH, "jdbc:postgresql://%s:%d/?ssl=%s&sslmode=%s",
                        address.getHostName(), address.getPort(), useSSL, useSSL ? "require" : "disable");
                }
                return null;
            }

            @Override
            public SQLOperations sqlOperations() {
                return internalCluster().getInstance(SQLOperations.class);
            }
        }));
}
 
Example #7
Source File: TransportService.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStart() {
    transport.addMessageListener(this);
    connectionManager.addListener(this);
    transport.start();
    if (transport.boundAddress() != null && LOGGER.isInfoEnabled()) {
        LOGGER.info("{}", transport.boundAddress());
        for (Map.Entry<String, BoundTransportAddress> entry : transport.profileBoundAddresses().entrySet()) {
            LOGGER.info("profile [{}]: {}", entry.getKey(), entry.getValue());
        }
    }
    localNode = localNodeFactory.apply(transport.boundAddress());
}
 
Example #8
Source File: Netty4HttpServerTransport.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public HttpInfo info() {
    BoundTransportAddress boundTransportAddress = boundAddress();
    if (boundTransportAddress == null) {
        return null;
    }
    return new HttpInfo(boundTransportAddress, maxContentLength.getBytes());
}
 
Example #9
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 #10
Source File: Node.java    From crate with Apache License 2.0 5 votes vote down vote up
protected TransportService newTransportService(Settings settings,
                                               Transport transport,
                                               ThreadPool threadPool,
                                               TransportInterceptor interceptor,
                                               Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                                               ClusterSettings clusterSettings) {
    return new TransportService(settings, transport, threadPool, interceptor, localNodeFactory, clusterSettings);
}
 
Example #11
Source File: Node.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public DiscoveryNode apply(BoundTransportAddress boundTransportAddress) {
    // CRATE_PATCH: use existing node attributes to pass and stream http_address between the nodes
    Map<String, String> attributes = new HashMap<>(NODE_ATTRIBUTES.getAsMap(settings));
    Set<DiscoveryNode.Role> roles = getRolesFromSettings(settings);
    if (httpPublishAddress != null) {
        attributes.put("http_address", httpPublishAddress);
    }
    localNode.set(new DiscoveryNode(Node.NODE_NAME_SETTING.get(settings), persistentNodeId, boundTransportAddress.publishAddress(), attributes, roles, Version.CURRENT));
    return localNode.get();
}
 
Example #12
Source File: BootstrapChecks.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the bootstrap checks if the node has the transport protocol bound to a non-loopback interface. If the system property
 * {@code es.enforce.bootstrap.checks} is set to {@code true} then the bootstrap checks will be enforced regardless of whether or not
 * the transport protocol is bound to a non-loopback interface.
 *
 * @param boundTransportAddress the node network bindings
 */
static void check(final Settings settings,
                  final BoundTransportAddress boundTransportAddress,
                  List<BootstrapCheck> additionalChecks) throws NodeValidationException {
    final List<BootstrapCheck> builtInChecks = checks();
    final List<BootstrapCheck> combinedChecks = new ArrayList<>(builtInChecks);
    combinedChecks.addAll(additionalChecks);
    check(settings,
          enforceLimits(boundTransportAddress, DiscoveryModule.DISCOVERY_TYPE_SETTING.get(settings)),
          Collections.unmodifiableList(combinedChecks));
}
 
Example #13
Source File: BootstrapChecks.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if the checks should be enforced.
 *
 * @param boundTransportAddress the node network bindings
 * @param discoveryType the discovery type
 * @return {@code true} if the checks should be enforced
 */
static boolean enforceLimits(final BoundTransportAddress boundTransportAddress, final String discoveryType) {
    final Predicate<TransportAddress> isLoopbackAddress = t -> t.address().getAddress().isLoopbackAddress();
    final boolean bound =
            !(Arrays.stream(boundTransportAddress.boundAddresses()).allMatch(isLoopbackAddress) &&
            isLoopbackAddress.test(boundTransportAddress.publishAddress()));
    return bound && !"single-node".equals(discoveryType);
}
 
Example #14
Source File: NodeStatsContextFieldResolver.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
@SuppressWarnings("unused")
public NodeStatsContextFieldResolver(ClusterService clusterService,
                                     NodeService nodeService,
                                     @Nullable HttpServerTransport httpServerTransport,
                                     TransportService transportService,
                                     ThreadPool threadPool,
                                     ExtendedNodeInfo extendedNodeInfo,
                                     PostgresNetty postgresNetty) {
    this(
        clusterService::localNode,
        nodeService.getMonitorService(),
        () -> httpServerTransport == null ? null : httpServerTransport.info().getAddress().publishAddress(),
        () -> httpServerTransport == null ? null : httpServerTransport.stats(),
        threadPool,
        extendedNodeInfo,
        () -> new ConnectionStats(postgresNetty.openConnections(), postgresNetty.totalConnections()),
        () -> {
            BoundTransportAddress boundTransportAddress = postgresNetty.boundAddress();
            if (boundTransportAddress == null) {
                return null;
            }
            return boundTransportAddress.publishAddress();
        },
        () -> transportService.stats().getServerOpen(),
        () -> clusterService.state().version()
    );
}
 
Example #15
Source File: TransportInfo.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(StreamOutput out) throws IOException {
    address.writeTo(out);
    if (profileAddresses != null) {
        out.writeVInt(profileAddresses.size());
    } else {
        out.writeVInt(0);
    }
    if (profileAddresses != null && profileAddresses.size() > 0) {
        for (Map.Entry<String, BoundTransportAddress> entry : profileAddresses.entrySet()) {
            out.writeString(entry.getKey());
            entry.getValue().writeTo(out);
        }
    }
}
 
Example #16
Source File: TransportInfo.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    address = BoundTransportAddress.readBoundTransportAddress(in);
    int size = in.readVInt();
    if (size > 0) {
        profileAddresses = Maps.newHashMapWithExpectedSize(size);
        for (int i = 0; i < size; i++) {
            String key = in.readString();
            BoundTransportAddress value = BoundTransportAddress.readBoundTransportAddress(in);
            profileAddresses.put(key, value);
        }
    }
}
 
Example #17
Source File: TransportService.java    From crate with Apache License 2.0 5 votes vote down vote up
public TransportService(Settings settings,
                        Transport transport,
                        ThreadPool threadPool,
                        TransportInterceptor transportInterceptor,
                        Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                        @Nullable ClusterSettings clusterSettings,
                        ConnectionManager connectionManager) {
    this.transport = transport;
    this.threadPool = threadPool;
    this.localNodeFactory = localNodeFactory;
    this.connectionManager = connectionManager;
    this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
    setTracerLogInclude(TRACE_LOG_INCLUDE_SETTING.get(settings));
    setTracerLogExclude(TRACE_LOG_EXCLUDE_SETTING.get(settings));
    tracerLog = Loggers.getLogger(LOGGER, ".tracer");
    taskManager = createTaskManager(settings, threadPool);
    this.interceptor = transportInterceptor;
    this.asyncSender = interceptor.interceptSender(this::sendRequestInternal);
    responseHandlers = transport.getResponseHandlers();
    if (clusterSettings != null) {
        clusterSettings.addSettingsUpdateConsumer(TRACE_LOG_INCLUDE_SETTING, this::setTracerLogInclude);
        clusterSettings.addSettingsUpdateConsumer(TRACE_LOG_EXCLUDE_SETTING, this::setTracerLogExclude);
    }
    registerRequestHandler(
        HANDSHAKE_ACTION_NAME,
        HandshakeRequest::new,
        ThreadPool.Names.SAME,
        false, false,
        (request, channel, task) -> channel.sendResponse(
            new HandshakeResponse(localNode, clusterName, localNode.getVersion())));
}
 
Example #18
Source File: DisruptableMockTransport.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public TransportService createTransportService(Settings settings,
                                               ThreadPool threadPool,
                                               TransportInterceptor interceptor,
                                               Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                                               @Nullable ClusterSettings clusterSettings) {
    return new TransportService(settings, this, threadPool, interceptor, localNodeFactory, clusterSettings);
}
 
Example #19
Source File: NettyTransport.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private BoundTransportAddress createBoundTransportAddress(String name, Settings 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 InetSocketTransportAddress(boundAddress);
    }

    final String[] publishHosts;
    if (DEFAULT_PROFILE.equals(name)) {
        publishHosts = settings.getAsArray("transport.netty.publish_host", settings.getAsArray("transport.publish_host", settings.getAsArray("transport.host", null)));
    } else {
        publishHosts = profileSettings.getAsArray("publish_host", boundAddressesHostStrings);
    }

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

    final int publishPort = resolvePublishPort(name, settings, profileSettings, boundAddresses, publishInetAddress);
    final TransportAddress publishAddress = new InetSocketTransportAddress(new InetSocketAddress(publishInetAddress, publishPort));
    return new BoundTransportAddress(transportBoundAddresses, publishAddress);
}
 
Example #20
Source File: EnterpriseLicenseService.java    From crate with Apache License 2.0 5 votes vote down vote up
private boolean boundToLocalhost() {
    if (isBoundToLocalhost == null) {
        // boundAddress is initialized in LifecycleComponent.start;
        // We guard here against changes in the initialization order of the components
        BoundTransportAddress boundTransportAddress = transportService.boundAddress();
        if (boundTransportAddress == null) {
            return false;
        }
        Predicate<TransportAddress> isLoopbackAddress = t -> t.address().getAddress().isLoopbackAddress();
        isBoundToLocalhost = Arrays.stream(boundTransportAddress.boundAddresses()).allMatch(isLoopbackAddress)
                             && isLoopbackAddress.test(boundTransportAddress.publishAddress());
    }
    return isBoundToLocalhost;
}
 
Example #21
Source File: MockTransportService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * 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,
                            Function<BoundTransportAddress, DiscoveryNode> localNodeFactory,
                            @Nullable ClusterSettings clusterSettings) {
    this(settings, new StubbableTransport(transport), threadPool, interceptor, localNodeFactory, clusterSettings);
}
 
Example #22
Source File: TransportService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public TransportInfo info() {
    BoundTransportAddress boundTransportAddress = boundAddress();
    if (boundTransportAddress == null) {
        return null;
    }
    return new TransportInfo(boundTransportAddress, transport.profileBoundAddresses());
}
 
Example #23
Source File: TransportService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStart() {
    adapter.rxMetric.clear();
    adapter.txMetric.clear();
    transport.transportServiceAdapter(adapter);
    transport.start();
    if (transport.boundAddress() != null && logger.isInfoEnabled()) {
        logger.info("{}", transport.boundAddress());
        for (Map.Entry<String, BoundTransportAddress> entry : transport.profileBoundAddresses().entrySet()) {
            logger.info("profile [{}]: {}", entry.getKey(), entry.getValue());
        }
    }
}
 
Example #24
Source File: MockTransportService.java    From crate with Apache License 2.0 5 votes vote down vote up
public static TransportAddress[] extractTransportAddresses(TransportService transportService) {
    HashSet<TransportAddress> transportAddresses = new HashSet<>();
    BoundTransportAddress boundTransportAddress = transportService.boundAddress();
    transportAddresses.addAll(Arrays.asList(boundTransportAddress.boundAddresses()));
    transportAddresses.add(boundTransportAddress.publishAddress());
    return transportAddresses.toArray(new TransportAddress[transportAddresses.size()]);
}
 
Example #25
Source File: LocalTransport.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStart() {
    String address = settings.get(TRANSPORT_LOCAL_ADDRESS);
    if (address == null) {
        address = Long.toString(transportAddressIdGenerator.incrementAndGet());
    }
    localAddress = new LocalTransportAddress(address);
    LocalTransport previous = transports.put(localAddress, this);
    if (previous != null) {
        throw new ElasticsearchException("local address [" + address + "] is already bound");
    }
    boundAddress = new BoundTransportAddress(new TransportAddress[] { localAddress }, localAddress);
}
 
Example #26
Source File: HttpInfo.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    address = BoundTransportAddress.readBoundTransportAddress(in);
    maxContentLength = in.readLong();
}
 
Example #27
Source File: MockTransport.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, BoundTransportAddress> profileBoundAddresses() {
    return null;
}
 
Example #28
Source File: TransportService.java    From crate with Apache License 2.0 4 votes vote down vote up
public BoundTransportAddress boundAddress() {
    return transport.boundAddress();
}
 
Example #29
Source File: TcpTransport.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public BoundTransportAddress boundAddress() {
    return this.boundAddress;
}
 
Example #30
Source File: TcpTransport.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, BoundTransportAddress> profileBoundAddresses() {
    return unmodifiableMap(new HashMap<>(profileBoundAddresses));
}