Search in sources :

Example 1 with EnvironmentTags

use of com.sequenceiq.environment.environment.domain.EnvironmentTags in project cloudbreak by hortonworks.

the class EnvironmentDtoConverter method getTags.

private Json getTags(EnvironmentCreationDto creationDto) {
    boolean internalTenant = entitlementService.internalTenant(creationDto.getAccountId());
    Map<String, String> userDefinedTags = creationDto.getTags();
    Set<AccountTag> accountTags = accountTagService.get(creationDto.getAccountId());
    List<AccountTagResponse> accountTagResponses = accountTags.stream().map(accountTagToAccountTagResponsesConverter::convert).collect(Collectors.toList());
    defaultInternalAccountTagService.merge(accountTagResponses);
    Map<String, String> accountTagsMap = accountTagResponses.stream().collect(Collectors.toMap(AccountTagResponse::getKey, AccountTagResponse::getValue));
    CDPTagGenerationRequest request = CDPTagGenerationRequest.Builder.builder().withCreatorCrn(creationDto.getCreator()).withEnvironmentCrn(creationDto.getCrn()).withAccountId(creationDto.getAccountId()).withPlatform(creationDto.getCloudPlatform()).withResourceCrn(creationDto.getCrn()).withIsInternalTenant(internalTenant).withUserName(getUserNameFromCrn(creationDto.getCreator())).withAccountTags(accountTagsMap).withUserDefinedTags(userDefinedTags).build();
    try {
        Map<String, String> defaultTags = costTagging.prepareDefaultTags(request);
        return new Json(new EnvironmentTags(Objects.requireNonNullElseGet(userDefinedTags, HashMap::new), defaultTags));
    } catch (AccountTagValidationFailed aTVF) {
        throw new BadRequestException(aTVF.getMessage());
    } catch (Exception e) {
        throw new BadRequestException("Failed to convert dynamic tags. " + e.getMessage(), e);
    }
}
Also used : AccountTag(com.sequenceiq.environment.tags.domain.AccountTag) HashMap(java.util.HashMap) AccountTagResponse(com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponse) Json(com.sequenceiq.cloudbreak.common.json.Json) AccountTagValidationFailed(com.sequenceiq.cloudbreak.tag.AccountTagValidationFailed) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) EnvironmentTags(com.sequenceiq.environment.environment.domain.EnvironmentTags) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest)

Example 2 with EnvironmentTags

use of com.sequenceiq.environment.environment.domain.EnvironmentTags in project cloudbreak by hortonworks.

the class EnvironmentTagProviderTest method init.

@BeforeAll
static void init() {
    AccountTagResponse accountTagResponse = new AccountTagResponse();
    accountTagResponse.setAccountId(ACCOUNT_ID);
    accountTagResponse.setKey(OWNER_TAG);
    accountTagResponse.setValue("{{{userName}}}");
    ACCOUNT_TAGS.add(accountTagResponse);
    USER_DEFINED_TAGS.put("userKey", "userValue");
    ENVIRONMENT.setAccountId(ACCOUNT_ID);
    ENVIRONMENT.setTags(new EnvironmentTags(USER_DEFINED_TAGS, Map.of()));
    ENVIRONMENT.setCreator(USER_CRN);
    ENVIRONMENT.setResourceCrn(ENV_CRN);
    ENVIRONMENT.setCloudPlatform("platform");
    ENVIRONMENT.setNetwork(NetworkDto.builder().withResourceCrn(NETWORK_CRN).build());
}
Also used : EnvironmentTags(com.sequenceiq.environment.environment.domain.EnvironmentTags) AccountTagResponse(com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponse) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with EnvironmentTags

use of com.sequenceiq.environment.environment.domain.EnvironmentTags in project cloudbreak by hortonworks.

the class FreeIpaCreationHandlerTest method someEnvironmentWithFreeIpaCreation.

private EnvironmentDto someEnvironmentWithFreeIpaCreation() {
    EnvironmentDto dto = new EnvironmentDto();
    dto.setId(ENVIRONMENT_ID);
    dto.setResourceCrn(ENVIRONMENT_CRN);
    dto.setCloudPlatform(CloudPlatform.AWS.name());
    dto.setTags(new EnvironmentTags(emptyMap(), emptyMap()));
    dto.setAuthentication(AuthenticationDto.builder().build());
    dto.setRegions(Set.of(createRegion("someWhereOverTheRainbow")));
    dto.setFreeIpaCreation(FreeIpaCreationDto.builder().withCreate(true).build());
    dto.setNetwork(NetworkDto.builder().withNetworkCidr(YARN_NETWORK_CIDR).build());
    return dto;
}
Also used : EnvironmentTags(com.sequenceiq.environment.environment.domain.EnvironmentTags) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto)

Aggregations

EnvironmentTags (com.sequenceiq.environment.environment.domain.EnvironmentTags)3 AccountTagResponse (com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponse)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Json (com.sequenceiq.cloudbreak.common.json.Json)1 AccountTagValidationFailed (com.sequenceiq.cloudbreak.tag.AccountTagValidationFailed)1 CDPTagGenerationRequest (com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 AccountTag (com.sequenceiq.environment.tags.domain.AccountTag)1 HashMap (java.util.HashMap)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1