in compute/cloud-client/src/main/java/compute/custommachinetype/HelperClass.java [207:246]
public static String validate(CustomMachineType cmt) {
// Check the number of cores and if the coreCount is present in allowedCores.
if (cmt.typeLimit.allowedCores.length > 0 && Arrays.stream(cmt.typeLimit.allowedCores)
.noneMatch(x -> x == cmt.coreCount)) {
throw new Error(String.format(
"Invalid number of cores requested. Allowed number of cores for %s is: %s",
cmt.cpuSeries,
Arrays.toString(cmt.typeLimit.allowedCores)));
}
// Memory must be a multiple of 256 MB.
if (cmt.memory % 256 != 0) {
throw new Error("Requested memory must be a multiple of 256 MB");
}
// Check if the requested memory isn't too little.
if (cmt.memory < cmt.coreCount * cmt.typeLimit.minMemPerCore) {
throw new Error(
String.format("Requested memory is too low. Minimum memory for %s is %s MB per core",
cmt.cpuSeries, cmt.typeLimit.minMemPerCore));
}
// Check if the requested memory isn't too much.
if (cmt.memory > cmt.coreCount * cmt.typeLimit.maxMemPerCore
&& !cmt.typeLimit.allowExtraMemory) {
throw new Error(String.format(
"Requested memory is too large.. Maximum memory allowed for %s is %s MB per core",
cmt.cpuSeries, cmt.typeLimit.extraMemoryLimit));
}
// Check if the requested memory isn't too large.
if (cmt.memory > cmt.typeLimit.extraMemoryLimit && cmt.typeLimit.allowExtraMemory) {
throw new Error(
String.format("Requested memory is too large.. Maximum memory allowed for %s is %s MB",
cmt.cpuSeries, cmt.typeLimit.extraMemoryLimit));
}
return null;
}