Search in sources :

Example 6 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class ContainerConfigService method create.

private Component create(Stack stack, DockerContainer dc) throws CloudbreakException {
    try {
        ContainerConfig config;
        ContainerOrchestrator orchestrator = containerOrchestratorResolver.get(stack.getOrchestrator().getType());
        Map<String, String> customContainerConfig = getCustomContainerConfig(stack);
        Optional<String> customContainerName = Optional.ofNullable(customContainerConfig.get(dc.name()));
        Optional<String> customQueue = getCustomQueue(stack);
        switch(dc) {
            case AMBARI_SERVER:
                config = new Builder(orchestrator.ambariServerContainer(customContainerName), customQueue).build();
                break;
            case AMBARI_AGENT:
                config = new Builder(orchestrator.ambariClientContainer(customContainerName), customQueue).build();
                break;
            case AMBARI_DB:
                config = new Builder(orchestrator.ambariDbContainer(customContainerName), customQueue).build();
                break;
            default:
                throw new CloudbreakServiceException(String.format("No configuration exist for %s", dc));
        }
        Component component = new Component(ComponentType.CONTAINER, dc.name(), new Json(config), stack);
        return componentConfigProviderService.store(component);
    } catch (IllegalArgumentException ignored) {
        throw new CloudbreakServiceException(String.format("Failed to parse component ContainerConfig for stack: %d, container: %s", stack.getId(), dc.getName()));
    }
}
Also used : ContainerConfig(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConfig) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Builder(com.sequenceiq.cloudbreak.core.bootstrap.config.ContainerConfigBuilder.Builder) Json(com.sequenceiq.cloudbreak.common.json.Json) Component(com.sequenceiq.cloudbreak.domain.stack.Component)

Example 7 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class NetworkV4RequestToNetworkConverter method convert.

public Network convert(NetworkV4Request source) {
    Network network = new Network();
    network.setName(missingResourceNameGenerator.generateName(APIResourceType.NETWORK));
    network.setSubnetCIDR(source.getSubnetCIDR());
    network.setOutboundInternetTraffic(OutboundInternetTraffic.ENABLED);
    Map<String, Object> parameters = providerParameterCalculator.get(source).asMap();
    if (parameters != null) {
        try {
            network.setAttributes(new Json(parameters));
        } catch (IllegalArgumentException ignored) {
            throw new BadRequestException("Invalid parameters");
        }
    }
    return network;
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 8 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class GatewayTopologyToGatewayTopologyV4RequestConverter method convert.

public GatewayTopologyV4Request convert(GatewayTopology gatewayTopology) {
    GatewayTopologyV4Request gatewayTopologyJson = new GatewayTopologyV4Request();
    gatewayTopologyJson.setTopologyName(gatewayTopology.getTopologyName());
    Json exposedJson = gatewayTopology.getExposedServices();
    if (exposedJson != null && StringUtils.isNotEmpty(exposedJson.getValue())) {
        try {
            gatewayTopologyJson.setExposedServices(exposedJson.get(ExposedServices.class).getServices());
        } catch (IOException e) {
            LOGGER.info("Failed to add exposedServices to response", e);
            throw new CloudbreakApiException("Failed to add exposedServices to response", e);
        }
    }
    return gatewayTopologyJson;
}
Also used : GatewayTopologyV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 9 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class GatewayTopologyV4RequestToGatewayTopologyConverter method convertExposedServices.

private void convertExposedServices(GatewayTopology gatewayTopology, GatewayTopologyV4Request source) {
    try {
        if (!CollectionUtils.isEmpty(source.getExposedServices())) {
            ExposedServices exposedServices = gatewayTopologyV4RequestToExposedServicesConverter.convert(source);
            gatewayTopology.setExposedServices(new Json(exposedServices));
        }
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Invalid exposedServices in request. Could not be parsed to JSON.", e);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ExposedServices(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.ExposedServices) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 10 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class InstanceGroupToInstanceGroupV4ResponseConverter method convert.

public InstanceGroupV4Response convert(InstanceGroup source) {
    InstanceGroupV4Response instanceGroupResponse = new InstanceGroupV4Response();
    instanceGroupResponse.setId(source.getId());
    if (source.getTemplate() != null) {
        instanceGroupResponse.setTemplate(templateToInstanceTemplateV4ResponseConverter.convert(source.getTemplate()));
    }
    instanceGroupResponse.setMetadata(source.getNotTerminatedInstanceMetaDataSet().stream().map(s -> instanceMetaDataToInstanceMetaDataV4ResponseConverter.convert(s)).collect(Collectors.toSet()));
    if (source.getSecurityGroup() != null) {
        instanceGroupResponse.setSecurityGroup(securityGroupToSecurityGroupResponseConverter.convert(source.getSecurityGroup()));
    }
    Json attributes = source.getAttributes();
    if (attributes != null) {
        providerParameterCalculator.parse(attributes.getMap(), instanceGroupResponse);
    }
    instanceGroupResponse.setNodeCount(source.getNodeCount());
    instanceGroupResponse.setName(source.getGroupName());
    instanceGroupResponse.setMinimumNodeCount(source.getMinimumNodeCount());
    instanceGroupResponse.setType(source.getInstanceGroupType());
    if (source.getInstanceGroupNetwork() != null) {
        instanceGroupResponse.setNetwork(instanceGroupNetworkToInstanceGroupNetworkV4ResponseConverter.convert(source.getInstanceGroupNetwork()));
    }
    instanceGroupResponse.setAvailabilityZones(source.getAvailabilityZones());
    instanceGroupResponse.setScalabilityOption(source.getScalabilityOption() == null ? ScalabilityOption.ALLOWED : source.getScalabilityOption());
    return instanceGroupResponse;
}
Also used : InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) 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