private Map.Entry<String, Object> serialize(DataCenter dataCenter) { return Maps.<String, Object>immutableEntry(dataCenter.getName(), ImmutableMap.<String, Object>builder() .put("cluster", _cluster) .put("serviceUri", dataCenter.getServiceUri().toString()) .put("adminUri", dataCenter.getAdminUri().toString()) .put("system", dataCenter.isSystem()) .put("cassandraName", dataCenter.getCassandraName()) .put("cassandraKeyspaces", sorted(dataCenter.getCassandraKeyspaces())) .build()); }
private Map.Entry<String, Object> serialize(DataCenter dataCenter) { return Maps.<String, Object>immutableEntry(dataCenter.getName(), ImmutableMap.<String, Object>builder() .put("cluster", _cluster) .put("serviceUri", dataCenter.getServiceUri().toString()) .put("adminUri", dataCenter.getAdminUri().toString()) .put("system", dataCenter.isSystem()) .put("cassandraName", dataCenter.getCassandraName()) .put("cassandraKeyspaces", sorted(dataCenter.getCassandraKeyspaces())) .build()); }
@Override public void withEndPoints(Function<Collection<EndPoint>, ?> function) { List<EndPoint> endPoints = Lists.newArrayList(); DataCenter self = _dataCenters.getSelf(); for (DataCenter dataCenter : _dataCenters.getAll()) { if (!dataCenter.equals(self)) { final URI adminUri = dataCenter.getAdminUri(); endPoints.add(new EndPoint() { @Override public String getAddress() { return _endPointAdapter.toEndPointAddress(adminUri); } @Override public boolean isValid() { return true; } }); } } function.apply(endPoints); } }
@Override public void withEndPoints(Function<Collection<EndPoint>, ?> function) { List<EndPoint> endPoints = Lists.newArrayList(); DataCenter self = _dataCenters.getSelf(); for (DataCenter dataCenter : _dataCenters.getAll()) { if (!dataCenter.equals(self)) { final URI adminUri = dataCenter.getAdminUri(); endPoints.add(new EndPoint() { @Override public String getAddress() { return _endPointAdapter.toEndPointAddress(adminUri); } @Override public boolean isValid() { return true; } }); } } function.apply(endPoints); } }
@Provides @Singleton @AllCompactionControlSources public List<CompactionControlSource> getAllCompactionControlSources(@LocalCompactionControl CompactionControlSource localCompactionControlSource, @ServerCluster String serverCluster, Client client, DataCenters dataCenters, @CompControlApiKey String compControlApiKey, HealthCheckRegistry healthCheckRegistry, MetricRegistry metrics) { List<CompactionControlSource> compactionControlSources = Lists.newArrayList(); for (DataCenter dataCenter : dataCenters.getAll()) { MultiThreadedServiceFactory<CompactionControlSource> clientFactory = new CompactionControlClientFactory(serverCluster, new JerseyEmoClient(client), compControlApiKey); if (dataCenter.equals(dataCenters.getSelf())) { compactionControlSources.add(localCompactionControlSource); } else { ServiceEndPoint endPoint = new ServiceEndPointBuilder() .withServiceName(clientFactory.getServiceName()) .withId(dataCenter.getName()) .withPayload(new PayloadBuilder() .withUrl(dataCenter.getServiceUri().resolve(DataStoreClient.SERVICE_PATH)) .withAdminUrl(dataCenter.getAdminUri()) .toString()) .build(); compactionControlSources.add(ServicePoolBuilder.create(CompactionControlSource.class) .withHostDiscovery(new FixedHostDiscovery(endPoint)) .withServiceFactory(clientFactory) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .withMetricRegistry(metrics) .buildProxy(new ExponentialBackoffRetry(30, 1, 10, TimeUnit.SECONDS))); } } return compactionControlSources; }
/** Creates a ReplicationSource proxy to the remote data center. */ private ReplicationSource newRemoteReplicationSource(DataCenter dataCenter) { MultiThreadedServiceFactory<ReplicationSource> clientFactory = new ReplicationClientFactory(_jerseyClient) .usingApiKey(_replicationApiKey); ServiceEndPoint endPoint = new ServiceEndPointBuilder() .withServiceName(clientFactory.getServiceName()) .withId(dataCenter.getName()) .withPayload(new PayloadBuilder() .withUrl(dataCenter.getServiceUri().resolve(ReplicationClient.SERVICE_PATH)) .withAdminUrl(dataCenter.getAdminUri()) .toString()) .build(); return ServicePoolBuilder.create(ReplicationSource.class) .withHostDiscovery(new FixedHostDiscovery(endPoint)) .withServiceFactory(clientFactory) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .withHealthCheckExecutor(_healthCheckExecutor) .withMetricRegistry(_metrics) .buildProxy(new ExponentialBackoffRetry(30, 1, 10, TimeUnit.SECONDS)); } }
/** Creates a ReplicationSource proxy to the remote data center. */ private ReplicationSource newRemoteReplicationSource(DataCenter dataCenter) { MultiThreadedServiceFactory<ReplicationSource> clientFactory = new ReplicationClientFactory(_jerseyClient) .usingApiKey(_replicationApiKey); ServiceEndPoint endPoint = new ServiceEndPointBuilder() .withServiceName(clientFactory.getServiceName()) .withId(dataCenter.getName()) .withPayload(new PayloadBuilder() .withUrl(dataCenter.getServiceUri().resolve(ReplicationClient.SERVICE_PATH)) .withAdminUrl(dataCenter.getAdminUri()) .toString()) .build(); return ServicePoolBuilder.create(ReplicationSource.class) .withHostDiscovery(new FixedHostDiscovery(endPoint)) .withServiceFactory(clientFactory) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .withHealthCheckExecutor(_healthCheckExecutor) .withMetricRegistry(_metrics) .buildProxy(new ExponentialBackoffRetry(30, 1, 10, TimeUnit.SECONDS)); } }