Search in sources :

Example 1 with ReservationUsage

use of com.netflix.titus.api.endpoint.v2.rest.representation.ReservationUsage in project titus-control-plane by Netflix.

the class ReservationUsageCalculatorTest method testBuildCapacityGroupUsage.

@Test
public void testBuildCapacityGroupUsage() {
    ReservationUsage cg1Usage = calculator.buildCapacityGroupUsage("cg1");
    assertThat(cg1Usage).isNotNull();
    assertThat(cg1Usage.getCpu()).isEqualTo(CONTAINER_RESOURCES.getCpu() * 4);
    assertThat(cg1Usage.getMemoryMB()).isEqualTo(CONTAINER_RESOURCES.getMemoryMB() * 4);
    assertThat(cg1Usage.getDiskMB()).isEqualTo(CONTAINER_RESOURCES.getDiskMB() * 4);
    assertThat(cg1Usage.getNetworkMbs()).isEqualTo(CONTAINER_RESOURCES.getNetworkMbps() * 4);
}
Also used : ReservationUsage(com.netflix.titus.api.endpoint.v2.rest.representation.ReservationUsage) Test(org.junit.Test)

Example 2 with ReservationUsage

use of com.netflix.titus.api.endpoint.v2.rest.representation.ReservationUsage in project titus-control-plane by Netflix.

the class ReservationUsageCalculatorTest method testBuildUsage.

@Test
public void testBuildUsage() {
    Map<String, ReservationUsage> usage = calculator.buildUsage();
    ReservationUsage cg1Usage = usage.get("cg1");
    ReservationUsage cg2Usage = usage.get("cg2");
    assertThat(cg1Usage).isNotNull();
    assertThat(cg2Usage).isNotNull();
    assertThat(cg1Usage.getCpu()).isEqualTo(CONTAINER_RESOURCES.getCpu() * 4);
    assertThat(cg1Usage.getCpu() * 2).isEqualTo(cg2Usage.getCpu());
    assertThat(cg1Usage.getMemoryMB()).isEqualTo(CONTAINER_RESOURCES.getMemoryMB() * 4);
    assertThat(cg1Usage.getMemoryMB() * 2).isEqualTo(cg2Usage.getMemoryMB());
    assertThat(cg1Usage.getDiskMB()).isEqualTo(CONTAINER_RESOURCES.getDiskMB() * 4);
    assertThat(cg1Usage.getDiskMB() * 2).isEqualTo(cg2Usage.getDiskMB());
    assertThat(cg1Usage.getNetworkMbs()).isEqualTo(CONTAINER_RESOURCES.getNetworkMbps() * 4);
    assertThat(cg1Usage.getNetworkMbs() * 2).isEqualTo(cg2Usage.getNetworkMbs());
}
Also used : ReservationUsage(com.netflix.titus.api.endpoint.v2.rest.representation.ReservationUsage) Test(org.junit.Test)

Example 3 with ReservationUsage

use of com.netflix.titus.api.endpoint.v2.rest.representation.ReservationUsage in project titus-control-plane by Netflix.

the class ReservationUsageCalculator method buildUsage.

public Map<String, ReservationUsage> buildUsage() {
    Map<String, ResourceAccumulator> accumulatorMap = new HashMap<>();
    List<Pair<Job, List<Task>>> jobsAndTasks = jobOperations.getJobsAndTasks();
    Set<String> capacityGroupNames = capacityManagementService.getApplicationSLAs().stream().map(ApplicationSLA::getAppName).collect(Collectors.toSet());
    for (Pair<Job, List<Task>> jobAndTasks : jobsAndTasks) {
        Job job = jobAndTasks.getLeft();
        String capacityGroup = capacityGroupNames.contains(job.getJobDescriptor().getCapacityGroup()) ? job.getJobDescriptor().getCapacityGroup() : ApplicationSlaManagementService.DEFAULT_APPLICATION;
        ResourceAccumulator accumulator = accumulatorMap.computeIfAbsent(capacityGroup, cp -> new ResourceAccumulator());
        processJob(accumulator, jobAndTasks);
    }
    Map<String, ReservationUsage> result = new HashMap<>();
    accumulatorMap.forEach((capacityGroup, accumulator) -> result.put(capacityGroup, accumulator.toReservationUsage()));
    capacityManagementService.getApplicationSLAs().forEach(capacityGroup -> {
        if (!result.containsKey(capacityGroup.getAppName())) {
            result.put(capacityGroup.getAppName(), ReservationUsage.none());
        }
    });
    return result;
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) HashMap(java.util.HashMap) ReservationUsage(com.netflix.titus.api.endpoint.v2.rest.representation.ReservationUsage) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) Pair(com.netflix.titus.common.util.tuple.Pair)

Example 4 with ReservationUsage

use of com.netflix.titus.api.endpoint.v2.rest.representation.ReservationUsage in project titus-control-plane by Netflix.

the class ApplicationSlaManagementResource method getApplicationSLA.

@GET
@Path("/{applicationName}")
@Override
public ApplicationSlaRepresentation getApplicationSLA(@PathParam("applicationName") String applicationName, @QueryParam("extended") boolean extended) {
    ApplicationSLA applicationSLA = applicationSlaManagementService.getApplicationSLA(applicationName);
    if (applicationSLA == null) {
        throw new WebApplicationException(new IllegalArgumentException("SLA not defined for " + applicationName), Status.NOT_FOUND);
    }
    String cellId = extended ? configuration.getCellName() : null;
    ReservationUsage reservationUsage = extended ? reservationUsageCalculator.buildCapacityGroupUsage(applicationName) : null;
    return asRepresentation(applicationSLA, cellId, reservationUsage);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ReservationUsage(com.netflix.titus.api.endpoint.v2.rest.representation.ReservationUsage) ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

ReservationUsage (com.netflix.titus.api.endpoint.v2.rest.representation.ReservationUsage)4 Test (org.junit.Test)2 Job (com.netflix.titus.api.jobmanager.model.job.Job)1 Task (com.netflix.titus.api.jobmanager.model.job.Task)1 ApplicationSLA (com.netflix.titus.api.model.ApplicationSLA)1 Pair (com.netflix.titus.common.util.tuple.Pair)1 HashMap (java.util.HashMap)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1