public SecurityAuthenticationHttpHandler(String realm, TokenValidator tokenValidator, CConfiguration configuration, AccessTokenTransformer accessTokenTransformer, DiscoveryServiceClient discoveryServiceClient) { this.realm = realm; this.tokenValidator = tokenValidator; this.accessTokenTransformer = accessTokenTransformer; this.discoverables = discoveryServiceClient.discover(Constants.Service.EXTERNAL_AUTHENTICATION); this.configuration = configuration; }
@Override public ServiceDiscovered discover(String service) { return discoveryServiceClient.discover(service); } }
@Override public ServiceDiscovered discover(String name) { return discoveryServiceClient.discover(name); }
@Override public ServiceDiscovered discover(String name) { return discoveryServiceClient.discover(name); }
@Override public EndpointStrategy get() { return new RandomEndpointStrategy(() -> discoveryClient.discover(Service.EXPLORE_HTTP_USER_SERVICE)); } });
@Override public Boolean call() throws Exception { return discoveryServiceClient.discover(Constants.Service.TRANSACTION).iterator().hasNext(); } }, timeout, TimeUnit.SECONDS, Math.min(timeout, Math.max(10, timeout / 10)), TimeUnit.SECONDS);
@Override public EndpointStrategy get() { return new RandomEndpointStrategy(discoveryClient.discover(Service.EXPLORE_HTTP_USER_SERVICE)); } });
@Override public EndpointStrategy get() { return new RandomEndpointStrategy(() -> discoveryClient.discover(discoverableServiceName)); } });
@Override public EndpointStrategy get() { return new RandomEndpointStrategy(discoveryClient.discover(discoverableServiceName)); } });
@Override public Boolean call() throws Exception { return discoveryServiceClient.discover(Constants.Service.TRANSACTION).iterator().hasNext(); } }, timeout, TimeUnit.SECONDS, Math.min(timeout, Math.max(10, timeout / 10)), TimeUnit.SECONDS);
@Override public Connection getQueryClient(NamespaceId namespace) throws Exception { // this makes sure the Explore JDBC driver is loaded Class.forName(ExploreDriver.class.getName()); Discoverable discoverable = new StickyEndpointStrategy(() -> discoveryClient.discover(Constants.Service.EXPLORE_HTTP_USER_SERVICE)).pick(); if (null == discoverable) { throw new IOException("Explore service could not be discovered."); } InetSocketAddress address = discoverable.getSocketAddress(); String host = address.getHostName(); int port = address.getPort(); String connectString = String.format("%s%s:%d?namespace=%s", Constants.Explore.Jdbc.URL_PREFIX, host, port, namespace.getNamespace()); return DriverManager.getConnection(connectString); }
@Override public Connection getQueryClient(NamespaceId namespace) throws Exception { // this makes sure the Explore JDBC driver is loaded Class.forName(ExploreDriver.class.getName()); Discoverable discoverable = new StickyEndpointStrategy( discoveryClient.discover(Constants.Service.EXPLORE_HTTP_USER_SERVICE)).pick(); if (null == discoverable) { throw new IOException("Explore service could not be discovered."); } InetSocketAddress address = discoverable.getSocketAddress(); String host = address.getHostName(); int port = address.getPort(); String connectString = String.format("%s%s:%d?namespace=%s", Constants.Explore.Jdbc.URL_PREFIX, host, port, namespace.getNamespace()); return DriverManager.getConnection(connectString); }
@Override public boolean isServiceAvailable() { try { Discoverable discoverable = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(serviceName)) .pick(discoveryTimeout, TimeUnit.SECONDS); if (discoverable == null) { return false; } return txClient.status().equals(Constants.Monitor.STATUS_OK); } catch (IllegalArgumentException e) { return false; } catch (Exception e) { LOG.warn("Unable to ping {} : Reason {} ", serviceName, e.getMessage()); return false; } }
@Override public boolean isServiceAvailable() { try { ServiceDiscovered discovered = discoveryServiceClient.discover(serviceName); Discoverable discoverable = new RandomEndpointStrategy(discovered).pick(discoveryTimeout, TimeUnit.SECONDS); if (discoverable == null) { return false; } return txClient.status().equals(Constants.Monitor.STATUS_OK); } catch (IllegalArgumentException e) { return false; } catch (Exception e) { LOG.warn("Unable to ping {} : Reason {} ", serviceName, e.getMessage()); return false; } }
/** * Initialize the service discovery client, we will reuse that * every time we need to create a new client. */ private void initDiscovery() { if (discoveryServiceClient == null) { LOG.info("No DiscoveryServiceClient provided. Skipping service discovery."); return; } endpointStrategy = new TimeLimitEndpointStrategy( new RandomEndpointStrategy( discoveryServiceClient.discover( configuration.get(TxConstants.Service.CFG_DATA_TX_DISCOVERY_SERVICE_NAME, TxConstants.Service.DEFAULT_DATA_TX_DISCOVERY_SERVICE_NAME))), 2, TimeUnit.SECONDS); }
/** * Initialize the service discovery client, we will reuse that * every time we need to create a new client. */ private void initDiscovery() { if (discoveryServiceClient == null) { LOG.info("No DiscoveryServiceClient provided. Skipping service discovery."); return; } endpointStrategy = new TimeLimitEndpointStrategy( new RandomEndpointStrategy( discoveryServiceClient.discover( configuration.get(TxConstants.Service.CFG_DATA_TX_DISCOVERY_SERVICE_NAME, TxConstants.Service.DEFAULT_DATA_TX_DISCOVERY_SERVICE_NAME))), 2, TimeUnit.SECONDS); }
/** * Initialize the service discovery client, we will reuse that * every time we need to create a new client. */ private void initDiscovery() { if (discoveryServiceClient == null) { LOG.info("No DiscoveryServiceClient provided. Skipping service discovery."); return; } endpointStrategy = new TimeLimitEndpointStrategy( new RandomEndpointStrategy( discoveryServiceClient.discover( configuration.get(TxConstants.Service.CFG_DATA_TX_DISCOVERY_SERVICE_NAME, TxConstants.Service.DEFAULT_DATA_TX_DISCOVERY_SERVICE_NAME))), configuration.getInt(TxConstants.Service.CFG_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC, TxConstants.Service.DEFAULT_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC), TimeUnit.SECONDS); }
private EndpointStrategy discover(RouteDestination routeDestination) { LOG.debug("Looking up service name {}", routeDestination); // If its a user service, then use UserServiceEndpointStrategy Strategy String serviceName = routeDestination.getServiceName(); return ServiceDiscoverable.isUserService(serviceName) ? new UserServiceEndpointStrategy(() -> discoveryServiceClient.discover(serviceName), routeStore, ServiceDiscoverable.getId(serviceName), fallbackStrategy, routeDestination.getVersion()) : new RandomEndpointStrategy(() -> discoveryServiceClient.discover(serviceName)); } }