use of com.hartwig.pipeline.execution.PipelineStatus in project pipeline5 by hartwigmedical.
the class QuotaConstrainedComputeEngine method submit.
@Override
public PipelineStatus submit(final RuntimeBucket bucket, final VirtualMachineJobDefinition jobDefinition, final String discriminator) {
VirtualMachineJobDefinition constrained = jobDefinition;
MachineType machineType = jobDefinition.performanceProfile().machineType();
try {
QuotaBucket regionalQuota = serviceUsage.services().consumerQuotaMetrics().limits().get(cpuQuotaName(project)).execute().getQuotaBuckets().stream().filter(b -> b.getDimensions() != null).filter(b -> region(b) != null).filter(b -> region(b).equals(region)).findFirst().orElseThrow();
int maxCPU = (int) (regionalQuota.getEffectiveLimit().intValue() * constrainByPercentage);
if (machineType.cpus() > maxCPU) {
double reductionRatio = (double) maxCPU / machineType.cpus();
constrained = VirtualMachineJobDefinition.builder().from(constrained).performanceProfile(VirtualMachinePerformanceProfile.custom(maxCPU, (int) (machineType.memoryGB() * reductionRatio))).build();
}
return decorated.submit(bucket, constrained, discriminator);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations