Skip to content

Commit 6291842

Browse files
authored
replace curren cloud info url call to cloudInfo client (#7065)
Signed-off-by: jorgee <jorge.ejarque@seqera.io>
1 parent 944977e commit 6291842

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

plugins/nf-google/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ dependencies {
5858
api 'com.google.cloud:google-cloud-logging:3.23.5'
5959
api 'com.google.cloud:google-cloud-nio:0.128.5'
6060
api 'com.google.cloud:google-cloud-storage:2.58.0'
61-
61+
api 'io.seqera:lib-cloudinfo:1.0.0'
6262
// Force patched version to address CVE-2025-55163 (MadeYouReset HTTP/2 DDoS vulnerability)
6363
runtimeOnly 'io.grpc:grpc-netty-shaded:1.75.0'
6464
// Force patched version to address GHSA-72hv-8253-57qq (jackson-core Number Length Constraint Bypass DoS)

plugins/nf-google/src/main/nextflow/cloud/google/batch/GoogleBatchMachineTypeSelector.groovy

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616
package nextflow.cloud.google.batch
1717

18+
import io.seqera.cloudinfo.api.CloudPrice
19+
import io.seqera.cloudinfo.client.CloudInfoClient
20+
1821
import java.math.RoundingMode
1922

20-
import groovy.json.JsonSlurper
2123
import groovy.transform.CompileStatic
2224
import groovy.transform.Immutable
2325
import groovy.transform.Memoized
@@ -42,8 +44,6 @@ class GoogleBatchMachineTypeSelector {
4244

4345
static GoogleBatchMachineTypeSelector INSTANCE = new GoogleBatchMachineTypeSelector()
4446

45-
private static final CLOUD_INFO_API = "https://cloudinfo.seqera.io/api/v1"
46-
4747
/*
4848
* Some families CPUs are faster so this is a cost correction factor
4949
* for processes that request more than 2 CPUs or 2GB, smaller processes
@@ -101,6 +101,12 @@ class GoogleBatchMachineTypeSelector {
101101
*/
102102
private static final List<String> PARTIAL_LOCAL_SSD_SUPPORT_FAMILIES = ['c3-*', 'c3a-*', 'c3d-*', 'c4-*', 'c4a-*', 'c4d-*', 'h4d-*', 'z3-*']
103103

104+
private CloudInfoClient cloudInfo
105+
106+
GoogleBatchMachineTypeSelector(){
107+
cloudInfo = CloudInfoClient.create()
108+
}
109+
104110
@Immutable
105111
static class MachineType {
106112
String type
@@ -170,16 +176,14 @@ class GoogleBatchMachineTypeSelector {
170176
@Memoized
171177
protected List<MachineType> getAvailableMachineTypes(String region, boolean spot) {
172178
final priceModel = spot ? PriceModel.spot : PriceModel.standard
173-
final json = "${CLOUD_INFO_API}/providers/google/services/compute/regions/${region}/products".toURL().text
174-
final data = new JsonSlurper().parseText(json)
175-
final products = data['products'] as List<Map>
176-
final averageSpotPrice = (List<Map> prices) -> prices ? prices.collect{it.price as float}.average() as float : 0.0f
179+
final products = cloudInfo.getProducts('google', region)
180+
final averageSpotPrice = (List<CloudPrice> prices) -> prices ? prices.collect{it.price as float}.average() as float : 0.0f
177181

178182
products.collect {
179183
new MachineType(
180184
type: it.type,
181185
family: it.type.toString().split('-')[0],
182-
spotPrice: averageSpotPrice(it.spotPrice as List<Map>),
186+
spotPrice: averageSpotPrice(it.spotPrice as List<CloudPrice>),
183187
onDemandPrice: it.onDemandPrice as float,
184188
cpusPerVm: it.cpusPerVm as int,
185189
memPerVm: it.memPerVm as int,

0 commit comments

Comments
 (0)