Search in sources :

Example 1 with LoadBalancer

use of com.netflix.titus.api.connector.cloud.LoadBalancer 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 2 with LoadBalancer

use of com.netflix.titus.api.connector.cloud.LoadBalancer in project titus-control-plane by Netflix.

the class AwsLoadBalancerConnector method getLoadBalancer.

@Override
public Single<LoadBalancer> getLoadBalancer(String loadBalancerId) {
    final DescribeTargetHealthRequest request = new DescribeTargetHealthRequest().withTargetGroupArn(loadBalancerId);
    long startTime = registry.clock().wallTime();
    Single<DescribeTargetHealthResult> asyncResult = AwsObservableExt.asyncActionSingle(factory -> getClient(loadBalancerId).describeTargetHealthAsync(request, factory.handler()));
    return asyncResult.observeOn(scheduler).map(result -> {
        connectorMetrics.success(AwsLoadBalancerConnectorMetrics.AwsLoadBalancerMethods.DescribeTargetHealth, startTime);
        Set<String> ips = result.getTargetHealthDescriptions().stream().map(description -> description.getTarget().getId()).collect(Collectors.toSet());
        return new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, ips);
    }).onErrorResumeNext(throwable -> {
        connectorMetrics.failure(AwsLoadBalancerConnectorMetrics.AwsLoadBalancerMethods.DescribeTargetHealth, throwable, startTime);
        if (throwable instanceof TargetGroupNotFoundException) {
            return Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.REMOVED, Collections.emptySet()));
        }
        return Single.error(throwable);
    });
}
Also used : DescribeTargetHealthRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) Completable(rx.Completable) LoadBalancerConnector(com.netflix.titus.api.connector.cloud.LoadBalancerConnector) DeregisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DeregisterTargetsRequest) RegisterTargetsRequest(com.amazonaws.services.elasticloadbalancingv2.model.RegisterTargetsRequest) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) ProxyType(com.netflix.titus.common.util.guice.ProxyType) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) Observable(rx.Observable) Inject(javax.inject.Inject) TargetGroupNotFoundException(com.amazonaws.services.elasticloadbalancingv2.model.TargetGroupNotFoundException) Single(rx.Single) DescribeTargetGroupsRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsRequest) CloudConnectorException(com.netflix.titus.api.connector.cloud.CloudConnectorException) Schedulers(rx.schedulers.Schedulers) AmazonElasticLoadBalancingAsync(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingAsync) TargetDescription(com.amazonaws.services.elasticloadbalancingv2.model.TargetDescription) DescribeTargetGroupsResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetGroupsResult) Logger(org.slf4j.Logger) DescribeTargetHealthResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult) AmazonClientProvider(com.netflix.titus.ext.aws.AmazonClientProvider) Set(java.util.Set) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) AwsObservableExt(com.netflix.titus.ext.aws.AwsObservableExt) Scheduler(rx.Scheduler) Collectors(java.util.stream.Collectors) Registry(com.netflix.spectator.api.Registry) ProxyConfiguration(com.netflix.titus.common.util.guice.annotation.ProxyConfiguration) Arn(com.amazonaws.arn.Arn) Collections(java.util.Collections) DescribeTargetHealthRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthRequest) Set(java.util.Set) TargetGroupNotFoundException(com.amazonaws.services.elasticloadbalancingv2.model.TargetGroupNotFoundException) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) DescribeTargetHealthResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeTargetHealthResult)

Example 3 with LoadBalancer

use of com.netflix.titus.api.connector.cloud.LoadBalancer in project titus-control-plane by Netflix.

the class DefaultLoadBalancerReconcilerTest method deregisterExtraTargetsPreviouslyRegisteredByUs.

@Test(timeout = TEST_TIMEOUT_MS)
public void deregisterExtraTargetsPreviouslyRegisteredByUs() {
    List<Task> tasks = LoadBalancerTests.buildTasksStarted(3, jobId);
    JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, loadBalancerId);
    JobLoadBalancerState association = new JobLoadBalancerState(jobLoadBalancer, State.ASSOCIATED);
    when(v3JobOperations.getTasks(jobId)).thenReturn(tasks);
    reset(connector);
    when(connector.getLoadBalancer(loadBalancerId)).thenReturn(Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, CollectionsExt.asSet("1.1.1.1", "2.2.2.2", "3.3.3.3", "4.4.4.4", "5.5.5.5", "6.6.6.6"))));
    store.addOrUpdateLoadBalancer(association.getJobLoadBalancer(), association.getState()).await();
    store.addOrUpdateTargets(// 3 running tasks were previously registered by us and are in the load balancer
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(0).getId(), "1.1.1.1"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(1).getId(), "2.2.2.2"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(2).getId(), "3.3.3.3"), LoadBalancerTarget.State.REGISTERED), // Next two ips were previously registered by us, but their tasks do not exist anymore
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "some-dead-task", "4.4.4.4"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "another-dead-task", "5.5.5.5"), LoadBalancerTarget.State.DEREGISTERED)).block();
    testScheduler.triggerActions();
    subscriber.assertNotCompleted().assertNoValues();
    awaitReconciliationRuns(1);
    subscriber.assertNotCompleted().assertValueCount(2);
    subscriber.getOnNextEvents().forEach(update -> {
        assertThat(update.getState()).isEqualTo(LoadBalancerTarget.State.DEREGISTERED);
        assertThat(update.getPriority()).isEqualTo(Priority.LOW);
        assertThat(update.getLoadBalancerId()).isEqualTo(loadBalancerId);
        assertThat(update.getIdentifier().getTaskId()).isIn("some-dead-task", "another-dead-task");
        assertThat(update.getIdentifier().getIpAddress()).isIn("4.4.4.4", "5.5.5.5");
    });
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) Test(org.junit.Test)

Example 4 with LoadBalancer

use of com.netflix.titus.api.connector.cloud.LoadBalancer in project titus-control-plane by Netflix.

the class DefaultLoadBalancerReconcilerTest method deregisteredTargetsAreCleanedUp.

@Test(timeout = TEST_TIMEOUT_MS)
public void deregisteredTargetsAreCleanedUp() {
    List<Task> tasks = LoadBalancerTests.buildTasksStarted(1, jobId);
    JobLoadBalancer jobLoadBalancer = new JobLoadBalancer(jobId, loadBalancerId);
    JobLoadBalancerState association = new JobLoadBalancerState(jobLoadBalancer, State.ASSOCIATED);
    when(v3JobOperations.getTasks(jobId)).thenReturn(tasks);
    reset(connector);
    when(connector.getLoadBalancer(loadBalancerId)).thenReturn(Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, CollectionsExt.asSet("1.1.1.1", "10.10.10.10"))));
    store.addOrUpdateLoadBalancer(association.getJobLoadBalancer(), association.getState()).await();
    store.addOrUpdateTargets(// running tasks was previously registered by us and are in the load balancer
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(0).getId(), "1.1.1.1"), LoadBalancerTarget.State.REGISTERED), // Next three ips were previously registered by us, but their tasks do not exist anymore and are not in the load balancer anymore
    new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-inconsistent", "2.2.2.2"), LoadBalancerTarget.State.REGISTERED), new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-not-in-lb", "3.3.3.3"), LoadBalancerTarget.State.DEREGISTERED)).block();
    // no reconciliation ran yet
    testScheduler.triggerActions();
    subscriber.assertNotCompleted().assertNoValues();
    assertThat(store.getLoadBalancerTargets(loadBalancerId).collectList().block()).hasSize(3);
    // first pass, the one stored as DEREGISTERED is cleaned up, the other in an inconsistent state is fixed
    awaitReconciliationRuns(1);
    subscriber.assertNotCompleted().assertValueCount(1);
    TargetStateBatchable inconsistencyFix = subscriber.getOnNextEvents().get(0);
    assertThat(inconsistencyFix.getState()).isEqualTo(LoadBalancerTarget.State.DEREGISTERED);
    assertThat(inconsistencyFix.getLoadBalancerId()).isEqualTo(loadBalancerId);
    assertThat(inconsistencyFix.getIpAddress()).isEqualTo("2.2.2.2");
    List<LoadBalancerTargetState> storedTargets = store.getLoadBalancerTargets(loadBalancerId).collectList().block();
    assertThat(storedTargets).hasSize(2);
    assertThat(storedTargets).doesNotContain(new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-not-in-lb", "3.3.3.3"), LoadBalancerTarget.State.DEREGISTERED));
    // update with fix not applied yet, keep trying
    awaitReconciliationRuns(1);
    subscriber.assertNotCompleted().assertValueCount(2);
    TargetStateBatchable update2 = subscriber.getOnNextEvents().get(0);
    assertThat(update2.getState()).isEqualTo(LoadBalancerTarget.State.DEREGISTERED);
    assertThat(update2.getLoadBalancerId()).isEqualTo(loadBalancerId);
    assertThat(update2.getIpAddress()).isEqualTo("2.2.2.2");
    assertThat(store.getLoadBalancerTargets(loadBalancerId).collectList().block()).hasSize(2);
    // simulate the update with the fix above being applied
    store.addOrUpdateTargets(new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, "target-inconsistent", "2.2.2.2"), LoadBalancerTarget.State.DEREGISTERED)).block();
    // finally, corrected record is now cleaned up
    awaitReconciliationRuns(1);
    // no changes needed
    subscriber.assertNotCompleted().assertValueCount(2);
    assertThat(store.getLoadBalancerTargets(loadBalancerId).collectList().block()).containsOnly(new LoadBalancerTargetState(new LoadBalancerTarget(loadBalancerId, tasks.get(0).getId(), "1.1.1.1"), LoadBalancerTarget.State.REGISTERED));
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) Test(org.junit.Test)

Example 5 with LoadBalancer

use of com.netflix.titus.api.connector.cloud.LoadBalancer in project titus-control-plane by Netflix.

the class DefaultLoadBalancerReconcilerTest method setUp.

@Before
public void setUp() throws Exception {
    loadBalancerId = UUID.randomUUID().toString();
    jobId = UUID.randomUUID().toString();
    delayMs = 60_000L;
    /* 1 min */
    store = new InMemoryLoadBalancerStore();
    connector = mock(LoadBalancerConnector.class);
    when(connector.getLoadBalancer(loadBalancerId)).thenReturn(Single.just(new LoadBalancer(loadBalancerId, LoadBalancer.State.ACTIVE, Collections.emptySet())));
    v3JobOperations = mock(V3JobOperations.class);
    testScheduler = Schedulers.test();
    reconciliationCount = new AtomicLong(0);
    reconciler = new DefaultLoadBalancerReconciler(mockConfigWithDelay(delayMs), store, connector, new LoadBalancerJobOperations(v3JobOperations), () -> reconciliationCount.incrementAndGet(), new NoopRegistry(), testScheduler);
    subscriber = reconciler.events().test();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LoadBalancerConnector(com.netflix.titus.api.connector.cloud.LoadBalancerConnector) InMemoryLoadBalancerStore(com.netflix.titus.runtime.store.v3.memory.InMemoryLoadBalancerStore) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) NoopRegistry(com.netflix.spectator.api.NoopRegistry) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) LoadBalancer(com.netflix.titus.api.connector.cloud.LoadBalancer) Before(org.junit.Before)

Aggregations

LoadBalancer (com.netflix.titus.api.connector.cloud.LoadBalancer)11 JobLoadBalancer (com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)8 Test (org.junit.Test)8 LoadBalancerTarget (com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget)7 LoadBalancerTargetState (com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState)7 LoadBalancerConnector (com.netflix.titus.api.connector.cloud.LoadBalancerConnector)5 JobLoadBalancerState (com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState)5 Task (com.netflix.titus.api.jobmanager.model.job.Task)4 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)4 Collections (java.util.Collections)4 Collectors (java.util.stream.Collectors)4 Completable (rx.Completable)4 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)3 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)3 LoadBalancerStore (com.netflix.titus.api.loadbalancer.store.LoadBalancerStore)3 InMemoryLoadBalancerStore (com.netflix.titus.runtime.store.v3.memory.InMemoryLoadBalancerStore)3 List (java.util.List)3 Set (java.util.Set)3 TimeUnit (java.util.concurrent.TimeUnit)3 Before (org.junit.Before)3