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();
}
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);
}
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));
}
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);
}
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();
}
Aggregations