@@ -11,8 +11,8 @@ |
import static csip.annotations.ResourceType.*; |
import csip.utils.Binaries; |
import java.io.File; |
+import java.io.FilenameFilter; |
import java.io.IOException; |
-import java.util.ArrayList; |
import java.util.Arrays; |
import java.util.HashMap; |
import java.util.List; |
@@ -20,6 +20,8 @@ |
import javax.ws.rs.Path; |
import static m.oms.ages.V1_0.ID_AGES_JAR; |
import org.apache.commons.io.FileUtils; |
+import org.apache.commons.io.IOCase; |
+import org.apache.commons.io.filefilter.WildcardFileFilter; |
import org.apache.commons.lang.ArrayUtils; |
|
/** |
@@ -36,7 +38,6 @@ |
@Resource(file = "/bin/ages/ages-static.zip", type = ARCHIVE) |
@Resource(file = "java-*-std*.txt output/csip_run/out/*.csv", type = OUTPUT) |
@Resource(file = "${csip.dir}/bin/ages/simulation/ages.sim", type = REFERENCE, id = "ages.sim") |
- |
public class V1_0 extends ModelDataService { |
|
// parameter keys |
@@ -46,6 +47,8 @@ |
|
static final String ID_AGES_JAR = "ages.jar"; |
|
+ static final String RUN_INC = "run.inc"; |
+ |
|
@Override |
public void doProcess() throws Exception { |
@@ -71,41 +74,40 @@ |
private void createParamInclude(Map<String, String> p) throws IOException { |
StringBuilder b = new StringBuilder(); |
b.append("parameter {\n"); |
- for (String name : p.keySet()) { |
+ p.keySet().forEach((name) -> { |
b.append(" ").append(name).append(" ").append(p.get(name)).append("\n"); |
- } |
+ }); |
b.append("}\n"); |
- FileUtils.writeStringToFile(getWorkspaceFile("run.inc"), b.toString()); |
+ FileUtils.writeStringToFile(getWorkspaceFile(RUN_INC), b.toString()); |
} |
|
|
private void runAges(File dsl, String loglevel, String options) throws Exception { |
- Map sysprops = new HashMap(); |
- sysprops.put("oms_prj", getWorkspaceDir().toString()); |
- sysprops.put("csip_ages", resources().getFile(ID_AGES_JAR).getParent()); |
- sysprops.put("run_name", "olaf"); |
- |
- // Create a Process. |
- Executable p = createProcess(loglevel, dsl, sysprops, options); |
|
getWorkspaceFile("output").mkdirs(); |
getWorkspaceFile("logs").mkdirs(); |
|
+ // Create/execute a Ages. |
+ Executable p = createProcess(loglevel, dsl, options); |
int result = p.exec(); |
if (result != 0) { |
- File err = getWorkspaceFile("java-stderr.txt"); |
- if (err.exists()) { |
- throw new ServiceException(FileUtils.readFileToString(err)); |
+ FilenameFilter ff = new WildcardFileFilter("java*stderr.txt", IOCase.INSENSITIVE); |
+ File[] f = getWorkspaceDir().listFiles(ff); |
+ if (f != null && f.length > 0) { |
+ String err = FileUtils.readFileToString(f[0]); |
+ LOG.info("Ages execution error. " + f[0] + ":\n" + err); |
+ throw new ServiceException("Ages execution error. " + f[0] + ":\n" + err); |
} |
- throw new ServiceException("General Error." + result); |
+ throw new ServiceException("Ages execution error." + result); |
} |
} |
|
|
- private Executable createProcess(String loglevel, File dsl, |
- Map<String, String> sysprops, String options) throws Exception { |
+ private Executable createProcess(String loglevel, File dsl, String options) throws Exception { |
|
- List<File> jars = Arrays.asList(resources().getFile(ID_AGES_JAR)); |
+ Map<String, String> sysprops = new HashMap(); |
+ sysprops.put("oms_prj", getWorkspaceDir().toString()); |
+ sysprops.put("csip_ages", resources().getFile(ID_AGES_JAR).getParent()); |
|
String[] jvmOptions = Binaries.asSysProps(sysprops); |
if (options != null && !options.isEmpty()) { |
@@ -113,6 +115,7 @@ |
jvmOptions = (String[]) ArrayUtils.addAll(jvmOptions, opt); |
} |
|
+ List<File> jars = Arrays.asList(resources().getFile(ID_AGES_JAR)); |
// java -Doms_prj=. -cp "dist/AgES.jar" oms3.CLI -l OFF -r "projects/sfir30/simulation/sfir30.sim" |
return Binaries.getResourceOMSDSL(dsl, |
jvmOptions, getWorkspaceDir(), jars, loglevel, LOG); |