use of com.netflix.titus.api.model.ApplicationSLA in project titus-control-plane by Netflix.
the class ApplicationSlaStoreCache method findByName.
public Observable<ApplicationSLA> findByName(String applicationName) {
return Observable.create(subscriber -> {
ApplicationSLA applicationSLA = cache.get(applicationName);
if (applicationSLA != null) {
subscriber.onNext(applicationSLA);
subscriber.onCompleted();
} else {
subscriber.onError(new NotFoundException(ApplicationSLA.class, applicationName));
}
});
}
use of com.netflix.titus.api.model.ApplicationSLA in project titus-control-plane by Netflix.
the class ApplicationSlaStoreCache method create.
@Override
public Observable<Void> create(ApplicationSLA applicationSLA) {
return delegate.create(applicationSLA).doOnCompleted(() -> {
synchronized (lock) {
ApplicationSLA previous = cache.put(applicationSLA.getAppName(), applicationSLA);
if (previous != null) {
cacheBySchedulerName.remove(previous.getSchedulerName(), previous);
}
cacheBySchedulerName.put(applicationSLA.getSchedulerName(), applicationSLA);
}
});
}
use of com.netflix.titus.api.model.ApplicationSLA in project titus-control-plane by Netflix.
the class CassandraApplicationSlaStoreTest method testStoreAndRetrieveCapacityGroups.
@Test
public void testStoreAndRetrieveCapacityGroups() {
ApplicationSLA capacityGroup1 = ApplicationSlaSample.DefaultFlex.build();
ApplicationSLA capacityGroup2 = ApplicationSlaSample.CriticalLarge.build();
ApplicationSLA capacityGroup3 = ApplicationSlaSample.CriticalSmallKubeScheduler.build();
ApplicationSLA capacityGroup4 = ApplicationSlaSample.FlexSmallKubeScheduler.build();
List<ApplicationSLA> capacityGroups = Arrays.asList(capacityGroup1, capacityGroup2, capacityGroup3, capacityGroup4);
// Create initial
ApplicationSlaStore bootstrappingTitusStore = createStore();
capacityGroups.forEach(capacityGroup -> assertThat(bootstrappingTitusStore.create(capacityGroup).toCompletable().await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue());
// Read all
ApplicationSlaStore store = createStore();
List<ApplicationSLA> result = store.findAll().toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
assertThat(result).hasSize(4);
assertThat(result).containsAll(capacityGroups);
// Find by name
ApplicationSLA fetched = store.findByName(capacityGroup1.getAppName()).timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
assertThat(fetched).isEqualTo(capacityGroup1);
assertThat(fetched.getSchedulerName()).isEqualTo(SCHEDULER_NAME_FENZO);
assertThat(fetched.getResourcePool()).isEmpty();
// Find by scheduler name
List<ApplicationSLA> fetchedByFenzoScheduler = store.findBySchedulerName(SCHEDULER_NAME_FENZO).toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
assertThat(fetchedByFenzoScheduler).hasSize(2);
assertThat(fetchedByFenzoScheduler).containsAll(ImmutableList.of(capacityGroup1, capacityGroup2));
List<ApplicationSLA> fetchByKubeScheduler = store.findBySchedulerName(SCHEDULER_NAME_KUBE_SCHEDULER).toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
assertThat(fetchByKubeScheduler).hasSize(2);
assertThat(fetchByKubeScheduler).containsAll(ImmutableList.of(capacityGroup3, capacityGroup4));
ApplicationSLA fetchedByKubeSchedulerCriticalTierApplicationSLA = fetchByKubeScheduler.stream().filter(applicationSLA -> applicationSLA.getAppName().equals(capacityGroup3.getAppName())).findFirst().orElseThrow(() -> new AssertionError("Expected value not found in the result"));
assertThat(fetchedByKubeSchedulerCriticalTierApplicationSLA.getSchedulerName()).isEqualTo(SCHEDULER_NAME_KUBE_SCHEDULER);
assertThat(fetchedByKubeSchedulerCriticalTierApplicationSLA.getResourcePool()).isEqualTo(ApplicationSLA.DEFAULT_CRITICAL_TIER_RESOURCE_POOL);
ApplicationSLA fetchedByKubeSchedulerFlexTierApplicatonSLA = fetchByKubeScheduler.stream().filter(applicationSLA -> applicationSLA.getAppName().equals(capacityGroup4.getAppName())).findFirst().orElseThrow(() -> new AssertionError("Expected value not found in the result"));
assertThat(fetchedByKubeSchedulerFlexTierApplicatonSLA.getSchedulerName()).isEqualTo(SCHEDULER_NAME_KUBE_SCHEDULER);
assertThat(fetchedByKubeSchedulerFlexTierApplicatonSLA.getResourcePool()).isEqualTo(ApplicationSLA.DEFAULT_FLEX_TIER_RESOURCE_POOL);
// update an ApplicationSLA associated with fenzo to kubescheduler and verify the new set
ApplicationSLA updatedCapacityGroup = ApplicationSLA.newBuilder(capacityGroup1).withSchedulerName(SCHEDULER_NAME_KUBE_SCHEDULER).build();
assertThat(store.create(updatedCapacityGroup).toCompletable().await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
List<ApplicationSLA> fetchByKubeSchedulerAfterUpdate = store.findBySchedulerName(SCHEDULER_NAME_KUBE_SCHEDULER).toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
assertThat(fetchByKubeSchedulerAfterUpdate).hasSize(3);
assertThat(fetchByKubeSchedulerAfterUpdate).containsAll(ImmutableList.of(updatedCapacityGroup, capacityGroup3, capacityGroup4));
List<ApplicationSLA> fetchByFenzoAfterUpdate = store.findBySchedulerName(SCHEDULER_NAME_FENZO).toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
assertThat(fetchByFenzoAfterUpdate).hasSize(1);
assertThat(fetchByFenzoAfterUpdate).containsAll(ImmutableList.of(capacityGroup2));
List<ApplicationSLA> findAllResult = store.findAll().toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
assertThat(findAllResult).hasSize(4);
assertThat(findAllResult).containsAll(ImmutableList.of(updatedCapacityGroup, capacityGroup2, capacityGroup3, capacityGroup4));
// Now delete
assertThat(store.remove(capacityGroup1.getAppName()).toCompletable().await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
try {
store.findByName(capacityGroup1.getAppName()).timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
Assert.fail();
} catch (NoSuchElementException expected) {
}
}
use of com.netflix.titus.api.model.ApplicationSLA in project titus-control-plane by Netflix.
the class ApplicationSlaManagementResource method addApplicationSLA.
@POST
@Override
public Response addApplicationSLA(ApplicationSlaRepresentation applicationSLA) {
ApplicationSLA existing = applicationSlaManagementService.getApplicationSLA(applicationSLA.getAppName());
if (existing != null) {
throw new WebApplicationException(new IllegalStateException("Application SLA for " + applicationSLA.getAppName() + " already exist"), Status.CONFLICT);
}
applicationSlaManagementService.addApplicationSLA(asCoreEntity(applicationSLA)).timeout(1, TimeUnit.MINUTES).toBlocking().firstOrDefault(null);
return Response.created(URI.create(applicationSLA.getAppName())).build();
}
use of com.netflix.titus.api.model.ApplicationSLA in project titus-control-plane by Netflix.
the class ApplicationSlaManagementResource method updateApplicationSLA.
@PUT
@Path("/{applicationName}")
@Override
public Response updateApplicationSLA(@PathParam("applicationName") String applicationName, ApplicationSlaRepresentation applicationSLA) {
if (!applicationName.equals(applicationSLA.getAppName())) {
throw new IllegalArgumentException("application name in path different from appName in the request body");
}
ApplicationSLA existing = applicationSlaManagementService.getApplicationSLA(applicationSLA.getAppName());
if (existing == null) {
throw new WebApplicationException(new IllegalArgumentException("SLA not defined for " + applicationName), Status.NOT_FOUND);
}
applicationSlaManagementService.addApplicationSLA(asCoreEntity(applicationSLA)).timeout(1, TimeUnit.MINUTES).toBlocking().firstOrDefault(null);
return Response.status(Status.NO_CONTENT).build();
}
Aggregations