Search in sources :

Example 21 with DiskEncryptionSetInner

use of com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner in project cloudbreak by hortonworks.

the class DiskEncryptionSetCreationPollerTest method startPollingTestWhenScheduling.

@Test
void startPollingTestWhenScheduling() throws Exception {
    when(azurePollTaskFactory.diskEncryptionSetCreationCheckerTask(authenticatedContext, checkerContext)).thenReturn(checkerTask);
    when(checkerTask.completed(des)).thenReturn(false);
    DiskEncryptionSetInner desScheduled = mock(DiskEncryptionSetInner.class);
    when(syncPollingScheduler.schedule(checkerTask, CREATION_CHECK_INTERVAL, CREATION_CHECK_MAX_ATTEMPT, MAX_TOLERABLE_FAILURE_NUMBER)).thenReturn(desScheduled);
    DiskEncryptionSetInner result = underTest.startPolling(authenticatedContext, checkerContext, des);
    assertThat(result).isSameAs(desScheduled);
}
Also used : DiskEncryptionSetInner(com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner) Test(org.junit.jupiter.api.Test)

Example 22 with DiskEncryptionSetInner

use of com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner in project cloudbreak by hortonworks.

the class AzureEncryptionResources method getOrCreateDiskEncryptionSetOnCloud.

private CreatedDiskEncryptionSet getOrCreateDiskEncryptionSetOnCloud(AuthenticatedContext authenticatedContext, AzureClient azureClient, String desResourceGroupName, String sourceVaultId, DiskEncryptionSetCreationRequest diskEncryptionSetCreationRequest, boolean singleResourceGroup) {
    CloudContext cloudContext = diskEncryptionSetCreationRequest.getCloudContext();
    String region = cloudContext.getLocation().getRegion().getRegionName();
    Map<String, String> tags = diskEncryptionSetCreationRequest.getTags();
    String diskEncryptionSetName = azureUtils.generateDesNameByNameAndId(String.format("%s-DES-", cloudContext.getName()), diskEncryptionSetCreationRequest.getId());
    LOGGER.info("Checking if Disk Encryption Set \"{}\" exists", diskEncryptionSetName);
    DiskEncryptionSetInner createdSet = azureClient.getDiskEncryptionSetByName(desResourceGroupName, diskEncryptionSetName);
    if (createdSet == null) {
        if (!singleResourceGroup) {
            LOGGER.info("Check and create resource group \"{}\" for disk encryption set", desResourceGroupName);
            checkAndCreateDesResourceGroupByName(cloudContext, azureClient, desResourceGroupName, region, tags);
        }
        LOGGER.info("Creating Disk Encryption Set \"{}\" in resource group \"{}\"", diskEncryptionSetName, desResourceGroupName);
        createdSet = azureClient.createDiskEncryptionSet(diskEncryptionSetName, diskEncryptionSetCreationRequest.getEncryptionKeyUrl(), region, desResourceGroupName, sourceVaultId, tags);
    } else {
        LOGGER.info("Disk Encryption Set \"{}\" already exists, proceeding with the same", diskEncryptionSetName);
    }
    createdSet = pollDiskEncryptionSetCreation(authenticatedContext, desResourceGroupName, diskEncryptionSetName, createdSet);
    // Neither of createdSet, createdSet.id() or createdSet.identity().principalId() can be null at this point; polling will fail otherwise
    CloudResource desCloudResource = CloudResource.builder().name(diskEncryptionSetName).type(AZURE_DISK_ENCRYPTION_SET).reference(createdSet.id()).status(CommonStatus.CREATED).build();
    persistenceNotifier.notifyAllocation(desCloudResource, cloudContext);
    return new CreatedDiskEncryptionSet.Builder().withDiskEncryptionSetId(createdSet.id()).withDiskEncryptionSetPrincipalObjectId(createdSet.identity().principalId()).withDiskEncryptionSetLocation(createdSet.location()).withDiskEncryptionSetName(createdSet.name()).withTags(createdSet.getTags()).withDiskEncryptionSetResourceGroupName(desResourceGroupName).build();
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) DiskEncryptionSetInner(com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 23 with DiskEncryptionSetInner

use of com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner in project cloudbreak by hortonworks.

the class AzureEncryptionResources method deleteDiskEncryptionSetOnCloud.

private void deleteDiskEncryptionSetOnCloud(AzureClient azureClient, String desResourceGroupName, String desName) {
    String description = String.format("Disk Encryption Set \"%s\" in Resource Group \"%s\"", desName, desResourceGroupName);
    retryService.testWith2SecDelayMax15Times(() -> {
        try {
            LOGGER.info("Checking if {} exists.", description);
            DiskEncryptionSetInner existingDiskEncryptionSet = azureClient.getDiskEncryptionSetByName(desResourceGroupName, desName);
            if (existingDiskEncryptionSet != null) {
                LOGGER.info("Deleting {}.", description);
                azureClient.deleteDiskEncryptionSet(desResourceGroupName, desName);
                LOGGER.info("Deleted {}.", description);
                removeKeyVaultAccessPolicyFromDiskEncryptionSetServicePrincipal(azureClient, desResourceGroupName, desName, existingDiskEncryptionSet.activeKey().keyUrl(), existingDiskEncryptionSet.identity().principalId(), existingDiskEncryptionSet.activeKey().sourceVault().id());
            } else {
                LOGGER.info("No {} found to delete.", description);
            }
            return true;
        } catch (Exception e) {
            throw azureUtils.convertToActionFailedExceptionCausedByCloudConnectorException(e, "Deletion of " + description);
        }
    });
}
Also used : DiskEncryptionSetInner(com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)

Aggregations

DiskEncryptionSetInner (com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner)23 Test (org.junit.jupiter.api.Test)17 EncryptionSetIdentity (com.microsoft.azure.management.compute.EncryptionSetIdentity)14 KeyForDiskEncryptionSet (com.microsoft.azure.management.compute.KeyForDiskEncryptionSet)13 SourceVault (com.microsoft.azure.management.compute.SourceVault)13 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 DiskEncryptionSetCreationCheckerContext (com.sequenceiq.cloudbreak.cloud.azure.task.diskencryptionset.DiskEncryptionSetCreationCheckerContext)9 Subscription (com.microsoft.azure.management.resources.Subscription)7 DiskEncryptionSetCreationRequest (com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetCreationRequest)7 ResourcePersisted (com.sequenceiq.cloudbreak.cloud.notification.model.ResourcePersisted)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 CreatedDiskEncryptionSet (com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet)6 DiskEncryptionSetDeletionRequest (com.sequenceiq.cloudbreak.cloud.model.encryption.DiskEncryptionSetDeletionRequest)5 DiskEncryptionSetsInner (com.microsoft.azure.management.compute.implementation.DiskEncryptionSetsInner)1 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)1 DiskEncryptionSetCreationCheckerTask (com.sequenceiq.cloudbreak.cloud.azure.task.diskencryptionset.DiskEncryptionSetCreationCheckerTask)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1