/** * Creates a base {@link URL} for calling user service based on the given {@link Discoverable}. * * @return a {@link URL} or {@code null} if the discoverable is {@code null} or failed to construct a URL. */ @Nullable public static URL createServiceBaseURL(@Nullable Discoverable discoverable, ProgramId programId) { if (discoverable == null) { return null; } InetSocketAddress address = discoverable.getSocketAddress(); boolean ssl = Arrays.equals(Constants.Security.SSL_URI_SCHEME.getBytes(), discoverable.getPayload()); return createServiceBaseURL(address.getHostName(), address.getPort(), ssl, programId); }
/** * Creates a base {@link URL} for calling user service based on the given {@link Discoverable}. * * @return a {@link URL} or {@code null} if the discoverable is {@code null} or failed to construct a URL. */ @Nullable public static URL createServiceBaseURL(@Nullable Discoverable discoverable, ProgramId programId) { if (discoverable == null) { return null; } InetSocketAddress address = discoverable.getSocketAddress(); boolean ssl = Arrays.equals(Constants.Security.SSL_URI_SCHEME.getBytes(), discoverable.getPayload()); return createServiceBaseURL(address.getHostName(), address.getPort(), ssl, programId); }
@Override public URL getServiceURL(long timeout, TimeUnit timeoutUnit) { return ServiceDiscoverable.createServiceBaseURL( new RandomEndpointStrategy(() -> discoveryServiceClient.discover(ServiceDiscoverable.getName(programId))) .pick(timeout, timeoutUnit), programId); } }
@Override public URL getServiceURL(long timeout, TimeUnit timeoutUnit) { ServiceDiscovered discovered = discoveryServiceClient.discover(ServiceDiscoverable.getName(programId)); return ServiceDiscoverable.createServiceBaseURL(new RandomEndpointStrategy(discovered).pick(timeout, timeoutUnit), programId); } }
@Override public URL getServiceURL(long timeout, TimeUnit timeoutUnit) { return ServiceDiscoverable.createServiceBaseURL( new RandomEndpointStrategy(() -> discoveryServiceClient.discover(ServiceDiscoverable.getName(programId))) .pick(timeout, timeoutUnit), programId); }
@Override public URL getServiceURL(long timeout, TimeUnit timeoutUnit) { ServiceDiscovered discovered = discoveryServiceClient.discover(ServiceDiscoverable.getName(programId)); return ServiceDiscoverable.createServiceBaseURL(new RandomEndpointStrategy(discovered).pick(timeout, timeoutUnit), programId); }
@Override public URL getServiceURL(long timeout, TimeUnit timeoutUnit) { try { Tasks.waitFor(true, () -> { try { checkAvailability(); return true; } catch (ServiceUnavailableException e) { return false; } }, timeout, timeoutUnit); ConnectionConfig connectionConfig = clientConfig.getConnectionConfig(); return ServiceDiscoverable.createServiceBaseURL(connectionConfig.getHostname(), connectionConfig.getPort(), connectionConfig.isSSLEnabled(), programId); } catch (TimeoutException e) { return null; } catch (Exception e) { LOG.warn("Exception raised when waiting for Spark service to be available", e); return null; } }