use of com.linkedin.d2.balancer.simple.ClusterInfoItem in project rest.li by linkedin.
the class ClusterAwareTransportClient method getValidator.
/**
* Since the validator has validationStrings build in, the only time it needs to update is when the validationStrings
* change. So we always use the cached validator unless the clusterProperties change. This avoid repeatedly creating
* new sslSessionValidator object.
*/
private SslSessionValidator getValidator() {
ClusterInfoItem clusterInfoItem = _clusterInfo.get(_clusterName);
if (clusterInfoItem == null || clusterInfoItem.getClusterPropertiesItem() == null) {
return null;
}
long cachedVersion = _cachedClusterVersion.get();
long currentVersion = clusterInfoItem.getClusterPropertiesItem().getVersion();
if (currentVersion > cachedVersion && _cachedClusterVersion.updateAndGet(prev -> clusterInfoItem.getClusterPropertiesItem().getVersion()) > cachedVersion) {
ClusterProperties clusterProperties = clusterInfoItem.getClusterPropertiesItem().getProperty();
if (clusterProperties != null) {
_cachedSslSessionValidator = _sslSessionValidatorFactory.getSessionValidator(clusterProperties.getSslSessionValidationStrings());
}
}
return _cachedSslSessionValidator;
}
use of com.linkedin.d2.balancer.simple.ClusterInfoItem in project rest.li by linkedin.
the class D2ClientJmxManager method setSimpleLoadBalancerState.
public void setSimpleLoadBalancerState(SimpleLoadBalancerState state) {
_jmxManager.registerLoadBalancerState(_prefix + "-LoadBalancerState", state);
state.register(new SimpleLoadBalancerStateListener() {
@Override
public void onStrategyAdded(String serviceName, String scheme, LoadBalancerStrategy strategy) {
_jmxManager.registerLoadBalancerStrategy(getLoadBalancerStrategyJmxName(serviceName, scheme), strategy);
}
@Override
public void onStrategyRemoved(String serviceName, String scheme, LoadBalancerStrategy strategy) {
_jmxManager.unregister(getLoadBalancerStrategyJmxName(serviceName, scheme));
}
@Override
public void onClientAdded(String clusterName, TrackerClient client) {
// We currently think we can make this no-op as the info provided is not helpful
// _jmxManager.checkReg(new DegraderControl((DegraderImpl) client.getDegrader(DefaultPartitionAccessor.DEFAULT_PARTITION_ID)),
// _prefix + "-" + clusterName + "-" + client.getUri().toString().replace("://", "-") + "-TrackerClient-Degrader");
}
@Override
public void onClientRemoved(String clusterName, TrackerClient client) {
// We currently think we can make this no-op as the info provided is not helpful
// _jmxManager.unregister(_prefix + "-" + clusterName + "-" + client.getUri().toString().replace("://", "-") + "-TrackerClient-Degrader");
}
@Override
public void onClusterInfoUpdate(ClusterInfoItem clusterInfoItem) {
_jmxManager.registerClusterInfo(getClusterInfoJmxName(clusterInfoItem.getClusterPropertiesItem().getProperty().getClusterName()), clusterInfoItem);
}
@Override
public void onClusterInfoRemoval(ClusterInfoItem clusterInfoItem) {
_jmxManager.unregister(getClusterInfoJmxName(clusterInfoItem.getClusterPropertiesItem().getProperty().getClusterName()));
}
@Override
public void onServicePropertiesUpdate(LoadBalancerStateItem<ServiceProperties> serviceProperties) {
_jmxManager.registerServiceProperties(getServicePropertiesJmxName(serviceProperties.getProperty().getServiceName()), serviceProperties);
}
@Override
public void onServicePropertiesRemoval(LoadBalancerStateItem<ServiceProperties> serviceProperties) {
_jmxManager.unregister(getServicePropertiesJmxName(serviceProperties.getProperty().getServiceName()));
}
private String getClusterInfoJmxName(String clusterName) {
return String.format("%s-ClusterInfo", clusterName);
}
private String getServicePropertiesJmxName(String serviceName) {
return String.format("%s-ServiceProperties", serviceName);
}
private String getLoadBalancerStrategyJmxName(String serviceName, String scheme) {
return serviceName + "-" + scheme + "-LoadBalancerStrategy";
}
});
}
use of com.linkedin.d2.balancer.simple.ClusterInfoItem in project rest.li by linkedin.
the class D2ClientJmxManagerTest method setUp.
@BeforeMethod
public void setUp() {
MockitoAnnotations.initMocks(this);
AtomicLong version = new AtomicLong(0);
when(_simpleLoadBalancerState.getVersionAccess()).thenReturn(version);
_clusterInfoItem = new ClusterInfoItem(_simpleLoadBalancerState, new ClusterProperties("C_Foo"), new PartitionAccessor() {
@Override
public int getMaxPartitionId() {
return 0;
}
@Override
public int getPartitionId(URI uri) {
return 0;
}
}, CanaryDistributionProvider.Distribution.CANARY);
_servicePropertiesLBState = new LoadBalancerStateItem<>(new ServiceProperties("S_Foo", "Bar", "/", Collections.singletonList("Random")), 0, 0, CanaryDistributionProvider.Distribution.CANARY);
_d2ClientJmxManager = new D2ClientJmxManager("Foo", _jmxManager);
Mockito.doReturn(_jmxManager).when(_jmxManager).unregister(_unregisteredObjectNameCaptor.capture());
Mockito.doReturn(_jmxManager).when(_jmxManager).registerLoadBalancerState(_simpleLoadBalancerStateNameCaptor.capture(), _simpleLoadBalancerStateCaptor.capture());
Mockito.doReturn(_jmxManager).when(_jmxManager).registerClusterInfo(_registerObjectNameCaptor.capture(), _clusterInfoArgumentCaptor.capture());
Mockito.doReturn(_jmxManager).when(_jmxManager).registerServiceProperties(_registerObjectNameCaptor.capture(), _servicePropertiesArgumentCaptor.capture());
Mockito.doNothing().when(_simpleLoadBalancerState).register(_simpleLoadBalancerStateListenerCaptor.capture());
}
use of com.linkedin.d2.balancer.simple.ClusterInfoItem in project rest.li by linkedin.
the class JmxManagerTest method resetJmxObjects.
private void resetJmxObjects() {
_clusterInfoItem = new ClusterInfoItem(_mockedSimpleBalancerState, new ClusterProperties("Foo"), new PartitionAccessor() {
@Override
public int getMaxPartitionId() {
return 0;
}
@Override
public int getPartitionId(URI uri) {
return 0;
}
}, CanaryDistributionProvider.Distribution.CANARY);
_clusterInfoJmx = new ClusterInfoJmx(_clusterInfoItem);
_servicePropertiesLBState = new LoadBalancerStateItem<>(new ServiceProperties("Foo", "Bar", "/", Collections.singletonList("Random")), 0, 0, CanaryDistributionProvider.Distribution.CANARY);
_servicePropertiesJmx = new ServicePropertiesJmx(_servicePropertiesLBState);
}
Aggregations