Search in sources :

Example 6 with AzureParameters

use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testUpdateAzureResourceEncryptionParametersByEnvironmentCrn.

@Test
void testUpdateAzureResourceEncryptionParametersByEnvironmentCrn() {
    UpdateAzureResourceEncryptionDto updateAzureResourceEncryptionDto = UpdateAzureResourceEncryptionDto.builder().withAzureResourceEncryptionParametersDto(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl("dummyKeyUrl").withEncryptionKeyResourceGroupName("dummyResourceGroupName").build()).build();
    CreatedDiskEncryptionSet createdDiskEncryptionSet = new CreatedDiskEncryptionSet.Builder().withDiskEncryptionSetId("dummyId").build();
    Environment env = new Environment();
    env.setParameters(new AzureParameters());
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
    when(validatorService.validateEncryptionKeyUrl(any(String.class), any(String.class))).thenReturn(ValidationResult.builder().build());
    when(environmentDtoConverter.environmentToDto(env)).thenReturn(new EnvironmentDto());
    when(environmentEncryptionService.createEncryptionResources(any(EnvironmentDto.class))).thenReturn(createdDiskEncryptionSet);
    environmentModificationServiceUnderTest.updateAzureResourceEncryptionParametersByEnvironmentCrn(ACCOUNT_ID, ENVIRONMENT_NAME, updateAzureResourceEncryptionDto);
    ArgumentCaptor<AzureParameters> azureParametersArgumentCaptor = ArgumentCaptor.forClass(AzureParameters.class);
    verify(azureParametersRepository).save(azureParametersArgumentCaptor.capture());
    assertEquals("dummyKeyUrl", azureParametersArgumentCaptor.getValue().getEncryptionKeyUrl());
    assertEquals("dummyResourceGroupName", azureParametersArgumentCaptor.getValue().getEncryptionKeyResourceGroupName());
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) Environment(com.sequenceiq.environment.environment.domain.Environment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UpdateAzureResourceEncryptionDto(com.sequenceiq.environment.environment.dto.UpdateAzureResourceEncryptionDto) Test(org.junit.jupiter.api.Test)

Example 7 with AzureParameters

use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.

the class ResourceEncryptionInitializationHandlerTest method acceptTestEnvironmentShouldBeUpdatedWhenEncryptionKeyUrlIsPresentAndStatusNotYetInitialized.

@Test
void acceptTestEnvironmentShouldBeUpdatedWhenEncryptionKeyUrlIsPresentAndStatusNotYetInitialized() {
    doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEventCaptor.capture(), any(Headers.class));
    Environment environment = new Environment();
    environment.setParameters(newAzureParameters());
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
    CreatedDiskEncryptionSet createdDiskEncryptionSet = new CreatedDiskEncryptionSet.Builder().withDiskEncryptionSetId(DISK_ENCRYPTION_SET_ID).build();
    when(environmentEncryptionService.createEncryptionResources(any(EnvironmentDto.class))).thenReturn(createdDiskEncryptionSet);
    underTest.accept(environmentDtoEvent);
    verify(eventSender).sendEvent(baseNamedFlowEventCaptor.capture(), headersArgumentCaptor.capture());
    verify(environmentService).save(environment);
    AzureParameters azureParameters = (AzureParameters) environment.getParameters();
    assertEquals(azureParameters.getDiskEncryptionSetId(), DISK_ENCRYPTION_SET_ID);
    assertEquals(environment.getStatus(), EnvironmentStatus.ENVIRONMENT_ENCRYPTION_RESOURCES_INITIALIZED);
    verifyEnvCreationEvent();
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) Headers(reactor.bus.Event.Headers) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 8 with AzureParameters

use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.

the class EnvironmentModificationService method updateAzureResourceEncryptionParameters.

private EnvironmentDto updateAzureResourceEncryptionParameters(String accountId, String environmentName, AzureResourceEncryptionParametersDto dto, Environment environment) {
    AzureParameters azureParameters = (AzureParameters) environment.getParameters();
    if (azureParameters.getEncryptionKeyUrl() == null) {
        ValidationResult validateKey = environmentService.getValidatorService().validateEncryptionKeyUrl(dto.getEncryptionKeyUrl(), accountId);
        if (!validateKey.hasError()) {
            azureParameters.setEncryptionKeyUrl(dto.getEncryptionKeyUrl());
            azureParameters.setEncryptionKeyResourceGroupName(dto.getEncryptionKeyResourceGroupName());
            // creating the DES
            try {
                CreatedDiskEncryptionSet createdDiskEncryptionSet = environmentEncryptionService.createEncryptionResources(environmentDtoConverter.environmentToDto(environment));
                azureParameters.setDiskEncryptionSetId(createdDiskEncryptionSet.getDiskEncryptionSetId());
                azureParametersRepository.save(azureParameters);
            } catch (Exception e) {
                throw new BadRequestException(e);
            }
            LOGGER.debug("Successfully created the Disk encryption set for the environment {}.", environmentName);
        } else {
            throw new BadRequestException(validateKey.getFormattedErrors());
        }
    } else if (azureParameters.getEncryptionKeyUrl().equals(dto.getEncryptionKeyUrl())) {
        LOGGER.info("Encryption Key '%s' is already set for the environment '%s'. ", azureParameters.getEncryptionKeyUrl(), environmentName);
    } else {
        throw new BadRequestException(String.format("Encryption Key '%s' is already set for the environment '%s'. " + "Modifying the encryption key is not allowed.", azureParameters.getEncryptionKeyUrl(), environmentName));
    }
    return environmentDtoConverter.environmentToDto(environment);
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) BadRequestException(javax.ws.rs.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 9 with AzureParameters

use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.

the class AzureEnvironmentParametersConverterTest method convertTest.

@Test
void convertTest() {
    when(environmentViewConverter.convert(any(Environment.class))).thenReturn(ENVIRONMENT_VIEW);
    ParametersDto parameters = ParametersDto.builder().withId(ID).withAzureParameters(AzureParametersDto.builder().withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl(KEY_URL).withEncryptionKeyResourceGroupName(KEY_RESOURCE_GROUP_NAME).build()).build()).build();
    Environment environment = new Environment();
    environment.setName(ENV_NAME);
    environment.setAccountId(ACCOUNT_ID);
    BaseParameters result = underTest.convert(environment, parameters);
    assertEquals(AzureParameters.class, result.getClass());
    AzureParameters azureResult = (AzureParameters) result;
    assertEquals(ENV_NAME, azureResult.getName());
    assertEquals(ACCOUNT_ID, azureResult.getAccountId());
    assertEquals(ENVIRONMENT_VIEW, azureResult.getEnvironment());
    assertEquals(ID, azureResult.getId());
    assertEquals(KEY_URL, azureResult.getEncryptionKeyUrl());
    assertEquals(KEY_RESOURCE_GROUP_NAME, azureResult.getEncryptionKeyResourceGroupName());
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) Test(org.junit.jupiter.api.Test)

Example 10 with AzureParameters

use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.

the class AzureEnvironmentParametersConverterTest method convertToDtoTest.

@Test
void convertToDtoTest() {
    EnvironmentView environmentView = ENVIRONMENT_VIEW;
    AzureParameters parameters = new AzureParameters();
    parameters.setAccountId(ACCOUNT_ID);
    parameters.setEnvironment(environmentView);
    parameters.setId(ID);
    parameters.setName(ENV_NAME);
    parameters.setEncryptionKeyUrl(KEY_URL);
    parameters.setDiskEncryptionSetId("DummyDesId");
    parameters.setEncryptionKeyResourceGroupName(KEY_RESOURCE_GROUP_NAME);
    ParametersDto result = underTest.convertToDto(parameters);
    assertEquals(ACCOUNT_ID, result.getAccountId());
    assertEquals(ID, result.getId());
    assertEquals(ENV_NAME, result.getName());
    assertEquals(KEY_URL, result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyUrl());
    assertEquals("DummyDesId", result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getDiskEncryptionSetId());
    assertEquals(KEY_RESOURCE_GROUP_NAME, result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyResourceGroupName());
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) EnvironmentView(com.sequenceiq.environment.environment.domain.EnvironmentView) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) Test(org.junit.jupiter.api.Test)

Aggregations

AzureParameters (com.sequenceiq.environment.parameters.dao.domain.AzureParameters)13 Test (org.junit.jupiter.api.Test)7 Environment (com.sequenceiq.environment.environment.domain.Environment)6 CreatedDiskEncryptionSet (com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 UpdateAzureResourceEncryptionDto (com.sequenceiq.environment.environment.dto.UpdateAzureResourceEncryptionDto)4 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)3 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)3 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)2 BadRequestException (javax.ws.rs.BadRequestException)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)1 EnvironmentView (com.sequenceiq.environment.environment.domain.EnvironmentView)1 AzureResourceGroupDto (com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto)1 Headers (reactor.bus.Event.Headers)1