use of com.linkedin.d2.discovery.stores.PropertyStoreException 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;
}
use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class ZooKeeperAnnouncerJmx method markUp.
@Override
public void markUp() throws PropertyStoreException {
FutureCallback<None> callback = new FutureCallback<None>();
_announcer.markUp(callback);
try {
callback.get(10, TimeUnit.SECONDS);
} catch (Exception e) {
throw new PropertyStoreException(e);
}
}
use of com.linkedin.d2.discovery.stores.PropertyStoreException 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.discovery.stores.PropertyStoreException 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.discovery.stores.PropertyStoreException in project rest.li by linkedin.
the class LoadBalancerClientCli method startStore.
private static <T> void startStore(PropertyStore<T> store) throws PropertyStoreException {
try {
FutureCallback<None> callback = new FutureCallback<None>();
store.start(callback);
callback.get(30, TimeUnit.SECONDS);
} catch (Exception e) {
throw new PropertyStoreException("Failed to start store", e);
}
}
Aggregations