use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class TestD2Config method verifyClusterProperties.
public static void verifyClusterProperties(String cluster) throws IOException, URISyntaxException, PropertyStoreException {
ClusterProperties clusterprops = getClusterProperties(_zkclient, cluster);
assertEquals(clusterprops.getClusterName(), cluster);
assertEquals(clusterprops.getPrioritizedSchemes(), Arrays.asList(new String[] { "http" }));
assertEquals(clusterprops.getProperties().get("requestTimeout"), String.valueOf(10000));
assertEquals(clusterprops.getBannedUris(), new TreeSet<>());
}
use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class LastSeenBalancerWithFacilitiesFactory method getClusterPropertiesLastSeenZKStore.
private LastSeenZKStore<ClusterProperties> getClusterPropertiesLastSeenZKStore(D2ClientConfig config, ZKPersistentConnection zkPersistentConnection, D2ClientJmxManager d2ClientJmxManager, ScheduledExecutorService executorService, int zookeeperReadWindowMs) {
ZooKeeperPermanentStoreBuilder<ClusterProperties> zkClusterStoreBuilder = new ZooKeeperPermanentStoreBuilder<ClusterProperties>().setSerializer(new ClusterPropertiesJsonSerializer()).setPath(ZKFSUtil.clusterPath(config.basePath)).setExecutorService(executorService).setZookeeperReadWindowMs(zookeeperReadWindowMs).addOnBuildListener(d2ClientJmxManager::setZkClusterRegistry);
FileStore<ClusterProperties> fileStore = new FileStore<>(FileSystemDirectory.getClusterDirectory(config.fsBasePath), new ClusterPropertiesJsonSerializer());
d2ClientJmxManager.setFsClusterStore(fileStore);
return new LastSeenZKStore<>(fileStore, zkClusterStoreBuilder, zkPersistentConnection, config._executorService, config.warmUpTimeoutSeconds, config.warmUpConcurrentRequests);
}
use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class LoadBalancerClientCli method getLoadBalancer.
public static SimpleLoadBalancer getLoadBalancer(ZKConnection zkclient, String zkserver, String d2path, String service) throws IOException, IllegalStateException, URISyntaxException, PropertyStoreException, ExecutionException, TimeoutException, InterruptedException {
// zk stores
String clstoreString = zkserver + ZKFSUtil.clusterPath(d2path);
String scstoreString = zkserver + ZKFSUtil.servicePath(d2path);
String uristoreString = zkserver + ZKFSUtil.uriPath(d2path);
ZooKeeperPermanentStore<ClusterProperties> zkClusterRegistry = (ZooKeeperPermanentStore<ClusterProperties>) getStore(zkclient, clstoreString, new ClusterPropertiesJsonSerializer());
ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry = (ZooKeeperPermanentStore<ServiceProperties>) getStore(zkclient, scstoreString, new ServicePropertiesJsonSerializer());
ZooKeeperEphemeralStore<UriProperties> zkUriRegistry = (ZooKeeperEphemeralStore<UriProperties>) getEphemeralStore(zkclient, uristoreString, new UriPropertiesJsonSerializer(), new UriPropertiesMerger());
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("D2 PropertyEventExecutor"));
PropertyEventBus<ServiceProperties> serviceBus = new PropertyEventBusImpl<>(executor, zkServiceRegistry);
PropertyEventBus<UriProperties> uriBus = new PropertyEventBusImpl<>(executor, zkUriRegistry);
PropertyEventBus<ClusterProperties> clusterBus = new PropertyEventBusImpl<>(executor, zkClusterRegistry);
Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories = new HashMap<>();
loadBalancerStrategyFactories.put("random", new RandomLoadBalancerStrategyFactory());
loadBalancerStrategyFactories.put("degrader", new DegraderLoadBalancerStrategyFactoryV3());
loadBalancerStrategyFactories.put("degraderV2", new DegraderLoadBalancerStrategyFactoryV3());
loadBalancerStrategyFactories.put("degraderV3", new DegraderLoadBalancerStrategyFactoryV3());
loadBalancerStrategyFactories.put("degraderV2_1", new DegraderLoadBalancerStrategyFactoryV3());
Map<String, TransportClientFactory> clientFactories = new HashMap<>();
clientFactories.put("http", new HttpClientFactory.Builder().build());
// create the state
SimpleLoadBalancerState state = new SimpleLoadBalancerState(executor, uriBus, clusterBus, serviceBus, clientFactories, loadBalancerStrategyFactories, null, null, false);
SimpleLoadBalancer balancer = new SimpleLoadBalancer(state, 5, TimeUnit.SECONDS, executor);
FutureCallback<None> callback = new FutureCallback<>();
balancer.start(callback);
callback.get(5, TimeUnit.SECONDS);
new JmxManager().registerLoadBalancer("balancer", balancer).registerLoadBalancerState("state", state).registerScheduledThreadPoolExecutor("executorService", executor).registerZooKeeperPermanentStore("zkClusterRegistry", zkClusterRegistry).registerZooKeeperPermanentStore("zkServiceRegistry", zkServiceRegistry).registerZooKeeperEphemeralStore("zkUriRegistry", zkUriRegistry);
return balancer;
}
use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class LoadBalancerClientCli method shutdown.
public void shutdown() throws Exception {
if (_zkClusterRegistry != null) {
try {
shutdownZKRegistry(_zkClusterRegistry);
} catch (Exception e) {
_log.error("Failed to shutdown ZooKeeperPermanentStore<ClusterProperties> zkClusterRegistry.");
}
}
if (_zkServiceRegistry != null) {
try {
shutdownZKRegistry(_zkServiceRegistry);
} catch (Exception e) {
_log.error("Failed to shutdown ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry.");
}
}
if (_zkUriRegistry != null) {
try {
shutdownZKRegistry(_zkUriRegistry);
} catch (Exception e) {
_log.error("Failed to shutdown ZooKeeperEphemeralStore<UriProperties> zkUriRegistry.");
}
}
try {
if (_client != null) {
LoadBalancerUtil.syncShutdownClient(_client, _log);
}
} catch (Exception e) {
_log.error("Failed to shutdown dynamic client.");
}
if (_zkfsLoadBalancer != null) {
try {
final CountDownLatch latch = new CountDownLatch(1);
_zkfsLoadBalancer.shutdown(new PropertyEventShutdownCallback() {
@Override
public void done() {
latch.countDown();
}
});
if (!latch.await(5, TimeUnit.SECONDS)) {
_log.error("unable to shut down store");
}
} catch (Exception e) {
_log.error("Failed to shutdown zkfsLoadBalancer.");
}
}
try {
deleteTempDir();
} catch (Exception e) {
_log.error("Failed to delete directory " + _tmpDir);
}
try {
_zkclient.shutdown();
} catch (Exception e) {
_log.error("Failed to shutdown zk client.");
}
}
use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class StaticLoadBalancerState method refreshDefaultProperties.
/**
* Since property objects are immutable, this function has to be called to refresh them when new properties are added.
*/
public void refreshDefaultProperties() {
_serviceProperties.replace(TEST_SERVICE, new ServiceProperties(TEST_SERVICE, TEST_CLUSTER, TEST_SERVICE_PATH, TEST_SERVICE_STRATEGIES_LIST, TEST_SERVICE_LB_STRATEGY_PROPERTIES, TEST_SERVICE_TRANSPORT_CLIENT_PROPERTIES, TEST_SERVICE_DEGRADER_PROPERTIES, TEST_SERVICE_PRIORITIZED_SCHEMES, TEST_SERVICE_BANNED_URIS, TEST_SERVICE_META_PROPERTIES, TEST_SERVICE_BACKUP_REQUEST_PROPERTIES));
_clusterPropertie.replace(TEST_CLUSTER, new ClusterProperties(TEST_CLUSTER, TEST_SERVICE_PRIORITIZED_SCHEMES, TEST_CLUSTER_PROPERTIES, TEST_CLUSTER_BANNED_URIS, TEST_CLUSTER_PARTITION_PROPERTIES, TEST_CLUSTER_SSL_VALIDATION_STRINGS, (Map<String, Object>) null, false));
_uriProperties.replace(TEST_CLUSTER, new UriProperties(TEST_CLUSTER, TEST_URIS_PARTITIONDESCRIPTIONS, TEST_URI_PROPERTIES));
}
Aggregations