Search in sources :

Example 46 with PartitionData

use of com.linkedin.d2.balancer.properties.PartitionData in project rest.li by linkedin.

the class ZookeeperConnectionManagerTest method testMarkDownAndUpDuringDisconnection.

@Test
public void testMarkDownAndUpDuringDisconnection() throws IOException, ExecutionException, InterruptedException, PropertyStoreException, TimeoutException {
    final String uri = "http://cluster-5/test";
    final String cluster = "cluster-5";
    final double weight = 0.5d;
    ZooKeeperAnnouncer announcer = new ZooKeeperAnnouncer(new ZooKeeperServer());
    announcer.setCluster(cluster);
    announcer.setUri(uri);
    Map<Integer, PartitionData> partitionWeight = new HashMap<Integer, PartitionData>();
    partitionWeight.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(weight));
    announcer.setPartitionData(partitionWeight);
    ZooKeeperConnectionManager manager = createManager(announcer);
    FutureCallback<None> managerStartCallback = new FutureCallback<None>();
    manager.start(managerStartCallback);
    managerStartCallback.get();
    ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
    UriProperties properties = store.get(cluster);
    assertNotNull(properties);
    assertEquals(properties.getPartitionDataMap(URI.create(uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), weight);
    assertEquals(properties.Uris().size(), 1);
    _zkServer.shutdown(false);
    FutureCallback<None> markDownCallback = new FutureCallback<None>();
    announcer.markDown(markDownCallback);
    FutureCallback<None> markUpCallback = new FutureCallback<None>();
    announcer.markUp(markUpCallback);
    // ugly, but we need to wait for a while just so that Disconnect event is propagated
    // to the caller before we restart zk sever.
    Thread.sleep(1000);
    _zkServer.restart();
    markUpCallback.get(10, TimeUnit.SECONDS);
    try {
        markDownCallback.get();
        Assert.fail("mark down should have thrown CancellationException.");
    } catch (ExecutionException e) {
        Assert.assertTrue(e.getCause() instanceof CancellationException);
    }
    properties = store.get(cluster);
    assertNotNull(properties);
    assertEquals(properties.getPartitionDataMap(URI.create(uri)).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), weight);
    assertEquals(properties.Uris().size(), 1);
}
Also used : HashMap(java.util.HashMap) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) CancellationException(java.util.concurrent.CancellationException) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) ExecutionException(java.util.concurrent.ExecutionException) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) Test(org.testng.annotations.Test)

Example 47 with PartitionData

use of com.linkedin.d2.balancer.properties.PartitionData in project rest.li by linkedin.

the class ZooKeeperServerJmx method setMarkUp.

@Override
public void setMarkUp(String clusterName, String uri, double weight) throws PropertyStoreException {
    Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>(1);
    partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(weight));
    setMarkup(clusterName, uri, partitionDataMap, Collections.<String, Object>emptyMap());
}
Also used : HashMap(java.util.HashMap) PartitionData(com.linkedin.d2.balancer.properties.PartitionData)

Example 48 with PartitionData

use of com.linkedin.d2.balancer.properties.PartitionData in project rest.li by linkedin.

the class ZooKeeperServerJmx method setMarkup.

@Override
public void setMarkup(String clusterName, String uri, Map<Integer, PartitionData> partitionDataMap, Map<String, Object> uriSpecificProperties) throws PropertyStoreException {
    FutureCallback<None> callback = new FutureCallback<None>();
    _server.markUp(clusterName, URI.create(uri), partitionDataMap, uriSpecificProperties, callback);
    try {
        callback.get(10, TimeUnit.SECONDS);
    } catch (Exception e) {
        throw new PropertyStoreException(e);
    }
}
Also used : PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException)

Example 49 with PartitionData

use of com.linkedin.d2.balancer.properties.PartitionData in project rest.li by linkedin.

the class LoadBalancerTestState method getClient.

@Override
public TrackerClient getClient(String clusterName, URI uri) {
    Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>(2);
    partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1));
    return (getClient) ? new TrackerClient(uri, partitionDataMap, new TestClient()) : null;
}
Also used : TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) HashMap(java.util.HashMap) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) TestClient(com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient)

Example 50 with PartitionData

use of com.linkedin.d2.balancer.properties.PartitionData in project rest.li by linkedin.

the class SimpleLoadBalancerState method getTrackerClient.

private TrackerClient getTrackerClient(String serviceName, URI uri, Map<Integer, PartitionData> partitionDataMap, DegraderImpl.Config config, Clock clk, long callTrackerInterval, String errorStatusPattern) {
    Map<String, TransportClient> clientsByScheme = _serviceClients.get(serviceName);
    if (clientsByScheme == null) {
        _log.error("getTrackerClient: unknown service name {} for URI {} and partitionDataMap {}", new Object[] { serviceName, uri, partitionDataMap });
        return null;
    }
    TransportClient client = clientsByScheme.get(uri.getScheme().toLowerCase());
    if (client == null) {
        // logging this at debug because there may be situations where a service may want some of its
        // clients talking https while others are ok using http.
        debug(_log, "No TransportClient for scheme {}, service {}, URI {} and partitionDataMap {}. " + "This client may not be configured to handle URIs in this scheme.", new Object[] { uri.getScheme(), serviceName, uri, partitionDataMap });
        return null;
    }
    TrackerClient trackerClient = new TrackerClient(uri, partitionDataMap, client, clk, config, callTrackerInterval, errorStatusPattern);
    return trackerClient;
}
Also used : TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient)

Aggregations

PartitionData (com.linkedin.d2.balancer.properties.PartitionData)55 HashMap (java.util.HashMap)53 Test (org.testng.annotations.Test)36 URI (java.net.URI)35 Map (java.util.Map)31 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)28 ArrayList (java.util.ArrayList)25 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)21 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)20 None (com.linkedin.common.util.None)15 FutureCallback (com.linkedin.common.callback.FutureCallback)14 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)13 DegraderLoadBalancerTest (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)13 NullStateListenerCallback (com.linkedin.d2.balancer.LoadBalancerState.NullStateListenerCallback)12 RequestContext (com.linkedin.r2.message.RequestContext)11 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)9 LoadBalancerState (com.linkedin.d2.balancer.LoadBalancerState)8 PartitionAccessor (com.linkedin.d2.balancer.util.partitions.PartitionAccessor)7 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)7 HashSet (java.util.HashSet)7