Search in sources :

Example 11 with ManagementError

use of com.azure.core.management.exception.ManagementError in project terra-workspace-manager by DataBiosphere.

the class CreateAzureStorageStepTest method setup.

@BeforeEach
public void setup() {
    when(mockAzureCloudContext.getAzureResourceGroupId()).thenReturn(STUB_STRING_RETURN);
    when(mockCrlService.getStorageManager(mockAzureCloudContext, mockAzureConfig)).thenReturn(mockStorageManager);
    when(mockStorageManager.storageAccounts()).thenReturn(mockStorageAccounts);
    resourceNotFoundException = new ManagementException("Resource was not found.", /*response=*/
    null, new ManagementError("ResourceNotFound", "Resource was not found."));
    // Creation stages mocks
    when(mockStorageAccounts.define(anyString())).thenReturn(mockStorageBlankStage);
    when(mockStorageBlankStage.withRegion(anyString())).thenReturn(mockStorageGroupStage);
    when(mockStorageGroupStage.withExistingResourceGroup(anyString())).thenReturn(mockStorageCreateStage);
    when(mockStorageCreateStage.withHnsEnabled(true)).thenReturn(mockStorageCreateStage);
    when(mockStorageCreateStage.withTag(anyString(), anyString())).thenReturn(mockStorageCreateStage);
    when(mockStorageCreateStage.create(any(Context.class))).thenReturn(mockStorageAccount);
    when(mockStorageAccount.id()).thenReturn(STUB_STRING_RETURN);
    creationParameters = ControlledResourceFixtures.getAzureStorageCreationParameters();
    // Exception mock
    when(mockFlightContext.getWorkingMap()).thenReturn(mockWorkingMap);
    when(mockWorkingMap.get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class)).thenReturn(mockAzureCloudContext);
}
Also used : Context(com.azure.core.util.Context) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) FlightContext(bio.terra.stairway.FlightContext) ManagementException(com.azure.core.management.exception.ManagementException) ManagementError(com.azure.core.management.exception.ManagementError) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with ManagementError

use of com.azure.core.management.exception.ManagementError in project terra-workspace-manager by DataBiosphere.

the class CreateAzureVmStepTest method setup.

@BeforeEach
public void setup() {
    when(mockCrlService.getComputeManager(any(AzureCloudContext.class), any(AzureConfiguration.class))).thenReturn(mockComputeManager);
    when(mockAzureCloudContext.getAzureResourceGroupId()).thenReturn(STUB_STRING_RETURN);
    when(mockAzureCloudContext.getAzureTenantId()).thenReturn(STUB_STRING_RETURN);
    when(mockAzureCloudContext.getAzureSubscriptionId()).thenReturn(STUB_STRING_RETURN);
    when(mockComputeManager.virtualMachines()).thenReturn(mockVms);
    // get disk mocks
    when(mockComputeManager.disks()).thenReturn(mockDisks);
    when(mockDisks.getByResourceGroup(anyString(), anyString())).thenReturn(mockDisk);
    // get ip mocks
    when(mockComputeManager.networkManager()).thenReturn(mockNetworkManager);
    when(mockNetworkManager.publicIpAddresses()).thenReturn(mockPublicIpAddresses);
    when(mockPublicIpAddresses.getByResourceGroup(anyString(), anyString())).thenReturn(mockPublicIpAddress);
    // get network mocks
    when(mockNetworkManager.networks()).thenReturn(mockNetworks);
    when(mockNetworks.getByResourceGroup(anyString(), anyString())).thenReturn(mockNetwork);
    when(mockNetworkManager.networkInterfaces()).thenReturn(mockNis);
    when(mockNis.define(anyString())).thenReturn(mockNicDefine);
    when(mockNicDefine.withRegion(anyString())).thenReturn(mockNicWithRegion);
    when(mockNicWithRegion.withExistingResourceGroup(anyString())).thenReturn(mockNicWithExistingRg);
    when(mockNicWithExistingRg.withExistingPrimaryNetwork(mockNetwork)).thenReturn(mockNicWithExistingPrimaryNetwork);
    when(mockNicWithExistingPrimaryNetwork.withSubnet(anyString())).thenReturn(mockNicWithPrivateIp);
    when(mockNicWithPrivateIp.withPrimaryPrivateIPAddressDynamic()).thenReturn(mockNicWithCreate);
    when(mockNicWithCreate.withExistingPrimaryPublicIPAddress(mockPublicIpAddress)).thenReturn(mockNicWithCreate);
    when(mockNicWithCreate.create()).thenReturn(mockNi);
    // create network security group mocks
    when(mockNetworkManager.networkSecurityGroups()).thenReturn(mockNsgs);
    when(mockNsgs.define(anyString())).thenReturn(mockNetworkStage1);
    when(mockNetworkStage1.withRegion(anyString())).thenReturn(mockNetworkStage1a);
    when(mockNetworkStage1a.withExistingResourceGroup(anyString())).thenReturn(mockNetworkStage2);
    when(mockNetworkStage2.withTag(anyString(), anyString())).thenReturn(mockNetworkStage2);
    when(mockNetworkStage2.defineRule(anyString())).thenReturn(mockNetworkStage3);
    when(mockNetworkStage3.allowInbound()).thenReturn(mockNetworkStage4);
    when(mockNetworkStage3.denyOutbound()).thenReturn(mockNetworkStage4);
    when(mockNetworkStage4.fromAddress(anyString())).thenReturn(mockNetworkStage5);
    when(mockNetworkStage4.fromAnyAddress()).thenReturn(mockNetworkStage5);
    when(mockNetworkStage5.fromAnyPort()).thenReturn(mockNetworkStage6);
    when(mockNetworkStage6.toAnyAddress()).thenReturn(mockNetworkStage7);
    when(mockNetworkStage6.toAddress(anyString())).thenReturn(mockNetworkStage7);
    when(mockNetworkStage7.toPort(anyInt())).thenReturn(mockNetworkStage8);
    when(mockNetworkStage7.toAnyPort()).thenReturn(mockNetworkStage8);
    when(mockNetworkStage8.withProtocol(any(SecurityRuleProtocol.class))).thenReturn(mockNetworkStage9);
    when(mockNetworkStage8.withAnyProtocol()).thenReturn(mockNetworkStage9);
    when(mockNetworkStage9.attach()).thenReturn(mockNetworkStage2);
    when(mockNetworkStage2.create(any(Context.class))).thenReturn(mockNsg);
    // create network mocks
    when(mockNetworks.define(anyString())).thenReturn(mockNetworkStage10);
    when(mockNetworkStage10.withRegion(anyString())).thenReturn(mockNetworkStage11);
    when(mockNetworkStage11.withExistingResourceGroup(anyString())).thenReturn(mockNetworkStage12);
    when(mockNetworkStage12.withTag(anyString(), anyString())).thenReturn(mockNetworkStage12);
    when(mockNetworkStage12.withAddressSpace(anyString())).thenReturn(mockNetworkStage13);
    when(mockNetworkStage13.defineSubnet(anyString())).thenReturn(mockNetworkStage14);
    when(mockNetworkStage14.withAddressPrefix(anyString())).thenReturn(mockNetworkStage15);
    when(mockNetworkStage15.withExistingNetworkSecurityGroup(any(NetworkSecurityGroup.class))).thenReturn(mockNetworkStage15);
    when(mockNetworkStage15.attach()).thenReturn(mockNetworkStage13);
    when(mockNetworkStage13.create(any(Context.class))).thenReturn(mockNetwork);
    // Creation vm stages mocks
    when(mockVms.define(anyString())).thenReturn(mockVmStage1);
    when(mockVmStage1.withRegion(anyString())).thenReturn(mockVmStage2);
    when(mockVmStage2.withExistingResourceGroup(anyString())).thenReturn(mockVmStage3);
    when(mockVmStage3.withExistingPrimaryNetworkInterface(mockNi)).thenReturn(mockVmStage7);
    when(mockVmStage7.withSpecializedLinuxCustomImage(anyString())).thenReturn(mockVmStage10);
    when(mockVmStage10.withExistingDataDisk(any(Disk.class))).thenReturn(mockVmStage11);
    when(mockVmStage11.withTag(anyString(), anyString())).thenReturn(mockVmStage11a);
    when(mockVmStage11a.withTag(anyString(), anyString())).thenReturn(mockVmStage12);
    when(mockVmStage12.withSize(any(VirtualMachineSizeTypes.class))).thenReturn(mockVmStage12);
    when(mockVmStage12.defineNewExtension(anyString())).thenReturn(mockVmStage13);
    when(mockVmStage13.withPublisher(anyString())).thenReturn(mockVmStage14);
    when(mockVmStage14.withType(anyString())).thenReturn(mockVmStage15);
    when(mockVmStage15.withVersion(anyString())).thenReturn(mockVmStage16);
    when(mockVmStage16.withPublicSettings(any())).thenReturn(mockVmStage16);
    when(mockVmStage16.withProtectedSettings(any())).thenReturn(mockVmStage16);
    when(mockVmStage16.withTags(any())).thenReturn(mockVmStage16);
    when(mockVmStage16.withoutMinorVersionAutoUpgrade()).thenReturn(mockVmStage16);
    when(mockVmStage16.attach()).thenReturn(mockVmStage12);
    when(mockVmStage12.create(any(Context.class))).thenReturn(mockVm);
    // Resource dao mocks
    when(mockResourceDao.getResource(any(UUID.class), any(UUID.class))).thenReturn(mockWsmResource);
    when(mockWsmResource.castByEnum(WsmResourceType.CONTROLLED_AZURE_DISK)).thenReturn(mockAzureDiskResource);
    when(mockWsmResource.castByEnum(WsmResourceType.CONTROLLED_AZURE_IP)).thenReturn(mockAzureIpResource);
    when(mockWsmResource.castByEnum(WsmResourceType.CONTROLLED_AZURE_NETWORK)).thenReturn(mockAzureNetworkResource);
    // Resource mocks
    when(mockAzureDiskResource.getDiskName()).thenReturn(STUB_DISK_NAME);
    when(mockAzureIpResource.getIpName()).thenReturn(STUB_IP_NAME);
    when(mockAzureNetworkResource.getNetworkName()).thenReturn(STUB_NETWORK_NAME);
    when(mockAzureNetworkResource.getSubnetName()).thenReturn(STUB_SUBNET_NAME);
    // Exception mock
    when(mockException.getValue()).thenReturn(new ManagementError("Conflict", "Resource already exists."));
    when(mockFlightContext.getWorkingMap()).thenReturn(mockWorkingMap);
    when(mockWorkingMap.get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class)).thenReturn(mockAzureCloudContext);
}
Also used : AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) FlightContext(bio.terra.stairway.FlightContext) Context(com.azure.core.util.Context) NetworkSecurityGroup(com.azure.resourcemanager.network.models.NetworkSecurityGroup) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) AzureConfiguration(bio.terra.workspace.app.configuration.external.AzureConfiguration) ManagementError(com.azure.core.management.exception.ManagementError) VirtualMachineSizeTypes(com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes) UUID(java.util.UUID) Disk(com.azure.resourcemanager.compute.models.Disk) SecurityRuleProtocol(com.azure.resourcemanager.network.models.SecurityRuleProtocol) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ManagementError (com.azure.core.management.exception.ManagementError)12 BeforeEach (org.junit.jupiter.api.BeforeEach)11 FlightContext (bio.terra.stairway.FlightContext)5 AzureCloudContext (bio.terra.workspace.service.workspace.model.AzureCloudContext)5 Context (com.azure.core.util.Context)5 AzureConfiguration (bio.terra.workspace.app.configuration.external.AzureConfiguration)2 ManagementException (com.azure.core.management.exception.ManagementException)2 NetworkSecurityGroup (com.azure.resourcemanager.network.models.NetworkSecurityGroup)2 SecurityRuleProtocol (com.azure.resourcemanager.network.models.SecurityRuleProtocol)2 Disk (com.azure.resourcemanager.compute.models.Disk)1 VirtualMachineSizeTypes (com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes)1 RedisManager (com.azure.resourcemanager.redis.RedisManager)1 RedisClient (com.azure.resourcemanager.redis.fluent.RedisClient)1 CheckNameAvailabilityParameters (com.azure.resourcemanager.redis.models.CheckNameAvailabilityParameters)1 CheckNameAvailabilityResultEntity (com.microsoft.azure.toolkit.lib.common.entity.CheckNameAvailabilityResultEntity)1 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)1 UUID (java.util.UUID)1