Skip to content

Commit

Permalink
Support updating the name of Tower entities (#327)
Browse files Browse the repository at this point in the history
* organization cmd update org name

* workspaces cmd update wsp name

* pipelines cmd update pipeline name

* update reflection files

* use 'distribution' instead of 'version' in CI pipeline

* update jdk to 17.0.8

* set language level in nativeCompile task options

* update reflection files

* fix: update pipeline test

* actions cmd update actions name

* compute-env cmd update CE name

* unit tests for CE update cmd

* update reflection files
  • Loading branch information
JaimeSeqLabs authored Sep 21, 2023
1 parent 845d6d7 commit df3870c
Show file tree
Hide file tree
Showing 19 changed files with 611 additions and 85 deletions.
15 changes: 3 additions & 12 deletions conf/jni-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,15 @@
},
{
"name":"java.lang.ClassLoader",
"methods":[
{"name":"getPlatformClassLoader","parameterTypes":[] },
{"name":"loadClass","parameterTypes":["java.lang.String"] }
]
"methods":[{"name":"getPlatformClassLoader","parameterTypes":[] }, {"name":"loadClass","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.lang.String",
"methods":[
{"name":"lastIndexOf","parameterTypes":["int"] },
{"name":"substring","parameterTypes":["int"] }
]
"methods":[{"name":"lastIndexOf","parameterTypes":["int"] }, {"name":"substring","parameterTypes":["int"] }]
},
{
"name":"java.lang.System",
"methods":[
{"name":"getProperty","parameterTypes":["java.lang.String"] },
{"name":"setProperty","parameterTypes":["java.lang.String","java.lang.String"] }
]
"methods":[{"name":"getProperty","parameterTypes":["java.lang.String"] }, {"name":"setProperty","parameterTypes":["java.lang.String","java.lang.String"] }]
},
{
"name":"jdk.internal.loader.ClassLoaders$PlatformClassLoader"
Expand Down
27 changes: 19 additions & 8 deletions conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,12 @@
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.computeenvs.ComputeEnvUpdated",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true
},
{
"name":"io.seqera.tower.cli.responses.computeenvs.ComputeEnvExport",
"allDeclaredFields":true,
Expand Down Expand Up @@ -2181,7 +2187,8 @@
"name":"io.seqera.tower.model.AwsBatchConfig",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
"allDeclaredConstructors":true,
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"getCliPath","parameterTypes":[] }, {"name":"getComputeJobRole","parameterTypes":[] }, {"name":"getComputeQueue","parameterTypes":[] }, {"name":"getDiscriminator","parameterTypes":[] }, {"name":"getDragenQueue","parameterTypes":[] }, {"name":"getEnvironment","parameterTypes":[] }, {"name":"getExecutionRole","parameterTypes":[] }, {"name":"getForge","parameterTypes":[] }, {"name":"getForgedResources","parameterTypes":[] }, {"name":"getFusion2Enabled","parameterTypes":[] }, {"name":"getHeadJobCpus","parameterTypes":[] }, {"name":"getHeadJobMemoryMb","parameterTypes":[] }, {"name":"getHeadJobRole","parameterTypes":[] }, {"name":"getHeadQueue","parameterTypes":[] }, {"name":"getLogGroup","parameterTypes":[] }, {"name":"getNvnmeStorageEnabled","parameterTypes":[] }, {"name":"getPostRunScript","parameterTypes":[] }, {"name":"getPreRunScript","parameterTypes":[] }, {"name":"getRegion","parameterTypes":[] }, {"name":"getVolumes","parameterTypes":[] }, {"name":"getWaveEnabled","parameterTypes":[] }, {"name":"getWorkDir","parameterTypes":[] }, {"name":"setCliPath","parameterTypes":["java.lang.String"] }, {"name":"setComputeJobRole","parameterTypes":["java.lang.String"] }, {"name":"setComputeQueue","parameterTypes":["java.lang.String"] }, {"name":"setDragenQueue","parameterTypes":["java.lang.String"] }, {"name":"setEnvironment","parameterTypes":["java.util.List"] }, {"name":"setExecutionRole","parameterTypes":["java.lang.String"] }, {"name":"setForge","parameterTypes":["io.seqera.tower.model.ForgeConfig"] }, {"name":"setForgedResources","parameterTypes":["java.util.List"] }, {"name":"setFusion2Enabled","parameterTypes":["java.lang.Boolean"] }, {"name":"setHeadJobCpus","parameterTypes":["java.lang.Integer"] }, {"name":"setHeadJobMemoryMb","parameterTypes":["java.lang.Integer"] }, {"name":"setHeadJobRole","parameterTypes":["java.lang.String"] }, {"name":"setHeadQueue","parameterTypes":["java.lang.String"] }, {"name":"setLogGroup","parameterTypes":["java.lang.String"] }, {"name":"setNvnmeStorageEnabled","parameterTypes":["java.lang.Boolean"] }, {"name":"setPostRunScript","parameterTypes":["java.lang.String"] }, {"name":"setPreRunScript","parameterTypes":["java.lang.String"] }, {"name":"setRegion","parameterTypes":["java.lang.String"] }, {"name":"setVolumes","parameterTypes":["java.util.List"] }, {"name":"setWaveEnabled","parameterTypes":["java.lang.Boolean"] }, {"name":"setWorkDir","parameterTypes":["java.lang.String"] }]
},
{
"name":"io.seqera.tower.model.AwsSecurityKeys",
Expand Down Expand Up @@ -2299,7 +2306,8 @@
{
"name":"io.seqera.tower.model.ComputeEnvStatus",
"allDeclaredFields":true,
"allDeclaredMethods":true
"allDeclaredMethods":true,
"methods":[{"name":"fromValue","parameterTypes":["java.lang.String"] }]
},
{
"name":"io.seqera.tower.model.ComputePlatformDto",
Expand Down Expand Up @@ -2556,7 +2564,8 @@
"name":"io.seqera.tower.model.DescribeComputeEnvResponse",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
"allDeclaredConstructors":true,
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"setComputeEnv","parameterTypes":["io.seqera.tower.model.ComputeEnvResponseDto"] }]
},
{
"name":"io.seqera.tower.model.DescribeCredentialsResponse",
Expand Down Expand Up @@ -3054,11 +3063,6 @@
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"io.seqera.tower.model.PipelineOptimizationStatus",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true
},
{
"name":"io.seqera.tower.model.PipelineSecret",
"allDeclaredFields":true,
Expand Down Expand Up @@ -3176,6 +3180,13 @@
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"io.seqera.tower.model.UpdateComputeEnvRequest",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"getName","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.model.UpdateCredentialsRequest",
"allDeclaredFields":true,
Expand Down
53 changes: 26 additions & 27 deletions conf/resource-config.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
{
"resources":{
"includes":[
{
"pattern":"\\QMETA-INF/build-info.properties\\E"
},
{
"pattern":"\\QMETA-INF/services/org.glassfish.hk2.extension.ServiceLocatorGenerator\\E"
},
{
"pattern":"\\QMETA-INF/services/org.glassfish.jersey.internal.inject.InjectionManagerFactory\\E"
},
{
"pattern":"\\QMETA-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable\\E"
}
]},
"bundles":[
{
"name":"org.glassfish.jersey.client.internal.localization",
"locales":["und"]
},
{
"name":"org.glassfish.jersey.internal.localization",
"locales":["und"]
},
{
"name":"org.glassfish.jersey.media.multipart.internal.localization"
}
]
"includes":[{
"pattern":"\\QMETA-INF/build-info.properties\\E"
}, {
"pattern":"\\QMETA-INF/services/org.glassfish.hk2.extension.ServiceLocatorGenerator\\E"
}, {
"pattern":"\\QMETA-INF/services/org.glassfish.jersey.internal.inject.InjectionManagerFactory\\E"
}, {
"pattern":"\\QMETA-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable\\E"
}, {
"pattern":"java.base:\\Qjdk/internal/icu/impl/data/icudt67b/nfkc.nrm\\E"
}, {
"pattern":"java.base:\\Qjdk/internal/icu/impl/data/icudt67b/uprops.icu\\E"
}, {
"pattern":"java.base:\\Qsun/net/idn/uidna.spp\\E"
}, {
"pattern":"java.base:\\Qsun/text/resources/LineBreakIteratorData\\E"
}]},
"bundles":[{
"name":"org.glassfish.jersey.client.internal.localization",
"locales":["", "und"]
}, {
"name":"org.glassfish.jersey.internal.localization",
"locales":["", "und"]
}, {
"name":"org.glassfish.jersey.media.multipart.internal.localization"
}]
}
10 changes: 8 additions & 2 deletions conf/serialization-config.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
[
]
{
"types":[
],
"lambdaCapturingTypes":[
],
"proxies":[
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.seqera.tower.cli.commands.computeenvs.ImportCmd;
import io.seqera.tower.cli.commands.computeenvs.ListCmd;
import io.seqera.tower.cli.commands.computeenvs.PrimaryCmd;
import io.seqera.tower.cli.commands.computeenvs.UpdateCmd;
import io.seqera.tower.cli.commands.computeenvs.ViewCmd;
import picocli.CommandLine.Command;

Expand All @@ -26,6 +27,7 @@
description = "Manage workspace compute environments.",
subcommands = {
AddCmd.class,
UpdateCmd.class,
DeleteCmd.class,
ViewCmd.class,
ListCmd.class,
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/actions/UpdateCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.seqera.tower.ApiException;
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
import io.seqera.tower.cli.commands.pipelines.LaunchOptions;
import io.seqera.tower.cli.exceptions.InvalidResponseException;
import io.seqera.tower.cli.exceptions.TowerException;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.actions.ActionUpdate;
Expand All @@ -38,6 +39,9 @@ public class UpdateCmd extends AbstractActionsCmd {
@CommandLine.Option(names = {"-s", "--status"}, description = "Action status (pause or active).")
public String status;

@CommandLine.Option(names = {"--new-name"}, description = "Action new name.")
public String newName;

@CommandLine.Mixin
public WorkspaceOptionalOptions workspace;

Expand All @@ -50,6 +54,15 @@ protected Response exec() throws ApiException, IOException {
ActionResponseDto action = fetchDescribeActionResponse(actionRefOptions, wspId).getAction();
String actionName = action.getName();

// Validate new action name if any
if (newName != null) {
try {
api().validateActionName(wspId, newName);
} catch (ApiException ex) {
throw new InvalidResponseException(String.format("Action name '%s' is not valid", newName));
}
}

// Retrieve the provided computeEnv or use the primary if not provided
String ceId = opts.computeEnv != null ? computeEnvByRef(wspId, opts.computeEnv).getId() : action.getLaunch().getComputeEnv().getId();

Expand Down Expand Up @@ -78,6 +91,7 @@ protected Response exec() throws ApiException, IOException {
.entryName(opts.entryName);

UpdateActionRequest request = new UpdateActionRequest();
request.setName(newName != null ? newName : actionName);
request.setLaunch(workflowLaunchRequest);

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.cli.commands.computeenvs;

import io.seqera.tower.ApiException;
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
import io.seqera.tower.cli.exceptions.ComputeEnvNotFoundException;
import io.seqera.tower.cli.exceptions.InvalidResponseException;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.computeenvs.ComputeEnvUpdated;
import io.seqera.tower.model.ComputeEnvResponseDto;
import io.seqera.tower.model.UpdateComputeEnvRequest;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
import picocli.CommandLine.Option;

import java.io.IOException;

@Command(
name = "update",
description = "Update compute environments."
)
public class UpdateCmd extends AbstractComputeEnvCmd {

@Mixin
public ComputeEnvRefOptions computeEnvRefOptions;

@Mixin
public WorkspaceOptionalOptions workspace;

@Option(names = {"--new-name"}, description = "Compute environment new name.")
public String newName;

@Override
protected Response exec() throws ApiException, IOException {
Long wspId = workspaceId(workspace.workspace);

if (newName != null) {
try {
api().validateComputeEnvName(wspId, newName);
} catch (ApiException ex) {
throw new InvalidResponseException(String.format("Compute environment name '%s' is not valid", newName));
}
}
ComputeEnvResponseDto ce = describeCE(computeEnvRefOptions, wspId);


UpdateComputeEnvRequest req = new UpdateComputeEnvRequest()
.name(newName != null ? newName : ce.getName());

api().updateComputeEnv(ce.getId(), req, wspId);


return new ComputeEnvUpdated(workspaceRef(wspId), ce.getName());

}

private ComputeEnvResponseDto describeCE(ComputeEnvRefOptions computeEnvRefOptions, Long wspId) throws ComputeEnvNotFoundException, ApiException {
try {
return fetchComputeEnv(computeEnvRefOptions, wspId);

} catch (ApiException e) {
if (e.getCode() == 403) {
String ref = computeEnvRefOptions.computeEnv.computeEnvId != null
? computeEnvRefOptions.computeEnv.computeEnvId
: computeEnvRefOptions.computeEnv.computeEnvName;
// Customize the forbidden message
throw new ComputeEnvNotFoundException(ref, workspaceRef(wspId));
}

throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class UpdateCmd extends AbstractOrganizationsCmd {
@CommandLine.Mixin
OrganizationRefOptions organizationRefOptions;

@CommandLine.Option(names = {"--new-name"}, description = "Organization new name.")
public String newName;

@CommandLine.Option(names = {"-f", "--full-name"}, description = "Organization full name.")
public String fullName;

Expand All @@ -43,6 +46,7 @@ protected Response exec() throws ApiException, IOException {
OrganizationDbDto organization = response.getOrganization();

UpdateOrganizationRequest request = new UpdateOrganizationRequest();
request.setName(newName != null ? newName : organization.getName());
request.setFullName(fullName != null ? fullName : organization.getFullName());
request.setDescription(opts.description != null ? opts.description : organization.getDescription());
request.setLocation(opts.location != null ? opts.location : organization.getLocation());
Expand Down
Loading

0 comments on commit df3870c

Please sign in to comment.