Search in sources :

Example 1 with CDPTagGenerationRequest

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

the class StackService method setDefaultTags.

private void setDefaultTags(Stack stack) {
    try {
        StackTags stackTag = stack.getTags().get(StackTags.class);
        Map<String, String> userDefinedTags = stackTag.getUserDefinedTags();
        String accountId = Crn.safeFromString(stack.getResourceCrn()).getAccountId();
        boolean internalTenant = entitlementService.internalTenant(accountId);
        CDPTagGenerationRequest request = CDPTagGenerationRequest.Builder.builder().withCreatorCrn(stack.getCreator().getUserCrn()).withEnvironmentCrn(stack.getEnvironmentCrn()).withPlatform(stack.getCloudPlatform()).withAccountId(accountId).withResourceCrn(stack.getResourceCrn()).withIsInternalTenant(internalTenant).withUserName(stack.getCreator().getUserName()).withAccountTags(accountTagClientService.list()).withUserDefinedTags(userDefinedTags).build();
        Map<String, String> defaultTags = stackTag.getDefaultTags();
        defaultTags.putAll(costTagging.prepareDefaultTags(request));
        stack.setTags(new Json(new StackTags(userDefinedTags, stackTag.getApplicationTags(), defaultTags)));
    } catch (AccountTagValidationFailed aTVF) {
        throw new BadRequestException(aTVF.getMessage(), aTVF);
    } catch (Exception e) {
        LOGGER.debug("Exception during reading default tags.", e);
    }
}
Also used : StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest) Json(com.sequenceiq.cloudbreak.common.json.Json) AccountTagValidationFailed(com.sequenceiq.cloudbreak.tag.AccountTagValidationFailed) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) IOException(java.io.IOException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)

Example 2 with CDPTagGenerationRequest

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

the class CreateFreeIpaRequestToStackConverter method getDefaultTags.

private Map<String, String> getDefaultTags(Stack stack, String userCrn, String userName) {
    Map<String, String> result = new HashMap<>();
    try {
        boolean internalTenant = entitlementService.internalTenant(stack.getAccountId());
        Map<String, String> accountTags = accountTagService.list();
        CDPTagGenerationRequest request = CDPTagGenerationRequest.Builder.builder().withCreatorCrn(userCrn).withEnvironmentCrn(stack.getEnvironmentCrn()).withPlatform(stack.getCloudPlatform()).withAccountId(stack.getAccountId()).withResourceCrn(stack.getResourceCrn()).withIsInternalTenant(internalTenant).withUserName(userName).withAccountTags(accountTags).build();
        result.putAll(costTagging.prepareDefaultTags(request));
    } catch (Exception e) {
        LOGGER.debug("Exception during reading default tags.", e);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest) TimeoutException(java.util.concurrent.TimeoutException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with CDPTagGenerationRequest

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

the class EnvironmentTagProvider method getDefaultTags.

private Map<String, String> getDefaultTags(EnvironmentDto environmentDto, Map<String, String> userDefinedTags, Map<String, String> accountTagsMap, String resourceCrn) {
    boolean internalTenant = entitlementService.internalTenant(environmentDto.getAccountId());
    CDPTagGenerationRequest request = CDPTagGenerationRequest.Builder.builder().withCreatorCrn(environmentDto.getCreator()).withEnvironmentCrn(environmentDto.getResourceCrn()).withAccountId(environmentDto.getAccountId()).withPlatform(environmentDto.getCloudPlatform()).withResourceCrn(resourceCrn).withIsInternalTenant(internalTenant).withUserName(getUserNameFromCrn(environmentDto.getCreator())).withAccountTags(accountTagsMap).withUserDefinedTags(userDefinedTags).build();
    return costTagging.prepareDefaultTags(request);
}
Also used : CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest)

Example 4 with CDPTagGenerationRequest

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

the class DefaultCostTaggingServiceTest method testAccountTagUserTagConflictGeneratesError.

@Test
public void testAccountTagUserTagConflictGeneratesError() {
    Map<String, String> envMap = new HashMap<>();
    envMap.put("apple1", "apple1");
    envMap.put("apple2", "apple2");
    envMap.put("owner", "owner");
    Map<String, String> requestTag = new HashMap<>();
    requestTag.put("pear1", "pear1");
    requestTag.put("owner", "conflict");
    CDPTagGenerationRequest tagRequest = tagRequest("AWS", new HashMap<>(), envMap, requestTag);
    Map<String, String> result = underTest.prepareDefaultTags(tagRequest);
    Assert.assertEquals(6L, result.size());
    Assert.assertEquals("owner", result.get("owner"));
    Assert.assertEquals("creator-crn", result.get("Cloudera-Creator-Resource-Name"));
    Assert.assertEquals("apple1", result.get("apple1"));
    Assert.assertEquals("resource-crn", result.get("Cloudera-Resource-Name"));
    Assert.assertEquals("environment-crn", result.get("Cloudera-Environment-Resource-Name"));
    Assert.assertEquals("apple2", result.get("apple2"));
}
Also used : HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest) Test(org.junit.Test)

Example 5 with CDPTagGenerationRequest

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

the class DefaultCostTaggingServiceTest method testAccountTagUserTagEqualityNoError.

@Test
public void testAccountTagUserTagEqualityNoError() {
    Map<String, String> envMap = new HashMap<>();
    envMap.put("apple1", "apple1");
    envMap.put("apple2", "apple2");
    envMap.put("owner", "owner");
    Map<String, String> requestTag = new HashMap<>();
    requestTag.put("pear1", "pear1");
    requestTag.put("owner", "owner");
    CDPTagGenerationRequest tagRequest = tagRequest("AWS", new HashMap<>(), envMap, requestTag);
    underTest.prepareDefaultTags(tagRequest);
}
Also used : HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest) Test(org.junit.Test)

Aggregations

CDPTagGenerationRequest (com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest)8 HashMap (java.util.HashMap)5 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 Json (com.sequenceiq.cloudbreak.common.json.Json)3 StackTags (com.sequenceiq.cloudbreak.cloud.model.StackTags)2 AccountTagValidationFailed (com.sequenceiq.cloudbreak.tag.AccountTagValidationFailed)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)1 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)1 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)1 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)1 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)1 AccountTagResponse (com.sequenceiq.environment.api.v1.tags.model.response.AccountTagResponse)1 EnvironmentTags (com.sequenceiq.environment.environment.domain.EnvironmentTags)1 AccountTag (com.sequenceiq.environment.tags.domain.AccountTag)1 IOException (java.io.IOException)1