Search in sources :

Example 1 with ApplicationSLA

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));
        }
    });
}
Also used : ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) NotFoundException(com.netflix.titus.api.store.v2.exception.NotFoundException)

Example 2 with ApplicationSLA

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);
        }
    });
}
Also used : ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA)

Example 3 with 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) {
    }
}
Also used : ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) NoSuchElementException(java.util.NoSuchElementException) ApplicationSlaStore(com.netflix.titus.api.store.v2.ApplicationSlaStore) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 4 with ApplicationSLA

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();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) POST(javax.ws.rs.POST)

Example 5 with ApplicationSLA

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();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Aggregations

ApplicationSLA (com.netflix.titus.api.model.ApplicationSLA)28 Test (org.junit.Test)9 List (java.util.List)5 NotFoundException (com.netflix.titus.api.store.v2.exception.NotFoundException)4 Pair (com.netflix.titus.common.util.tuple.Pair)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 Job (com.netflix.titus.api.jobmanager.model.job.Job)3 Task (com.netflix.titus.api.jobmanager.model.job.Task)3 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TaskAttributes (com.netflix.titus.api.jobmanager.TaskAttributes)2 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)2 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)2 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)2 ResourceDimension (com.netflix.titus.api.model.ResourceDimension)2 Tier (com.netflix.titus.api.model.Tier)2 ApplicationSlaStore (com.netflix.titus.api.store.v2.ApplicationSlaStore)2 TitusChangeAction (com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction)2