Search in sources :

Example 21 with CommandOutput

use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.

the class ListRDisksCommandTest method setup.

@BeforeClass
public static synchronized void setup() {
    CommandOutput commandOutput = new CommandOutput(OUTPUT, null, 0);
    command = createMockBuilder(ListRDisksCommand.class).withConstructor().addMockedMethod("getOutput").createMock();
    EasyMock.expect(command.getOutput()).andReturn(commandOutput).anyTimes();
    EasyMock.replay(command);
}
Also used : CommandOutput(com.iwave.ext.command.CommandOutput) BeforeClass(org.junit.BeforeClass)

Example 22 with CommandOutput

use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.

the class MultipathCommand method processError.

@Override
protected void processError() throws CommandException {
    CommandOutput output = getOutput();
    if (isNotLoaded(output)) {
        throw new MultipathException("multipath kernel driver is not loaded", output);
    }
    if (isNotInstalled(output)) {
        throw new MultipathException("multipath is not installed", output);
    }
    super.processError();
}
Also used : CommandOutput(com.iwave.ext.command.CommandOutput)

Example 23 with CommandOutput

use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.

the class LinuxMountUtils method mountPath.

public void mountPath(String path) throws InternalException {
    MountCommand command = new MountCommand(STD_TIMEOUT);
    command.setPath(path);
    command.addArgument("; if [ $? -eq 124 ] ; then >&2 echo TIMEOUT ; else >&2 echo SUCCESSFUL ; fi");
    _log.info("mount 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.unableToMount(host.getHostName(), new Exception(errMessage));
            throw exception;
        }
    }
}
Also used : ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) MountCommand(com.iwave.ext.linux.command.MountCommand) CommandOutput(com.iwave.ext.command.CommandOutput) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 24 with CommandOutput

use of com.iwave.ext.command.CommandOutput in project coprhd-controller by CoprHD.

the class CustomServicesRemoteAnsibleExecution method executeTask.

@Override
public CustomServicesTaskResult executeTask() throws Exception {
    ExecutionUtils.currentContext().logInfo("customServicesScriptExecution.statusInfo", step.getId(), step.getFriendlyName());
    final CommandOutput result;
    try {
        final CustomServicesDBRemoteAnsiblePrimitive primitive = dbClient.queryObject(CustomServicesDBRemoteAnsiblePrimitive.class, step.getOperation());
        if (null == primitive) {
            logger.error("Error retrieving the ansible primitive from DB. {} not found in DB", step.getOperation());
            ExecutionUtils.currentContext().logError("customServicesOperationExecution.logStatus", step.getId(), step.getFriendlyName(), "\"Error retrieving the Remote Ansible primitive from DB.");
            throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed(step.getOperation() + " not found in DB");
        }
        result = executeRemoteCmd(AnsibleHelper.makeExtraArg(input, step), primitive);
    } catch (final Exception e) {
        ExecutionUtils.currentContext().logError("customServicesOperationExecution.logStatus", step.getId(), step.getFriendlyName(), "Custom Service Task Failed" + e);
        logger.error("Exception:", e);
        throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Custom Service Task Failed" + e);
    }
    ExecutionUtils.currentContext().logInfo("customServicesScriptExecution.doneInfo", step.getId(), step.getFriendlyName());
    if (result == null) {
        ExecutionUtils.currentContext().logError("customServicesOperationExecution.logStatus", step.getId(), step.getFriendlyName(), "Remote Ansible execution Failed");
        throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Remote Ansible execution Failed");
    }
    logger.info("CustomScript Execution result:output{} error{} exitValue:{}", result.getStdout(), result.getStderr(), result.getExitValue());
    final String parsedOut = AnsibleHelper.parseOut(result.getStdout());
    if (!StringUtils.isEmpty(parsedOut)) {
        ExecutionUtils.currentContext().logInfo("customServicesScriptExecution.doneInfo", step.getId(), step.getFriendlyName());
        return new CustomServicesScriptTaskResult(parsedOut, result.getStdout(), result.getStderr(), result.getExitValue());
    }
    return new CustomServicesScriptTaskResult(result.getStdout(), result.getStdout(), result.getStderr(), result.getExitValue());
}
Also used : CommandOutput(com.iwave.ext.command.CommandOutput) CustomServicesDBRemoteAnsiblePrimitive(com.emc.storageos.db.client.model.uimodels.CustomServicesDBRemoteAnsiblePrimitive) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)

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