Search in sources :

Example 1 with InputParameter

use of com.emc.storageos.primitives.input.InputParameter in project coprhd-controller by CoprHD.

the class CustomServicesRESTExecution method executeTask.

@Override
public CustomServicesTaskResult executeTask() throws Exception {
    try {
        ExecutionUtils.currentContext().logInfo("customServicesRESTExecution.startInfo", step.getId(), step.getFriendlyName());
        final Map<String, String> attrs = primitive.attributes();
        final String authType = attrs.get(CustomServicesConstants.AUTH_TYPE);
        if (StringUtils.isEmpty(authType)) {
            logger.error("Auth type cannot be undefined");
            ExecutionUtils.currentContext().logError("customServicesOperationExecution.logStatus", step.getId(), step.getFriendlyName(), "Auth type cannot be undefined");
            throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Cannot find Auth type");
        }
        final Client client = BuildRestRequest.makeClient(new DefaultClientConfig(), coordinator, authType, attrs.get(CustomServicesConstants.PROTOCOL), AnsibleHelper.getOptions(CustomServicesConstants.USER, input), AnsibleHelper.getOptions(CustomServicesConstants.PASSWORD, input));
        final Map<String, List<InputParameter>> inputKeys = primitive.input() == null ? Collections.emptyMap() : primitive.input();
        final List<InputParameter> queryParams = inputKeys.get(CustomServicesConstants.QUERY_PARAMS);
        final WebResource webResource = BuildRestRequest.makeWebResource(client, getUrl(primitive, queryParams).toString());
        final WebResource.Builder builder = BuildRestRequest.makeRequestBuilder(webResource, step, input);
        final CustomServicesConstants.RestMethods method = CustomServicesConstants.RestMethods.valueOf(attrs.get(CustomServicesConstants.METHOD));
        final CustomServicesTaskResult result;
        switch(method) {
            case PUT:
            case POST:
                final String body = RESTHelper.makePostBody(primitive.attributes().get(CustomServicesConstants.BODY), 0, input);
                result = executeRest(method, body, builder);
                break;
            default:
                result = executeRest(method, null, builder);
        }
        ExecutionUtils.currentContext().logInfo("customServicesRESTExecution.doneInfo", step.getId(), step.getFriendlyName());
        return result;
    } catch (final Exception e) {
        ExecutionUtils.currentContext().logError("customServicesRESTExecution.doneInfo", step.getId(), step.getFriendlyName() + "Custom Service Task Failed" + e);
        logger.error("Exception:", e);
        throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Custom Service Task Failed" + e);
    }
}
Also used : CustomServicesConstants(com.emc.storageos.primitives.CustomServicesConstants) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) WebResource(com.sun.jersey.api.client.WebResource) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) List(java.util.List) Client(com.sun.jersey.api.client.Client) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) InputParameter(com.emc.storageos.primitives.input.InputParameter)

Example 2 with InputParameter

use of com.emc.storageos.primitives.input.InputParameter in project coprhd-controller by CoprHD.

the class CustomServicesViprExecution method executeTask.

@Override
public CustomServicesTaskResult executeTask() throws Exception {
    final String requestBody;
    final String templatePath = primitive.path();
    final String body = primitive.body();
    final String method = primitive.method();
    final Map<String, List<InputParameter>> inputKeys = primitive.input() == null ? Collections.emptyMap() : primitive.input();
    if (CustomServicesConstants.BODY_REST_METHOD.contains(method) && !body.isEmpty()) {
        requestBody = RESTHelper.makePostBody(body, 0, input);
    } else {
        requestBody = "";
    }
    final List<InputParameter> queryParams = inputKeys.get(CustomServicesConstants.QUERY_PARAMS);
    final UriBuilder builder = client.uriBuilder().path(RESTHelper.makePath(templatePath, input));
    RESTHelper.addQueryParams(builder, queryParams, input);
    ExecutionUtils.currentContext().logInfo("customServicesViprExecution.startInfo", step.getId(), primitive.friendlyName());
    CustomServicesTaskResult result = makeRestCall(builder.build(), requestBody, method);
    logger.info("result is:{}", result.getOut());
    ExecutionUtils.currentContext().logInfo("customServicesViprExecution.doneInfo", step.getId(), primitive.friendlyName());
    return result;
}
Also used : ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) List(java.util.List) UriBuilder(javax.ws.rs.core.UriBuilder) InputParameter(com.emc.storageos.primitives.input.InputParameter)

Example 3 with InputParameter

use of com.emc.storageos.primitives.input.InputParameter in project coprhd-controller by CoprHD.

the class CustomServicesPrimitiveMapper method mapInputGroup.

private static InputGroup mapInputGroup(final List<InputParameter> list) {
    final ImmutableList.Builder<InputParameterRestRep> builder = ImmutableList.<InputParameterRestRep>builder();
    if (list != null) {
        for (final InputParameter param : list) {
            builder.add(mapInputParameter(param.asBasicInputParameter()));
        }
    }
    final InputGroup inputGroup = new InputGroup();
    inputGroup.setInputGroup(builder.build());
    return inputGroup;
}
Also used : InputGroup(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep.InputGroup) ImmutableList(com.google.common.collect.ImmutableList) InputParameterRestRep(com.emc.storageos.model.customservices.InputParameterRestRep) InputParameter(com.emc.storageos.primitives.input.InputParameter) BasicInputParameter(com.emc.storageos.primitives.input.BasicInputParameter)

Aggregations

InputParameter (com.emc.storageos.primitives.input.InputParameter)3 List (java.util.List)2 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)1 TaskList (com.emc.storageos.model.TaskList)1 InputGroup (com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep.InputGroup)1 InputParameterRestRep (com.emc.storageos.model.customservices.InputParameterRestRep)1 CustomServicesConstants (com.emc.storageos.primitives.CustomServicesConstants)1 BasicInputParameter (com.emc.storageos.primitives.input.BasicInputParameter)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 ImmutableList (com.google.common.collect.ImmutableList)1 Client (com.sun.jersey.api.client.Client)1 WebResource (com.sun.jersey.api.client.WebResource)1 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)1 ArrayList (java.util.ArrayList)1 UriBuilder (javax.ws.rs.core.UriBuilder)1