use of com.sequenceiq.environment.parameter.dto.AzureParametersDto in project cloudbreak by hortonworks.
the class EnvironmentResponseConverter method azureEnvParamsToAzureEnvironmentParams.
private AzureEnvironmentParameters azureEnvParamsToAzureEnvironmentParams(ParametersDto parameters) {
AzureResourceGroupDto resourceGroupDto = Optional.ofNullable(parameters.getAzureParametersDto()).map(AzureParametersDto::getAzureResourceGroupDto).filter(rgDto -> Objects.nonNull(rgDto.getResourceGroupUsagePattern())).filter(rgDto -> Objects.nonNull(rgDto.getResourceGroupCreation())).orElse(null);
AzureResourceEncryptionParametersDto resourceEncryptionParametersDto = Optional.ofNullable(parameters.getAzureParametersDto()).map(AzureParametersDto::getAzureResourceEncryptionParametersDto).orElse(null);
return AzureEnvironmentParameters.builder().withAzureResourceGroup(getIfNotNull(resourceGroupDto, this::azureParametersToAzureResourceGroup)).withResourceEncryptionParameters(getIfNotNull(resourceEncryptionParametersDto, this::azureParametersToAzureResourceEncryptionParameters)).build();
}
use of com.sequenceiq.environment.parameter.dto.AzureParametersDto in project cloudbreak by hortonworks.
the class ResourceEncryptionInitializationHandler method accept.
@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
LOGGER.debug("Accepting ResourceEncryptionInitialization event");
EnvironmentDto environmentDto = environmentDtoEvent.getData();
try {
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
if (AZURE.name().equalsIgnoreCase(environmentDto.getCloudPlatform())) {
String encryptionKeyUrl = Optional.ofNullable(environmentDto.getParameters()).map(ParametersDto::getAzureParametersDto).map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyUrl).orElse(null);
String environmentName = environment.getName();
if (StringUtils.isNotEmpty(encryptionKeyUrl)) {
if (environment.getStatus() != EnvironmentStatus.ENVIRONMENT_ENCRYPTION_RESOURCES_INITIALIZED) {
initializeEncryptionResources(environmentDto, environment);
} else {
LOGGER.info("Initialization of encryption resources for environment \"{}\" has already been triggered, " + "continuing without new initialize trigger. Environment status: {}", environmentName, environment.getStatus());
}
} else {
LOGGER.info("Environment \"{}\" has not requested for SSE with CMK.", environmentName);
}
}
});
EnvCreationEvent envCreationEvent = getEnvCreateEvent(environmentDto);
eventSender().sendEvent(envCreationEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
LOGGER.error("ResourceEncryptionInitialization failed with error.", e);
EnvCreationFailureEvent failedEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), e, environmentDto.getResourceCrn());
Event<EnvCreationFailureEvent> ev = new Event<>(environmentDtoEvent.getHeaders(), failedEvent);
eventBus.notify(failedEvent.selector(), ev);
}
}
use of com.sequenceiq.environment.parameter.dto.AzureParametersDto in project cloudbreak by hortonworks.
the class ResourceEncryptionDeleteHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
LOGGER.debug("Accepting ResourceEncryptionDelete event");
EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
try {
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
if (AZURE.name().equalsIgnoreCase(environmentDto.getCloudPlatform())) {
String encryptionKeyUrl = Optional.ofNullable(environmentDto.getParameters()).map(ParametersDto::getAzureParametersDto).map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyUrl).orElse(null);
if (StringUtils.isNotEmpty(encryptionKeyUrl) && (environment.getStatus() != EnvironmentStatus.ENVIRONMENT_ENCRYPTION_RESOURCES_DELETED)) {
deleteEncryptionResources(environmentDto, environment);
} else {
LOGGER.info("No encryption resources found to delete for environment \"{}\".", environment.getName());
}
}
});
eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
LOGGER.error("ResourceEncryptionDelete failed with error.", e);
exceptionProcessor.handle(new HandlerFailureConjoiner(e, environmentDtoEvent, envDeleteEvent), LOGGER, eventSender(), selector());
}
}
use of com.sequenceiq.environment.parameter.dto.AzureParametersDto in project cloudbreak by hortonworks.
the class AzureParameterValidator method validate.
@Override
public ValidationResult validate(EnvironmentValidationDto environmentValidationDto, ParametersDto parametersDto, ValidationResultBuilder validationResultBuilder) {
EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
LOGGER.debug("ParametersDto: {}", parametersDto);
AzureParametersDto azureParametersDto = parametersDto.azureParametersDto();
if (Objects.isNull(azureParametersDto)) {
return validationResultBuilder.build();
}
ValidationResult validationResult;
AzureResourceEncryptionParametersDto azureResourceEncryptionParametersDto = azureParametersDto.getAzureResourceEncryptionParametersDto();
if (azureResourceEncryptionParametersDto != null) {
validationResult = validateEncryptionParameters(validationResultBuilder, azureParametersDto, environmentDto.getAccountId());
if (validationResult.hasError()) {
return validationResult;
}
}
AzureResourceGroupDto azureResourceGroupDto = azureParametersDto.getAzureResourceGroupDto();
if (Objects.isNull(azureResourceGroupDto)) {
return validationResultBuilder.build();
}
validationResult = validateEntitlement(validationResultBuilder, azureResourceGroupDto, environmentDto.getAccountId());
if (validationResult.hasError()) {
return validationResult;
}
if (USE_MULTIPLE.equals(azureResourceGroupDto.getResourceGroupUsagePattern())) {
return validateMultipleResourceGroupUsage(validationResultBuilder, azureResourceGroupDto);
}
if (USE_EXISTING.equals(azureResourceGroupDto.getResourceGroupCreation())) {
return validateExistingResourceGroupUsage(validationResultBuilder, environmentDto, azureResourceGroupDto);
}
return validationResultBuilder.build();
}
use of com.sequenceiq.environment.parameter.dto.AzureParametersDto in project cloudbreak by hortonworks.
the class AzureEnvironmentParametersConverter method postConvert.
@Override
protected void postConvert(BaseParameters baseParameters, Environment environment, ParametersDto parametersDto) {
super.postConvert(baseParameters, environment, parametersDto);
AzureParameters azureParameters = (AzureParameters) baseParameters;
Optional<AzureParametersDto> azureParametersDto = Optional.of(parametersDto).map(ParametersDto::getAzureParametersDto);
azureParameters.setResourceGroupName(azureParametersDto.map(AzureParametersDto::getAzureResourceGroupDto).map(AzureResourceGroupDto::getName).orElse(null));
azureParameters.setResourceGroupCreation(azureParametersDto.map(AzureParametersDto::getAzureResourceGroupDto).map(AzureResourceGroupDto::getResourceGroupCreation).orElse(null));
azureParameters.setResourceGroupUsagePattern(azureParametersDto.map(AzureParametersDto::getAzureResourceGroupDto).map(AzureResourceGroupDto::getResourceGroupUsagePattern).orElse(null));
azureParameters.setEncryptionKeyUrl(azureParametersDto.map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyUrl).orElse(null));
azureParameters.setEncryptionKeyResourceGroupName(azureParametersDto.map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyResourceGroupName).orElse(null));
}
Aggregations