Search in sources :

Example 96 with Json

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);
    }
}
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 97 with Json

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();
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) HashSet(java.util.HashSet)

Example 98 with Json

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;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroupNetwork(com.sequenceiq.freeipa.entity.InstanceGroupNetwork) HashSet(java.util.HashSet) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup)

Example 99 with Json

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;
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException)

Example 100 with Json

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);
}
Also used : Network(com.sequenceiq.cloudbreak.cloud.model.Network) Json(com.sequenceiq.cloudbreak.common.json.Json)

Aggregations

Json (com.sequenceiq.cloudbreak.common.json.Json)266 Test (org.junit.jupiter.api.Test)95 HashMap (java.util.HashMap)49 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)31 Template (com.sequenceiq.freeipa.entity.Template)26 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)25 List (java.util.List)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)24 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)23 Map (java.util.Map)22 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)21 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)21 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)21 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)20 IOException (java.io.IOException)20 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)18 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)16 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)16 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)14