Search in sources :

Example 6 with ManagementError

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

the class CreateAzureIpStepTest method setup.

@BeforeEach
public void setup() {
    // PublicIpAddresses mocks
    when(mockAzureCloudContext.getAzureResourceGroupId()).thenReturn(STUB_STRING_RETURN);
    when(mockAzureCloudContext.getAzureTenantId()).thenReturn(STUB_STRING_RETURN);
    when(mockAzureCloudContext.getAzureSubscriptionId()).thenReturn(STUB_STRING_RETURN);
    when(mockCrlService.getComputeManager(mockAzureCloudContext, mockAzureConfig)).thenReturn(mockComputeManager);
    when(mockComputeManager.networkManager()).thenReturn(mockNetworkManager);
    when(mockNetworkManager.publicIpAddresses()).thenReturn(mockPublicIpAddresses);
    // Creation stages mocks
    when(mockPublicIpAddresses.define(anyString())).thenReturn(mockIpStage1);
    when(mockIpStage1.withRegion(anyString())).thenReturn(mockIpStage2);
    when(mockIpStage2.withExistingResourceGroup(anyString())).thenReturn(mockIpStage3);
    when(mockIpStage3.withDynamicIP()).thenReturn(mockIpStage3);
    when(mockIpStage3.withTag(anyString(), anyString())).thenReturn(mockIpStage3);
    when(mockIpStage3.create(any(Context.class))).thenReturn(mockPublicIpAddress);
    // Deletion mocks
    doNothing().when(mockPublicIpAddresses).deleteByResourceGroup(anyString(), anyString());
    // 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 : Context(com.azure.core.util.Context) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) FlightContext(bio.terra.stairway.FlightContext) ManagementError(com.azure.core.management.exception.ManagementError) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with ManagementError

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

the class GetAzureIpStepTest method setup.

@BeforeEach
public void setup() {
    // PublicIpAddresses mocks
    when(mockAzureCloudContext.getAzureResourceGroupId()).thenReturn(STUB_STRING_RETURN);
    when(mockCrlService.getComputeManager(mockAzureCloudContext, mockAzureConfig)).thenReturn(mockComputeManager);
    when(mockComputeManager.networkManager()).thenReturn(mockNetworkManager);
    when(mockNetworkManager.publicIpAddresses()).thenReturn(mockPublicIpAddresses);
    when(mockException.getValue()).thenReturn(new ManagementError("ResourceNotFound", "Resource was not found."));
    when(mockFlightContext.getWorkingMap()).thenReturn(mockWorkingMap);
    when(mockWorkingMap.get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class)).thenReturn(mockAzureCloudContext);
}
Also used : ManagementError(com.azure.core.management.exception.ManagementError) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with ManagementError

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

the class CreateAzureNetworkStepTest method setup.

@BeforeEach
public void setup() {
    when(mockAzureCloudContext.getAzureResourceGroupId()).thenReturn(STUB_STRING_RETURN);
    when(mockAzureCloudContext.getAzureTenantId()).thenReturn(STUB_STRING_RETURN);
    when(mockAzureCloudContext.getAzureSubscriptionId()).thenReturn(STUB_STRING_RETURN);
    when(mockCrlService.getComputeManager(any(AzureCloudContext.class), any(AzureConfiguration.class))).thenReturn(mockComputeManager);
    when(mockComputeManager.networkManager()).thenReturn(mockNetworkManager);
    when(mockNetworkManager.networks()).thenReturn(mockNetworks);
    when(mockNetworks.getByResourceGroup(anyString(), anyString())).thenReturn(mockNetwork);
    // 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);
    // Deletion mocks
    // 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 : Context(com.azure.core.util.Context) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) FlightContext(bio.terra.stairway.FlightContext) 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) SecurityRuleProtocol(com.azure.resourcemanager.network.models.SecurityRuleProtocol) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with ManagementError

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

the class GetAzureNetworkStepTest method setup.

@BeforeEach
public void setup() {
    when(mockAzureCloudContext.getAzureResourceGroupId()).thenReturn(STUB_STRING_RETURN);
    when(mockCrlService.getComputeManager(mockAzureCloudContext, mockAzureConfig)).thenReturn(mockComputeManager);
    when(mockComputeManager.networkManager()).thenReturn(mockNetworkManager);
    when(mockNetworkManager.networks()).thenReturn(mockNetworks);
    when(mockException.getValue()).thenReturn(new ManagementError("ResourceNotFound", "Resource was not found."));
    when(mockFlightContext.getWorkingMap()).thenReturn(mockWorkingMap);
    when(mockWorkingMap.get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class)).thenReturn(mockAzureCloudContext);
}
Also used : ManagementError(com.azure.core.management.exception.ManagementError) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with ManagementError

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

the class CreateAzureRelayNamespaceStepTest method setup.

@BeforeEach
public void setup() {
    when(dummyAzureCloudContext.getAzureResourceGroupId()).thenReturn(STUB_STRING_RETURN);
    when(dummyAzureCloudContext.getAzureTenantId()).thenReturn(STUB_STRING_RETURN);
    when(dummyAzureCloudContext.getAzureSubscriptionId()).thenReturn(STUB_STRING_RETURN);
    when(mockCrlService.getRelayManager(dummyAzureCloudContext, mockAzureConfig)).thenReturn(mockRelayManager);
    when(dummyAzureCloudContext.getAzureResourceGroupId()).thenReturn(STUB_STRING_RETURN);
    when(mockCrlService.getRelayManager(dummyAzureCloudContext, mockAzureConfig)).thenReturn(mockRelayManager);
    when(mockRelayManager.namespaces()).thenReturn(mockNamespaces);
    when(mockNamespaces.define(anyString())).thenReturn(mockStage1);
    when(mockStage1.withRegion(anyString())).thenReturn(mockStage2);
    when(mockStage2.withExistingResourceGroup(anyString())).thenReturn(mockStage3);
    when(mockStage3.create(any())).thenReturn(mockRelayNamespace);
    // 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(dummyAzureCloudContext);
    // Deletion mocks
    doNothing().when(mockNamespaces).deleteByResourceGroup(anyString(), anyString());
    // 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(dummyAzureCloudContext);
}
Also used : ManagementError(com.azure.core.management.exception.ManagementError) 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