Skip to content

Commit

Permalink
Fixes #300 - Add ability to create a job using REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem committed Jul 12, 2024
1 parent a4a4fa5 commit 1341b04
Show file tree
Hide file tree
Showing 14 changed files with 565 additions and 225 deletions.
20 changes: 0 additions & 20 deletions api/src/main/webapp/WEB-INF/web.xml

This file was deleted.

19 changes: 9 additions & 10 deletions cli/src/main/java/com/manorrock/sphynx/cli/CreateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public class CreateCommand implements Callable<Integer> {
*/
@Option(names = "--base-directory", description = "The base directory used for storage")
protected File baseDirectory = new File(System.getProperty("user.home") + "/.manorrock/sphynx");

/**
* Stores the name.
*/
@Option(names = "--name", description = "The name of the job")
protected String name;

/**
* Stores the script.
*/
Expand All @@ -80,15 +80,15 @@ public class CreateCommand implements Callable<Integer> {
public Integer call() throws Exception {
/*
* Step 1 - determine name.
*/
*/
LOGGER.log(DEBUG, "Determining name of the job");
if (name == null || name.trim().equals("")) {
LOGGER.log(TRACE, "No name specified");
LOGGER.log(TRACE, "Generating name");
name = UUID.randomUUID().toString();
}
LOGGER.log(INFO, "Using name: " + name);

/*
* Step 2 - determine script.
*/
Expand All @@ -99,7 +99,7 @@ public Integer call() throws Exception {
script = "";
}
LOGGER.log(INFO, "Using script: " + script);

/*
* Step 3 - create directory structure.
*/
Expand Down Expand Up @@ -130,7 +130,7 @@ public Integer call() throws Exception {
return 5;
}
}
File executionsDirectory = new File (jobDirectory, "executions");
File executionsDirectory = new File(jobDirectory, "executions");
if (executionsDirectory.exists()) {
LOGGER.log(ERROR, "Unable to create job executions directory as it already exists");
return 6;
Expand All @@ -141,10 +141,10 @@ public Integer call() throws Exception {
}
}
LOGGER.log(INFO, "Created directory structure at: " + jobDirectory);

/*
* Step 4 - copy script into directory structure.
*/
*/
File scriptFilename = new File(jobDirectory, "script" + File.separator + "run.sh");
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
scriptFilename = new File(jobDirectory, "script" + File.separator + "run.cmd");
Expand All @@ -157,8 +157,7 @@ public Integer call() throws Exception {
}
try {
Files.write(scriptFilename.toPath(), script.getBytes());
}
catch (IOException ioe) {
} catch (IOException ioe) {
LOGGER.log(ERROR, "Unable to write script to file");
return 9;
}
Expand Down
Loading

0 comments on commit 1341b04

Please sign in to comment.