use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.
the class LinuxMountUtils method isDirectoryExists.
public Boolean isDirectoryExists(String directory) throws InternalException {
String command = "[ -d \"" + directory + "\" ] &&echo \"exists\"||echo \"not exists\" ";
CommandOutput output = cli.executeCommand(command);
if ("exists".equalsIgnoreCase(output.getStdout())) {
return true;
}
return false;
}
use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.
the class LinuxMountUtils method isDirectoryEmpty.
public Boolean isDirectoryEmpty(String directory) throws InternalException {
String command = "ls " + directory;
CommandOutput output = cli.executeCommand(command);
if (StringUtils.isBlank(output.getStdout())) {
return Collections.emptyList().isEmpty();
} else {
return Lists.newArrayList(output.getStdout().split("\n")).isEmpty();
}
}
use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.
the class LinuxMountUtils method unmountPath.
public void unmountPath(String path) throws InternalException {
UnmountCommand command = new UnmountCommand(STD_TIMEOUT);
command.setPath(path);
command.addArgument("; if [ $? -eq 124 ] ; then >&2 echo TIMEOUT ; else >&2 echo SUCCESSFUL ; fi");
_log.info("unmount command:" + command.getResolvedCommandLine());
cli.executeCommand(command);
CommandOutput output = command.getOutput();
if (output.getStderr().contains("TIMEOUT")) {
ComputeSystemControllerException exception = ComputeSystemControllerException.exceptions.commandTimedOut(host.getHostName());
throw exception;
} else {
String errMessage = output.getStderr().replace("SUCCESSFUL", "").replace("\n", "");
if (!errMessage.isEmpty()) {
ComputeSystemControllerException exception = ComputeSystemControllerException.exceptions.unableToUnmount(host.getHostName(), new Exception(errMessage));
throw exception;
}
}
}
use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.
the class SSHCommandExecutor method executeCommand.
@Override
public CommandOutput executeCommand(Command command) throws CommandException {
try {
if (!isConnected()) {
connect();
}
ChannelExec channel = (ChannelExec) session.openChannel("exec");
try {
StreamConsumer stdout = new StreamConsumer(channel.getInputStream());
StreamConsumer stderr = new StreamConsumer(channel.getErrStream());
connect(command, channel);
waitForDone(channel);
stdout.close();
stderr.close();
int exitCode = channel.getExitStatus();
return new CommandOutput(stdout.toString(), stderr.toString(), exitCode);
} finally {
channel.disconnect();
}
} catch (JSchException | IOException | InterruptedException | SSHException e) {
log.error(String.format("SSH '%s' command failed: ", command.getCommand()), e);
throw new CommandException(e);
} finally {
if (isAutoDisconnect()) {
disconnect();
}
}
}
use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.
the class ListHDisksCommandTest method setup.
@BeforeClass
public static synchronized void setup() {
CommandOutput commandOutput = new CommandOutput(output, null, 0);
hdisksCommand = createMockBuilder(ListHDisksCommand.class).addMockedMethod("getOutput").createMock();
EasyMock.expect(hdisksCommand.getOutput()).andReturn(commandOutput).anyTimes();
EasyMock.replay(hdisksCommand);
}
Aggregations