use of com.linkedin.d2.jmx.D2ClientJmxManager in project rest.li by linkedin.
the class ZKFSLoadBalancerWithFacilitiesFactory method createLoadBalancerFactory.
private ZKFSLoadBalancer.TogglingLoadBalancerFactory createLoadBalancerFactory(D2ClientConfig config) {
final ZKFSTogglingLoadBalancerFactoryImpl.ComponentFactory loadBalancerComponentFactory;
if (config.componentFactory == null) {
loadBalancerComponentFactory = new ZKFSComponentFactory();
} else {
loadBalancerComponentFactory = config.componentFactory;
}
D2ClientJmxManager d2ClientJmxManager = new D2ClientJmxManager(config.d2JmxManagerPrefix, config.jmxManager);
return new ZKFSTogglingLoadBalancerFactoryImpl(loadBalancerComponentFactory, config.lbWaitTimeout, config.lbWaitUnit, config.basePath, config.fsBasePath, config.clientFactories, config.loadBalancerStrategyFactories, config.d2ServicePath, config.sslContext, config.sslParameters, config.isSSLEnabled, config.clientServicesConfig, config.useNewEphemeralStoreWatcher, config.partitionAccessorRegistry, config.enableSaveUriDataOnDisk, config.sslSessionValidatorFactory, d2ClientJmxManager, config.zookeeperReadWindowMs, config.deterministicSubsettingMetadataProvider);
}
use of com.linkedin.d2.jmx.D2ClientJmxManager in project rest.li by linkedin.
the class LastSeenBalancerWithFacilitiesFactory method create.
@Override
public LoadBalancerWithFacilities create(D2ClientConfig config) {
LOG.info("Creating D2 LoadBalancer based on LastSeenLoadBalancerWithFacilities");
D2ClientJmxManager d2ClientJmxManager = new D2ClientJmxManager(config.d2JmxManagerPrefix, config.jmxManager);
// init connection
ZKConnectionBuilder zkConnectionBuilder = new ZKConnectionBuilder(config.zkHosts);
zkConnectionBuilder.setShutdownAsynchronously(config.shutdownAsynchronously).setIsSymlinkAware(config.isSymlinkAware).setTimeout((int) config.zkSessionTimeoutInMs);
ZKPersistentConnection zkPersistentConnection;
if (config.zkConnectionToUseForLB != null) {
LOG.info("LastSeenLoadBalancer using shared connection to zookeeper");
zkPersistentConnection = config.zkConnectionToUseForLB;
} else {
LOG.info("LastSeenLoadBalancer using its own connection to zookeeper");
zkPersistentConnection = new ZKPersistentConnection(zkConnectionBuilder);
}
// init all the stores
LastSeenZKStore<ClusterProperties> lsClusterStore = getClusterPropertiesLastSeenZKStore(config, zkPersistentConnection, d2ClientJmxManager, config._executorService, config.zookeeperReadWindowMs);
PropertyEventBus<ClusterProperties> clusterBus = new PropertyEventBusImpl<>(config._executorService);
clusterBus.setPublisher(lsClusterStore);
LastSeenZKStore<ServiceProperties> lsServiceStore = getServicePropertiesLastSeenZKStore(config, zkPersistentConnection, d2ClientJmxManager, config._executorService, config.zookeeperReadWindowMs);
PropertyEventBus<ServiceProperties> serviceBus = new PropertyEventBusImpl<>(config._executorService);
serviceBus.setPublisher(lsServiceStore);
LastSeenZKStore<UriProperties> lsUrisStore = getUriPropertiesLastSeenZKStore(config, zkPersistentConnection, d2ClientJmxManager, config._executorService, config.zookeeperReadWindowMs);
PropertyEventBus<UriProperties> uriBus = new PropertyEventBusImpl<>(config._executorService);
uriBus.setPublisher(lsUrisStore);
// create the simple load balancer
SimpleLoadBalancerState state = new SimpleLoadBalancerState(config._executorService, uriBus, clusterBus, serviceBus, config.clientFactories, config.loadBalancerStrategyFactories, config.sslContext, config.sslParameters, config.isSSLEnabled, config.partitionAccessorRegistry, config.sslSessionValidatorFactory, config.deterministicSubsettingMetadataProvider);
d2ClientJmxManager.setSimpleLoadBalancerState(state);
SimpleLoadBalancer simpleLoadBalancer = new SimpleLoadBalancer(state, config.lbWaitTimeout, config.lbWaitUnit, config._executorService);
d2ClientJmxManager.setSimpleLoadBalancer(simpleLoadBalancer);
// add facilities
LastSeenLoadBalancerWithFacilities lastSeenLoadBalancer = new LastSeenLoadBalancerWithFacilities(simpleLoadBalancer, config.basePath, config.d2ServicePath, zkPersistentConnection, lsClusterStore, lsServiceStore, lsUrisStore);
LoadBalancerWithFacilities balancer = lastSeenLoadBalancer;
if (config.warmUp) {
balancer = new WarmUpLoadBalancer(balancer, lastSeenLoadBalancer, config.startUpExecutorService, config.fsBasePath, config.d2ServicePath, config.downstreamServicesFetcher, config.warmUpTimeoutSeconds, config.warmUpConcurrentRequests);
}
return balancer;
}
use of com.linkedin.d2.jmx.D2ClientJmxManager in project rest.li by linkedin.
the class D2LoadBalancerJmxTest method testD2ClientJmxManagerRegisteringStrategies.
/**
* NOTE: when you find yourself modifying this test, make sure you are modifying it in a BACKWARD-COMPATIBLE way.
*/
@Test
private void testD2ClientJmxManagerRegisteringStrategies() {
JmxManager mockJmxManager = mock(JmxManager.class);
D2ClientJmxManager d2ClientJmxManager = new D2ClientJmxManager(DUMMY_STRING, mockJmxManager);
SimpleLoadBalancerState simpleLoadBalancerState = mock(SimpleLoadBalancerState.class);
d2ClientJmxManager.setSimpleLoadBalancerState(simpleLoadBalancerState);
ArgumentCaptor<SimpleLoadBalancerState.SimpleLoadBalancerStateListener> captor = ArgumentCaptor.forClass(SimpleLoadBalancerState.SimpleLoadBalancerStateListener.class);
// check it is registering the strategy correctly
Mockito.verify(simpleLoadBalancerState).register(captor.capture());
captor.getValue().onStrategyAdded(DUMMY_STRING, DUMMY_STRING, mock(LoadBalancerStrategy.class));
verify(mockJmxManager, times(1)).registerLoadBalancerStrategy(anyString(), any());
verify(mockJmxManager, times(0)).unregister(anyString());
// check it is unregistering correctly
captor.getValue().onStrategyRemoved(DUMMY_STRING, DUMMY_STRING, mock(LoadBalancerStrategy.class));
verify(mockJmxManager, times(1)).registerLoadBalancerStrategy(anyString(), any());
verify(mockJmxManager, times(1)).unregister(anyString());
// this should not trigger anything in the current version
captor.getValue().onClientAdded(DUMMY_STRING, mock(TrackerClient.class));
captor.getValue().onClientRemoved(DUMMY_STRING, mock(TrackerClient.class));
verify(mockJmxManager, times(1)).registerLoadBalancerStrategy(anyString(), any());
verify(mockJmxManager, times(1)).unregister(anyString());
}
use of com.linkedin.d2.jmx.D2ClientJmxManager in project rest.li by linkedin.
the class LastSeenBalancerWithFacilitiesFactory method getClusterPropertiesLastSeenZKStore.
private LastSeenZKStore<ClusterProperties> getClusterPropertiesLastSeenZKStore(D2ClientConfig config, ZKPersistentConnection zkPersistentConnection, D2ClientJmxManager d2ClientJmxManager, ScheduledExecutorService executorService, int zookeeperReadWindowMs) {
ZooKeeperPermanentStoreBuilder<ClusterProperties> zkClusterStoreBuilder = new ZooKeeperPermanentStoreBuilder<ClusterProperties>().setSerializer(new ClusterPropertiesJsonSerializer()).setPath(ZKFSUtil.clusterPath(config.basePath)).setExecutorService(executorService).setZookeeperReadWindowMs(zookeeperReadWindowMs).addOnBuildListener(d2ClientJmxManager::setZkClusterRegistry);
FileStore<ClusterProperties> fileStore = new FileStore<>(FileSystemDirectory.getClusterDirectory(config.fsBasePath), new ClusterPropertiesJsonSerializer());
d2ClientJmxManager.setFsClusterStore(fileStore);
return new LastSeenZKStore<>(fileStore, zkClusterStoreBuilder, zkPersistentConnection, config._executorService, config.warmUpTimeoutSeconds, config.warmUpConcurrentRequests);
}
use of com.linkedin.d2.jmx.D2ClientJmxManager in project rest.li by linkedin.
the class LastSeenBalancerWithFacilitiesFactory method getUriPropertiesLastSeenZKStore.
private LastSeenZKStore<UriProperties> getUriPropertiesLastSeenZKStore(D2ClientConfig config, ZKPersistentConnection zkPersistentConnection, D2ClientJmxManager d2ClientJmxManager, ScheduledExecutorService executorService, int zookeeperReadWindowMs) {
ZooKeeperEphemeralStoreBuilder<UriProperties> zkUrisStoreBuilder = new ZooKeeperEphemeralStoreBuilder<UriProperties>().setSerializer(new UriPropertiesJsonSerializer()).setPath(ZKFSUtil.uriPath(config.basePath)).setMerger(new UriPropertiesMerger()).setUseNewWatcher(config.useNewEphemeralStoreWatcher).setExecutorService(executorService).setZookeeperReadWindowMs(zookeeperReadWindowMs).addOnBuildListener(d2ClientJmxManager::setZkUriRegistry);
FileStore<UriProperties> fileStore = new FileStore<>(config.fsBasePath + File.separator + ZKFSUtil.URI_PATH, new UriPropertiesJsonSerializer());
d2ClientJmxManager.setFsUriStore(fileStore);
if (config.enableSaveUriDataOnDisk) {
zkUrisStoreBuilder.setBackupStoreFilePath(config.fsBasePath);
}
return new LastSeenZKStore<>(fileStore, zkUrisStoreBuilder, zkPersistentConnection, config._executorService, config.warmUpTimeoutSeconds, config.warmUpConcurrentRequests);
}
Aggregations