Skip to content

Commit

Permalink
Merge pull request #4 from sanctuuary/cwl_input_yml
Browse files Browse the repository at this point in the history
Cwl input yml
  • Loading branch information
kretep committed Sep 7, 2023
2 parents 5be389b + 3e19005 commit e614dee
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 150 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:17-jdk-jammy
WORKDIR /app
COPY restape-0.2.2.jar /app
ENTRYPOINT ["java", "-jar", "restape-0.2.2.jar"]
COPY restape-0.2.4.jar /app
ENTRYPOINT ["java", "-jar", "restape-0.2.4.jar"]
38 changes: 22 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>nl.esciencecenter</groupId>
<artifactId>restape</artifactId>
<version>0.2.2</version>
<version>0.2.4</version>
<name>restape</name>
<description>RESTful API for the APE library</description>
<licenses>
Expand Down Expand Up @@ -41,6 +41,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.1.2</version>
</dependency>

<dependency>
Expand All @@ -58,25 +59,43 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>3.1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>3.1.0</version>
<version>3.1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>3.1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>3.1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.220</version>
<scope>runtime</scope>
</dependency>


<dependency>
<groupId>io.github.sanctuuary</groupId>
<artifactId>APE</artifactId>
<version>2.1.5</version>
<version>2.1.8</version>
</dependency>

<dependency>
Expand All @@ -92,26 +111,13 @@
<version>22.3.2</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>


</dependencies>

<build>
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/nl/esciencecenter/RestapeApplication.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package nl.esciencecenter;

import java.util.Arrays;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.servers.Server;

@SpringBootApplication
@OpenAPIDefinition(info = @Info(title = "RestApe API", version = "0.0.1", description = "RESTfull API for the APE (Automated Pipeline Explorer) library."), servers = @Server(url = "http://localhost:8080", description = "Local server"))
@OpenAPIDefinition(info = @Info(title = "RestApe API", version = "0.0.1", description = "RESTfull API for the APE (Automated Pipeline Explorer) library."), servers = @Server(url = "http://localhost:4444", description = "Local server"))
public class RestapeApplication {

public static void main(String[] args) {
Expand Down
162 changes: 115 additions & 47 deletions src/main/java/nl/esciencecenter/controller/RestApeController.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
package nl.esciencecenter.models.documentation;

import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

/**
* This class represents a single constraint template.
* TODO: This class is not used at the moment, but it is a good idea to use it
* in the future.
*
*/
@NoArgsConstructor
@AllArgsConstructor
public class ConstraintElem {
public String id;
public String label;
public TaxonomyElem[] subsets;
public ConstraintParam[] parameters;

public ConstraintElem() {
}
}

class ConstraintParam {
public String dimension1Root;
public String dimension2Root;
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package nl.esciencecenter.models.documentation;

import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

/**
* This class represents a single element of the taxonomy.
* TODO: This class is not used at the moment, but it is a good idea to use it
* in the future.
*
*/
@NoArgsConstructor
@AllArgsConstructor
public class TaxonomyElem {
public String constraintID;
public String description;
public Map[] parameters;

public TaxonomyElem() {
}
public String id;
public String label;
public String root;
public TaxonomyElem[] subsets;
}
52 changes: 26 additions & 26 deletions src/main/java/nl/esciencecenter/restape/ApeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ private static JSONObject getPredicates(TaxonomyPredicate currType, AllPredicate
}
objType.put("id", currType.getPredicateID());
objType.put("label", currType.getPredicateLabel());
objType.put("root", currType.getRootNodeID());
if (arrayTypes.length() > 0) {
objType.put("subsets", arrayTypes);
}
Expand Down Expand Up @@ -144,56 +145,55 @@ public static JSONArray getConstraints(String configFileURL) throws OWLOntologyC
*
* @param configJson - configuration of the synthesis run
* @return - JSONArray with the results of the synthesis, each element describes
* a workflow
* a workflow solution (name,length, runID, etc.).
* @throws IOException
* @throws OWLOntologyCreationException
*/
public static JSONArray runSynthesis(JSONObject configJson) throws OWLOntologyCreationException, IOException {
JSONArray generatedSolutions = new JSONArray();
APE apeFramework = null;

// set up the APE framework
apeFramework = new APE(configJson);


String runID = RestApeUtils.generateUniqueString(configJson.toString());
String solutionPath = RestApeUtils.createDirectory(runID);

SolutionsList solutions;
// configJson = IOUtils.extractConstraintsFromApeConfig(configJson);
// set up the APE framework
apeFramework = new APE(configJson);

APERunConfig runConfig = new APERunConfig(configJson, apeFramework.getDomainSetup());

runConfig.setSolutionPath(solutionPath);
int maxSol = runConfig.getMaxNoSolutions();
runConfig.setNoCWL(maxSol);
runConfig.setNoGraphs(maxSol);
runConfig.setDebugMode(true);
// run the synthesis and retrieve the solutions
solutions = apeFramework.runSynthesis(runConfig);
SolutionsList solutions = apeFramework.runSynthesis(runConfig);

/*
* Writing solutions to the specified file in human readable format
*/
if (solutions.isEmpty()) {
return new JSONArray("The given problem is UNSAT");
return new JSONArray();
} else {
// Write solutions to the file system.
APE.writeDataFlowGraphs(solutions, RankDir.TOP_TO_BOTTOM);
APE.writeCWLWorkflows(solutions);

// Generate objects that return the solutions in JSON format
int noSolutions = solutions.getNumberOfSolutions();
for (int i = 0; i < noSolutions; i++) {
SolutionWorkflow sol = solutions.get(i);
JSONObject solJson = new JSONObject();
solJson.put("name", sol.getFileName());
solJson.put("workflow_length", sol.getSolutionLength());
solJson.put("cwl_name", sol.getFileName() + ".cwl");
solJson.put("figure_name", sol.getFileName() + ".png");
solJson.put("run_id", runID);

generatedSolutions.put(solJson);
}
return generatedSolutions;
// Write solutions to the file system.
APE.writeDataFlowGraphs(solutions, RankDir.TOP_TO_BOTTOM);
APE.writeCWLWorkflows(solutions);

// Generate objects that return the solutions in JSON format
int noSolutions = solutions.getNumberOfSolutions();
for (int i = 0; i < noSolutions; i++) {
SolutionWorkflow sol = solutions.get(i);
JSONObject solJson = new JSONObject();
solJson.put("name", sol.getFileName());
solJson.put("workflow_length", sol.getSolutionLength());
solJson.put("cwl_name", sol.getFileName() + ".cwl");
solJson.put("figure_name", sol.getFileName() + ".png");
solJson.put("run_id", runID);

generatedSolutions.put(solJson);
}
return generatedSolutions;
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/nl/esciencecenter/restape/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;

import javax.imageio.ImageIO;

import org.apache.commons.io.FileUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import nl.uu.cs.ape.io.APEFiles;

public class IOUtils {


/**
* Get byte array that represents the image from the file system at the given path.
* Get byte array that represents the image from the file system at the given
* path.
*
* @param filePath - path to the image
* @return byte array that represents the image
* @throws IOException - if the image cannot be read
Expand All @@ -36,11 +45,13 @@ public static byte[] getImageFromFileSystem(Path filePath) throws IOException {

/**
* Get the CWL content of the file at the given path.
*
* @param filePath - path to the CWL file
* @return CWL content of the file representing a workflow
* @throws IOException - if the file cannot be read
*/
public static String getLocalCwlFile(Path filePath) throws IOException {
return FileUtils.readFileToString(filePath.toFile(), StandardCharsets.UTF_8);
}

}

0 comments on commit e614dee

Please sign in to comment.