Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.beust.jcommander.Parameter;
import java.io.PrintStream;
import java.io.Serializable;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -32,7 +33,7 @@ public class BenchmarkConfiguration implements Serializable {

/** */
@Parameter(names = {"-cfg", "--config"}, description = "Framework configuration file path")
private String propsFileName = "config/benchmark.properties";
private String propsFileName = Paths.get("config", "benchmark.properties").toString();

/** For internal use. Should not be used in configs. */
@Parameter(names = {"--logsFolder"}, description = "Logs directory")
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/org/yardstickframework/BenchmarkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand All @@ -44,13 +45,16 @@ public class BenchmarkUtils {
public static final String WEIGHT_DELIMITER = ":";

/** Indicates whether current OS is Windows. */
private static boolean isWin;
private static final boolean isWin;

private static final String javaExecutable;

/**
* Initializes statics.
*/
static {
isWin = System.getProperty("os.name").toLowerCase().contains("win");
javaExecutable = isWin ? "java.exe" : "java";
}

/**
Expand All @@ -73,6 +77,30 @@ public static JCommander jcommander(String[] a, Object args, String programName)
return jCommander;
}

/**
* Get OS specific path to java
*
* @return system JAVA_HOME/bin/java
*/
public static String getJava() {
String javaHome = System.getProperty("java.home");

return getJava(javaHome);
}

/**
* Get OS specific path to java with defined JAVA_HOME
*
* @return system JAVA_HOME/bin/java
*/
public static String getJava(String javaHome) {
// safely remove " from JAVA_HOME path
javaHome = javaHome.replace("\"", "");

return Paths.get(javaHome, "bin", javaExecutable).toString();
}


/**
* Prints usage string to output.
*
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/org/yardstickframework/runners/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -32,6 +33,8 @@
import org.yardstickframework.runners.context.RunContext;
import org.yardstickframework.runners.context.RunMode;

import static org.yardstickframework.BenchmarkUtils.getJava;

/**
* Command handler.
*/
Expand Down Expand Up @@ -491,9 +494,7 @@ public CommandExecutionResult runLocalJava(String args) {
while (args.contains(" "))
args = args.replace(" ", " ");

String javaHome = System.getProperty("java.home");

String cmd = String.format("%s/bin/java %s", javaHome, args);
String cmd = String.format("%s %s", getJava(), args);

String[] cmdArr = cmd.split(" ");

Expand Down Expand Up @@ -558,10 +559,7 @@ public CommandExecutionResult runDockerCmd(String host, String cmd) throws IOExc
String fullCmd = String.format("docker %s", cmd);

if (isLocal(host)) {
if(fullCmd.endsWith("'echo $JAVA_HOME'") || fullCmd.contains(">"))
return runLocCmd(fullCmd);
else
return runRmtCmd(fullCmd);
return fullCmd.endsWith("'echo $JAVA_HOME'") || fullCmd.contains(">") ? runLocCmd(fullCmd) : runRmtCmd(fullCmd);
}
else {
fullCmd = String.format("%s docker %s", getFullSSHPref(host), cmd);
Expand All @@ -575,7 +573,7 @@ public CommandExecutionResult runDockerCmd(String host, String cmd) throws IOExc
* @return {@code true} if host address is "localhost" or "127.0.0.1" or {@code false} otherwise.
*/
private boolean isLocal(String host) {
return host.equalsIgnoreCase("localhost") || host.equals("127.0.0.1");
return "localhost".equalsIgnoreCase(host) || "127.0.0.1".equals(host);
}

/**
Expand Down Expand Up @@ -641,7 +639,7 @@ public boolean checkConn(String host) {
return res != null
&& res.exitCode() == 0
&& !res.outputList().isEmpty()
&& res.outputList().get(0).equals("check");
&& "check".equals(res.outputList().get(0));
}

/**
Expand All @@ -651,9 +649,9 @@ public boolean checkConn(String host) {
*/
public boolean checkJava(String host, String javaHome) {
if (isLocal(host))
return new File(javaHome + "/bin/java").exists();
return new File(getJava(javaHome)).exists();

String checkCmd = String.format("%s test -f %s/bin/java", getFullSSHPref(host), javaHome);
String checkCmd = String.format("%s test -f %s", getFullSSHPref(host), getJava(javaHome));

CommandExecutionResult res = null;

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/yardstickframework/runners/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Set;
import java.util.List;
Expand Down Expand Up @@ -274,11 +275,17 @@ protected Logger log() {
*
*/
private void createCharts() {
String mainResDir = String.format("%s/output/result-%s", runCtx.localeWorkDirectory(), runCtx.mainDateTime());
String mainResDir = Paths.get(runCtx.localeWorkDirectory(),
" output",
String.format("result-%s", runCtx.mainDateTime())
).toString();

log().info(String.format("Creating charts for result directory '%s'.", mainResDir));

String cp = String.format("%s/libs/*", runCtx.localeWorkDirectory());
String cp = String.format("%s%s%s",
Paths.get(runCtx.localeWorkDirectory(), "libs").toString(),
File.separator,
"*");

String mainCls = "org.yardstickframework.report.jfreechart.JFreeChartGraphPlotter";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.yardstickframework.runners.context;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
Expand Down Expand Up @@ -267,7 +268,7 @@ public String description(String src) {
*/
public String resolveRemotePath(String srcPath) {
if (!srcPath.startsWith(remWorkDir))
return String.format("%s/%s", remWorkDir, srcPath);
return Paths.get(remWorkDir, srcPath).toString();

return srcPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.net.SocketException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -40,6 +41,8 @@
import org.yardstickframework.BenchmarkConfiguration;
import org.yardstickframework.BenchmarkUtils;

import static org.yardstickframework.BenchmarkUtils.getJava;

/**
* Initializes run context.
*/
Expand Down Expand Up @@ -138,7 +141,7 @@ private boolean handleArgs(String[] args) {
LOG.debug(String.format("Locale work directory is '%s'.", ctx.localeWorkDirectory()));

if (ctx.config().propertyFile() == null) {
String dfltPropPath = String.format("%s/config/benchmark.properties", ctx.localeWorkDirectory());
String dfltPropPath = Paths.get(ctx.localeWorkDirectory(), "config", "benchmark.properties").toString();

LOG.info(String.format("Using as a default property file '%s'.", dfltPropPath));

Expand Down Expand Up @@ -438,8 +441,9 @@ private void setJavaHome() {

String locJavaHome = System.getProperty("java.home");

if (ctx.properties().getProperty("JAVA_HOME") != null && new File(String.format("%s/bin/java", remJavaHome)).exists())
locJavaHome = String.format("%s/bin/java", remJavaHome);
// TODO: 3/14/2019 locaJavaHome may be direct link to JAVA_HOME/bin/java
if (ctx.properties().getProperty("JAVA_HOME") != null && new File(getJava(remJavaHome)).exists())
locJavaHome = getJava(remJavaHome);

ctx.localeJavaHome(locJavaHome);

Expand Down Expand Up @@ -559,8 +563,7 @@ private List<String> hostsToList(String commaSepList) {

String[] ips = commaSepList.split(",");

for (String ip : ips)
res.add(ip);
Collections.addAll(res, ips);

return res;
}
Expand All @@ -572,7 +575,11 @@ private void setDockerContext() {
String dockerCtxPropPath;

if (ctx.properties().getProperty("DOCKER_CONTEXT_PATH") == null) {
dockerCtxPropPath = String.format("%s/config/docker/docker-context-default.yaml", ctx.localeWorkDirectory());
dockerCtxPropPath = Paths.get(ctx.localeWorkDirectory(),
"config",
"docker",
"docker-context-default.yaml"
).toString();

LOG.info("'DOCKER_CONTEXT_PATH' is not defined in property file. Will " +
"use default docker context configuration:");
Expand Down Expand Up @@ -609,7 +616,7 @@ private String resolvePath(String srcPath) {
String fullPath = null;

if(!srcPath.startsWith(ctx.localeWorkDirectory()))
fullPath = String.format("%s/%s", ctx.localeWorkDirectory(), srcPath);
fullPath = Paths.get(ctx.localeWorkDirectory(), srcPath).toString();

if (new File(fullPath).exists())
return fullPath;
Expand Down Expand Up @@ -643,7 +650,7 @@ private boolean checkPropertyFile() throws IOException {
if (!line.contains("=") || line.startsWith("#") || prevLine.contains("\\"))
continue;

int idx0 = line.indexOf("=");
int idx0 = line.indexOf('=');

String propName = line.substring(0, idx0);

Expand All @@ -665,10 +672,11 @@ private boolean checkPropertyFile() throws IOException {
*
*/
private void configLog() {
String logPropPath = String.format("%s/config/log4j.properties", ctx.localeWorkDirectory());
String logPropPath = Paths.get(ctx.localeWorkDirectory(), "config", "log4j.properties").toString();

String logPath = Paths.get(ctx.localeWorkDirectory(), "output", String.format("logs-%s/%s-run.log",
ctx.mainDateTime(), ctx.mainDateTime())).toString();
String logPath = Paths.get(ctx.localeWorkDirectory(), "output",
String.format("logs-%s", ctx.mainDateTime()),
String.format("%s-run.log", ctx.mainDateTime())).toString();

if (new File(logPropPath).exists()){
Properties logProps = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.yardstickframework.runners.context.DockerInfo;
import org.yardstickframework.runners.context.RunContext;

import static org.yardstickframework.BenchmarkUtils.getJava;

/**
* Starts nodes in docker containers.
*/
Expand All @@ -47,7 +49,7 @@ public InDockerNodeStarter(RunContext runCtx) {
try {
String mkdirCmd = String.format("exec %s mkdir -p %s", contName, nodeLogDir);

String startNodeCmd = String.format("%s/bin/java %s", javaHome, javaParams);
String startNodeCmd = String.format("%s %s", getJava(javaHome), javaParams);

String cmd = String.format("exec --workdir %s %s nohup %s > %s 2>& 1 &",
runCtx.remoteWorkDirectory(), contName, startNodeCmd, nodeInfo.logPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.yardstickframework.runners.context.NodeInfo;
import org.yardstickframework.runners.context.RunContext;

import static org.yardstickframework.BenchmarkUtils.getJava;

/**
* Starts nodes.
*/
Expand All @@ -45,12 +47,10 @@ public PlainNodeStarter(RunContext runCtx) {

String javaHome = runCtx.getHostJava(host);

CommandExecutionResult res = null;

try {
String withJavaHome = String.format("%s/bin/java %s", javaHome, param);
String withJavaHome = String.format("%s %s", getJava(javaHome), param);

res = runCtx.handler().startNode(host, withJavaHome, nodeInfo.logPath());
CommandExecutionResult res = runCtx.handler().startNode(host, withJavaHome, nodeInfo.logPath());

nodeInfo.commandExecutionResult(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.yardstickframework.runners.workers.WorkResult;
import org.yardstickframework.runners.context.RunContext;

import static org.yardstickframework.BenchmarkUtils.getJava;

/**
* Checks java on remote hosts and set host map.
*/
Expand Down Expand Up @@ -59,8 +61,7 @@ public CheckJavaWorker(RunContext runCtx, Set<String> hostSet) {

if (runCtx.remoteJavaHome() != null) {
if (!runCtx.handler().checkJava(host, runCtx.remoteJavaHome())) {
log().info(String.format("Failed to find %s/bin/java on the host %s.",
runCtx.remoteJavaHome(), host));
log().info(String.format("Failed to find %s on the host %s.", getJava(runCtx.remoteJavaHome()), host));

res.exit(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.yardstickframework.runners.workers.host;

import java.io.IOException;
import java.nio.file.Paths;
import java.util.Set;
import org.yardstickframework.runners.workers.CheckWorkResult;
import org.yardstickframework.runners.workers.WorkResult;
Expand Down Expand Up @@ -53,8 +54,9 @@ private WorkResult clean(String host) {

try {
for (String name : toClean) {
String cleanCmd = String.format("rm -rf %s/%s",
runCtx.remoteWorkDirectory(), name);
String pathToClean = Paths.get(runCtx.remoteWorkDirectory(), name).toString();

String cleanCmd = String.format("rm -rf %s", pathToClean);

runCtx.handler().runCmd(host, cleanCmd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Set;
import org.yardstickframework.runners.CommandHandler;
import org.yardstickframework.runners.workers.CheckWorkResult;
Expand All @@ -33,7 +34,7 @@ public class CollectWorker extends HostWorker {
public CollectWorker(RunContext runCtx, Set<String> hostSet) {
super(runCtx, hostSet);

outDir = new File(String.format("%s/output", runCtx.localeWorkDirectory()));
outDir = Paths.get(runCtx.localeWorkDirectory(), "output").toFile();
}

/** {@inheritDoc} */
Expand All @@ -49,14 +50,14 @@ public CollectWorker(RunContext runCtx, Set<String> hostSet) {
if (isLocal(host) && runCtx.dirsEquals())
return res;

String nodeOutDir = String.format("%s/output", runCtx.remoteWorkDirectory());
String nodeOutDir = Paths.get(runCtx.remoteWorkDirectory(), "output").toString();

log().info(String.format("Collecting data from the host '%s'.", host));

String pathLoc = outDir.getAbsolutePath();

try {
String pathRem = String.format("%s/*", nodeOutDir);
String pathRem = String.format("%s%s%s", nodeOutDir, File.separator, "*");

runCtx.handler().download(host, pathLoc, pathRem);
}
Expand Down
Loading