diff options
Diffstat (limited to 'cmso-optimizer/src')
4 files changed, 53 insertions, 32 deletions
diff --git a/cmso-optimizer/src/main/docker/Dockerfile b/cmso-optimizer/src/main/docker/Dockerfile index 9ef42ab..fde2caf 100644 --- a/cmso-optimizer/src/main/docker/Dockerfile +++ b/cmso-optimizer/src/main/docker/Dockerfile @@ -10,10 +10,26 @@ ENV HTTPS_PROXY=$https_proxy ENV http_proxy=$HTTP_PROXY ENV https_proxy=$HTTPS_PROXY +ENV MZN 2.2.3 +ENV MZN_BASENAME MiniZincIDE-${MZN}-bundle-linux-x86_64 +ENV MZN_UNZIPNAME MiniZincIDE-${MZN}-bundle-linux +ENV MZN_GH_BASE https://github.com/MiniZinc/MiniZincIDE +ENV MZN_DL_URL ${MZN_GH_BASE}/releases/download/${MZN}/${MZN_BASENAME}.tgz + RUN test -n "$http_proxy" && echo "Acquire::Proxy \"http://$http_proxy\";" > /etc/apt/apt.conf.d/02proxy || true && \ apt-get update && \ apt-get -y dist-upgrade && \ - apt-get install -y openjdk-8-jre-headless + apt-get install -y openjdk-8-jre-headless && \ + apt-get install wget + + +# Minizinc +RUN wget -q $MZN_DL_URL -O mz.tgz +RUN tar xzf mz.tgz +RUN mv $MZN_UNZIPNAME /mz-dist +RUN rm mz.tgz +RUN echo PATH=/mz-dist:$PATH >> ~/.bashrc + COPY onap-cmso-optimizer/cmso-optimizer.jar ${APP_HOME}/app.jar @@ -23,6 +39,7 @@ VOLUME /share/debug-logs COPY onap-cmso-optimizer/startService.sh ${APP_HOME}/startService.sh COPY onap-cmso-optimizer/data ${APP_HOME}/data +COPY onap-cmso-optimizer/scripts ${APP_HOME}/scripts RUN chmod 700 ${APP_HOME}/startService.sh RUN ln -s /share/etc ${APP_HOME}/etc diff --git a/cmso-optimizer/src/main/docker/assembly/cmso-files.xml b/cmso-optimizer/src/main/docker/assembly/cmso-files.xml index 2e3f19e..cf96a35 100644 --- a/cmso-optimizer/src/main/docker/assembly/cmso-files.xml +++ b/cmso-optimizer/src/main/docker/assembly/cmso-files.xml @@ -44,6 +44,13 @@ <outputDirectory>/data</outputDirectory> </fileSet> <fileSet> + <includes> + <include>**</include> + </includes> + <directory>scripts</directory> + <outputDirectory>/scripts</outputDirectory> + </fileSet> + <fileSet> <directory>${project.basedir}/src/main/resources</directory> <outputDirectory>./resources</outputDirectory> <includes> 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; } + + } |