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