diff --git a/src/main/java/io/seqera/tower/cli/commands/pipelines/UpdateCmd.java b/src/main/java/io/seqera/tower/cli/commands/pipelines/UpdateCmd.java index be8b769c..f87ea6d5 100644 --- a/src/main/java/io/seqera/tower/cli/commands/pipelines/UpdateCmd.java +++ b/src/main/java/io/seqera/tower/cli/commands/pipelines/UpdateCmd.java @@ -91,7 +91,15 @@ protected Response exec() throws ApiException, IOException { Launch launch = api().describePipelineLaunch(id, wspId, sourceWorkspaceId).getLaunch(); // Retrieve the provided computeEnv or use the primary if not provided - String ceId = opts.computeEnv != null ? computeEnvByRef(wspId, opts.computeEnv).getId() : launch.getComputeEnv().getId(); + String ceId = null; + if (opts.computeEnv != null) { + ceId = computeEnvByRef(wspId, opts.computeEnv).getId(); + } else { + final var ce = launch.getComputeEnv(); + if (ce != null) { + ceId = ce.getId(); + } + } UpdatePipelineRequest updateReq = new UpdatePipelineRequest() .name(coalesce(newName, pipe.getName())) diff --git a/src/test/java/io/seqera/tower/cli/pipelines/PipelinesCmdTest.java b/src/test/java/io/seqera/tower/cli/pipelines/PipelinesCmdTest.java index b881d01b..145cf1a7 100644 --- a/src/test/java/io/seqera/tower/cli/pipelines/PipelinesCmdTest.java +++ b/src/test/java/io/seqera/tower/cli/pipelines/PipelinesCmdTest.java @@ -220,6 +220,61 @@ void testUpdatePipelineInvalidName(MockServerClient mock) { assertEquals(1, out.exitCode); } + @Test + void testUpdateInSharedWorkspaceWithoutCE(MockServerClient mock) throws IOException { + + mock.reset(); + + mock.when( + request().withMethod("GET").withPath("/user-info") + ).respond( + response().withStatusCode(200) + .withContentType(MediaType.APPLICATION_JSON) + .withBody("{\"user\":{\"id\":312,\"userName\":\"user\",\"email\":\"email@seqera.io\",\"firstName\":null,\"lastName\":null,\"organization\":null,\"description\":null,\"avatar\":\"https://avatars.githubusercontent.com/u/118266524?v=4\",\"avatarId\":null,\"notification\":null,\"termsOfUseConsent\":true,\"marketingConsent\":false,\"lastAccess\":\"2024-11-12T13:14:55Z\",\"dateCreated\":\"2023-10-14T08:30:58Z\",\"lastUpdated\":\"2024-11-12T13:14:55Z\",\"deleted\":false,\"trusted\":true,\"options\":{\"githubToken\":\"some\",\"maxRuns\":null,\"hubspotId\":1}},\"needConsent\":false,\"defaultWorkspaceId\":null}\n") + ); + + mock.when( + request().withPath("GET").withPath("/user/312/workspaces") + ).respond( + response().withStatusCode(200) + .withContentType(MediaType.APPLICATION_JSON) + .withBody("{\"orgsAndWorkspaces\":[{\"orgId\":44406019030987,\"orgName\":\"test-cli-org\",\"orgLogoUrl\":null,\"workspaceId\":59563405657242,\"workspaceName\":\"SharedWS\",\"workspaceFullName\":\"SharedWS\",\"visibility\":\"SHARED\",\"roles\":[\"owner\"]}]}\n") + + ); + + mock.when( + request().withMethod("GET").withPath("/pipelines/68359275903286").withQueryStringParameter("workspaceId","59563405657242") + ).respond( + response().withStatusCode(200) + .withContentType(MediaType.APPLICATION_JSON) + .withBody("{\"pipeline\":{\"pipelineId\":68359275903286,\"name\":\"hello-pipeline\",\"description\":null,\"icon\":null,\"repository\":\"https://github.com/nextflow-io/hello\",\"userId\":312,\"userName\":\"user\",\"userFirstName\":null,\"userLastName\":null,\"orgId\":44406019030987,\"orgName\":\"test-cli-org\",\"workspaceId\":59563405657242,\"workspaceName\":\"SharedWS\",\"visibility\":\"SHARED\",\"deleted\":false,\"lastUpdated\":\"2024-11-12T13:27:32Z\",\"optimizationId\":null,\"optimizationTargets\":null,\"optimizationStatus\":null,\"labels\":null,\"computeEnv\":null}}\n") + ); + + mock.when( + request().withMethod("GET").withPath("/pipelines/68359275903286/launch").withQueryStringParameter("workspaceId","59563405657242") + ).respond( + response().withStatusCode(200) + .withContentType(MediaType.APPLICATION_JSON) + .withBody("{\"launch\":{\"id\":\"64nBrwcvM7WYdDRgNvpWrZ\",\"computeEnv\":null,\"pipeline\":\"https://github.com/nextflow-io/hello\",\"workDir\":null,\"revision\":\"master\",\"configText\":null,\"towerConfig\":null,\"paramsText\":null,\"preRunScript\":\"xxx\\n\",\"postRunScript\":null,\"mainScript\":null,\"entryName\":null,\"schemaName\":null,\"resume\":false,\"resumeLaunchId\":null,\"pullLatest\":false,\"stubRun\":false,\"sessionId\":null,\"runName\":null,\"configProfiles\":null,\"userSecrets\":null,\"workspaceSecrets\":null,\"optimizationId\":null,\"optimizationTargets\":null,\"headJobCpus\":null,\"headJobMemoryMb\":null,\"launchContainer\":null,\"dateCreated\":\"2024-11-12T13:16:23Z\",\"lastUpdated\":\"2024-11-12T13:27:32Z\"}}\n") + + ); + mock.when( + request().withMethod("PUT").withPath("/pipelines/68359275903286").withQueryStringParameter("workspaceId","59563405657242") + .withContentType(MediaType.APPLICATION_JSON) + .withBody("{\"name\":\"hello-pipeline\",\"launch\":{\"pipeline\":\"https://github.com/nextflow-io/hello\",\"revision\":\"master\",\"preRunScript\":\"yyy\",\"pullLatest\":false,\"stubRun\":false}}"), + exactly(1) + ).respond( + response().withStatusCode(200) + .withContentType(MediaType.APPLICATION_JSON) + .withBody("{\"pipeline\":{\"pipelineId\":68359275903286,\"name\":\"hello-pipeline\",\"description\":null,\"icon\":null,\"repository\":\"https://github.com/nextflow-io/hello\",\"userId\":312,\"userName\":\"andrea-tortorella\",\"userFirstName\":null,\"userLastName\":null,\"orgId\":44406019030987,\"orgName\":\"test-cli-org\",\"workspaceId\":59563405657242,\"workspaceName\":\"SharedWS\",\"visibility\":\"SHARED\",\"deleted\":false,\"lastUpdated\":\"2024-11-12T13:34:06.403300434Z\",\"optimizationId\":null,\"optimizationTargets\":null,\"optimizationStatus\":null,\"labels\":null,\"computeEnv\":null}}") + ); + + ExecOut out = exec(mock,"--verbose", "pipelines", "update", "--id", "68359275903286", "--workspace", "59563405657242", "--pre-run", tempFile("yyy","pre-run","txt")); + assertEquals("", out.stdErr); + assertEquals(0, out.exitCode); + assertEquals(new PipelinesUpdated("[test-cli-org / SharedWS]", "hello-pipeline").toString(), out.stdOut); + } + @Test void testAdd(MockServerClient mock) throws IOException {