use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class R2D2Server method run.
public void run() throws Exception {
// start everything
for (Map.Entry<String, List<LoadBalancerEchoServer>> servers : _clusters.entrySet()) {
List<String> schemes = new ArrayList<String>();
schemes.add("http");
putCluster(new ClusterProperties(servers.getKey(), schemes));
for (final LoadBalancerEchoServer server : servers.getValue()) {
for (int i = 1; i <= 3; ++i) {
putService(new ServiceProperties("service-" + i + "-" + servers.getKey(), servers.getKey(), File.separator + "service-" + i + "-" + servers.getKey(), Arrays.asList("degrader")));
}
server.startServer();
server.markUp();
}
}
}
use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class R2D2Server method putCluster.
private void putCluster(ClusterProperties clusterProperties) throws Exception {
System.err.println("put: " + clusterProperties);
ZKConnection client = new ZKConnection(_zookeeperHost + ":" + _zookeeperPort, 30000);
PropertyStore<ClusterProperties> store = new ZooKeeperPermanentStore<ClusterProperties>(client, new ClusterPropertiesJsonSerializer(), _basePath + "/clusters");
store.put(clusterProperties.getClusterName(), clusterProperties);
client.getZooKeeper().close();
}
use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class SimpleLoadBalancerStateTest method testVersion.
@Test(groups = { "small", "back-end" })
public void testVersion() throws URISyntaxException {
reset();
int expectedVersion = 0;
URI uri = URI.create("http://cluster-1/test");
List<String> schemes = new ArrayList<String>();
Map<Integer, PartitionData> partitionData = new HashMap<Integer, PartitionData>(1);
partitionData.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
Map<URI, Map<Integer, PartitionData>> uriData = new HashMap<URI, Map<Integer, PartitionData>>();
uriData.put(uri, partitionData);
schemes.add("http");
// set up state
_state.listenToCluster("cluster-1", new NullStateListenerCallback());
// one for uri properties onInit, and one for cluster properties onInit
expectedVersion += 2;
assertEquals(_state.getVersion(), expectedVersion);
_state.listenToService("service-1", new NullStateListenerCallback());
// one for service onInit
++expectedVersion;
assertEquals(_state.getVersion(), expectedVersion);
_clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1", schemes));
// one for cluster onAdd
++expectedVersion;
assertEquals(_state.getVersion(), expectedVersion);
_uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));
// one for uri onAdd
++expectedVersion;
assertEquals(_state.getVersion(), expectedVersion);
_serviceRegistry.put("service-1", new ServiceProperties("service-1", "cluster-1", "/test", Arrays.asList("random")));
// one for service onAdd
++expectedVersion;
assertEquals(_state.getVersion(), expectedVersion);
// this shouldn't change the version
_state.getClient("cluster-1", uri);
assertEquals(_state.getVersion(), expectedVersion);
// this shouldn't change the version
_state.getStrategy("service-1", "http");
assertEquals(_state.getVersion(), expectedVersion);
}
use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class TestD2Config method verifyPartitionProperties.
public static void verifyPartitionProperties(String cluster, Map<String, Object> propertiesMap) throws IOException, URISyntaxException, PropertyStoreException {
final ClusterProperties clusterprops = getClusterProperties(_zkclient, cluster);
if (propertiesMap.get("partitionProperties") != null) {
@SuppressWarnings("unchecked") Map<String, Object> properties = (Map<String, Object>) propertiesMap.get("partitionProperties");
PartitionProperties.PartitionType partitionType = PartitionProperties.PartitionType.valueOf((String) properties.get("partitionType"));
switch(partitionType) {
case RANGE:
{
long keyRangeStart = ((Number) properties.get("keyRangeStart")).longValue();
long partitionSize = ((Number) properties.get("partitionSize")).longValue();
int partitionCount = ((Number) properties.get("partitionCount")).intValue();
String regex = (String) properties.get("partitionKeyRegex");
RangeBasedPartitionProperties rbp = (RangeBasedPartitionProperties) clusterprops.getPartitionProperties();
assertEquals(keyRangeStart, rbp.getKeyRangeStart());
assertEquals(partitionSize, rbp.getPartitionSize());
assertEquals(partitionCount, rbp.getPartitionCount());
assertEquals(regex, rbp.getPartitionKeyRegex());
}
break;
case HASH:
{
int partitionCount = ((Number) properties.get("partitionCount")).intValue();
String regex = (String) properties.get("partitionKeyRegex");
String algorithm = (String) properties.get("hashAlgorithm");
HashBasedPartitionProperties.HashAlgorithm hashAlgorithm = HashBasedPartitionProperties.HashAlgorithm.valueOf(algorithm.toUpperCase());
HashBasedPartitionProperties hbp = (HashBasedPartitionProperties) clusterprops.getPartitionProperties();
assertEquals(partitionCount, hbp.getPartitionCount());
assertEquals(regex, hbp.getPartitionKeyRegex());
assertEquals(hashAlgorithm, hbp.getHashAlgorithm());
}
break;
default:
break;
}
}
}
use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class TestD2Config method verifyClusterProperties.
@SuppressWarnings("unchecked")
public static void verifyClusterProperties(String cluster, Map<String, Object> propertiesMap) throws PropertyStoreException, IOException, URISyntaxException {
ClusterProperties clusterProperties = getClusterProperties(_zkclient, cluster);
if (propertiesMap.get(PropertyKeys.COLO_VARIANTS) != null) {
String coloVariantsString = clusterProperties.getProperties().get(PropertyKeys.COLO_VARIANTS);
List<String> coloVariants = Arrays.asList(coloVariantsString.split(D2Config.LIST_SEPARATOR));
List<String> expectedColoVariants = (List<String>) propertiesMap.get(PropertyKeys.COLO_VARIANTS);
Assert.assertTrue(coloVariants.containsAll(expectedColoVariants));
Assert.assertTrue(expectedColoVariants.containsAll(coloVariants));
}
if (propertiesMap.get(PropertyKeys.MASTER_COLO) != null) {
String masterColo = clusterProperties.getProperties().get(PropertyKeys.MASTER_COLO);
String expectedMasterColo = (String) propertiesMap.get(PropertyKeys.MASTER_COLO);
Assert.assertEquals(masterColo, expectedMasterColo);
}
if (propertiesMap.get(PropertyKeys.CLUSTER_VARIANTS) != null) {
String clusterVariantsString = clusterProperties.getProperties().get(PropertyKeys.CLUSTER_VARIANTS);
List<String> clusterVariants = Arrays.asList(clusterVariantsString.split(D2Config.LIST_SEPARATOR));
List<String> expectedClusterVariants = (List<String>) propertiesMap.get(PropertyKeys.CLUSTER_VARIANTS);
Assert.assertTrue(clusterVariants.containsAll(expectedClusterVariants));
Assert.assertTrue(expectedClusterVariants.containsAll(clusterVariants));
}
}
Aggregations