Search in sources :

Example 11 with ZKServer

use of com.linkedin.d2.discovery.stores.zk.ZKServer 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<ServiceProperties>(executor, zkServiceRegistry);
    PropertyEventBus<UriProperties> uriBus = new PropertyEventBusImpl<UriProperties>(executor, zkUriRegistry);
    PropertyEventBus<ClusterProperties> clusterBus = new PropertyEventBusImpl<ClusterProperties>(executor, zkClusterRegistry);
    Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories = new HashMap<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>>();
    loadBalancerStrategyFactories.put("random", new RandomLoadBalancerStrategyFactory());
    loadBalancerStrategyFactories.put("degrader", new DegraderLoadBalancerStrategyFactoryV2());
    loadBalancerStrategyFactories.put("degraderV2", new DegraderLoadBalancerStrategyFactoryV2());
    loadBalancerStrategyFactories.put("degraderV3", new DegraderLoadBalancerStrategyFactoryV3());
    loadBalancerStrategyFactories.put("degraderV2_1", new DegraderLoadBalancerStrategyFactoryV2_1());
    Map<String, TransportClientFactory> clientFactories = new HashMap<String, TransportClientFactory>();
    clientFactories.put("http", new HttpClientFactory());
    // create the state
    SimpleLoadBalancerState state = new SimpleLoadBalancerState(executor, uriBus, clusterBus, serviceBus, clientFactories, loadBalancerStrategyFactories, null, null, false);
    SimpleLoadBalancer balancer = new SimpleLoadBalancer(state, 5, TimeUnit.SECONDS);
    FutureCallback<None> callback = new FutureCallback<None>();
    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 : DegraderLoadBalancerStrategyFactoryV2(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV2) 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) 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) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) 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) DegraderLoadBalancerStrategyFactoryV2_1(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV2_1) PropertyEventBusImpl(com.linkedin.d2.discovery.event.PropertyEventBusImpl) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) None(com.linkedin.common.util.None)

Example 12 with ZKServer

use of com.linkedin.d2.discovery.stores.zk.ZKServer in project rest.li by linkedin.

the class ZKFSTest method startServer.

private void startServer() throws IOException, InterruptedException {
    _zkServer = new ZKServer(PORT);
    _zkServer.startup();
}
Also used : ZKServer(com.linkedin.d2.discovery.stores.zk.ZKServer)

Example 13 with ZKServer

use of com.linkedin.d2.discovery.stores.zk.ZKServer in project rest.li by linkedin.

the class ZooKeeperStorePublisherTest method doSetup.

@BeforeMethod
public void doSetup() throws InterruptedException {
    try {
        _zkServer = new ZKServer(PORT);
        _zkServer.startup();
    } catch (IOException e) {
        fail("unable to instantiate real zk server on port " + PORT);
    }
}
Also used : ZKServer(com.linkedin.d2.discovery.stores.zk.ZKServer) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 14 with ZKServer

use of com.linkedin.d2.discovery.stores.zk.ZKServer in project rest.li by linkedin.

the class ZookeeperConnectionManagerTest method setUp.

@BeforeMethod
public void setUp() throws InterruptedException {
    try {
        _zkServer = new ZKServer(PORT);
        _zkServer.startup();
    } catch (IOException e) {
        fail("unable to instantiate real zk server on port " + PORT);
    }
}
Also used : ZKServer(com.linkedin.d2.discovery.stores.zk.ZKServer) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 15 with ZKServer

use of com.linkedin.d2.discovery.stores.zk.ZKServer in project rest.li by linkedin.

the class ZooKeeperServerTest method doOneTimeSetUp.

@BeforeSuite
public void doOneTimeSetUp() throws InterruptedException {
    try {
        _zkServer = new ZKServer(PORT);
        _zkServer.startup();
    } catch (IOException e) {
        fail("unable to instantiate real zk server on port " + PORT);
    }
}
Also used : ZKServer(com.linkedin.d2.discovery.stores.zk.ZKServer) IOException(java.io.IOException) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)6 ServicePropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer)6 ZKServer (com.linkedin.d2.discovery.stores.zk.ZKServer)6 IOException (java.io.IOException)6 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)5 UriPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer)5 UriPropertiesMerger (com.linkedin.d2.balancer.properties.UriPropertiesMerger)5 ZooKeeperEphemeralStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore)4 ZooKeeperPermanentStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperPermanentStore)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)3 ClusterPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer)3 HashMap (java.util.HashMap)3 PartitionAccessException (com.linkedin.d2.balancer.util.partitions.PartitionAccessException)2 PropertyStoreException (com.linkedin.d2.discovery.stores.PropertyStoreException)2 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 KeeperException (org.apache.zookeeper.KeeperException)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1