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);
}
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());
}
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);
}
}
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;
}
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;
}
Aggregations