Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Batch validates the region before checking available VMs #5108

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,26 @@ class AzBatchService implements Closeable {

@Memoized
private List<Map> listAllVms(String location) {

final locationNames = listLocationNames()
if( !locationNames.contains(location) )
log.warn("[AZURE BATCH] No location called ${location} found! Please confirm it exists and the name is correct!")

if( !location )
throw new IllegalArgumentException("Missing Azure location parameter")
final json = AzBatchService.class.getResourceAsStream("/nextflow/cloud/azure/vm-list-size-${location}.json")
if( !json ) {
log.warn "Unable to find Azure VM names for location: $location"
log.warn("[AZURE BATCH] Unable to find Azure VM names for location: $location")
return Collections.emptyList()
}

return (List<Map>) new JsonSlurper().parse(json)
final vmList = (List<Map>) new JsonSlurper().parse(json)

if ( vmList.isEmpty() )
log.warn("[AZURE BATCH] No VM sizes found for location: $location")

log.debug("[AZURE BATCH] vmList: ${vmList}")
return vmList
}

@Memoized
Expand Down Expand Up @@ -189,9 +200,12 @@ class AzBatchService implements Closeable {
* @return The `AzVmType` instance that best accommodate the resource requirement
*/
AzVmType findBestVm(String location, int cpus, MemoryUnit mem, String allFamilies) {
log.debug "[AZURE BATCH] Finding best VM given location=$location; cpus=$cpus; mem=$mem; family=$allFamilies"
def all = listAllVms(location)
log.debug "[AZURE BATCH] Found ${all.size()} VM types in location $location"
def scores = new TreeMap<Double,String>()
def list = allFamilies ? allFamilies.tokenize(',') : ['']
log.debug "[AZURE BATCH] Listing VM families"
for( String family : list ) {
for( Map entry : all ) {
if( !matchType(family, entry.name as String) )
Expand All @@ -201,7 +215,7 @@ class AzBatchService implements Closeable {
scores.put(score, entry.name as String)
}
}

log.debug "[AZURE BATCH] Found ${scores.size()} VM types matching the criteria"
return scores ? getVmType(location, scores.firstEntry().value) : null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,50 @@ class AzBatchServiceTest extends Specification {
'Standard_D5_v2' in names
}

def 'should list all VMs in region' () {
given:
def exec = Mock(AzBatchExecutor) {
getConfig() >> new AzConfig([:])
}
def svc = new AzBatchService(exec)

when:
def vms = svc.listAllVms('northeurope')

then:
[
maxDataDiskCount: 32,
memoryInMB: 28672,
name: "Standard_D4_v2",
numberOfCores: 8,
osDiskSizeInMB: 1047552,
resourceDiskSizeInMB: 409600
] in vms
[
maxDataDiskCount: 8,
memoryInMB: 7168,
name: "Basic_A3",
numberOfCores: 4,
osDiskSizeInMB: 1047552,
resourceDiskSizeInMB: 122880
] in vms
}

def 'should fail to list VMs in region' () {
given:
def exec = Mock(AzBatchExecutor) {
getConfig() >> new AzConfig([:])
}
def svc = new AzBatchService(exec)

when:
def vms = svc.listAllVms('mars')

then:
vms instanceof List
vms.isEmpty()
}

def 'should get size for vm' () {
given:
def exec = Mock(AzBatchExecutor) {
Expand Down
Loading