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);
}
}
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;
}
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;
}
Aggregations