Search in sources :

Example 36 with Action

use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.

the class DescribeAvailabilityZonesAction method execute.

/**
 * Describes one or more of the Availability Zones that are available to you. The results include zones only for the
 * region you're currently using. If there is an event impacting an Availability Zone, you can use this request to
 * view the state and any provided message for that Availability Zone.
 * For more information, see Regions and Availability Zones in the Amazon Elastic Compute Cloud User Guide:
 * http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
 *
 * @param endpoint           Endpoint to which request will be sent.
 *                           Default: "https://ec2.amazonaws.com"
 * @param identity           ID of the secret access key associated with your Amazon AWS or IAM account.
 *                           Example: "AKIAIOSFODNN7EXAMPLE"
 * @param credential         Secret access key associated with your Amazon AWS or IAM account.
 *                           Example: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
 * @param proxyHost          Optional - proxy server used to connect to Amazon API. If empty no proxy
 *                           will be used.
 *                           Default: ""
 * @param proxyPort          Optional - proxy server port. You must either specify values for both
 *                           proxyHost and proxyPort inputs or leave them both empty.
 *                           Default: ""
 * @param proxyUsername      Optional - proxy server user name.
 *                           Default: ""
 * @param proxyPassword      Optional - proxy server password associated with the proxyUsername
 *                           input value.
 *                           Default: ""
 * @param headers            Optional - string containing the headers to use for the request separated
 *                           by new line (CRLF). The header name-value pair will be separated by ":".
 *                           Format: Conforming with HTTP standard for headers (RFC 2616)
 *                           Examples: "Accept:text/plain"
 *                           Default: ""
 * @param queryParams        Optional - string containing query parameters that will be appended to
 *                           the URL. The names and the values must not be URL encoded because if
 *                           they are encoded then a double encoded will occur. The separator between
 *                           name-value pairs is "&" symbol. The query name will be separated from
 *                           query value by "=".
 *                           Examples: "parameterName1=parameterValue1&parameterName2=parameterValue2"
 *                           Default: ""
 * @param version            Version of the web service to made the call against it.
 *                           Example: "2016-11-15"
 *                           Default: "2016-11-15"
 * @param delimiter          Optional - Delimiter that will be used.
 * @param keyFiltersString   Optional - String that contains one or more filter keys separated by delimiter.
 *                           For a complete list of valid filters see: http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAvailabilityZones.html
 *                           Valid values: "message", "region-name", "state", "zone-name"
 *                           Default: ""
 * @param valueFiltersString Optional - String that contains one or more filter values separated by delimiter.
 *                           For a complete list of valid filters see: http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeAvailabilityZones.html
 *                           Default: ""
 * @param zoneNamesString    Optional - String that contains names of one or more Availability Zones.
 *                           Example: "us-east-1a,us-east-1d"
 * @return A map with strings as keys and strings as values that contains: outcome of the action, returnCode of the
 *         operation, or failure message and the exception if there is one
 */
@Action(name = "Describe Instances", outputs = { @Output(RETURN_CODE), @Output(RETURN_RESULT), @Output(EXCEPTION) }, responses = { @Response(text = SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR) })
public Map<String, String> execute(@Param(value = ENDPOINT) String endpoint, @Param(value = IDENTITY, required = true) String identity, @Param(value = CREDENTIAL, required = true, encrypted = true) String credential, @Param(value = PROXY_HOST) String proxyHost, @Param(value = PROXY_PORT) String proxyPort, @Param(value = PROXY_USERNAME) String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true) String proxyPassword, @Param(value = HEADERS) String headers, @Param(value = QUERY_PARAMS) String queryParams, @Param(value = VERSION) String version, @Param(value = DELIMITER) String delimiter, @Param(value = KEY_FILTERS_STRING) String keyFiltersString, @Param(value = VALUE_FILTERS_STRING) String valueFiltersString, @Param(value = ZONE_NAMES_STRING) String zoneNamesString) {
    try {
        version = getDefaultStringInput(version, REGIONS_DEFAULT_API_VERSION);
        final CommonInputs commonInputs = new CommonInputs.Builder().withEndpoint(endpoint, EC2_API, EMPTY).withIdentity(identity).withCredential(credential).withProxyHost(proxyHost).withProxyPort(proxyPort).withProxyUsername(proxyUsername).withProxyPassword(proxyPassword).withHeaders(headers).withQueryParams(queryParams).withVersion(version).withDelimiter(delimiter).withAction(DESCRIBE_AVAILABILITY_ZONES).withApiService(EC2_API).withRequestUri(EMPTY).withRequestPayload(EMPTY).withHttpClientMethod(HTTP_CLIENT_METHOD_GET).build();
        final CustomInputs customInputs = new CustomInputs.Builder().withAvailabilityZonesString(zoneNamesString).withKeyFiltersString(keyFiltersString).withValueFiltersString(valueFiltersString).build();
        return new QueryApiExecutor().execute(commonInputs, customInputs);
    } catch (Exception e) {
        return ExceptionProcessor.getExceptionResult(e);
    }
}
Also used : CommonInputs(io.cloudslang.content.amazon.entities.inputs.CommonInputs) QueryApiExecutor(io.cloudslang.content.amazon.execute.QueryApiExecutor) CustomInputs(io.cloudslang.content.amazon.entities.inputs.CustomInputs) Action(com.hp.oo.sdk.content.annotations.Action)

Example 37 with Action

use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.

the class DescribeSecurityGroupsAction method execute.

/**
 * Describes the security groups that you own. By default, this operation returns information about all of your
 * security groups, but you can specify a list of group names or group IDs to restrict the results to only
 * those specified.
 *
 * @param endpoint                 Endpoint to which request will be sent.
 *                                 Default: "https://ec2.amazonaws.com"
 * @param identity                 ID of the secret access key associated with your Amazon AWS or IAM account.
 *                                 Example: "AKIAIOSFODNN7EXAMPLE"
 * @param credential               Secret access key associated with your Amazon AWS or IAM account.
 *                                 Example: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
 * @param securityGroupIdsString   Optional - The IDs of the groups that you want to describe. This input can be
 *                                 used also for security groups in a nondefault VPC
 *                                 Example: "sg-01234567,sg-7654321,sg-abcdef01"
 *                                 Default: ""
 * @param securityGroupNamesString Optional - The names of the groups that you want to describe. Only EC2-Classic
 *                                 and default VPC security groups can be referenced by name.
 *                                 Default: ""
 * @param proxyHost                Optional - proxy server used to connect to Amazon API. If empty no proxy
 *                                 will be used.
 *                                 Default: ""
 * @param proxyPort                Optional - proxy server port. You must either specify values for both
 *                                 proxyHost and proxyPort inputs or leave them both empty.
 *                                 Default: ""
 * @param proxyUsername            Optional - proxy server username.
 *                                 Default: ""
 * @param proxyPassword            Optional - proxy server password associated with the proxyUsername
 *                                 input value.
 *                                 Default: ""
 * @param headers                  Optional - string containing the headers to use for the request separated
 *                                 by new line (CRLF). The header name-value pair will be separated by ":".
 *                                 Format: Conforming with HTTP standard for headers (RFC 2616)
 *                                 Examples: "Accept:text/plain"
 *                                 Default: ""
 * @param queryParams              Optional - string containing query parameters that will be appended to
 *                                 the URL. The names and the values must not be URL encoded because if
 *                                 they are encoded then a double encoded will occur. The separator between
 *                                 name-value pairs is "&" symbol. The query name will be separated from
 *                                 query value by "=".
 *                                 Examples: "parameterName1=parameterValue1&parameterName2=parameterValue2"
 *                                 Default: ""
 * @param version                  Optional - Version of the web service to made the call against it.
 *                                 Example: "2016-11-15"
 *                                 Default: ""
 * @param delimiter                Optional - Delimiter that will be used.
 * @param filterNamesString        Optional - String that contains one or more values that represents filters for
 *                                 the search.
 *                                 For a complete list of valid filters see: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSecurityGroups.html
 *                                 Example: "description,group-id,group-name,ip-permission.cidr,
 *                                 ip-permission.from-port,ip-permission.group-id,ip-permission.group-name,
 *                                 ip-permission.protocol,ip-permission.to-port,ip-permission.user-id,owner-id,
 *                                 tag-key,tag-value,vpc-id"
 *                                 Default: ""
 * @param filterValuesString       Optional - String that contains one or more values that represents filters values.
 *                                 For a complete list of valid filters see: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSecurityGroups.html
 *                                 Default (describes all your security groups): ""
 * @param maxResults               Optional - The maximum number of results to return in a single call. To retrieve the
 *                                 remaining results, make another call with the returned NextToken value. This value can
 *                                 be between 5 and 1000. You cannot specify this parameter and the instance IDs parameter
 *                                 or tag filters in the same call.
 *                                 Default: ""
 * @param nextToken                Optional - The token to use to retrieve the next page of results. This value is null when
 *                                 there are no more results to return.
 *                                 Default: ""
 * @return A map with strings as keys and strings as values that contains: outcome of the action, returnCode of the
 * operation, or failure message and the exception if there is one
 */
@Action(name = "Describe Security Groups", outputs = { @Output(RETURN_CODE), @Output(RETURN_RESULT), @Output(EXCEPTION) }, responses = { @Response(text = SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR) })
public Map<String, String> execute(@Param(value = ENDPOINT) String endpoint, @Param(value = IDENTITY, required = true) String identity, @Param(value = CREDENTIAL, required = true, encrypted = true) String credential, @Param(value = SECURITY_GROUP_IDS) String securityGroupIdsString, @Param(value = SECURITY_GROUP_NAMES) String securityGroupNamesString, @Param(value = PROXY_HOST) String proxyHost, @Param(value = PROXY_PORT) String proxyPort, @Param(value = PROXY_USERNAME) String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true) String proxyPassword, @Param(value = HEADERS) String headers, @Param(value = QUERY_PARAMS) String queryParams, @Param(value = VERSION) String version, @Param(value = DELIMITER) String delimiter, @Param(value = SECURITY_GROUP_FILTER_NAMES_STRING) String filterNamesString, @Param(value = SECURITY_GROUP_FILTER_VALUES_STRING) String filterValuesString, @Param(value = MAX_RESULTS) String maxResults, @Param(value = NEXT_TOKEN) String nextToken) {
    try {
        version = getDefaultStringInput(version, SECURITY_GROUPS_DEFAULT_API_VERSION);
        final CommonInputs commonInputs = new CommonInputs.Builder().withEndpoint(endpoint, EC2_API, EMPTY).withIdentity(identity).withCredential(credential).withProxyHost(proxyHost).withProxyPort(proxyPort).withProxyUsername(proxyUsername).withProxyPassword(proxyPassword).withHeaders(headers).withQueryParams(queryParams).withVersion(version).withDelimiter(delimiter).withAction(DESCRIBE_SECURITY_GROUPS).withApiService(EC2_API).withRequestUri(EMPTY).withRequestPayload(EMPTY).withHttpClientMethod(HTTP_CLIENT_METHOD_GET).build();
        final SecurityGroupInputs securityGroupInputs = new SecurityGroupInputs.Builder().withSecurityGroupIdsString(securityGroupIdsString).withSecurityGroupNamesString(securityGroupNamesString).build();
        final CustomInputs customInputs = new CustomInputs.Builder().withKeyFiltersString(filterNamesString).withValueFiltersString(filterValuesString).build();
        final FilterInputs filterInputs = new FilterInputs.Builder().withMaxResults(maxResults).withNextToken(nextToken).build();
        return new QueryApiExecutor().execute(commonInputs, securityGroupInputs, customInputs, filterInputs);
    } catch (Exception e) {
        return ExceptionProcessor.getExceptionResult(e);
    }
}
Also used : CommonInputs(io.cloudslang.content.amazon.entities.inputs.CommonInputs) CommonInputs(io.cloudslang.content.amazon.entities.constants.Inputs.CommonInputs) FilterInputs(io.cloudslang.content.amazon.entities.inputs.FilterInputs) QueryApiExecutor(io.cloudslang.content.amazon.execute.QueryApiExecutor) SecurityGroupInputs(io.cloudslang.content.amazon.entities.inputs.SecurityGroupInputs) CustomInputs(io.cloudslang.content.amazon.entities.inputs.CustomInputs) CustomInputs(io.cloudslang.content.amazon.entities.constants.Inputs.CustomInputs) Action(com.hp.oo.sdk.content.annotations.Action)

Example 38 with Action

use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.

the class ProvisionProductAction method execute.

@Action(name = "Provision Product", description = PROVISION_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), @Output(value = Outputs.CREATED_TIME, description = CREATED_TIME_DESC), @Output(value = Outputs.PATH_ID, description = PATH_ID_DESC), @Output(value = Outputs.PRODUCT_ID, description = PRODUCT_ID_DESC), @Output(value = Outputs.PROVISIONED_PRODUCT_ID, description = PROVISIONED_PRODUCT_ID_DESC), @Output(value = Outputs.PROVISIONED_PRODUCT_NAME, description = PROVISIONED_PRODUCT_NAME_DESC), @Output(value = Outputs.PROVISIONED_PRODUCT_TYPE, description = PROVISIONED_PRODUCT_TYPE_DESC), @Output(value = Outputs.PROVISIONING_ARTIFACT_ID, description = PROVISIONING_ARTIFACT_ID_OUT_DESC), @Output(value = Outputs.STATUS, description = STATUS_DESC), @Output(value = Outputs.STACK_ID, description = STACK_ID_DESC), @Output(value = Outputs.STACK_NAME, description = STACK_NAME_DESC), @Output(value = Outputs.STACK_OUTPUTS, description = STACK_OUTPUTS_DESC), @Output(value = Outputs.STACK_RESOURCES, description = STACK_RESOURCES_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 = POLLING_INTERVAL, description = POLLING_INTERVAL_DESC) String pollingInterval, @Param(value = ASYNC, description = ASYNC_DESC) String async, @Param(value = PRODUCT_ID, required = true, description = PRODUCT_ID_DESC) String productId, @Param(value = PROVISIONED_PRODUCT_NAME, required = true, description = PROVISIONED_PRODUCT_NAME_DESC) String provisionedProductName, @Param(value = PROVISIONING_ARTIFACT_ID, required = true, description = PROVISIONING_ARTIFACT_ID_DESC) String provisioningArtifactId, @Param(value = PROVISIONING_PARAMETERS, description = PROVISIONING_PARAMETERS_DESC) String provisioningParameters, @Param(value = DELIMITER, description = DELIMITER_DESC) String delimiter, @Param(value = TAGS, description = TAGS_DESC) String tags, @Param(value = PROVISION_TOKEN, description = PROVISION_TOKEN_DESC) String provisionTokens, @Param(value = ACCEPT_LANGUAGE, description = ACCEPT_LANGUAGE_DESC) String acceptLanguage, @Param(value = NOTIFICATION_ARNS, description = NOTIFICATION_ARNS_DESC) String notificationArns, @Param(value = PATH_ID, description = PATH_ID_DESC) String pathId, @Param(value = REGION, description = REGION_DESC) String region) {
    // 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 pollingIntervalVal = defaultIfEmpty(pollingInterval, DefaultValues.POLLING_INTERVAL_DEFAULT);
    final String delimiterVal = defaultIfEmpty(delimiter, COMMA);
    final String regionVal = defaultIfEmpty(region, DefaultValues.REGION);
    final String acceptLanguageVal = defaultIfEmpty(acceptLanguage, DefaultValues.ACCEPTED_LANGUAGE);
    // Validate inputs
    Validator validator = new Validator().validatePort(proxyPortVal, PROXY_PORT).validateInt(connectTimeoutVal, CONNECT_TIMEOUT).validateInt(execTimeoutVal, EXECUTION_TIMEOUT).validateBoolean(asyncVal, ASYNC);
    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 Long pollingIntervalImp = Long.valueOf(pollingIntervalVal);
    final Boolean asyncImp = Boolean.valueOf(asyncVal);
    try {
        final AWSServiceCatalog awsServiceCatalog = ServiceCatalogClientBuilder.getServiceCatalogClientBuilder(identity, credential, proxyHost, proxyPortImp, proxyUsername, proxyPassword, connectTimeoutImp, execTimeoutImp, regionVal, asyncImp);
        final ProvisionProductResult result = AmazonServiceCatalogService.provisionProduct(provisionedProductName, toArrayOfParameters(provisioningParameters, delimiterVal), productId, provisionTokens, provisioningArtifactId, toArrayOfTags(tags, delimiterVal), acceptLanguageVal, notificationArns, pathId, awsServiceCatalog);
        String provisionStatus = result.getRecordDetail().getStatus();
        while (UPDATE_STATUSES.contains(provisionStatus)) {
            Thread.sleep(pollingIntervalImp);
            provisionStatus = getUpdatedProductStatus(result.getRecordDetail().getRecordId(), awsServiceCatalog);
        }
        if (provisionStatus.equals(FAILED)) {
            final DescribeRecordResult recordResult = AmazonServiceCatalogService.describeRecord(result.getRecordDetail().getRecordId(), awsServiceCatalog);
            throw new RuntimeException(PROVISION_PRODUCT_FAILED_REASON + recordResult.getRecordDetail().getRecordErrors().toString());
        }
        final AmazonCloudFormation awsCloudFormation = CloudFormationClientBuilder.getCloudFormationClient(identity, credential, proxyHost, proxyPort, proxyUsername, proxyPassword, connectTimeoutVal, execTimeoutVal, regionVal);
        final String cloudFormationStackName = getCloudFormationStackName(result.getRecordDetail().getRecordId(), awsServiceCatalog, pollingIntervalImp);
        List<Stack> stacks = describeCloudFormationStack(cloudFormationStackName, awsCloudFormation);
        String stackOutputs = getStackOutputsToJson(getStack(stacks));
        String stackResources = getStackResourcesToJson(describeStackResourcesResult(cloudFormationStackName, awsCloudFormation));
        Map<String, String> results = getSuccessResultMapProvisionProduct(result);
        results.put(STACK_NAME, getStack(stacks).getStackName());
        results.put(STACK_ID, getStack(stacks).getStackId());
        results.put(STACK_OUTPUTS, stackOutputs);
        results.put(STACK_RESOURCES, stackResources);
        return results;
    } catch (Exception e) {
        return getFailureResultsMap(e);
    }
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeRecordResult(com.amazonaws.services.servicecatalog.model.DescribeRecordResult) Stack(com.amazonaws.services.cloudformation.model.Stack) ProvisionProductResult(com.amazonaws.services.servicecatalog.model.ProvisionProductResult) AWSServiceCatalog(com.amazonaws.services.servicecatalog.AWSServiceCatalog) Validator(io.cloudslang.content.amazon.entities.validators.Validator) Action(com.hp.oo.sdk.content.annotations.Action) ProvisionProductAction(io.cloudslang.content.amazon.entities.constants.Descriptions.ProvisionProductAction)

Example 39 with Action

use of com.hp.oo.sdk.content.annotations.Action 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);
    }
}
Also used : AWSServiceCatalog(com.amazonaws.services.servicecatalog.AWSServiceCatalog) Validator(io.cloudslang.content.amazon.entities.validators.Validator) TerminateProvisionedProductResult(com.amazonaws.services.servicecatalog.model.TerminateProvisionedProductResult) DescribeRecordResult(com.amazonaws.services.servicecatalog.model.DescribeRecordResult) UnprovisionProductAction(io.cloudslang.content.amazon.entities.constants.Descriptions.UnprovisionProductAction) Action(com.hp.oo.sdk.content.annotations.Action)

Example 40 with Action

use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.

the class UpdateProvisionedProduct method execute.

@Action(name = "Update Provisioned Product", description = UPDATE_PROVISIONED_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), @Output(value = Outputs.CREATED_TIME, description = CREATED_TIME_DESC), @Output(value = Outputs.PATH_ID, description = PATH_ID_DESC), @Output(value = Outputs.PRODUCT_ID, description = PRODUCT_ID_DESC), @Output(value = Outputs.PROVISIONED_PRODUCT_ID, description = PROVISIONED_PRODUCT_ID_DESC), @Output(value = Outputs.PROVISIONED_PRODUCT_NAME, description = PROVISIONED_PRODUCT_NAME_DESCRIPTION), @Output(value = Outputs.PROVISIONED_PRODUCT_TYPE, description = PROVISIONED_PRODUCT_TYPE_DESC), @Output(value = Outputs.PROVISIONING_ARTIFACT_ID, description = PROVISIONING_ARTIFACT_ID_DESC), @Output(value = Outputs.UPDATE_TIME, description = UPDATE_TIME_DESC), @Output(value = Outputs.RECORD_ID, description = RECORD_ID_DESC), @Output(value = Outputs.RECORD_TYPE, description = RECORD_TYPE_DESC), @Output(value = Outputs.RECORD_ERRORS, description = RECORD_ERRORS_DESC), @Output(value = Outputs.RECORD_TAGS, description = RECORD_TAGS_DESC), @Output(value = Outputs.STATUS, description = STATUS_DESC) }, responses = { @Response(text = Outputs.SUCCESS, field = Outputs.RETURN_CODE, value = Outputs.SUCCESS_RETURN_CODE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESCRIPTION), @Response(text = Outputs.FAILURE, field = Outputs.RETURN_CODE, value = Outputs.FAILURE_RETURN_CODE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, description = FAILURE_DESCRIPTION) })
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 = ACCEPTED_LANGUAGE, description = PROVISIONED_PRODUCT_ACCEPTED_LANGUAGE_DESCRIPTION) String acceptedLanguage, @Param(value = PATH_ID, description = PATH_ID_DESC) String pathId, @Param(value = PRODUCT_ID, required = true, description = PRODUCT_ID_DESC) String productId, @Param(value = PROVISIONED_PRODUCT_ID, description = Descriptions.UpdateProvisionedProductDescriptions.PROVISIONED_PRODUCT_ID_DESCRIPTION) String provisionedProductId, @Param(value = PROVISIONED_PRODUCT_NAME, description = PROVISIONED_PRODUCT_NAME_DESCRIPTION) String provisionedProductName, @Param(value = PROVISIONING_ARTIFACT_ID, required = true, description = PROVISIONING_ARTIFACT_ID_DESC) String provisioningArtifactId, @Param(value = PROVISIONING_PARAMETERS, description = PROVISIONING_PARAMETERS_DESC) String provisioningParameters, @Param(value = PROVISIONING_USE_PREVIOUS_VALUE, description = PROVISIONING_USE_PREVIOUS_VALUE_DES) String usePreviousValue, @Param(value = DELIMITER, description = DELIMITER_DESC) String delimiter, @Param(value = UPDATE_TOKEN, description = UPDATE_TOKEN_DESCRIPTION) String updateToken) {
    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 acceptedLanguageVal = defaultIfEmpty(acceptedLanguage, DefaultValues.ACCEPTED_LANGUAGE);
    final String pollingIntervalVal = defaultIfEmpty(pollingInterval, DefaultValues.POLLING_INTERVAL_DEFAULT);
    final String regionVal = defaultIfEmpty(region, DefaultValues.REGION);
    final String asyncVal = defaultIfEmpty(async, DefaultValues.ASYNC);
    final String delimiterVal = defaultIfEmpty(delimiter, DefaultValues.COMMA);
    final String usePreviousVal = defaultIfEmpty(usePreviousValue, DefaultValues.PREVIOUS_VALUE);
    // Validate inputs
    Validator validator = new Validator().validatePort(proxyPortVal, PROXY_PORT).validateInt(connectTimeoutVal, CONNECT_TIMEOUT).validateInt(execTimeoutVal, EXECUTION_TIMEOUT).validateBoolean(asyncVal, ASYNC);
    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 usePreviousValueImp = Boolean.valueOf(usePreviousVal);
    final Long pollingIntervalImp = Long.valueOf(pollingIntervalVal);
    try {
        // The client
        final AWSServiceCatalog awsServiceCatalog = ServiceCatalogClientBuilder.getServiceCatalogClientBuilder(identity, credential, proxyHost, proxyPortImp, proxyUsername, proxyPassword, connectTimeoutImp, execTimeoutImp, regionVal, asyncImp);
        // The result
        final UpdateProvisionedProductResult result = AmazonServiceCatalogService.updateProvisionedProduct(acceptedLanguageVal, pathId, productId, provisionedProductId, toArrayOfUpdateParameters(provisioningParameters, delimiterVal, usePreviousValueImp), provisionedProductName, provisioningArtifactId, updateToken, awsServiceCatalog);
        String updateStatus = result.getRecordDetail().getStatus();
        while (UPDATE_STATUSES.contains(updateStatus)) {
            Thread.sleep(pollingIntervalImp);
            updateStatus = getUpdatedProductStatus(result.getRecordDetail().getRecordId(), awsServiceCatalog);
        }
        if (updateStatus.equals(FAILED)) {
            final DescribeRecordResult recordResult = AmazonServiceCatalogService.describeRecord(result.getRecordDetail().getRecordId(), awsServiceCatalog);
            throw new RuntimeException(UPDATE_PROVISIONED_PRODUCT_FAILED_REASON + recordResult.getRecordDetail().getRecordErrors().toString());
        }
        final AmazonCloudFormation awsCloudFormation = CloudFormationClientBuilder.getCloudFormationClient(identity, credential, proxyHost, proxyPort, proxyUsername, proxyPassword, connectTimeoutVal, execTimeoutVal, regionVal);
        final String cloudFormationStackName = getCloudFormationStackName(result.getRecordDetail().getRecordId(), awsServiceCatalog, pollingIntervalImp);
        List<Stack> stacks = describeCloudFormationStack(cloudFormationStackName, awsCloudFormation);
        String stackOutputs = getStackOutputsToJson(getStack(stacks));
        String stackResources = getStackResourcesToJson(describeStackResourcesResult(cloudFormationStackName, awsCloudFormation));
        Map<String, String> results = getSuccessResultMapUpdateProvisioningProduct(result);
        results.put(STACK_OUTPUTS, stackOutputs);
        results.put(STACK_RESOURCES, stackResources);
        return results;
    } catch (Exception e) {
        return getFailureResultsMap(e);
    }
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) DescribeRecordResult(com.amazonaws.services.servicecatalog.model.DescribeRecordResult) Stack(com.amazonaws.services.cloudformation.model.Stack) ServiceCatalogUtil.getStack(io.cloudslang.content.amazon.utils.ServiceCatalogUtil.getStack) UpdateProvisionedProductResult(com.amazonaws.services.servicecatalog.model.UpdateProvisionedProductResult) AWSServiceCatalog(com.amazonaws.services.servicecatalog.AWSServiceCatalog) Validator(io.cloudslang.content.amazon.entities.validators.Validator) Action(com.hp.oo.sdk.content.annotations.Action) ProvisionProductAction(io.cloudslang.content.amazon.entities.constants.Descriptions.ProvisionProductAction)

Aggregations

Action (com.hp.oo.sdk.content.annotations.Action)230 CommonInputs (io.cloudslang.content.amazon.entities.inputs.CommonInputs)48 QueryApiExecutor (io.cloudslang.content.amazon.execute.QueryApiExecutor)47 CustomInputs (io.cloudslang.content.amazon.entities.inputs.CustomInputs)32 HttpClientInputs (io.cloudslang.content.httpclient.entities.HttpClientInputs)29 HashMap (java.util.HashMap)22 VmInputs (io.cloudslang.content.vmware.entities.VmInputs)21 HttpInputs (io.cloudslang.content.vmware.entities.http.HttpInputs)21 CommonInputs (io.cloudslang.content.couchbase.entities.inputs.CommonInputs)15 CouchbaseService (io.cloudslang.content.couchbase.execute.CouchbaseService)15 InputsUtil.getHttpClientInputs (io.cloudslang.content.couchbase.utils.InputsUtil.getHttpClientInputs)15 NetworkInputs (io.cloudslang.content.amazon.entities.inputs.NetworkInputs)11 Map (java.util.Map)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 CommonInputs (io.cloudslang.content.amazon.entities.constants.Inputs.CommonInputs)9 InstanceInputs (io.cloudslang.content.amazon.entities.inputs.InstanceInputs)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 JsonParser (com.google.gson.JsonParser)8 SFTPService (io.cloudslang.content.rft.services.SFTPService)8 ClusterComputeResourceService (io.cloudslang.content.vmware.services.ClusterComputeResourceService)8