Skip to content

Commit

Permalink
Precompute "safe" application name
Browse files Browse the repository at this point in the history
Change `app.getName()` to return a string suitable to use as a filename.
The app name as written by the user is accessible via
`app.getRawName()`.

Fixes #33
  • Loading branch information
rudi committed Oct 21, 2024
1 parent ec17c08 commit 0110dd8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static List<String> getMetricList(NebulousApp app) {
public static String generateAMPL(NebulousApp app, JsonNode kubevela) {
final StringWriter result = new StringWriter();
final PrintWriter out = new PrintWriter(result);
out.format("# AMPL file for application '%s' with id %s%n", app.getName(), app.getUUID());
out.format("# AMPL file for application '%s' with id %s%n", app.getRawName(), app.getUUID());
out.println();

generateVariablesSection(app, kubevela, out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ public class NebulousApp {
private String UUID;
/**
* The app name, a user-readable string. Not safe to assume that this is
* a unique value.
* a unique value. Might contain whitespace, unicode and everything else
* a user can type into a form.
*/
@Getter private String rawName;

/**
* A version of the app name that is safe to use as a filename.
*/
@Getter private String name;

Expand Down Expand Up @@ -218,7 +224,8 @@ public enum State {
// optimiser-controller/src/test/resources/
public NebulousApp(JsonNode app_message, String kubevela_string, ExnConnector exnConnector) {
this.UUID = app_message.at(uuid_path).textValue();
this.name = app_message.at(name_path).textValue();
this.rawName = app_message.at(name_path).textValue();
this.name = rawName.replaceAll("[^a-zA-Z0-9-_]", "_");
this.state = State.NEW;
this.clusterName = NebulousApps.calculateUniqueClusterName(this.UUID);
this.originalAppMessage = app_message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,9 @@ public static void deployApplication(NebulousApp app, JsonNode kubevela) {
app.setStateFailed();
return;
}
// The application name is typed in by the user, and is used
// internally by SAL as an unquoted filename in a generated shell
// script. It shouldn't be this way but it is what it is.
String safeAppName = app.getName().replaceAll("[^a-zA-Z0-9-_]", "_");
ExnConnector conn = app.getExnConnector();
log.info("Starting initial deployment for application");


// The overall flow:
//
// - Extract node requirements and node counts from the KubeVela
Expand Down Expand Up @@ -621,7 +616,7 @@ public static void deployApplication(NebulousApp app, JsonNode kubevela) {
// Deploy application

log.info("Calling deployApplication");
long proActiveJobID = conn.deployApplication(appUUID, clusterName, safeAppName, rewritten_kubevela);
long proActiveJobID = conn.deployApplication(appUUID, clusterName, app.getName(), rewritten_kubevela);
log.info("deployApplication returned ProActive Job ID {}", proActiveJobID);
if (proActiveJobID == 0) {
// 0 means conversion from long has failed (because of an invalid
Expand Down

0 comments on commit 0110dd8

Please sign in to comment.