Search in sources :

Example 1 with CustomServicesDBRemoteAnsiblePrimitive

use of com.emc.storageos.db.client.model.uimodels.CustomServicesDBRemoteAnsiblePrimitive 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

CustomServicesDBRemoteAnsiblePrimitive (com.emc.storageos.db.client.model.uimodels.CustomServicesDBRemoteAnsiblePrimitive)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 CommandOutput (com.iwave.ext.command.CommandOutput)1