Search in sources :

Example 6 with JobLoadBalancer

use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.

the class CellWithLoadBalancers method addLoadBalancer.

@Override
public void addLoadBalancer(AddLoadBalancerRequest request, StreamObserver<Empty> responseObserver) {
    jobLoadBalancerList.add(new JobLoadBalancer(request.getJobId(), request.getLoadBalancerId().getId()));
    responseObserver.onNext(Empty.getDefaultInstance());
    responseObserver.onCompleted();
}
Also used : JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)

Example 7 with JobLoadBalancer

use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.

the class CassandraLoadBalancerStoreTest method testParallelUpdates.

@Test
public void testParallelUpdates() throws Exception {
    Map<JobLoadBalancer, JobLoadBalancer.State> testData = generateTestData(100, 20, 1).getAssociations();
    CassandraLoadBalancerStore store = getInitdStore();
    // Create an thread pool to generate concurrent updates
    ExecutorService executorService = Executors.newFixedThreadPool(10);
    testData.forEach((jobLoadBalancer, state) -> executorService.execute(() -> store.addOrUpdateLoadBalancer(jobLoadBalancer, state).await(TIMEOUT_MS, TimeUnit.MILLISECONDS)));
    // Wait till all jobs were submitted
    executorService.shutdown();
    assertThat(executorService.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
    // Verify data is consistent
    checkDataSetExists(store, testData);
}
Also used : JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) ExecutorService(java.util.concurrent.ExecutorService) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 8 with JobLoadBalancer

use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.

the class CassandraLoadBalancerStoreTest method testAssociationStateIsCaseInsensitive.

@Test
public void testAssociationStateIsCaseInsensitive() throws Exception {
    Session session = cassandraCQLUnit.getSession();
    PreparedStatement insertStmt = session.prepare("INSERT INTO load_balancer_jobs(job_id, load_balancer_id, state) VALUES(?, ?, ?);");
    ResultSet rs1 = session.execute(insertStmt.bind("job-1", "lb-1", "Associated"));
    assertThat(rs1.isExhausted()).isTrue();
    assertThat(rs1.wasApplied()).isTrue();
    ResultSet rs2 = session.execute(insertStmt.bind("job-2", "lb-2", "Dissociated"));
    assertThat(rs2.isExhausted()).isTrue();
    assertThat(rs2.wasApplied()).isTrue();
    ResultSet rs3 = session.execute(insertStmt.bind("job-3", "lb-3", "aSsOcIaTeD"));
    assertThat(rs3.isExhausted()).isTrue();
    assertThat(rs3.wasApplied()).isTrue();
    CassandraLoadBalancerStore store = getInitdStore();
    assertThat(store.getAssociations()).containsExactlyInAnyOrder(new JobLoadBalancerState(new JobLoadBalancer("job-1", "lb-1"), ASSOCIATED), new JobLoadBalancerState(new JobLoadBalancer("job-2", "lb-2"), DISSOCIATED), new JobLoadBalancerState(new JobLoadBalancer("job-3", "lb-3"), ASSOCIATED));
}
Also used : JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Session(com.datastax.driver.core.Session) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 9 with JobLoadBalancer

use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.

the class CassandraLoadBalancerStore method buildLoadBalancerStatePairFromRow.

private static Pair<JobLoadBalancer, JobLoadBalancer.State> buildLoadBalancerStatePairFromRow(Row row) {
    String jobId = row.getString(COLUMN_JOB_ID);
    String loadBalancerId = row.getString(COLUMN_LOAD_BALANCER);
    String state = row.getString(COLUMN_STATE);
    JobLoadBalancer.State parsedState;
    if (state == null) {
        logger.warn("Unexpected null state for association {}:{}", jobId, loadBalancerId);
        parsedState = JobLoadBalancer.State.DISSOCIATED;
    } else {
        parsedState = JobLoadBalancer.State.valueOf(state.toUpperCase());
    }
    return Pair.of(new JobLoadBalancer(jobId, loadBalancerId), parsedState);
}
Also used : JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)

Example 10 with JobLoadBalancer

use of com.netflix.titus.api.loadbalancer.model.JobLoadBalancer in project titus-control-plane by Netflix.

the class CassandraLoadBalancerStore method removeLoadBalancer.

/**
 * Removes the persisted Job/load balancer and state and removes in-memory state.
 *
 * @param jobLoadBalancer
 * @return
 */
@Override
public Completable removeLoadBalancer(JobLoadBalancer jobLoadBalancer) {
    logger.debug("Removing load balancer {}", jobLoadBalancer);
    BoundStatement stmt = deleteAssociation.bind(jobLoadBalancer.getJobId(), jobLoadBalancer.getLoadBalancerId());
    return storeHelper.execute(stmt).map(rs -> {
        loadBalancerStateMap.remove(jobLoadBalancer);
        removeJobLoadBalancerAssociation(jobLoadBalancer);
        return jobLoadBalancer;
    }).toCompletable();
}
Also used : Completable(rx.Completable) Arrays(java.util.Arrays) EntitySanitizer(com.netflix.titus.common.model.sanitizer.EntitySanitizer) SortedSet(java.util.SortedSet) LoadBalancerStoreException(com.netflix.titus.api.loadbalancer.store.LoadBalancerStoreException) JobLoadBalancerState(com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState) LoadBalancerTargetState(com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState) Row(com.datastax.driver.core.Row) LoggerFactory(org.slf4j.LoggerFactory) QueryBuilder.bindMarker(com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker) Singleton(javax.inject.Singleton) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) ReactorExt(com.netflix.titus.common.util.rx.ReactorExt) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) Observable(rx.Observable) Inject(javax.inject.Inject) PreparedStatement(com.datastax.driver.core.PreparedStatement) ResultSet(com.datastax.driver.core.ResultSet) BoundStatement(com.datastax.driver.core.BoundStatement) Pair(com.netflix.titus.common.util.tuple.Pair) Duration(java.time.Duration) Map(java.util.Map) Session(com.datastax.driver.core.Session) QueryBuilder.insertInto(com.datastax.driver.core.querybuilder.QueryBuilder.insertInto) Schedulers(rx.schedulers.Schedulers) Named(javax.inject.Named) LOAD_BALANCER_SANITIZER(com.netflix.titus.api.loadbalancer.model.sanitizer.LoadBalancerSanitizerBuilder.LOAD_BALANCER_SANITIZER) LoadBalancerTarget(com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget) LoadBalancerStore(com.netflix.titus.api.loadbalancer.store.LoadBalancerStore) Logger(org.slf4j.Logger) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) QueryBuilder.eq(com.datastax.driver.core.querybuilder.QueryBuilder.eq) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Mono(reactor.core.publisher.Mono) QueryBuilder.delete(com.datastax.driver.core.querybuilder.QueryBuilder.delete) Collectors(java.util.stream.Collectors) Activator(com.netflix.titus.common.util.guice.annotation.Activator) Flux(reactor.core.publisher.Flux) List(java.util.List) QueryBuilder.select(com.datastax.driver.core.querybuilder.QueryBuilder.select) Collections(java.util.Collections) BoundStatement(com.datastax.driver.core.BoundStatement)

Aggregations

JobLoadBalancer (com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)36 Test (org.junit.Test)27 JobLoadBalancerState (com.netflix.titus.api.loadbalancer.model.JobLoadBalancerState)14 Task (com.netflix.titus.api.jobmanager.model.job.Task)10 LoadBalancerTarget (com.netflix.titus.api.loadbalancer.model.LoadBalancerTarget)10 LoadBalancerTargetState (com.netflix.titus.api.loadbalancer.model.LoadBalancerTargetState)10 LoadBalancer (com.netflix.titus.api.connector.cloud.LoadBalancer)7 List (java.util.List)6 GetJobLoadBalancersResult (com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult)5 Collections (java.util.Collections)5 Collectors (java.util.stream.Collectors)5 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)4 LoadBalancerStore (com.netflix.titus.api.loadbalancer.store.LoadBalancerStore)4 GetAllLoadBalancersResult (com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult)4 Completable (rx.Completable)4 Schedulers (rx.schedulers.Schedulers)4 LoadBalancerConnector (com.netflix.titus.api.connector.cloud.LoadBalancerConnector)3 TaskAttributes (com.netflix.titus.api.jobmanager.TaskAttributes)3 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)3 ArrayList (java.util.ArrayList)3