Search in sources :

Example 1 with ApplicationSlaStore

use of com.netflix.titus.api.store.v2.ApplicationSlaStore 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 2 with ApplicationSlaStore

use of com.netflix.titus.api.store.v2.ApplicationSlaStore in project titus-control-plane by Netflix.

the class InMemoryApplicationSlaStoreTest method createStore.

private ApplicationSlaStore createStore() {
    ApplicationSlaStoreCache applicationSlaStoreCache = new ApplicationSlaStoreCache(new InMemoryApplicationSlaStore());
    applicationSlaStoreCache.enterActiveMode();
    return applicationSlaStoreCache;
}
Also used : ApplicationSlaStoreCache(com.netflix.titus.api.store.v2.ApplicationSlaStoreCache)

Example 3 with ApplicationSlaStore

use of com.netflix.titus.api.store.v2.ApplicationSlaStore in project titus-control-plane by Netflix.

the class InMemoryApplicationSlaStoreTest method testStoreAndRetrieveCapacityGroups.

@Test
public void testStoreAndRetrieveCapacityGroups() {
    ApplicationSlaStore store = createStore();
    ApplicationSLA capacityGroup1 = DefaultFlex.build();
    ApplicationSLA capacityGroup2 = CriticalSmall.builder().withSchedulerName(SCHEDULER_NAME_KUBE_SCHEDULER).build();
    List<ApplicationSLA> capacityGroups = Arrays.asList(capacityGroup1, capacityGroup2);
    // Create initial
    capacityGroups.forEach(capacityGroup -> assertThat(store.create(capacityGroup).toCompletable().await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue());
    List<ApplicationSLA> result;
    // find all
    result = store.findAll().toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
    assertThat(result).containsExactlyInAnyOrder(capacityGroup1, capacityGroup2);
    // find by name
    result = store.findByName(capacityGroup1.getAppName()).toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
    assertThat(result).containsExactlyInAnyOrder(capacityGroup1);
    // find by scheduler name
    result = store.findBySchedulerName(SCHEDULER_NAME_FENZO).toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
    assertThat(result).containsExactlyInAnyOrder(capacityGroup1);
    result = store.findBySchedulerName(SCHEDULER_NAME_KUBE_SCHEDULER).toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
    assertThat(result).containsExactlyInAnyOrder(capacityGroup2);
    // find by non-existent scheduler name
    result = store.findBySchedulerName("").toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
    assertThat(result).isEmpty();
    // update scheduler name and verify
    ApplicationSLA updatedCapacityGroup = ApplicationSLA.newBuilder(capacityGroup1).withSchedulerName(SCHEDULER_NAME_KUBE_SCHEDULER).build();
    assertThat(store.create(updatedCapacityGroup).toCompletable().await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
    result = store.findAll().toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first();
    assertThat(result).containsExactlyInAnyOrder(updatedCapacityGroup, capacityGroup2);
    // remove
    assertThat(store.remove(updatedCapacityGroup.getAppName()).toCompletable().await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
    assertThat(store.remove(capacityGroup2.getAppName()).toCompletable().await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue();
    assertThat(store.findAll().toList().timeout(TIMEOUT, TimeUnit.MILLISECONDS).toBlocking().first()).isEmpty();
}
Also used : ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) ApplicationSlaStore(com.netflix.titus.api.store.v2.ApplicationSlaStore) Test(org.junit.Test)

Aggregations

ApplicationSLA (com.netflix.titus.api.model.ApplicationSLA)2 ApplicationSlaStore (com.netflix.titus.api.store.v2.ApplicationSlaStore)2 Test (org.junit.Test)2 ApplicationSlaStoreCache (com.netflix.titus.api.store.v2.ApplicationSlaStoreCache)1 IntegrationNotParallelizableTest (com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)1 NoSuchElementException (java.util.NoSuchElementException)1