Skip to content

Commit

Permalink
Improve GLS location validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Jan 27, 2020
1 parent 8db8d8a commit 5b89ab5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 17 deletions.
Expand Up @@ -138,24 +138,20 @@ class GoogleLifeSciencesConfig {

static String fallbackToRegionOrZone(List<String> regions, List<String> zones) {
if( regions ) {
if( regions.size()>1 ) {
log.warn "Google LifeSciences location is missing -- Defaulting to region: ${regions[0]}"
}
return regions[0]
return bestLocationForRegion(regions[0])
}
if( zones ) {
def norm = zones
.collect { int p = zones[0].lastIndexOf('-'); p!=-1 ? it.substring(0,p) : it }
.unique()
if( norm.size()>1 ) {
log.warn "Google LifeSciences location is missing -- Defaulting to zone: ${norm[0]}"
}

return norm[0]
return bestLocationForRegion(norm[0])
}
throw new AbortOperationException("Missing Google region or location information")
throw new AbortOperationException("Missing Google region or zone information")
}

static String bestLocationForRegion(String region) {
region.startsWith('europe-') ? 'europe-west2' : 'us-central1'
}

static String getProjectIdFromCreds(String credsFilePath) {
if( !credsFilePath )
Expand Down
Expand Up @@ -87,6 +87,8 @@ class GoogleLifeSciencesExecutor extends Executor {

log.debug "Google Life Science config=$config"
helper = initClient()
// validate specified location
helper.checkValidLocation()
}

protected GoogleLifeSciencesHelper initClient() {
Expand Down
Expand Up @@ -51,10 +51,14 @@ import nextflow.util.Escape
@CompileStatic
class GoogleLifeSciencesHelper {

/*
* Avail location see https://cloud.google.com/life-sciences/docs/concepts/locations
*/
public static final List<String> DEFAULT_LOCATIONS = ['us-central1','europe-west2']

public static final String SSH_DAEMON_NAME = 'ssh-daemon'
public static final String DEFAULT_APP_NAME = "Nextflow/GLS"
public static final String SCOPE_CLOUD_PLATFORM = "https://www.googleapis.com/auth/cloud-platform"
public static final List<String> ENV_VAR_TO_INCLUDE = ["NXF_DEBUG"]

CloudLifeSciences client
GoogleCredentials credentials
Expand Down Expand Up @@ -306,4 +310,24 @@ class GoogleLifeSciencesHelper {
result += "{ cd $localTaskDir; bash ${TaskRun.CMD_RUN} nxf_unstage; } >> $localTaskDir/${TaskRun.CMD_LOG} 2>&1"
return result
}

void checkValidLocation() {
if( config.location in DEFAULT_LOCATIONS ) {
// that's fine, just return
return
}
// check the current list of location to make sure the specified one really exists
final availLocations = client
.projects()
.locations()
.list("projects/$config.project")
.execute()
.getLocations()
*.getLocationId()
if( config.location in availLocations ) {
return
}
// show a warning message
log.warn "The specified Google Life Sciences location is not available: \"$config.location\" -- Please choose open of the following ${availLocations.join(',')}"
}
}
Expand Up @@ -15,6 +15,8 @@
*/
package nextflow.cloud.google.lifesciences

import spock.lang.Unroll

import nextflow.exception.AbortOperationException
import nextflow.util.MemoryUnit
import spock.lang.Specification
Expand Down Expand Up @@ -75,13 +77,13 @@ class GoogleLifeSciencesConfigTest extends Specification {
def map = [google:
[
project: 'bar',
zone: 'eu-west1-a',
zone: 'europe-west1-a',
lifeSciences: [preemptible: false, disableRemoteBinDir: false]
]]
def config = GoogleLifeSciencesConfig.fromSession0(map)
then:
config.project == 'bar'
config.location == 'eu-west1'
config.location == 'europe-west2'
!config.preemptible
!config.disableBinDir

Expand All @@ -90,13 +92,13 @@ class GoogleLifeSciencesConfigTest extends Specification {
map = [google:
[
project: 'bar',
zone: 'eu-west1-a',
zone: 'europe-west1-a',
lifeSciences: [preemptible: true, disableRemoteBinDir: true]
]]
config = GoogleLifeSciencesConfig.fromSession0(map)
then:
config.project == 'bar'
config.location == 'eu-west1'
config.location == 'europe-west2'
config.preemptible
config.disableBinDir
}
Expand All @@ -112,7 +114,7 @@ class GoogleLifeSciencesConfigTest extends Specification {
config.project == 'foo'
config.regions == ['us-central']
config.zones == []
config.location == 'us-central'
config.location == 'us-central1'
}

def 'should config location from zone' () {
Expand All @@ -126,7 +128,7 @@ class GoogleLifeSciencesConfigTest extends Specification {
config.project == 'foo'
config.regions == []
config.zones == ['us-east4-a','us-east4-c']
config.location == 'us-east4'
config.location == 'us-central1'
}

def 'should report missing region' () {
Expand Down Expand Up @@ -195,4 +197,23 @@ class GoogleLifeSciencesConfigTest extends Specification {
then:
config.copyImage == 'foo'
}

@Unroll
def 'should return location from region'( ){
given:
def config = new GoogleLifeSciencesConfig()

expect:
config.bestLocationForRegion(REGION) == LOCATION

where:
REGION | LOCATION
'europe-west1' | 'europe-west2'
'europe-west2' | 'europe-west2'
'europe-any' | 'europe-west2'
'us-central1' | 'us-central1'
'us-any' | 'us-central1'
'foo' | 'us-central1'
}

}

0 comments on commit 5b89ab5

Please sign in to comment.