Search in sources :

Example 11 with CommandOutput

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

Example 12 with CommandOutput

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

Example 13 with CommandOutput

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);
}
Also used : CommandOutput(com.iwave.ext.command.CommandOutput) StrBuilder(org.apache.commons.lang.text.StrBuilder)

Example 14 with CommandOutput

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

Example 15 with CommandOutput

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

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