Skip to content

Commit 8b20d18

Browse files
committed
feat: Support passing standard machine types to Google Batch by reusing the cpuPlatform field in the RuntimeAttributes
1 parent 081318d commit 8b20d18

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

supportedBackends/google/batch/src/main/scala/cromwell/backend/google/batch/api/GcpBatchRequestFactoryImpl.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,10 @@ class GcpBatchRequestFactoryImpl()(implicit gcsTransferConfiguration: GcsTransfe
234234
googleLegacyMachineSelection = false,
235235
jobLogger = jobLogger
236236
)
237+
// Don't set cpuPlatform if the field was used to specify standard machine type when submitting the GCP Batch request
238+
val cpuPlatformBatchRequest = if (GcpBatchMachineConstraints.isStandardMachineType(cpuPlatform)) "" else cpuPlatform
237239
val instancePolicy =
238-
createInstancePolicy(cpuPlatform = cpuPlatform, spotModel, accelerators, allDisks, machineType = machineType)
240+
createInstancePolicy(cpuPlatform = cpuPlatformBatchRequest, spotModel, accelerators, allDisks, machineType = machineType)
239241
val locationPolicy = LocationPolicy.newBuilder.addAllowedLocations(zones).build
240242
val allocationPolicy =
241243
createAllocationPolicy(data, locationPolicy, instancePolicy.build, networkPolicy, gcpSa, accelerators)

supportedBackends/google/batch/src/main/scala/cromwell/backend/google/batch/models/GcpBatchCustomMachineType.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import wom.format.MemorySize
1111

1212
import scala.math.{log, pow}
1313

14+
case class StandardMachineType(machineType: String) {}
15+
1416
/**
1517
* Adjusts memory and cpu for custom machine types.
1618
*

supportedBackends/google/batch/src/main/scala/cromwell/backend/google/batch/util/GcpBatchMachineConstraints.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,28 @@ import cromwell.backend.google.batch.models.{
44
GcpBatchRuntimeAttributes,
55
N1CustomMachineType,
66
N2CustomMachineType,
7-
N2DCustomMachineType
7+
N2DCustomMachineType,
8+
StandardMachineType
89
}
910
import cromwell.core.logging.JobLogger
1011
import eu.timepit.refined.api.Refined
1112
import eu.timepit.refined.numeric.Positive
13+
import scala.util.matching.Regex
1214
import wdl4s.parser.MemoryUnit
1315
import wom.format.MemorySize
1416

1517
object GcpBatchMachineConstraints {
18+
private val machineTypePattern: Regex = """^\w{2}\w?-\w+-\w+$""".r
19+
1620
def machineType(memory: MemorySize,
1721
cpu: Int Refined Positive,
1822
cpuPlatformOption: Option[String],
1923
googleLegacyMachineSelection: Boolean,
2024
jobLogger: JobLogger
2125
): String =
22-
if (googleLegacyMachineSelection) {
26+
if (isStandardMachineType(cpuPlatformOption.getOrElse(""))) {
27+
StandardMachineType(cpuPlatformOption.getOrElse("")).machineType
28+
} else if (googleLegacyMachineSelection) {
2329
s"predefined-$cpu-${memory.to(MemoryUnit.MB).amount.intValue()}"
2430
} else {
2531
// If someone requests Intel Cascade Lake or Intel Ice Lake as their CPU platform then switch the machine type to n2.
@@ -33,4 +39,6 @@ object GcpBatchMachineConstraints {
3339
}
3440
customMachineType.machineType(memory, cpu, jobLogger)
3541
}
42+
43+
def isStandardMachineType(machineType: String): Boolean = machineTypePattern.matches(machineType)
3644
}

0 commit comments

Comments
 (0)