Search in sources :

Example 1 with AmazonElasticLoadBalancingAsync

use of com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync in project titus-control-plane by Netflix.

the class AwsLoadBalancerConnectorTest method validateExceptionsAreUnmodifiedWithMockClientTest.

@Test
public void validateExceptionsAreUnmodifiedWithMockClientTest() {
    Class defaultExceptionClass = TargetGroupAssociationLimitException.class;
    TestSubscriber testSubscriber = new TestSubscriber();
    AmazonElasticLoadBalancingAsync albClient = mock(AmazonElasticLoadBalancingAsync.class);
    when(albClient.describeTargetHealthAsync(any(), any())).thenThrow(defaultExceptionClass);
    awsLoadBalancerConnector = getAwsLoadBalancerConnector(albClient);
    awsLoadBalancerConnector.getLoadBalancer(targetGroupWithTargets).subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    List<Throwable> errors = testSubscriber.getOnErrorEvents();
    assertEquals(1, errors.size());
    Throwable throwable = errors.get(0);
    assertFalse(throwable instanceof LoadBalancerException);
    assertTrue(throwable instanceof TargetGroupAssociationLimitException);
}
Also used : LoadBalancerException(com.netflix.titus.api.loadbalancer.service.LoadBalancerException) TestSubscriber(rx.observers.TestSubscriber) AmazonElasticLoadBalancingAsync(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync) TargetGroupAssociationLimitException(com.amazonaws.services.elasticloadbalancingv2.model.TargetGroupAssociationLimitException) Test(org.junit.Test)

Example 2 with AmazonElasticLoadBalancingAsync

use of com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync in project titus-control-plane by Netflix.

the class AwsLoadBalancerConnectorTest method validateTargetGroupNotFoundExceptionIsTranslatedToRemovedState.

@Test
public void validateTargetGroupNotFoundExceptionIsTranslatedToRemovedState() {
    TestSubscriber testSubscriber = new TestSubscriber();
    AmazonElasticLoadBalancingAsync albClient = mock(AmazonElasticLoadBalancingAsync.class);
    when(albClient.describeTargetHealthAsync(any(), any())).thenThrow(TargetGroupNotFoundException.class);
    awsLoadBalancerConnector = getAwsLoadBalancerConnector(albClient);
    awsLoadBalancerConnector.getLoadBalancer(targetGroupWithTargets).subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    LoadBalancer loadBalancer = (LoadBalancer) testSubscriber.getOnNextEvents().get(0);
    assertEquals(targetGroupWithTargets, loadBalancer.getId());
    assertEquals(LoadBalancer.State.REMOVED, loadBalancer.getState());
}
Also used : TestSubscriber(rx.observers.TestSubscriber) AmazonElasticLoadBalancingAsync(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) Test(org.junit.Test)

Example 3 with AmazonElasticLoadBalancingAsync

use of com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync in project titus-control-plane by Netflix.

the class AwsLoadBalancerConnectorTest method setUp.

@Before
public void setUp() {
    ProfileCredentialsProvider credentialsProvider = new ProfileCredentialsProvider();
    AmazonElasticLoadBalancingAsync albClient = AmazonElasticLoadBalancingAsyncClientBuilder.standard().withCredentials(credentialsProvider).withRegion(REGION).build();
    awsLoadBalancerConnector = getAwsLoadBalancerConnector(albClient);
}
Also used : ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) AmazonElasticLoadBalancingAsync(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync) Before(org.junit.Before)

Example 4 with AmazonElasticLoadBalancingAsync

use of com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync in project titus-control-plane by Netflix.

the class AmazonClientProvider method getLoadBalancingClient.

public AmazonElasticLoadBalancingAsync getLoadBalancingClient(String accountId) {
    AmazonElasticLoadBalancingAsync client = loadBalancerClients.get(accountId);
    if (client == null) {
        synchronized (this) {
            client = loadBalancerClients.get(accountId);
            if (client == null) {
                String region = AwsRegionConfigurationUtil.resolveDataPlaneRegion(configuration);
                AWSCredentialsProvider credentialsProvider = getAwsCredentialsProvider(accountId);
                client = AmazonElasticLoadBalancingAsyncClientBuilder.standard().withCredentials(credentialsProvider).withRegion(region).withMetricsCollector(new SpectatorRequestMetricCollector(registry)).build();
                loadBalancerClients.put(accountId, client);
            }
        }
    }
    return client;
}
Also used : SpectatorRequestMetricCollector(com.netflix.spectator.aws.SpectatorRequestMetricCollector) AmazonElasticLoadBalancingAsync(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Aggregations

AmazonElasticLoadBalancingAsync (com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync)4 Test (org.junit.Test)2 TestSubscriber (rx.observers.TestSubscriber)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)1 TargetGroupAssociationLimitException (com.amazonaws.services.elasticloadbalancingv2.model.TargetGroupAssociationLimitException)1 SpectatorRequestMetricCollector (com.netflix.spectator.aws.SpectatorRequestMetricCollector)1 LoadBalancer (com.netflix.titus.api.connector.cloud.LoadBalancer)1 LoadBalancerException (com.netflix.titus.api.loadbalancer.service.LoadBalancerException)1 Before (org.junit.Before)1