use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.
the class ShellCommandExecutor method executeCommands.
public List<CommandOutput> executeCommands(List<? extends Command> commands) throws CommandException {
List<CommandOutput> results = Lists.newArrayList();
for (Command command : commands) {
command.setCommandExecutor(this);
command.execute();
results.add(command.getOutput());
}
return results;
}
use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.
the class ShellCommandExecutor method sendCommand.
/**
* Sends a command to the remote host. This returns a CommandOutput, but the exit value is
* always 0 since it is being handled by the remote shell.
*
* @param command the command to send.
* @return the command output.
*/
protected CommandOutput sendCommand(String command) {
try {
send(command);
String matched = waitFor(promptPattern);
String stdout = getCurrentCommandOutput();
stdoutPos += StringUtils.length(stdout);
// Strip the command from the start of the output (ignoring any inserted line breaks)
stdout = IWaveStringUtils.removeStartIgnoringWhiteSpace(stdout, command);
if (StringUtils.startsWith(stdout, "\r\n")) {
stdout = StringUtils.removeStart(stdout, "\r\n");
} else if (StringUtils.startsWith(stdout, "\r") || StringUtils.startsWith(stdout, "\n")) {
stdout = StringUtils.substring(stdout, 1);
}
// Strip the prompt from the end of the output
stdout = StringUtils.removeEnd(stdout, matched);
return new CommandOutput(stdout, null, 0);
} catch (Exception e) {
CommandException ce = new CommandException(e);
ce.setOutput(tryGetCommandOutput());
throw ce;
}
}
use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.
the class WinRS method receiveOutput.
/**
* Receives output from the remote shell command.
*
* @param shellId the shell ID.
* @param commandId the command ID.
* @return the command output.
*
* @throws WinRMException if an error occurs.
*/
protected CommandOutput receiveOutput(String shellId, String commandId) throws WinRMException {
StrBuilder stdout = new StrBuilder();
StrBuilder stderr = new StrBuilder();
int exitCode = 0;
int sequenceId = 0;
boolean done = false;
while (!done) {
ReceiveData data = newReceiveOutput(shellId, commandId, sequenceId).execute();
stdout.append(data.getStdout());
stderr.append(data.getStderr());
if (data.getExitCode() != null) {
exitCode = data.getExitCode();
}
done = data.isDone();
sequenceId++;
}
return new CommandOutput(stdout.toString(), stderr.toString(), exitCode);
}
use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.
the class CheckForFileSystemCompatibility method execute.
@Override
public void execute() throws Exception {
CheckForFileSystemCompatibilityCommand command = new CheckForFileSystemCompatibilityCommand();
command.setFileSystemType(fsType);
executeCommand(command, SHORT_TIMEOUT);
CommandOutput output = command.getOutput();
if (!output.getStdout().contains(fsType)) {
throw stateException("CheckForFileSystemCompatibility.illegalState.fileSystemTypeUnsupported", fsType);
}
}
use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.
the class CheckForMultipath method executeTask.
@Override
public String executeTask() throws Exception {
MultipathCommand command = new MultipathCommand();
command.addArgument("-l");
try {
executeCommand(command, SHORT_TIMEOUT);
CommandOutput output = command.getOutput();
if (output.getExitValue() != 0) {
return getMessage("CheckForMultipath.noMultipath");
}
return null;
} catch (Exception e) {
return e.getMessage();
}
}
Aggregations