use of com.sequenceiq.cloudbreak.common.json.Json 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);
}
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class MultiAzCalculatorService method collectSubnetIds.
private Set<String> collectSubnetIds(InstanceGroup instanceGroup) {
InstanceGroupNetwork instanceGroupNetwork = instanceGroup.getInstanceGroupNetwork();
if (instanceGroupNetwork != null && instanceGroupNetwork.getAttributes() != null) {
Json attributes = instanceGroupNetwork.getAttributes();
List<String> subnetIds = (List<String>) attributes.getMap().getOrDefault(SUBNET_IDS, List.of());
return new HashSet<>(subnetIds);
} else {
return Set.of();
}
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class MultiAzValidator method collectSubnetIds.
private Set<String> collectSubnetIds(Iterable<InstanceGroup> instanceGroups) {
Set<String> allSubnetIds = new HashSet<>();
for (InstanceGroup instanceGroup : instanceGroups) {
InstanceGroupNetwork instanceGroupNetwork = instanceGroup.getInstanceGroupNetwork();
if (instanceGroupNetwork != null) {
Json attributes = instanceGroupNetwork.getAttributes();
if (attributes != null) {
List<String> subnetIds = (List<String>) attributes.getMap().getOrDefault(NetworkConstants.SUBNET_IDS, new ArrayList<>());
allSubnetIds.addAll(subnetIds);
}
}
}
return allSubnetIds;
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class ResourceAttributeUtil method getTypedAttributes.
public Optional<Object> getTypedAttributes(Resource resource) {
Json attributes = resource.getAttributes();
Optional<Object> ret = Optional.empty();
try {
if (Objects.nonNull(attributes.getValue())) {
Map<String, Object> map = attributes.get(Map.class);
String className = map.getOrDefault(CloudResource.ATTRIBUTE_TYPE, VolumeSetAttributes.class.getCanonicalName()).toString();
LOGGER.debug("Casting resource attributes to class: {}", className);
ret = Optional.ofNullable(attributes.get(Class.forName(className)));
}
} catch (IOException e) {
throw new CloudbreakServiceException("Failed to parse attributes to type: " + attributes, e);
} catch (ClassNotFoundException e) {
LOGGER.debug("Cannot parse class: {}", e.getMessage());
}
return ret;
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class DBStackToDatabaseStackConverter method buildNetwork.
private Network buildNetwork(DBStack dbStack) {
com.sequenceiq.redbeams.domain.stack.Network dbStackNetwork = dbStack.getNetwork();
if (dbStackNetwork == null) {
return null;
}
Json attributes = dbStackNetwork.getAttributes();
Map<String, Object> params = attributes == null ? Collections.emptyMap() : attributes.getMap();
return new Network(null, params);
}
Aggregations