Search in sources :

Example 6 with ClusterInfoItem

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;
}
Also used : ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties)

Example 7 with ClusterInfoItem

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";
        }
    });
}
Also used : ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) SimpleLoadBalancerStateListener(com.linkedin.d2.balancer.simple.SimpleLoadBalancerState.SimpleLoadBalancerStateListener) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) ClusterInfoItem(com.linkedin.d2.balancer.simple.ClusterInfoItem)

Example 8 with ClusterInfoItem

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());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) PartitionAccessor(com.linkedin.d2.balancer.util.partitions.PartitionAccessor) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) ClusterInfoItem(com.linkedin.d2.balancer.simple.ClusterInfoItem) URI(java.net.URI) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with ClusterInfoItem

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);
}
Also used : PartitionAccessor(com.linkedin.d2.balancer.util.partitions.PartitionAccessor) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) ClusterInfoItem(com.linkedin.d2.balancer.simple.ClusterInfoItem) URI(java.net.URI)

Aggregations

ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)6 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)5 ClusterInfoItem (com.linkedin.d2.balancer.simple.ClusterInfoItem)5 PartitionAccessor (com.linkedin.d2.balancer.util.partitions.PartitionAccessor)5 URI (java.net.URI)5 Test (org.testng.annotations.Test)4 LoadBalancerStateItem (com.linkedin.d2.balancer.LoadBalancerStateItem)3 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)2 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)2 Callback (com.linkedin.common.callback.Callback)1 SimpleCallback (com.linkedin.common.callback.SimpleCallback)1 None (com.linkedin.common.util.None)1 LoadBalancerClusterListener (com.linkedin.d2.balancer.LoadBalancerClusterListener)1 SimpleLoadBalancerStateListener (com.linkedin.d2.balancer.simple.SimpleLoadBalancerState.SimpleLoadBalancerStateListener)1 DegraderLoadBalancerTest (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)1 RelativeLoadBalancerStrategy (com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy)1 DefaultPartitionAccessor (com.linkedin.d2.balancer.util.partitions.DefaultPartitionAccessor)1 PartitionAccessException (com.linkedin.d2.balancer.util.partitions.PartitionAccessException)1 PropertyEvent (com.linkedin.d2.discovery.event.PropertyEventThread.PropertyEvent)1 PropertyEventShutdownCallback (com.linkedin.d2.discovery.event.PropertyEventThread.PropertyEventShutdownCallback)1