Search in sources :

Example 6 with HostAndPort

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort in project beam by apache.

the class SocketAddressFactory method createFrom.

/**
 * Parse a {@link SocketAddress} from the given string.
 */
public static SocketAddress createFrom(String value) {
    if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
        // Unix Domain Socket address.
        // Create the underlying file for the Unix Domain Socket.
        String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length());
        File file = new File(filePath);
        if (!file.isAbsolute()) {
            throw new IllegalArgumentException("File path must be absolute: " + filePath);
        }
        try {
            if (file.createNewFile()) {
                // If this application created the file, delete it when the application exits.
                file.deleteOnExit();
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        // Create the SocketAddress referencing the file.
        return new DomainSocketAddress(file);
    } else {
        // Standard TCP/IP address.
        HostAndPort hostAndPort = HostAndPort.fromString(value);
        checkArgument(hostAndPort.hasPort(), "Address must be a unix:// path or be in the form host:port. Got: %s", value);
        return new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort());
    }
}
Also used : HostAndPort(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort) InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress) IOException(java.io.IOException) File(java.io.File)

Example 7 with HostAndPort

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort in project beam by apache.

the class GrpcWindmillServer method initializeWindmillService.

private synchronized void initializeWindmillService(Set<HostAndPort> endpoints) throws IOException {
    LOG.info("Initializing Streaming Engine GRPC client for endpoints: {}", endpoints);
    this.stubList.clear();
    this.syncStubList.clear();
    this.endpoints = ImmutableSet.<HostAndPort>copyOf(endpoints);
    for (HostAndPort endpoint : this.endpoints) {
        if ("localhost".equals(endpoint.getHost())) {
            initializeLocalHost(endpoint.getPort());
        } else {
            CallCredentials creds = MoreCallCredentials.from(new VendoredCredentialsAdapter(options.getGcpCredential()));
            this.stubList.add(CloudWindmillServiceV1Alpha1Grpc.newStub(remoteChannel(endpoint)).withCallCredentials(creds));
            this.syncStubList.add(CloudWindmillServiceV1Alpha1Grpc.newBlockingStub(remoteChannel(endpoint)).withCallCredentials(creds));
        }
    }
}
Also used : HostAndPort(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort) MoreCallCredentials(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.auth.MoreCallCredentials) CallCredentials(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.CallCredentials)

Example 8 with HostAndPort

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort in project beam by apache.

the class ServerFactoryTest method defaultServerWithPortSupplier.

@Test
public void defaultServerWithPortSupplier() throws Exception {
    Endpoints.ApiServiceDescriptor apiServiceDescriptor = runTestUsing(ServerFactory.createWithPortSupplier(() -> 65535), ManagedChannelFactory.createDefault());
    HostAndPort hostAndPort = HostAndPort.fromString(apiServiceDescriptor.getUrl());
    assertThat(hostAndPort.getHost(), anyOf(equalTo(InetAddress.getLoopbackAddress().getHostName()), equalTo(InetAddress.getLoopbackAddress().getHostAddress())));
    assertThat(hostAndPort.getPort(), is(65535));
}
Also used : Endpoints(org.apache.beam.model.pipeline.v1.Endpoints) HostAndPort(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort) ApiServiceDescriptor(org.apache.beam.model.pipeline.v1.Endpoints.ApiServiceDescriptor) Test(org.junit.Test)

Aggregations

HostAndPort (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort)8 Endpoints (org.apache.beam.model.pipeline.v1.Endpoints)3 ApiServiceDescriptor (org.apache.beam.model.pipeline.v1.Endpoints.ApiServiceDescriptor)3 Test (org.junit.Test)3 Configuration (org.apache.flink.configuration.Configuration)2 GlobalConfiguration (org.apache.flink.configuration.GlobalConfiguration)2 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 MapTask (com.google.api.services.dataflow.model.MapTask)1 StreamingComputationConfig (com.google.api.services.dataflow.model.StreamingComputationConfig)1 StreamingConfigTask (com.google.api.services.dataflow.model.StreamingConfigTask)1 WorkItem (com.google.api.services.dataflow.model.WorkItem)1 File (java.io.File)1 IOException (java.io.IOException)1 Inet4Address (java.net.Inet4Address)1 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)1 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)1 CallCredentials (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.CallCredentials)1 MoreCallCredentials (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.auth.MoreCallCredentials)1 DomainSocketAddress (org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress)1