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));
}
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());
}
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());
}
}
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);
}
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);
}
Aggregations