Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug updating pipelines in shared workspace #469

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
55 changes: 55 additions & 0 deletions src/test/java/io/seqera/tower/cli/pipelines/PipelinesCmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 protected]\",\"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,"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 {

Expand Down
Loading