Search in sources :

Example 1 with CDPTagMergeRequest

use of com.sequenceiq.cloudbreak.tag.request.CDPTagMergeRequest in project cloudbreak by hortonworks.

the class EnvironmentTagProvider method getTags.

public Map<String, String> getTags(EnvironmentDto environmentDto, String resourceCrn) {
    Map<String, String> userDefinedTags = environmentDto.getTags().getUserDefinedTags();
    Map<String, String> accountTags = getAccountTags(environmentDto.getAccountId());
    Map<String, String> defaultTags = getDefaultTags(environmentDto, userDefinedTags, accountTags, resourceCrn);
    CDPTagMergeRequest mergeRequest = CDPTagMergeRequest.Builder.builder().withEnvironmentTags(environmentDto.getTags().getUserDefinedTags()).withPlatform(environmentDto.getCloudPlatform()).withRequestTags(defaultTags).build();
    return costTagging.mergeTags(mergeRequest);
}
Also used : CDPTagMergeRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagMergeRequest)

Example 2 with CDPTagMergeRequest

use of com.sequenceiq.cloudbreak.tag.request.CDPTagMergeRequest in project cloudbreak by hortonworks.

the class StackV4RequestToStackConverter method getTags.

private Json getTags(StackV4Request source, DetailedEnvironmentResponse environment) {
    try {
        TagsV4Request tags = source.getTags();
        if (tags == null) {
            Map<String, String> userDefined = environment == null || environment.getTags() == null ? new HashMap<>() : environment.getTags().getUserDefined();
            return new Json(new StackTags(userDefined, new HashMap<>(), new HashMap<>()));
        }
        Map<String, String> userDefined = new HashMap<>();
        if (environment != null && environment.getTags() != null && environment.getTags().getUserDefined() != null && !environment.getTags().getUserDefined().isEmpty()) {
            userDefined = environment.getTags().getUserDefined();
        }
        CDPTagMergeRequest request = CDPTagMergeRequest.Builder.builder().withPlatform(source.getCloudPlatform().name()).withRequestTags(tags.getUserDefined() != null ? tags.getUserDefined() : Maps.newHashMap()).withEnvironmentTags(userDefined).build();
        return new Json(new StackTags(costTagging.mergeTags(request), tags.getApplication(), new HashMap<>()));
    } catch (Exception e) {
        throw new BadRequestException("Failed to convert dynamic tags. " + e.getMessage(), e);
    }
}
Also used : StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) CDPTagMergeRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagMergeRequest) HashMap(java.util.HashMap) TagsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Json(com.sequenceiq.cloudbreak.common.json.Json) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) IOException(java.io.IOException)

Aggregations

CDPTagMergeRequest (com.sequenceiq.cloudbreak.tag.request.CDPTagMergeRequest)2 TagsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request)1 StackTags (com.sequenceiq.cloudbreak.cloud.model.StackTags)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Json (com.sequenceiq.cloudbreak.common.json.Json)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1