Search in sources :

Example 81 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentInitHandlerTest method testInitFailure.

@Test
void testInitFailure() {
    EnvironmentDto dto = getEnvironmentDto();
    Event<EnvironmentDto> event = new Event<>(dto);
    Environment environment = getEnvironment();
    when(environmentService.findEnvironmentById(dto.getId())).thenReturn(Optional.of(environment));
    when(virtualGroupService.createVirtualGroups(anyString(), anyString())).thenThrow(IllegalStateException.class);
    environmentInitHandler.accept(event);
    verify(eventBus, times(1)).notify(eq(FAILED_ENV_CREATION_EVENT.name()), any(Event.class));
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Event(reactor.bus.Event) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 82 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentValidationHandlerTest method acceptAndSendStartNetworkCreationEventWhenNoValidationErrorFound.

@Test
void acceptAndSendStartNetworkCreationEventWhenNoValidationErrorFound() {
    EnvironmentValidationDto environmentValidationDto = createEnvironmentValidationDto();
    Environment environment = new Environment();
    when(environmentService.findEnvironmentById(anyLong())).thenReturn(Optional.of(environment));
    when(validatorService.validateRegionsAndLocation(any(), any(), eq(environment), any())).thenReturn(new ValidationResultBuilder());
    when(cloudStorageValidator.validateCloudStorage(any(), any())).thenReturn(ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build());
    underTest.accept(Event.wrap(environmentValidationDto));
    verify(eventSender, times(1)).sendEvent(any(EnvCreationEvent.class), any());
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) Test(org.junit.jupiter.api.Test)

Example 83 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class FreeIpaDeletionHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
    EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
    EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
    Environment environment = environmentService.findEnvironmentById(environmentDto.getId()).orElse(null);
    try {
        if (shouldRemoveFreeIpa(environment)) {
            if (Objects.nonNull(environment.getParentEnvironment())) {
                detachChildEnvironmentFromFreeIpa(environment);
            } else {
                deleteFreeIpa(environment, environmentDeletionDto.isForceDelete());
            }
        }
        eventSender().sendEvent(getNextStepObject(environmentDeletionDto), environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder().withEnvironmentID(environmentDto.getId()).withException(e).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteFailedEvent) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) NotFoundException(javax.ws.rs.NotFoundException) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 84 with Environment

use of com.sequenceiq.environment.environment.domain.Environment 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)

Example 85 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentModificationService method changeCredential.

private EnvironmentDto changeCredential(String accountId, String environmentName, EnvironmentChangeCredentialDto dto, Environment environment) {
    // CHECKSTYLE:OFF
    // TODO: 2019. 06. 03. also we have to check for SDXs and DistroXs what uses the given credential. If there is at least one, we have to update the crn reference
    // through the other services
    // CHECKSTYLE:ON
    Credential credential = credentialService.getByNameForAccountId(dto.getCredentialName(), accountId, ENVIRONMENT);
    environment.setCredential(credential);
    LOGGER.debug("About to change credential on environment \"{}\"", environmentName);
    Environment saved = environmentService.save(environment);
    return environmentDtoConverter.environmentToDto(saved);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Environment(com.sequenceiq.environment.environment.domain.Environment)

Aggregations

Environment (com.sequenceiq.environment.environment.domain.Environment)187 Test (org.junit.jupiter.api.Test)145 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)48 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)42 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)29 Credential (com.sequenceiq.environment.credential.domain.Credential)26 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)21 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)16 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)15 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)14 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)13 SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)12 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)11 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)11 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)11 Headers (reactor.bus.Event.Headers)11 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)10 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)10