private static TimestampManagementService createRemoteManagementService( MetricsManager metricsManager, Supplier<ServerListConfig> serverListConfig, String userAgent) { return new ServiceCreator<>(metricsManager, TimestampManagementService.class, userAgent) .applyDynamic(serverListConfig); }
private static LockAndTimestampServices createRawRemoteServices( MetricsManager metricsManager, AtlasDbConfig config, String userAgent) { LockService lockService = new ServiceCreator<>(metricsManager, LockService.class, userAgent) .apply(config.lock().get()); TimestampService timeService = new ServiceCreator<>(metricsManager, TimestampService.class, userAgent) .apply(config.timestamp().get()); TimestampManagementService timestampManagementService = new ServiceCreator<>(metricsManager, TimestampManagementService.class, userAgent) .apply(config.timestamp().get()); return ImmutableLockAndTimestampServices.builder() .lock(lockService) .timestamp(timeService) .timestampManagement(timestampManagementService) .timelock(new LegacyTimelockService(timeService, lockService, LOCK_CLIENT)) .build(); }
public T applyDynamic(Supplier<ServerListConfig> input) { return createService( metricsManager, input, SslSocketFactories::createTrustContext, ServiceCreator::createProxySelector, serviceClass, userAgent); }
userAgent); LeaderElectionService leader = localPaxosServices.leaderElectionService(); LockService localLock = ServiceCreator.createInstrumentedService(metricsManager.getRegistry(), AwaitingLeadershipProxy.newProxyInstance(LockService.class, lock, leader), LockService.class); TimestampService localTime = ServiceCreator.createInstrumentedService(metricsManager.getRegistry(), AwaitingLeadershipProxy.newProxyInstance(TimestampService.class, time, leader), TimestampService.class); TimestampManagementService localManagement = ServiceCreator.createInstrumentedService( metricsManager.getRegistry(), AwaitingLeadershipProxy.newProxyInstance(TimestampManagementService.class, .sslConfiguration(leaderConfig.sslConfiguration()) .build(); LockService remoteLock = new ServiceCreator<>(metricsManager, LockService.class, userAgent) .apply(serverListConfig); TimestampService remoteTime = new ServiceCreator<>(metricsManager, TimestampService.class, userAgent) .apply(serverListConfig); TimestampManagementService remoteManagement = new ServiceCreator<>(metricsManager, TimestampManagementService.class, userAgent) .apply(serverListConfig); String localServerId = localPingableLeader.getUUID(); PingableLeader remotePingableLeader = AtlasDbFeignTargetFactory.createRsProxy( ServiceCreator.createTrustContext(leaderConfig.sslConfiguration()), Iterables.getOnlyElement(leaderConfig.leaders()), PingableLeader.class,
@Override public T apply(ServerListConfig input) { return applyDynamic(() -> input); }
/** * The code below is copied from http-remoting and should be removed when we switch the clients to use remoting. */ public static ProxySelector createProxySelector(ProxyConfiguration proxyConfig) { switch (proxyConfig.type()) { case DIRECT: return fixedProxySelectorFor(Proxy.NO_PROXY); case HTTP: HostAndPort hostAndPort = HostAndPort.fromString(proxyConfig.hostAndPort() .orElseThrow(() -> new IllegalArgumentException( "Expected to find proxy hostAndPort configuration for HTTP proxy"))); InetSocketAddress addr = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort()); return fixedProxySelectorFor(new Proxy(Proxy.Type.HTTP, addr)); default: // fall through } throw new IllegalStateException("Failed to create ProxySelector for proxy configuration: " + proxyConfig); }
private static LockAndTimestampServices createRawEmbeddedServices( MetricsManager metricsManager, Consumer<Object> env, com.google.common.base.Supplier<LockService> lock, com.google.common.base.Supplier<TimestampService> time, com.google.common.base.Supplier<TimestampManagementService> timeManagement) { LockService lockService = ServiceCreator.createInstrumentedService( metricsManager.getRegistry(), lock.get(), LockService.class); TimestampService timeService = ServiceCreator.createInstrumentedService( metricsManager.getRegistry(), time.get(), TimestampService.class); TimestampManagementService timestampManagementService = ServiceCreator.createInstrumentedService( metricsManager.getRegistry(), timeManagement.get(), TimestampManagementService.class); env.accept(lockService); env.accept(timeService); env.accept(timestampManagementService); return ImmutableLockAndTimestampServices.builder() .lock(lockService) .timestamp(timeService) .timestampManagement(timestampManagementService) .timelock(new LegacyTimelockService(timeService, lockService, LOCK_CLIENT)) .build(); }
ServiceCreator.createTrustContext(config.sslConfiguration());
@Test public void directProxyIsConfigurableOnClientRequests() { Optional<ProxySelector> directProxySelector = Optional.of( ServiceCreator.createProxySelector(ProxyConfiguration.DIRECT)); TestResource clientWithDirectCall = AtlasDbHttpClients.createProxyWithFailover( new MetricRegistry(), NO_SSL, directProxySelector, ImmutableSet.of(getUriForPort(availablePort)), TestResource.class); clientWithDirectCall.getTestNumber(); String defaultUserAgent = UserAgents.fromStrings(UserAgents.DEFAULT_VALUE, UserAgents.DEFAULT_VALUE); availableServer.verify(getRequestedFor(urlMatching(TEST_ENDPOINT)) .withHeader(FeignOkHttpClients.USER_AGENT_HEADER, WireMock.equalTo(defaultUserAgent))); }
userAgent); LeaderElectionService leader = localPaxosServices.leaderElectionService(); LockService localLock = ServiceCreator.createInstrumentedService(metricsManager.getRegistry(), AwaitingLeadershipProxy.newProxyInstance(LockService.class, lock, leader), LockService.class); TimestampService localTime = ServiceCreator.createInstrumentedService(metricsManager.getRegistry(), AwaitingLeadershipProxy.newProxyInstance(TimestampService.class, time, leader), TimestampService.class); TimestampManagementService localManagement = ServiceCreator.createInstrumentedService( metricsManager.getRegistry(), AwaitingLeadershipProxy.newProxyInstance(TimestampManagementService.class, .sslConfiguration(leaderConfig.sslConfiguration()) .build(); LockService remoteLock = new ServiceCreator<>(metricsManager, LockService.class, userAgent) .apply(serverListConfig); TimestampService remoteTime = new ServiceCreator<>(metricsManager, TimestampService.class, userAgent) .apply(serverListConfig); TimestampManagementService remoteManagement = new ServiceCreator<>(metricsManager, TimestampManagementService.class, userAgent) .apply(serverListConfig); String localServerId = localPingableLeader.getUUID(); PingableLeader remotePingableLeader = AtlasDbFeignTargetFactory.createRsProxy( ServiceCreator.createTrustContext(leaderConfig.sslConfiguration()), Iterables.getOnlyElement(leaderConfig.leaders()), PingableLeader.class,
@Override public T apply(ServerListConfig input) { return applyDynamic(() -> input); }
/** * The code below is copied from http-remoting and should be removed when we switch the clients to use remoting. */ public static ProxySelector createProxySelector(ProxyConfiguration proxyConfig) { switch (proxyConfig.type()) { case DIRECT: return fixedProxySelectorFor(Proxy.NO_PROXY); case HTTP: HostAndPort hostAndPort = HostAndPort.fromString(proxyConfig.hostAndPort() .orElseThrow(() -> new IllegalArgumentException( "Expected to find proxy hostAndPort configuration for HTTP proxy"))); InetSocketAddress addr = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort()); return fixedProxySelectorFor(new Proxy(Proxy.Type.HTTP, addr)); default: // fall through } throw new IllegalStateException("Failed to create ProxySelector for proxy configuration: " + proxyConfig); }
private static LockAndTimestampServices createRawEmbeddedServices( MetricsManager metricsManager, Consumer<Object> env, com.google.common.base.Supplier<LockService> lock, com.google.common.base.Supplier<TimestampService> time, com.google.common.base.Supplier<TimestampManagementService> timeManagement) { LockService lockService = ServiceCreator.createInstrumentedService( metricsManager.getRegistry(), lock.get(), LockService.class); TimestampService timeService = ServiceCreator.createInstrumentedService( metricsManager.getRegistry(), time.get(), TimestampService.class); TimestampManagementService timestampManagementService = ServiceCreator.createInstrumentedService( metricsManager.getRegistry(), timeManagement.get(), TimestampManagementService.class); env.accept(lockService); env.accept(timeService); env.accept(timestampManagementService); return ImmutableLockAndTimestampServices.builder() .lock(lockService) .timestamp(timeService) .timestampManagement(timestampManagementService) .timelock(new LegacyTimelockService(timeService, lockService, LOCK_CLIENT)) .build(); }
ServiceCreator.createTrustContext(config.sslConfiguration());
@Test public void httpProxyIsConfigurableOnClientRequests() { Optional<ProxySelector> httpProxySelector = Optional.of( ServiceCreator.createProxySelector(ProxyConfiguration.of(getHostAndPort(proxyPort)))); TestResource clientWithHttpProxy = AtlasDbHttpClients.createProxyWithFailover( new MetricRegistry(), NO_SSL, httpProxySelector, ImmutableSet.of(getUriForPort(availablePort)), TestResource.class); clientWithHttpProxy.getTestNumber(); String defaultUserAgent = UserAgents.fromStrings(UserAgents.DEFAULT_VALUE, UserAgents.DEFAULT_VALUE); proxyServer.verify(getRequestedFor(urlMatching(TEST_ENDPOINT)) .withHeader(FeignOkHttpClients.USER_AGENT_HEADER, WireMock.equalTo(defaultUserAgent))); availableServer.verify(0, getRequestedFor(urlMatching(TEST_ENDPOINT))); }
private static LockAndTimestampServices getLockAndTimestampServices( MetricsManager metricsManager, Supplier<ServerListConfig> timelockServerListConfig, String userAgent) { LockService lockService = new ServiceCreator<>(metricsManager, LockService.class, userAgent) .applyDynamic(timelockServerListConfig); TimelockService timelockService = new ServiceCreator<>(metricsManager, TimelockService.class, userAgent) .applyDynamic(timelockServerListConfig); TimestampManagementService timestampManagementService = new ServiceCreator<>(metricsManager, TimestampManagementService.class, userAgent) .applyDynamic(timelockServerListConfig); return ImmutableLockAndTimestampServices.builder() .lock(lockService) .timestamp(new TimelockTimestampServiceAdapter(timelockService)) .timestampManagement(timestampManagementService) .timelock(timelockService) .build(); }
private static LockAndTimestampServices createRawRemoteServices( MetricsManager metricsManager, AtlasDbConfig config, String userAgent) { LockService lockService = new ServiceCreator<>(metricsManager, LockService.class, userAgent) .apply(config.lock().get()); TimestampService timeService = new ServiceCreator<>(metricsManager, TimestampService.class, userAgent) .apply(config.timestamp().get()); TimestampManagementService timestampManagementService = new ServiceCreator<>(metricsManager, TimestampManagementService.class, userAgent) .apply(config.timestamp().get()); return ImmutableLockAndTimestampServices.builder() .lock(lockService) .timestamp(timeService) .timestampManagement(timestampManagementService) .timelock(new LegacyTimelockService(timeService, lockService, LOCK_CLIENT)) .build(); }
public T applyDynamic(Supplier<ServerListConfig> input) { return createService( metricsManager, input, SslSocketFactories::createTrustContext, ServiceCreator::createProxySelector, serviceClass, userAgent); }
private static TimestampManagementService createRemoteManagementService( MetricsManager metricsManager, Supplier<ServerListConfig> serverListConfig, String userAgent) { return new ServiceCreator<>(metricsManager, TimestampManagementService.class, userAgent) .applyDynamic(serverListConfig); }
private static LockAndTimestampServices getLockAndTimestampServices( MetricsManager metricsManager, Supplier<ServerListConfig> timelockServerListConfig, String userAgent) { LockService lockService = new ServiceCreator<>(metricsManager, LockService.class, userAgent) .applyDynamic(timelockServerListConfig); TimelockService timelockService = new ServiceCreator<>(metricsManager, TimelockService.class, userAgent) .applyDynamic(timelockServerListConfig); TimestampManagementService timestampManagementService = new ServiceCreator<>(metricsManager, TimestampManagementService.class, userAgent) .applyDynamic(timelockServerListConfig); return ImmutableLockAndTimestampServices.builder() .lock(lockService) .timestamp(new TimelockTimestampServiceAdapter(timelockService)) .timestampManagement(timestampManagementService) .timelock(timelockService) .build(); }