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);
}
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();
}
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);
}
});
}
Aggregations