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);
}
}
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;
}
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);
}
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"));
}
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);
}
Aggregations