Skip to content
Snippets Groups Projects
Commit a9dff2bf authored by tpylak's avatar tpylak
Browse files

DMV-12 remote dmv watermark - sometimes the output of "df -k" is in 3 instead of two lines, e.g.:

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
1998672   1683064    212404  89% /

SVN: 6230
parent 5d3a345d
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,6 @@ package ch.systemsx.cisd.common.highwatermark; ...@@ -18,7 +18,6 @@ package ch.systemsx.cisd.common.highwatermark;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
...@@ -92,25 +91,43 @@ public final class RemoteFreeSpaceProvider implements IFreeSpaceProvider ...@@ -92,25 +91,43 @@ public final class RemoteFreeSpaceProvider implements IFreeSpaceProvider
final String path = file.getPath(); final String path = file.getPath();
assert StringUtils.isNotEmpty(path) : "Empty path."; assert StringUtils.isNotEmpty(path) : "Empty path.";
final String dfCommand = String.format(DF_COMMAND_TEMPLATE, path); final String dfCommand = String.format(DF_COMMAND_TEMPLATE, path);
final List<String> command = Arrays.asList(sshExecutable.getPath(), "-T", host, dfCommand); final List<String> command =
ProcessExecutionHelper.createSshCommand(dfCommand, sshExecutable, host);
final ProcessResult processResult = final ProcessResult processResult =
ProcessExecutionHelper.run(command, millisToWaitForCompletion, operationLog, ProcessExecutionHelper.run(command, millisToWaitForCompletion, operationLog,
machineLog); machineLog);
processResult.log(); processResult.log();
final List<String> processOutput = processResult.getProcessOutput(); final List<String> processOutput = processResult.getProcessOutput();
final String commandLine = StringUtils.join(processResult.getCommandLine(), SPACE); final String commandLine = StringUtils.join(processResult.getCommandLine(), SPACE);
if (processOutput.size() >= 2) String spaceOutputKb = tryParseFreeSpaceOutput(processOutput);
if (spaceOutputKb == null)
{ {
final String output = processOutput.get(1); throw new IOException(String.format(
"Command line '%s' did not return info as expected. Response was '%s'",
commandLine, processOutput));
}
return parseKbytes(spaceOutputKb, dfCommand);
}
// NOTE sometimes the line with results breaks if the value in the column is longer then the
// header. So we cannot take the 3rd token from the second line, we have to count tokens in all
// the lines which appear
private static String tryParseFreeSpaceOutput(final List<String> outputLines)
{
int line = 1;
int seenTokens = 0;
while (line < outputLines.size())
{
final String output = outputLines.get(line);
final String[] split = StringUtils.split(output, SPACE); final String[] split = StringUtils.split(output, SPACE);
if (split.length >= 4) if (seenTokens + split.length >= 4)
{ {
// The column 'avail' (3th column) interests us. // The column 'avail' (3th column) interests us.
return parseKbytes(split[3], commandLine); return split[3 - seenTokens];
} }
seenTokens += split.length;
line++;
} }
throw new IOException(String.format( return null;
"Command line '%s' did not return info as expected. Response was '%s'",
commandLine, processOutput));
} }
} }
\ No newline at end of file
...@@ -17,9 +17,11 @@ ...@@ -17,9 +17,11 @@
package ch.systemsx.cisd.common.process; package ch.systemsx.cisd.common.process;
import java.io.BufferedReader; import java.io.BufferedReader;
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.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
...@@ -63,6 +65,15 @@ public final class ProcessExecutionHelper ...@@ -63,6 +65,15 @@ public final class ProcessExecutionHelper
private final Logger machineLog; private final Logger machineLog;
public static List<String> createSshCommand(String command, File sshExecutable, String host)
{
ArrayList<String> wrappedCmd = new ArrayList<String>();
List<String> sshCommand = Arrays.asList(sshExecutable.getPath(), "-T", host);
wrappedCmd.addAll(sshCommand);
wrappedCmd.add(command);
return wrappedCmd;
}
/** /**
* Runs an Operating System process, specified by <var>cmd</var>. * Runs an Operating System process, specified by <var>cmd</var>.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment