Search in sources :

Example 1 with CommandOutput

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;
}
Also used : CommandOutput(com.iwave.ext.command.CommandOutput)

Example 2 with CommandOutput

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();
    }
}
Also used : CommandOutput(com.iwave.ext.command.CommandOutput)

Example 3 with CommandOutput

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;
        }
    }
}
Also used : ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) UnmountCommand(com.iwave.ext.linux.command.UnmountCommand) CommandOutput(com.iwave.ext.command.CommandOutput) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 4 with CommandOutput

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();
        }
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) CommandOutput(com.iwave.ext.command.CommandOutput) IOException(java.io.IOException) CommandException(com.iwave.ext.command.CommandException) ChannelExec(com.jcraft.jsch.ChannelExec)

Example 5 with CommandOutput

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);
}
Also used : CommandOutput(com.iwave.ext.command.CommandOutput) BeforeClass(org.junit.BeforeClass)

Aggregations

CommandOutput (com.iwave.ext.command.CommandOutput)24 BeforeClass (org.junit.BeforeClass)9 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 CommandException (com.iwave.ext.command.CommandException)2 JSchException (com.jcraft.jsch.JSchException)2 IOException (java.io.IOException)2 StrBuilder (org.apache.commons.lang.text.StrBuilder)2 CustomServicesDBRemoteAnsiblePrimitive (com.emc.storageos.db.client.model.uimodels.CustomServicesDBRemoteAnsiblePrimitive)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 Command (com.iwave.ext.command.Command)1 CheckForFileSystemCompatibilityCommand (com.iwave.ext.linux.command.CheckForFileSystemCompatibilityCommand)1 MountCommand (com.iwave.ext.linux.command.MountCommand)1 MultipathCommand (com.iwave.ext.linux.command.MultipathCommand)1 UnmountCommand (com.iwave.ext.linux.command.UnmountCommand)1 WinRMException (com.iwave.ext.windows.winrm.WinRMException)1 WinRS (com.iwave.ext.windows.winrm.winrs.WinRS)1 ChannelExec (com.jcraft.jsch.ChannelExec)1