From def1f9516e0d96e6e522cd1c03f0d541402f9eb5 Mon Sep 17 00:00:00 2001 From: Jaime Date: Mon, 24 Jun 2024 17:43:15 +0200 Subject: [PATCH] allow setting the service account email when creating a google batch CE --- .../platforms/GoogleBatchPlatform.java | 13 +++++-- .../platforms/GoogleBatchPlatformTest.java | 38 +++++++++++++++++-- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/seqera/tower/cli/commands/computeenvs/platforms/GoogleBatchPlatform.java b/src/main/java/io/seqera/tower/cli/commands/computeenvs/platforms/GoogleBatchPlatform.java index f680f811..a8396d56 100644 --- a/src/main/java/io/seqera/tower/cli/commands/computeenvs/platforms/GoogleBatchPlatform.java +++ b/src/main/java/io/seqera/tower/cli/commands/computeenvs/platforms/GoogleBatchPlatform.java @@ -66,10 +66,11 @@ public GoogleBatchConfig computeConfig() throws ApiException, IOException { // Advanced if (adv != null) { config - .usePrivateAddress(adv.usePrivateAddress) - .bootDiskSizeGb(adv.bootDiskSizeGb) - .headJobCpus(adv.headJobCpus) - .headJobMemoryMb(adv.headJobMemoryMb); + .usePrivateAddress(adv.usePrivateAddress) + .bootDiskSizeGb(adv.bootDiskSizeGb) + .headJobCpus(adv.headJobCpus) + .headJobMemoryMb(adv.headJobMemoryMb) + .serviceAccount(adv.serviceAccountEmail); } return config; @@ -87,5 +88,9 @@ public static class AdvancedOptions { @Option(names = {"--head-job-memory"}, description = "The number of MiB of memory reserved for the Nextflow runner job (value should be a multiple of 256MiB and from 0.5 GB to 8 GB per CPU).") public Integer headJobMemoryMb; + + @Option(names = {"--service-account-email"}, description = "The service account email address used when deploying pipeline executions with this compute environment.") + public String serviceAccountEmail; + } } diff --git a/src/test/java/io/seqera/tower/cli/computeenvs/platforms/GoogleBatchPlatformTest.java b/src/test/java/io/seqera/tower/cli/computeenvs/platforms/GoogleBatchPlatformTest.java index 41104650..01ba056d 100644 --- a/src/test/java/io/seqera/tower/cli/computeenvs/platforms/GoogleBatchPlatformTest.java +++ b/src/test/java/io/seqera/tower/cli/computeenvs/platforms/GoogleBatchPlatformTest.java @@ -69,17 +69,49 @@ void testAddWithAdvancedOptions(MockServerClient mock) throws IOException { mock.when( request().withMethod("GET").withPath("/credentials").withQueryStringParameter("platformId", "google-batch"), exactly(1) ).respond( - response().withStatusCode(200).withBody("{\"credentials\":[{\"id\":\"6XfOhoztUq6de3Dw3X9LSb\",\"name\":\"google\",\"description\":null,\"discriminator\":\"google\",\"baseUrl\":null,\"category\":null,\"deleted\":null,\"lastUsed\":\"2021-09-08T18:20:46Z\",\"dateCreated\":\"2021-09-08T12:57:04Z\",\"lastUpdated\":\"2021-09-08T12:57:04Z\"}]}").withContentType(MediaType.APPLICATION_JSON) + response().withStatusCode(200) + .withBody(""" + { + "credentials":[{ + "id":"6XfOhoztUq6de3Dw3X9LSb", + "name":"google", + "description":null, + "discriminator":"google", + "baseUrl":null, + "category":null, + "deleted":null, + "lastUsed":"2021-09-08T18:20:46Z", + "dateCreated":"2021-09-08T12:57:04Z","lastUpdated":"2021-09-08T12:57:04Z" + }] + }""") + .withContentType(MediaType.APPLICATION_JSON) ); mock.when( request().withMethod("POST").withPath("/compute-envs") - .withBody(JsonBody.json("{\"computeEnv\":{\"name\":\"google\",\"platform\":\"google-batch\",\"config\":{\"location\":\"europe\",\"fusion2Enabled\":true,\"waveEnabled\":true,\"workDir\":\"gs://workdir\",\"usePrivateAddress\":true},\"credentialsId\":\"6XfOhoztUq6de3Dw3X9LSb\"}}")), exactly(1) + .withBody(JsonBody.json(""" + { + "computeEnv": { + "name": "google", + "platform": "google-batch", + "config": { + "location": "europe", + "fusion2Enabled": true, + "waveEnabled": true, + "workDir": "gs://workdir", + "usePrivateAddress": true, + "serviceAccount": "service.account@google.com" + }, + "credentialsId": "6XfOhoztUq6de3Dw3X9LSb" + } + }""") + ), + exactly(1) ).respond( response().withStatusCode(200).withBody("{\"computeEnvId\":\"isnEDBLvHDAIteOEF44ow\"}").withContentType(MediaType.APPLICATION_JSON) ); - ExecOut out = exec(mock, "compute-envs", "add", "google-batch", "-n", "google", "--work-dir", "gs://workdir", "-l", "europe", "--fusion-v2", "--wave", "--use-private-address"); + ExecOut out = exec(mock, "compute-envs", "add", "google-batch", "-n", "google", "--work-dir", "gs://workdir", "-l", "europe", "--fusion-v2", "--wave", "--use-private-address", "--service-account-email", "service.account@google.com"); assertEquals("", out.stdErr); assertEquals(new ComputeEnvAdded("google-batch", "isnEDBLvHDAIteOEF44ow", "google", null, USER_WORKSPACE_NAME).toString(), out.stdOut); assertEquals(0, out.exitCode);