Search in sources :

Example 1 with ApiAzureVmCreationParameters

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

the class CreateAzureVmStepTest method deleteVm.

@Test
public void deleteVm() throws InterruptedException {
    final ApiAzureVmCreationParameters creationParameters = ControlledResourceFixtures.getAzureVmCreationParameters();
    var createAzureVmStep = new CreateAzureVmStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureVm(creationParameters), mockResourceDao);
    final StepResult stepResult = createAzureVmStep.undoStep(mockFlightContext);
    // Verify step returns success
    assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
    // Verify Azure deletion was called
    verify(mockVms).deleteByResourceGroup(mockAzureCloudContext.getAzureResourceGroupId(), creationParameters.getName());
}
Also used : ApiAzureVmCreationParameters(bio.terra.workspace.generated.model.ApiAzureVmCreationParameters) StepResult(bio.terra.stairway.StepResult) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 2 with ApiAzureVmCreationParameters

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

the class CreateAzureVmStepTest method createVm.

@Test
void createVm() throws InterruptedException {
    final ApiAzureVmCreationParameters creationParameters = ControlledResourceFixtures.getAzureVmCreationParameters();
    var createAzureVmStep = new CreateAzureVmStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureVm(creationParameters), mockResourceDao);
    final StepResult stepResult = createAzureVmStep.doStep(mockFlightContext);
    // Verify step returns success
    assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
    // Verify Azure create call was made correctly
    verify(mockVmStage12).create(contextCaptor.capture());
    Context context = contextCaptor.getValue();
    Optional<CreateVirtualMachineRequestData> requestDataOpt = context.getValues().values().stream().filter(CreateVirtualMachineRequestData.class::isInstance).map(CreateVirtualMachineRequestData.class::cast).findFirst();
    CreateVirtualMachineRequestData expected = CreateVirtualMachineRequestData.builder().setName(creationParameters.getName()).setRegion(Region.fromName(creationParameters.getRegion())).setTenantId(mockAzureCloudContext.getAzureTenantId()).setSubscriptionId(mockAzureCloudContext.getAzureSubscriptionId()).setResourceGroupName(mockAzureCloudContext.getAzureResourceGroupId()).setDisk(mockDisk).setNetwork(mockNetwork).setSubnetName(STUB_SUBNET_NAME).setPublicIpAddress(mockPublicIpAddress).setImage(ControlledResourceFixtures.getAzureVmCreationParameters().getVmImageUri()).build();
    assertThat(requestDataOpt, equalTo(Optional.of(expected)));
}
Also used : AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) FlightContext(bio.terra.stairway.FlightContext) Context(com.azure.core.util.Context) ApiAzureVmCreationParameters(bio.terra.workspace.generated.model.ApiAzureVmCreationParameters) StepResult(bio.terra.stairway.StepResult) CreateVirtualMachineRequestData(bio.terra.cloudres.azure.resourcemanager.compute.data.CreateVirtualMachineRequestData) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 3 with ApiAzureVmCreationParameters

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

the class CreateAzureVmStepTest method createVm_alreadyExists.

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

Example 4 with ApiAzureVmCreationParameters

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

the class CreateAndDeleteAzureControlledResourceFlightTest method createAndDeleteAzureVmControlledResource.

@Test
public void createAndDeleteAzureVmControlledResource() throws InterruptedException {
    // Setup workspace and cloud context
    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());
    // Create ip
    ControlledAzureIpResource ipResource = createIp(workspaceId, userRequest);
    // Create disk
    ControlledAzureDiskResource diskResource = createDisk(workspaceId, userRequest);
    // Create network
    ControlledAzureNetworkResource networkResource = createNetwork(workspaceId, userRequest);
    final ApiAzureVmCreationParameters creationParameters = ControlledResourceFixtures.getAzureVmCreationParameters();
    // TODO: make this application-private resource once the POC supports it
    final UUID resourceId = UUID.randomUUID();
    ControlledAzureVmResource resource = ControlledAzureVmResource.builder().common(ControlledResourceFields.builder().workspaceId(workspaceId).resourceId(resourceId).name(getAzureName("vm")).description(getAzureName("vm-desc")).cloningInstructions(CloningInstructions.COPY_RESOURCE).accessScope(AccessScopeType.fromApi(ApiAccessScope.SHARED_ACCESS)).managedBy(ManagedByType.fromApi(ApiManagedBy.USER)).build()).vmName(creationParameters.getName()).vmSize(creationParameters.getVmSize()).vmImageUri(creationParameters.getVmImageUri()).region(creationParameters.getRegion()).ipId(ipResource.getResourceId()).diskId(diskResource.getResourceId()).networkId(networkResource.getResourceId()).build();
    // Submit a VM 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 {
        ControlledAzureVmResource azureVmResource = res.castByEnum(WsmResourceType.CONTROLLED_AZURE_VM);
        assertEquals(resource, azureVmResource);
    } catch (Exception e) {
        fail("Failed to cast resource to ControlledAzureVmResource", e);
    }
    // Exercise resource enumeration for the underlying resources.
    // Verify that the resources we created are in the enumeration.
    List<WsmResource> resourceList = wsmResourceService.enumerateResources(workspaceId, null, null, 0, 100, userRequest);
    checkForResource(resourceList, ipResource);
    checkForResource(resourceList, diskResource);
    checkForResource(resourceList, networkResource);
    checkForResource(resourceList, resource);
    ComputeManager computeManager = azureTestUtils.getComputeManager();
    VirtualMachine vmTemp = null;
    var retries = 20;
    while (vmTemp == null) {
        try {
            retries = retries - 1;
            if (retries >= 0) {
                vmTemp = computeManager.virtualMachines().getByResourceGroup(azureTestUtils.getAzureCloudContext().getAzureResourceGroupId(), creationParameters.getName());
            } else
                throw new RuntimeException(String.format("%s is not created in time in Azure", creationParameters.getName()));
        } catch (com.azure.core.exception.HttpResponseException ex) {
            if (ex.getResponse().getStatusCode() == 404)
                Thread.sleep(10000);
            else
                throw ex;
        }
    }
    final VirtualMachine resolvedVm = vmTemp;
    // Submit a VM deletion flight.
    FlightState deleteFlightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), DeleteControlledResourceFlight.class, azureTestUtils.deleteControlledResourceInputParameters(workspaceId, resourceId, userRequest, resource), STAIRWAY_FLIGHT_TIMEOUT, null);
    assertEquals(FlightStatus.SUCCESS, deleteFlightState.getFlightStatus());
    Thread.sleep(10000);
    resolvedVm.networkInterfaceIds().forEach(nic -> assertThrows(com.azure.core.exception.HttpResponseException.class, () -> computeManager.networkManager().networks().getById(nic)));
    assertThrows(com.azure.core.exception.HttpResponseException.class, () -> computeManager.disks().getById(resolvedVm.osDiskId()));
}
Also used : ControlledAzureIpResource(bio.terra.workspace.service.resource.controlled.cloud.azure.ip.ControlledAzureIpResource) WsmResource(bio.terra.workspace.service.resource.model.WsmResource) ControlledAzureVmResource(bio.terra.workspace.service.resource.controlled.cloud.azure.vm.ControlledAzureVmResource) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ApiAzureVmCreationParameters(bio.terra.workspace.generated.model.ApiAzureVmCreationParameters) ManagementException(com.azure.core.management.exception.ManagementException) ComputeManager(com.azure.resourcemanager.compute.ComputeManager) FlightState(bio.terra.stairway.FlightState) ControlledAzureDiskResource(bio.terra.workspace.service.resource.controlled.cloud.azure.disk.ControlledAzureDiskResource) ControlledResource(bio.terra.workspace.service.resource.controlled.model.ControlledResource) UUID(java.util.UUID) ControlledAzureNetworkResource(bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource) VirtualMachine(com.azure.resourcemanager.compute.models.VirtualMachine) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 5 with ApiAzureVmCreationParameters

use of bio.terra.workspace.generated.model.ApiAzureVmCreationParameters 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

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