Search in sources :

Example 1 with PublicEndpointAccessGateway

use of com.sequenceiq.common.api.type.PublicEndpointAccessGateway in project cloudbreak by hortonworks.

the class EnvironmentCreationService method create.

public EnvironmentDto create(EnvironmentCreationDto creationDto) {
    LOGGER.info("Environment creation initiated.");
    PublicEndpointAccessGateway endpointAccessGateway = creationDto.getNetwork() == null ? null : creationDto.getNetwork().getPublicEndpointAccessGateway();
    loadBalancerEntitlementService.validateNetworkForEndpointGateway(creationDto.getCloudPlatform(), creationDto.getName(), endpointAccessGateway);
    if (environmentService.isNameOccupied(creationDto.getName(), creationDto.getAccountId())) {
        throw new BadRequestException(String.format("Environment with name '%s' already exists in account '%s'.", creationDto.getName(), creationDto.getAccountId()));
    }
    Environment environment = initializeEnvironment(creationDto);
    initializeEnvironmentTunnel(environment);
    if (StringUtils.isNotEmpty(creationDto.getParentEnvironmentName())) {
        LOGGER.debug("Setting parent environment '{}'.", creationDto.getParentEnvironmentName());
        Optional<Environment> parentEnvironment = environmentService.findByNameAndAccountIdAndArchivedIsFalse(creationDto.getParentEnvironmentName(), creationDto.getAccountId());
        parentEnvironment.ifPresent(environment::setParentEnvironment);
    }
    environmentService.setSecurityAccess(environment, creationDto.getSecurityAccess());
    validateCreation(creationDto, environment);
    try {
        environment = environmentService.save(environment);
        environmentResourceService.createAndSetNetwork(environment, creationDto.getNetwork(), creationDto.getAccountId(), getIfNotNull(creationDto.getNetwork(), NetworkDto::getSubnetMetas), getIfNotNull(creationDto.getNetwork(), NetworkDto::getEndpointGatewaySubnetMetas));
        createAndSetParameters(environment, creationDto.getParameters());
        environmentService.saveWithOwnerRoleAssignment(environment);
        reactorFlowManager.triggerCreationFlow(environment.getId(), environment.getName(), creationDto.getCreator(), environment.getResourceCrn());
    } catch (Exception e) {
        environment.setStatus(EnvironmentStatus.CREATE_FAILED);
        environment.setStatusReason(e.getMessage());
        environmentService.save(environment);
        throw e;
    }
    return environmentDtoConverter.environmentToDto(environment);
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) Environment(com.sequenceiq.environment.environment.domain.Environment) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) BadRequestException(javax.ws.rs.BadRequestException)

Aggregations

PublicEndpointAccessGateway (com.sequenceiq.common.api.type.PublicEndpointAccessGateway)1 Environment (com.sequenceiq.environment.environment.domain.Environment)1 BadRequestException (javax.ws.rs.BadRequestException)1