1515 */
1616package nextflow.cloud.google.batch
1717
18+ import io.seqera.cloudinfo.api.CloudPrice
19+ import io.seqera.cloudinfo.client.CloudInfoClient
20+
1821import java.math.RoundingMode
1922
20- import groovy.json.JsonSlurper
2123import groovy.transform.CompileStatic
2224import groovy.transform.Immutable
2325import 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