Search in sources :

Example 6 with DiskEncryptionSetDeletionRequest

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

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetShouldReturnSilentlyWhenThereIsNoCloudResource.

@Test
void testDeleteDiskEncryptionSetShouldReturnSilentlyWhenThereIsNoCloudResource() {
    List<CloudResource> resources = List.of();
    DiskEncryptionSetDeletionRequest deletionRequest = new DiskEncryptionSetDeletionRequest.Builder().withCloudCredential(cloudCredential).withCloudContext(cloudContext).withCloudResources(resources).build();
    initCloudResourceHelper(resources);
    underTest.deleteDiskEncryptionSet(deletionRequest);
    verify(azureClientService, never()).getClient(any(CloudCredential.class));
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with DiskEncryptionSetDeletionRequest

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

the class AzureEncryptionResourcesTest method testDeleteDiskEncryptionSetShouldNotMakeCloudCallWhenDiskEncryptionSetIsNotFound.

@Test
public void testDeleteDiskEncryptionSetShouldNotMakeCloudCallWhenDiskEncryptionSetIsNotFound() {
    List<CloudResource> resources = getResources("/subscriptions/dummySubscriptionId/resourceGroups/dummyResourceGroup/providers/" + "Microsoft.Compute/diskEncryptionSets/dummyDesId");
    DiskEncryptionSetDeletionRequest deletionRequest = new DiskEncryptionSetDeletionRequest.Builder().withCloudCredential(cloudCredential).withCloudContext(cloudContext).withCloudResources(resources).build();
    initCloudResourceHelper(resources);
    when(azureClient.getDiskEncryptionSetByName(any(), any())).thenReturn(null);
    when(azureClientService.getClient(cloudCredential)).thenReturn(azureClient);
    initRetry();
    underTest.deleteDiskEncryptionSet(deletionRequest);
    verify(azureClient, never()).deleteDiskEncryptionSet("dummyResourceGroup", "dummyDesId");
    verify(persistenceNotifier).notifyDeletion(deletionRequest.getCloudResources().iterator().next(), deletionRequest.getCloudContext());
}
Also used : DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with DiskEncryptionSetDeletionRequest

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

the class EnvironmentEncryptionServiceTest method verifyDiskEncryptionSetDeletionRequestForResourceGroup.

private void verifyDiskEncryptionSetDeletionRequestForResourceGroup() {
    DiskEncryptionSetDeletionRequest deletionRequest = diskEncryptionSetDeletionRequestCaptor.getValue();
    List<CloudResource> cloudResources = deletionRequest.getCloudResources();
    Optional<CloudResource> rgCloudResourceOptional = cloudResources.stream().filter(r -> r.getType() == ResourceType.AZURE_RESOURCE_GROUP).findFirst();
    assertThat(rgCloudResourceOptional).isNotEmpty();
    CloudResource rgCloudResource = rgCloudResourceOptional.get();
    assertEquals(rgCloudResource.getReference(), "uniqueDummyId");
    assertEquals(rgCloudResource.getName(), "dummyenv-CDP_DES-ResourceGroup");
    assertEquals(rgCloudResource.getType(), ResourceType.AZURE_RESOURCE_GROUP);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EncryptionResources(com.sequenceiq.cloudbreak.cloud.EncryptionResources) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Captor(org.mockito.Captor) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResourceRetrieverService(com.sequenceiq.environment.resourcepersister.CloudResourceRetrieverService) ResourceGroupUsagePattern(com.sequenceiq.environment.parameter.dto.ResourceGroupUsagePattern) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DiskEncryptionSetCreationRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetCreationRequest) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Map.entry(java.util.Map.entry) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) InjectMocks(org.mockito.InjectMocks) ResourceType(com.sequenceiq.common.api.type.ResourceType) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) EnvironmentTagProvider(com.sequenceiq.environment.environment.service.EnvironmentTagProvider) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) LocationDto(com.sequenceiq.environment.environment.dto.LocationDto) Optional(java.util.Optional) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) CredentialToCloudCredentialConverter(com.sequenceiq.environment.credential.v1.converter.CredentialToCloudCredentialConverter) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 9 with DiskEncryptionSetDeletionRequest

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

the class EnvironmentEncryptionServiceTest method testCreateEncryptionResourcesDeletionRequestShouldReturnWithANewDeletionRequest.

@Test
void testCreateEncryptionResourcesDeletionRequestShouldReturnWithANewDeletionRequest() {
    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().withDiskEncryptionSetId(DISK_ENCRYPTION_SET_ID).withEncryptionKeyUrl(KEY_URL).build()).build()).build()).withCreator(USER_NAME).withAccountId(ACCOUNT_ID).build();
    CloudResource desCloudResource = CloudResource.builder().name(DISK_ENCRYPTION_SET_NAME).type(ResourceType.AZURE_DISK_ENCRYPTION_SET).reference(DISK_ENCRYPTION_SET_ID).status(CommonStatus.CREATED).build();
    when(resourceRetriever.findByEnvironmentIdAndType(ENVIRONMENT_ID, ResourceType.AZURE_DISK_ENCRYPTION_SET)).thenReturn(Optional.of(desCloudResource));
    when(credentialToCloudCredentialConverter.convert(credential)).thenReturn(cloudCredential);
    DiskEncryptionSetDeletionRequest deletionRequest = underTest.createEncryptionResourcesDeletionRequest(environmentDto);
    Optional<CloudResource> dummyResourceOptional = deletionRequest.getCloudResources().stream().filter(r -> r.getType() == ResourceType.AZURE_DISK_ENCRYPTION_SET).findFirst();
    assertNotNull(dummyResourceOptional);
    assertThat(dummyResourceOptional).isNotEmpty();
    assertEquals(dummyResourceOptional.get().getReference(), DISK_ENCRYPTION_SET_ID);
    verifyCloudContext(deletionRequest.getCloudContext());
    assertThat(deletionRequest.getCloudCredential()).isSameAs(cloudCredential);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EncryptionResources(com.sequenceiq.cloudbreak.cloud.EncryptionResources) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Captor(org.mockito.Captor) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResourceRetrieverService(com.sequenceiq.environment.resourcepersister.CloudResourceRetrieverService) ResourceGroupUsagePattern(com.sequenceiq.environment.parameter.dto.ResourceGroupUsagePattern) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DiskEncryptionSetCreationRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetCreationRequest) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Map.entry(java.util.Map.entry) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) InjectMocks(org.mockito.InjectMocks) ResourceType(com.sequenceiq.common.api.type.ResourceType) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) EnvironmentTagProvider(com.sequenceiq.environment.environment.service.EnvironmentTagProvider) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) LocationDto(com.sequenceiq.environment.environment.dto.LocationDto) Optional(java.util.Optional) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) CredentialToCloudCredentialConverter(com.sequenceiq.environment.credential.v1.converter.CredentialToCloudCredentialConverter) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test)

Example 10 with DiskEncryptionSetDeletionRequest

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

the class EnvironmentEncryptionServiceTest method verifyDiskEncryptionSetDeletionRequestForDes.

private void verifyDiskEncryptionSetDeletionRequestForDes() {
    DiskEncryptionSetDeletionRequest deletionRequest = diskEncryptionSetDeletionRequestCaptor.getValue();
    CloudContext cloudContext = deletionRequest.getCloudContext();
    List<CloudResource> cloudResources = deletionRequest.getCloudResources();
    Optional<CloudResource> desCloudResourceOptional = cloudResources.stream().filter(r -> r.getType() == ResourceType.AZURE_DISK_ENCRYPTION_SET).findFirst();
    assertThat(desCloudResourceOptional).isNotEmpty();
    CloudResource desCloudResource = desCloudResourceOptional.get();
    assertEquals(desCloudResource.getReference(), DISK_ENCRYPTION_SET_ID);
    assertEquals(desCloudResource.getName(), DISK_ENCRYPTION_SET_NAME);
    assertEquals(desCloudResource.getType(), ResourceType.AZURE_DISK_ENCRYPTION_SET);
    assertEquals(cloudContext.getAccountId(), ACCOUNT_ID);
    assertEquals(cloudContext.getCrn(), ENVIRONMENT_CRN);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EncryptionResources(com.sequenceiq.cloudbreak.cloud.EncryptionResources) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Captor(org.mockito.Captor) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResourceRetrieverService(com.sequenceiq.environment.resourcepersister.CloudResourceRetrieverService) ResourceGroupUsagePattern(com.sequenceiq.environment.parameter.dto.ResourceGroupUsagePattern) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) DiskEncryptionSetCreationRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetCreationRequest) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Map.entry(java.util.Map.entry) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) InjectMocks(org.mockito.InjectMocks) ResourceType(com.sequenceiq.common.api.type.ResourceType) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) EnvironmentTagProvider(com.sequenceiq.environment.environment.service.EnvironmentTagProvider) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) LocationDto(com.sequenceiq.environment.environment.dto.LocationDto) Optional(java.util.Optional) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) CredentialToCloudCredentialConverter(com.sequenceiq.environment.credential.v1.converter.CredentialToCloudCredentialConverter) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DiskEncryptionSetDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)14 DiskEncryptionSetDeletionRequest (com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest)14 Test (org.junit.jupiter.api.Test)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 EncryptionSetIdentity (com.microsoft.azure.management.compute.EncryptionSetIdentity)5 KeyForDiskEncryptionSet (com.microsoft.azure.management.compute.KeyForDiskEncryptionSet)5 SourceVault (com.microsoft.azure.management.compute.SourceVault)5 DiskEncryptionSetInner (com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner)5 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)4 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)3 EncryptionResources (com.sequenceiq.cloudbreak.cloud.EncryptionResources)3 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)3 CloudPlatformConnectors (com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors)3 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)3 Location (com.sequenceiq.cloudbreak.cloud.model.Location)3 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)3 Region (com.sequenceiq.cloudbreak.cloud.model.Region)3 Variant (com.sequenceiq.cloudbreak.cloud.model.Variant)3 CreatedDiskEncryptionSet (com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet)3 DiskEncryptionSetCreationRequest (com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetCreationRequest)3