Search in sources :

Example 1 with ApiAzureNetworkCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters in project terra-workspace-manager by DataBiosphere.

the class CreateAzureNetworkStepTest method createNetwork.

@Test
void createNetwork() throws InterruptedException {
    final ApiAzureNetworkCreationParameters creationParameters = ControlledResourceFixtures.getAzureNetworkCreationParameters();
    var createAzureNetworkStep = new CreateAzureNetworkStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureNetwork(creationParameters));
    final StepResult stepResult = createAzureNetworkStep.doStep(mockFlightContext);
    // Verify step returns success
    assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
    // Verify Azure create call was made correctly
    verify(mockNetworkStage13).create(contextCaptor.capture());
    Context context = contextCaptor.getValue();
    Optional<CreateNetworkRequestData> requestDataOpt = context.getValues().values().stream().filter(CreateNetworkRequestData.class::isInstance).map(CreateNetworkRequestData.class::cast).findFirst();
    CreateNetworkRequestData expected = CreateNetworkRequestData.builder().setName(creationParameters.getName()).setRegion(Region.fromName(creationParameters.getRegion())).setSubnetName(creationParameters.getSubnetName()).setAddressSpaceCidr(creationParameters.getAddressSpaceCidr()).setNetworkSecurityGroup(mockNsg).setAddressPrefix(creationParameters.getSubnetAddressCidr()).setTenantId(mockAzureCloudContext.getAzureTenantId()).setSubscriptionId(mockAzureCloudContext.getAzureSubscriptionId()).setResourceGroupName(mockAzureCloudContext.getAzureResourceGroupId()).build();
    assertThat(requestDataOpt, equalTo(Optional.of(expected)));
}
Also used : Context(com.azure.core.util.Context) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) FlightContext(bio.terra.stairway.FlightContext) CreateNetworkRequestData(bio.terra.cloudres.azure.resourcemanager.compute.data.CreateNetworkRequestData) ApiAzureNetworkCreationParameters(bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters) StepResult(bio.terra.stairway.StepResult) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 2 with ApiAzureNetworkCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters in project terra-workspace-manager by DataBiosphere.

the class CreateAzureNetworkStepTest method createNetwork_alreadyExists.

@Test
public void createNetwork_alreadyExists() throws InterruptedException {
    final ApiAzureNetworkCreationParameters creationParameters = ControlledResourceFixtures.getAzureNetworkCreationParameters();
    CreateAzureNetworkStep createAzureNetworkStep = new CreateAzureNetworkStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureNetwork(creationParameters));
    // Stub creation to throw Conflict exception.
    when(mockNetworkStage13.create(any(Context.class))).thenThrow(mockException);
    final StepResult stepResult = createAzureNetworkStep.doStep(mockFlightContext);
    // Verify step still returns success
    assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
}
Also used : Context(com.azure.core.util.Context) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) FlightContext(bio.terra.stairway.FlightContext) ApiAzureNetworkCreationParameters(bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters) StepResult(bio.terra.stairway.StepResult) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 3 with ApiAzureNetworkCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters in project terra-workspace-manager by DataBiosphere.

the class CreateAndDeleteAzureControlledResourceFlightTest method createAzureNetworkControlledResource.

@Test
public void createAzureNetworkControlledResource() throws InterruptedException {
    UUID workspaceId = azureTestUtils.createWorkspace(workspaceService);
    AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
    // Cloud context needs to be created first
    FlightState createAzureContextFlightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateAzureContextFlight.class, azureTestUtils.createAzureContextInputParameters(workspaceId, userRequest), STAIRWAY_FLIGHT_TIMEOUT, null);
    assertEquals(FlightStatus.SUCCESS, createAzureContextFlightState.getFlightStatus());
    assertTrue(workspaceService.getAuthorizedAzureCloudContext(workspaceId, userRequest).isPresent());
    final ApiAzureNetworkCreationParameters creationParams = ControlledResourceFixtures.getAzureNetworkCreationParameters();
    // TODO: make this application-private resource once the POC supports it
    final UUID resourceId = UUID.randomUUID();
    ControlledAzureNetworkResource resource = ControlledAzureNetworkResource.builder().common(ControlledResourceFields.builder().workspaceId(workspaceId).resourceId(resourceId).name("testNetwork").description("testDesc").cloningInstructions(CloningInstructions.COPY_RESOURCE).accessScope(AccessScopeType.fromApi(ApiAccessScope.SHARED_ACCESS)).managedBy(ManagedByType.fromApi(ApiManagedBy.USER)).build()).networkName(creationParams.getName()).region(creationParams.getRegion()).subnetName(creationParams.getSubnetName()).addressSpaceCidr(creationParams.getAddressSpaceCidr()).subnetAddressCidr(creationParams.getSubnetAddressCidr()).build();
    // Submit a Network creation flight.
    FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateControlledResourceFlight.class, azureTestUtils.createControlledResourceInputParameters(workspaceId, userRequest, resource), STAIRWAY_FLIGHT_TIMEOUT, null);
    assertEquals(FlightStatus.SUCCESS, flightState.getFlightStatus());
    // Verify controlled resource exists in the workspace.
    ControlledResource res = controlledResourceService.getControlledResource(workspaceId, resourceId, userRequest);
    try {
        ControlledAzureNetworkResource azureNetworkResource = res.castByEnum(WsmResourceType.CONTROLLED_AZURE_NETWORK);
        assertEquals(resource, azureNetworkResource);
    } catch (Exception e) {
        fail("Failed to cast resource to ControlledAzureNetworkResource", e);
    }
}
Also used : FlightState(bio.terra.stairway.FlightState) ControlledResource(bio.terra.workspace.service.resource.controlled.model.ControlledResource) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) UUID(java.util.UUID) ApiAzureNetworkCreationParameters(bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters) ControlledAzureNetworkResource(bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource) ManagementException(com.azure.core.management.exception.ManagementException) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 4 with ApiAzureNetworkCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters in project terra-workspace-manager by DataBiosphere.

the class CreateAndDeleteAzureControlledResourceFlightTest method createNetwork.

private ControlledAzureNetworkResource createNetwork(UUID workspaceId, AuthenticatedUserRequest userRequest) throws InterruptedException {
    final ApiAzureNetworkCreationParameters creationParameters = ControlledResourceFixtures.getAzureNetworkCreationParameters();
    // TODO: make this application-private resource once the POC supports it
    final UUID resourceId = UUID.randomUUID();
    ControlledAzureNetworkResource resource = ControlledAzureNetworkResource.builder().common(ControlledResourceFields.builder().workspaceId(workspaceId).resourceId(resourceId).name(getAzureName("network")).description(getAzureName("network-desc")).cloningInstructions(CloningInstructions.COPY_RESOURCE).accessScope(AccessScopeType.fromApi(ApiAccessScope.SHARED_ACCESS)).managedBy(ManagedByType.fromApi(ApiManagedBy.USER)).build()).networkName(creationParameters.getName()).region(creationParameters.getRegion()).subnetName(creationParameters.getSubnetName()).addressSpaceCidr(creationParameters.getAddressSpaceCidr()).subnetAddressCidr(creationParameters.getSubnetAddressCidr()).build();
    // Submit a Disk creation flight.
    FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateControlledResourceFlight.class, azureTestUtils.createControlledResourceInputParameters(workspaceId, userRequest, resource), STAIRWAY_FLIGHT_TIMEOUT, null);
    assertEquals(FlightStatus.SUCCESS, flightState.getFlightStatus());
    return resource;
}
Also used : FlightState(bio.terra.stairway.FlightState) ApiAzureNetworkCreationParameters(bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters) UUID(java.util.UUID) ControlledAzureNetworkResource(bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource)

Example 5 with ApiAzureNetworkCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters in project terra-workspace-manager by DataBiosphere.

the class AzureDisabledTest method azureDisabledTest.

@Test
public void azureDisabledTest() throws InterruptedException {
    Workspace request = Workspace.builder().workspaceId(UUID.randomUUID()).workspaceStage(WorkspaceStage.MC_WORKSPACE).build();
    UUID workspaceId = workspaceService.createWorkspace(request, userAccessUtils.defaultUserAuthRequest());
    AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
    final UUID uuid = UUID.randomUUID();
    assertThrows(FeatureNotSupportedException.class, () -> workspaceService.createAzureCloudContext(workspaceId, uuid.toString(), userRequest, null, null));
    assertThrows(FeatureNotSupportedException.class, () -> workspaceService.getAuthorizedAzureCloudContext(workspaceId, userRequest));
    final ApiAzureIpCreationParameters ipCreationParameters = ControlledResourceFixtures.getAzureIpCreationParameters();
    ControlledResourceFields commonFields = ControlledResourceFixtures.makeDefaultControlledResourceFields(workspaceId);
    ControlledAzureIpResource ipResource = ControlledAzureIpResource.builder().common(commonFields).ipName(ipCreationParameters.getName()).region(ipCreationParameters.getRegion()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createControlledResourceSync(ipResource, null, userRequest, ipCreationParameters));
    final ApiAzureDiskCreationParameters diskCreationParameters = ControlledResourceFixtures.getAzureDiskCreationParameters();
    ControlledAzureDiskResource diskResource = ControlledAzureDiskResource.builder().common(commonFields).diskName(diskCreationParameters.getName()).region(diskCreationParameters.getRegion()).size(diskCreationParameters.getSize()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createControlledResourceSync(diskResource, null, userRequest, diskCreationParameters));
    final ApiAzureNetworkCreationParameters networkCreationParameters = ControlledResourceFixtures.getAzureNetworkCreationParameters();
    ControlledAzureNetworkResource networkResource = ControlledAzureNetworkResource.builder().common(commonFields).networkName(networkCreationParameters.getName()).region(networkCreationParameters.getRegion()).subnetName(networkCreationParameters.getSubnetName()).addressSpaceCidr(networkCreationParameters.getAddressSpaceCidr()).subnetAddressCidr(networkCreationParameters.getSubnetAddressCidr()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createControlledResourceSync(networkResource, null, userRequest, networkCreationParameters));
    final ApiAzureVmCreationParameters vmCreationParameters = ControlledResourceFixtures.getAzureVmCreationParameters();
    ControlledAzureVmResource vmResource = ControlledAzureVmResource.builder().common(commonFields).vmName(vmCreationParameters.getName()).vmSize(vmCreationParameters.getVmSize()).vmImageUri(vmCreationParameters.getVmImageUri()).region(vmCreationParameters.getRegion()).ipId(ipResource.getResourceId()).diskId(diskResource.getResourceId()).networkId(networkResource.getResourceId()).build();
    assertThrows(FeatureNotSupportedException.class, () -> controlledResourceService.createAzureVm(vmResource, vmCreationParameters, null, null, null, userRequest));
}
Also used : ApiAzureIpCreationParameters(bio.terra.workspace.generated.model.ApiAzureIpCreationParameters) ControlledAzureIpResource(bio.terra.workspace.service.resource.controlled.cloud.azure.ip.ControlledAzureIpResource) ControlledAzureVmResource(bio.terra.workspace.service.resource.controlled.cloud.azure.vm.ControlledAzureVmResource) ControlledAzureDiskResource(bio.terra.workspace.service.resource.controlled.cloud.azure.disk.ControlledAzureDiskResource) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ApiAzureVmCreationParameters(bio.terra.workspace.generated.model.ApiAzureVmCreationParameters) UUID(java.util.UUID) ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) ApiAzureNetworkCreationParameters(bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters) ApiAzureDiskCreationParameters(bio.terra.workspace.generated.model.ApiAzureDiskCreationParameters) ControlledAzureNetworkResource(bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource) Workspace(bio.terra.workspace.service.workspace.model.Workspace) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) Test(org.junit.jupiter.api.Test)

Aggregations

ApiAzureNetworkCreationParameters (bio.terra.workspace.generated.model.ApiAzureNetworkCreationParameters)8 Test (org.junit.jupiter.api.Test)7 BaseAzureTest (bio.terra.workspace.common.BaseAzureTest)6 StepResult (bio.terra.stairway.StepResult)5 ControlledAzureNetworkResource (bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource)3 UUID (java.util.UUID)3 FlightContext (bio.terra.stairway.FlightContext)2 FlightState (bio.terra.stairway.FlightState)2 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)2 AzureCloudContext (bio.terra.workspace.service.workspace.model.AzureCloudContext)2 Context (com.azure.core.util.Context)2 CreateNetworkRequestData (bio.terra.cloudres.azure.resourcemanager.compute.data.CreateNetworkRequestData)1 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)1 ApiAzureDiskCreationParameters (bio.terra.workspace.generated.model.ApiAzureDiskCreationParameters)1 ApiAzureIpCreationParameters (bio.terra.workspace.generated.model.ApiAzureIpCreationParameters)1 ApiAzureVmCreationParameters (bio.terra.workspace.generated.model.ApiAzureVmCreationParameters)1 ControlledAzureDiskResource (bio.terra.workspace.service.resource.controlled.cloud.azure.disk.ControlledAzureDiskResource)1 ControlledAzureIpResource (bio.terra.workspace.service.resource.controlled.cloud.azure.ip.ControlledAzureIpResource)1 ControlledAzureVmResource (bio.terra.workspace.service.resource.controlled.cloud.azure.vm.ControlledAzureVmResource)1 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)1