Merge branch 'master' of github.com:OpenVidu/openvidu into master

pull/553/head
cruizba 2020-11-02 19:26:29 +01:00
commit 8b96a5f6ea
2 changed files with 23 additions and 8 deletions

View File

@ -10,6 +10,7 @@ RUN apt-get update && apt-get install -y \
redis-tools \ redis-tools \
jq \ jq \
docker.io \ docker.io \
ethtool \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
RUN mkdir -p /opt/openvidu /usr/local/bin/ RUN mkdir -p /opt/openvidu /usr/local/bin/

View File

@ -21,7 +21,9 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -37,13 +39,20 @@ public class CommandExecutor {
public static String execCommand(long msTimeout, String... command) throws IOException, InterruptedException { public static String execCommand(long msTimeout, String... command) throws IOException, InterruptedException {
ProcessBuilder processBuilder = new ProcessBuilder(command); ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.redirectErrorStream(true); processBuilder.redirectErrorStream(true);
return commonExecCommand(msTimeout, processBuilder); return commonExecCommand(msTimeout, processBuilder, true).get(0);
}
public static List<String> execCommandReturnList(long msTimeout, String... command)
throws IOException, InterruptedException {
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.redirectErrorStream(true);
return commonExecCommand(msTimeout, processBuilder, false);
} }
public static String execCommandRedirectError(long msTimeout, File errorOutputFile, String... command) public static String execCommandRedirectError(long msTimeout, File errorOutputFile, String... command)
throws IOException, InterruptedException { throws IOException, InterruptedException {
ProcessBuilder processBuilder = new ProcessBuilder(command).redirectError(errorOutputFile); ProcessBuilder processBuilder = new ProcessBuilder(command).redirectError(errorOutputFile);
return commonExecCommand(msTimeout, processBuilder); return commonExecCommand(msTimeout, processBuilder, true).get(0);
} }
public static void execCommandRedirectStandardOutputAndError(long msTimeout, File standardOutputFile, public static void execCommandRedirectStandardOutputAndError(long msTimeout, File standardOutputFile,
@ -59,11 +68,11 @@ public class CommandExecutor {
} }
} }
private static String commonExecCommand(long msTimeout, ProcessBuilder processBuilder) private static List<String> commonExecCommand(long msTimeout, ProcessBuilder processBuilder, boolean singleString)
throws IOException, InterruptedException { throws IOException, InterruptedException {
Process process = processBuilder.start(); Process process = processBuilder.start();
StringBuilder processOutput = new StringBuilder(); StringBuilder processOutput = new StringBuilder();
String output; List<String> outputList = new ArrayList<>();
InputStreamReader inputStreamReader = null; InputStreamReader inputStreamReader = null;
BufferedReader processOutputReader = null; BufferedReader processOutputReader = null;
try { try {
@ -71,9 +80,15 @@ public class CommandExecutor {
processOutputReader = new BufferedReader(inputStreamReader); processOutputReader = new BufferedReader(inputStreamReader);
String readLine; String readLine;
while ((readLine = processOutputReader.readLine()) != null) { while ((readLine = processOutputReader.readLine()) != null) {
processOutput.append(readLine + System.lineSeparator()); if (singleString) {
processOutput.append(readLine + System.lineSeparator());
} else {
outputList.add(readLine);
}
}
if (singleString) {
outputList = Arrays.asList(processOutput.toString().trim());
} }
if (!process.waitFor(msTimeout, TimeUnit.MILLISECONDS)) { if (!process.waitFor(msTimeout, TimeUnit.MILLISECONDS)) {
log.error("Command {} did not receive a response in {} ms", log.error("Command {} did not receive a response in {} ms",
Arrays.toString(processBuilder.command().toArray()), msTimeout); Arrays.toString(processBuilder.command().toArray()), msTimeout);
@ -81,7 +96,6 @@ public class CommandExecutor {
log.error(errorMsg); log.error(errorMsg);
throw new IOException(errorMsg); throw new IOException(errorMsg);
} }
output = processOutput.toString().trim();
} finally { } finally {
if (inputStreamReader != null) { if (inputStreamReader != null) {
inputStreamReader.close(); inputStreamReader.close();
@ -90,7 +104,7 @@ public class CommandExecutor {
processOutputReader.close(); processOutputReader.close();
} }
} }
return output; return outputList;
} }
public static String gatherLinuxHostInformation() throws IOException, InterruptedException { public static String gatherLinuxHostInformation() throws IOException, InterruptedException {