Search in sources :

Example 6 with CreatedDiskEncryptionSet

use of com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet 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 CreatedDiskEncryptionSet

use of com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet 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 CreatedDiskEncryptionSet

use of com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet in project cloudbreak by hortonworks.

the class EnvironmentEncryptionServiceTest method testCreateEncryptionResourcesShouldCallCreateDiskEncryptionSetWhenCloudPlatformAzure.

@Test
void testCreateEncryptionResourcesShouldCallCreateDiskEncryptionSetWhenCloudPlatformAzure() {
    when(cloudPlatformConnectors.get(any(CloudPlatformVariant.class))).thenReturn(cloudConnector);
    when(cloudConnector.encryptionResources()).thenReturn(encryptionResources);
    EnvironmentDto environmentDto = EnvironmentDto.builder().withResourceCrn(ENVIRONMENT_CRN).withId(ENVIRONMENT_ID).withName(ENVIRONMENT_NAME).withCloudPlatform(CLOUD_PLATFORM).withCredential(credential).withLocationDto(LocationDto.builder().withName(REGION).build()).withParameters(ParametersDto.builder().withAzureParameters(AzureParametersDto.builder().withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl(KEY_URL).build()).withResourceGroup(AzureResourceGroupDto.builder().withResourceGroupUsagePattern(ResourceGroupUsagePattern.USE_SINGLE).withName(RESOURCE_GROUP_NAME).build()).build()).build()).build();
    CreatedDiskEncryptionSet dummyDes = new CreatedDiskEncryptionSet.Builder().withDiskEncryptionSetId(DISK_ENCRYPTION_SET_ID).build();
    when(encryptionResources.createDiskEncryptionSet(any(DiskEncryptionSetCreationRequest.class))).thenReturn(dummyDes);
    CreatedDiskEncryptionSet createdDes = underTest.createEncryptionResources(environmentDto);
    assertEquals(createdDes.getDiskEncryptionSetId(), DISK_ENCRYPTION_SET_ID);
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) DiskEncryptionSetCreationRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetCreationRequest) Test(org.junit.jupiter.api.Test)

Example 9 with CreatedDiskEncryptionSet

use of com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet 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 10 with CreatedDiskEncryptionSet

use of com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet in project cloudbreak by hortonworks.

the class ResourceEncryptionInitializationHandler method initializeEncryptionResources.

private void initializeEncryptionResources(EnvironmentDto environmentDto, Environment environment) {
    String environmentName = environment.getName();
    LOGGER.info("Initializing encryption resources for environment \"{}\".", environmentName);
    try {
        CreatedDiskEncryptionSet createdDiskEncryptionSet = environmentEncryptionService.createEncryptionResources(environmentDto);
        LOGGER.info("Created Disk Encryption Set resource for environment \"{}\": {}", environmentName, createdDiskEncryptionSet);
        AzureParameters azureParameters = (AzureParameters) environment.getParameters();
        azureParameters.setDiskEncryptionSetId(createdDiskEncryptionSet.getDiskEncryptionSetId());
        environment.setStatus(EnvironmentStatus.ENVIRONMENT_ENCRYPTION_RESOURCES_INITIALIZED);
        environment.setStatusReason(null);
        environmentService.save(environment);
        LOGGER.info("Finished initializing encryption resources for environment \"{}\".", environmentName);
    } catch (Exception e) {
        LOGGER.error(String.format("Failed to initialize encryption resources for environment \"%s\"", environmentName), e);
        throw new CloudbreakServiceException("Error occurred while initializing encryption resources: " + e.getMessage(), e);
    }
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Aggregations

CreatedDiskEncryptionSet (com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet)13 Test (org.junit.jupiter.api.Test)9 DiskEncryptionSetInner (com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)6 DiskEncryptionSetCreationRequest (com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetCreationRequest)6 EncryptionSetIdentity (com.microsoft.azure.management.compute.EncryptionSetIdentity)5 KeyForDiskEncryptionSet (com.microsoft.azure.management.compute.KeyForDiskEncryptionSet)5 SourceVault (com.microsoft.azure.management.compute.SourceVault)5 Subscription (com.microsoft.azure.management.resources.Subscription)5 DiskEncryptionSetCreationCheckerContext (com.sequenceiq.cloudbreak.cloud.azure.task.diskencryptionset.DiskEncryptionSetCreationCheckerContext)5 ResourcePersisted (com.sequenceiq.cloudbreak.cloud.notification.model.ResourcePersisted)5 AzureParameters (com.sequenceiq.environment.parameters.dao.domain.AzureParameters)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 Environment (com.sequenceiq.environment.environment.domain.Environment)3 UpdateAzureResourceEncryptionDto (com.sequenceiq.environment.environment.dto.UpdateAzureResourceEncryptionDto)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)1