use of com.amazonaws.services.servicecatalog.model.TerminateProvisionedProductResult in project cs-actions by CloudSlang.
the class UnprovisionProductAction method execute.
@Action(name = "Unprovision Product", description = UNPROVISION_PRODUCT_DESCRIPTION, outputs = { @Output(value = Outputs.RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = Outputs.RETURN_RESULT, description = RETURN_RESULT_DESC), @Output(value = Outputs.EXCEPTION, description = EXCEPTION_DESC) }, responses = { @Response(text = Outputs.SUCCESS, field = Outputs.RETURN_CODE, value = Outputs.SUCCESS_RETURN_CODE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), @Response(text = Outputs.FAILURE, field = Outputs.RETURN_CODE, value = Outputs.FAILURE_RETURN_CODE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, description = FAILURE_DESC) })
public Map<String, String> execute(@Param(value = IDENTITY, required = true, description = IDENTITY_DESC) final String identity, @Param(value = CREDENTIAL, required = true, encrypted = true, description = CREDENTIAL_DESC) final String credential, @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) final String proxyHost, @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) final String proxyPort, @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) final String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESC) final String proxyPassword, @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, @Param(value = EXECUTION_TIMEOUT, description = EXECUTION_TIMEOUT_DESC) String execTimeout, @Param(value = ASYNC, description = ASYNC_DESC) String async, @Param(value = POLLING_INTERVAL, description = POLLING_INTERVAL_DESC) String pollingInterval, @Param(value = REGION, description = REGION_DESC) String region, @Param(value = PROVISIONED_PRODUCT_ID, description = PROVISIONED_PRODUCT_ID_DESC) String provisionedProductId, @Param(value = PROVISIONED_PRODUCT_NAME, description = PROVISIONED_PRODUCT_NAME_DESC) String provisionedProductName, @Param(value = ACCEPT_LANGUAGE, description = ACCEPT_LANGUAGE_DESC) String acceptLanguage, @Param(value = IGNORE_ERRORS, description = IGNORE_ERRORS_DESC) String ignoreErrors, @Param(value = TERMINATE_TOKEN, description = TERMINATE_TOKEN_DESC) String terminateToken) {
// Assign default values to inputs
final String proxyPortVal = defaultIfEmpty(proxyPort, DefaultValues.PROXY_PORT);
final String connectTimeoutVal = defaultIfEmpty(connectTimeout, DefaultValues.CONNECT_TIMEOUT);
final String execTimeoutVal = defaultIfEmpty(execTimeout, DefaultValues.EXEC_TIMEOUT);
final String asyncVal = defaultIfEmpty(async, DefaultValues.ASYNC);
final String acceptLanguageVal = defaultIfEmpty(acceptLanguage, DefaultValues.ACCEPTED_LANGUAGE);
final String ignoreErrorsVal = defaultIfEmpty(ignoreErrors, IGNORE_ERRORS);
final String regionVal = defaultIfEmpty(region, DefaultValues.REGION);
final String pollingIntervalVal = defaultIfEmpty(pollingInterval, DefaultValues.POLLING_INTERVAL_DEFAULT);
// Validate inputs
Validator validator = new Validator().validatePort(proxyPortVal, PROXY_PORT).validateInt(connectTimeoutVal, CONNECT_TIMEOUT).validateInt(execTimeoutVal, EXECUTION_TIMEOUT).validateBoolean(asyncVal, ASYNC).validateBoolean(ignoreErrorsVal, IGNORE_ERRORS);
if (validator.hasErrors()) {
return getFailureResultsMap(validator.getErrors());
}
// Variable conversions
final Integer proxyPortImp = Integer.valueOf(proxyPortVal);
final Integer connectTimeoutImp = Integer.valueOf(connectTimeoutVal);
final Integer execTimeoutImp = Integer.valueOf(execTimeoutVal);
final Boolean asyncImp = Boolean.valueOf(asyncVal);
final Boolean ignoreErrorsImp = Boolean.valueOf(ignoreErrorsVal);
final Long pollingIntervalImp = Long.valueOf(pollingIntervalVal);
try {
final AWSServiceCatalog awsServiceCatalog = ServiceCatalogClientBuilder.getServiceCatalogClientBuilder(identity, credential, proxyHost, proxyPortImp, proxyUsername, proxyPassword, connectTimeoutImp, execTimeoutImp, regionVal, asyncImp);
final TerminateProvisionedProductResult result = AmazonServiceCatalogService.terminateProvisionedProduct(acceptLanguageVal, ignoreErrorsImp, provisionedProductId, provisionedProductName, terminateToken, awsServiceCatalog);
String undeployStatus = result.getRecordDetail().getStatus();
while (UPDATE_STATUSES.contains(undeployStatus)) {
Thread.sleep(pollingIntervalImp);
undeployStatus = getUpdatedProductStatus(result.getRecordDetail().getRecordId(), awsServiceCatalog);
}
if (undeployStatus.equals(SUCCEEDED)) {
return getSuccessResultsMap(result.toString());
}
final DescribeRecordResult recordResult = AmazonServiceCatalogService.describeRecord(result.getRecordDetail().getRecordId(), awsServiceCatalog);
throw new RuntimeException(UNPROVISION_PROVISIONED_PRODUCT_FAILED_REASON + recordResult.getRecordDetail().getRecordErrors().toString());
} catch (Exception e) {
return getFailureResultsMap(e);
}
}
Aggregations