aboutsummaryrefslogtreecommitdiffstats
path: root/cmso-optimizer/src/main/java
diff options
context:
space:
mode:
authorJerry Flood <jflood@att.com>2019-04-05 12:23:07 -0400
committerJerry Flood <jflood@att.com>2019-04-05 12:23:16 -0400
commit26b84388ba3eb179f9d4a9d4e2d478eba3df8201 (patch)
treeb121fb1f29c0fa07774784dce68aada4ba55a9dd /cmso-optimizer/src/main/java
parentb775e3842710fe1190675d318a0526b8dfb8eead (diff)
Integrate new mS into IT
Issue-ID: OPTFRA-458 Change-Id: I42966034101baa54c1b60e07b74c17d97680da81 Signed-off-by: Jerry Flood <jflood@att.com>
Diffstat (limited to 'cmso-optimizer/src/main/java')
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/OptimizerClient.java57
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/HealthCheckImpl.java2
2 files changed, 28 insertions, 31 deletions
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/OptimizerClient.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/OptimizerClient.java
index 3147bc5..9f2f8e6 100644
--- a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/OptimizerClient.java
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/OptimizerClient.java
@@ -32,7 +32,9 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.ParseException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
import org.onap.observations.Observation;
@@ -206,22 +208,22 @@ public class OptimizerClient {
workingFolder.mkdirs();
Long timeLimit = env.getProperty("cmso.minizinc.command.timelimit", Long.class);
// TODO calculate time limit
- Process p = null;
+ Process process = null;
try {
Path inputFileName = Paths.get(workingFolder.getAbsolutePath(), "input.dzn");
Path outputFileName = Paths.get(workingFolder.getAbsolutePath(), "results.yaml");
String dzn = request.toMiniZinc();
Files.write(inputFileName, dzn.getBytes());
- List<String> command = buildCommand(inputFileName, outputFileName, timeLimit.toString());
- debug.debug("engine command=", command.toString());
- ProcessBuilder pb = new ProcessBuilder(command);
- p = pb.start();
- String stdout = IOUtils.toString(p.getInputStream(), "UTF-8");
- String stderr = IOUtils.toString(p.getErrorStream(), "UTF-8");
+ Map<String, String> environment = new HashMap<>();
+ ProcessBuilder processBuilder = buildCommand(inputFileName, outputFileName, timeLimit.toString());
+ process = processBuilder.start();
+ //debug.debug("engine command=" + commandString);
+ String stdout = IOUtils.toString(process.getInputStream(), "UTF-8");
+ String stderr = IOUtils.toString(process.getErrorStream(), "UTF-8");
debug.debug("stdout=" + stdout);
debug.debug("stderr=" + stderr);
- if (p.isAlive()) {
- p.wait();
+ if (process.isAlive()) {
+ process.wait();
}
OptimizerResponseUtility responseUtility = new OptimizerResponseUtility();
OptimizerResults optimizerResults = responseUtility.parseOptimizerResult(outputFileName.toFile());
@@ -233,7 +235,7 @@ public class OptimizerClient {
apiResponse.setErrorMessage(
LogMessages.OPTIMIZER_REQUEST_TIMEOUT.format(uuid.toString(), timeLimit.toString()));
Observation.report(LogMessages.OPTIMIZER_REQUEST_TIMEOUT, uuid.toString(), timeLimit.toString());
- p.destroyForcibly();
+ process.destroyForcibly();
} catch (Exception e) {
apiResponse.setStatus(OptimizerEngineResponseStatus.FAILED);
apiResponse.setErrorMessage(LogMessages.UNEXPECTED_EXCEPTION.format(e.getMessage()));
@@ -246,32 +248,25 @@ public class OptimizerClient {
return apiResponse;
}
- private List<String> buildCommand(Path inputFileName, Path outputFileName, String timeLimit) {
+ private ProcessBuilder buildCommand(Path inputFileName, Path outputFileName, String timeLimit) {
+ ProcessBuilder processBuilder = new ProcessBuilder();
List<String> command = new ArrayList<>();
+ String commandline = env.getProperty("cmso.minizinc.command.commandline", "/bin/bash -x scripts/minizinc/run.sh");
String minizinc = env.getProperty("cmso.minizinc.command.exe", "minizinc");
String solver = env.getProperty("cmso.minizinc.command.solver", "OSICBC");
- String additional = env.getProperty("cmso.minizinc.command.additional", "");
String script = env.getProperty("cmso.minizinc.command.mzn", "scripts/minizinc/generic_attributes.mzn");
-
- command.add(minizinc);
- command.add("--solver");
- command.add(solver);
- command.add("--time-limit");
- command.add(timeLimit);
- command.add("--time-limit");
- command.add(timeLimit);
- command.add("--soln-sep");
- command.add("\"\"");
- command.add("--search-complete-msg");
- command.add("\"\"");
- for (String add : additional.split(" ")) {
- command.add(add);
+ Map<String, String> environment = processBuilder.environment();
+ environment.put("MINIZINC", minizinc);
+ environment.put("MINIZINC_SOLVER", solver);
+ environment.put("MINIZINC_TIMELIMIT", timeLimit);
+ environment.put("MINIZINC_OUTPUT", outputFileName.toString());
+ environment.put("MINIZINC_MZN", script);
+ environment.put("MINIZINC_DZN", inputFileName.toString());
+ for (String arg : commandline.split(" ")) {
+ command.add(arg);
}
- command.add("-o");
- command.add(outputFileName.toString());
- command.add(script);
- command.add(inputFileName.toString());
- return command;
+ processBuilder.command(command);
+ return processBuilder;
}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/HealthCheckImpl.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/HealthCheckImpl.java
index 80deaaf..bc7ce52 100644
--- a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/HealthCheckImpl.java
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/HealthCheckImpl.java
@@ -103,4 +103,6 @@ public class HealthCheckImpl implements HealthCheck {
return hcc;
}
+
+
}