Search in sources :

Example 66 with ClusterProperties

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<>());
}
Also used : ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties)

Example 67 with ClusterProperties

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);
}
Also used : FileStore(com.linkedin.d2.discovery.stores.file.FileStore) LastSeenZKStore(com.linkedin.d2.discovery.stores.zk.LastSeenZKStore) ClusterPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties)

Example 68 with ClusterProperties

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;
}
Also used : ServicePropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer) HashMap(java.util.HashMap) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ZooKeeperPermanentStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperPermanentStore) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) UriPropertiesMerger(com.linkedin.d2.balancer.properties.UriPropertiesMerger) UriPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer) JmxManager(com.linkedin.d2.jmx.JmxManager) ClusterPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) TransportClientFactory(com.linkedin.r2.transport.common.TransportClientFactory) FutureCallback(com.linkedin.common.callback.FutureCallback) SimpleLoadBalancerState(com.linkedin.d2.balancer.simple.SimpleLoadBalancerState) SimpleLoadBalancer(com.linkedin.d2.balancer.simple.SimpleLoadBalancer) RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) LoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory) NamedThreadFactory(com.linkedin.r2.util.NamedThreadFactory) RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) ZooKeeperEphemeralStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) PropertyEventBusImpl(com.linkedin.d2.discovery.event.PropertyEventBusImpl) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) None(com.linkedin.common.util.None)

Example 69 with ClusterProperties

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.");
    }
}
Also used : PropertyEventShutdownCallback(com.linkedin.d2.discovery.event.PropertyEventThread.PropertyEventShutdownCallback) CountDownLatch(java.util.concurrent.CountDownLatch) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) ParseException(org.apache.commons.cli.ParseException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 70 with ClusterProperties

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));
}
Also used : ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)72 HashMap (java.util.HashMap)51 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)49 Test (org.testng.annotations.Test)47 ArrayList (java.util.ArrayList)42 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)41 URI (java.net.URI)38 Map (java.util.Map)32 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)24 DegraderLoadBalancerTest (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)24 List (java.util.List)20 NullStateListenerCallback (com.linkedin.d2.balancer.LoadBalancerState.NullStateListenerCallback)18 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)18 None (com.linkedin.common.util.None)16 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)16 FutureCallback (com.linkedin.common.callback.FutureCallback)15 HashSet (java.util.HashSet)14 DarkClusterConfigMap (com.linkedin.d2.DarkClusterConfigMap)13 RequestContext (com.linkedin.r2.message.RequestContext)13 ClusterPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer)12