use of bio.terra.workspace.generated.model.ApiAzureDiskCreationParameters in project terra-workspace-manager by DataBiosphere.
the class CreateAzureDiskStepTest method deleteDisk.
@Test
public void deleteDisk() throws InterruptedException {
final ApiAzureDiskCreationParameters creationParameters = ControlledResourceFixtures.getAzureDiskCreationParameters();
CreateAzureDiskStep createAzureDiskStep = new CreateAzureDiskStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureDisk(creationParameters.getName(), creationParameters.getRegion(), creationParameters.getSize()));
final StepResult stepResult = createAzureDiskStep.undoStep(mockFlightContext);
// Verify step returns success
assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
// Verify Azure deletion was called
verify(mockDisks).deleteByResourceGroup(mockAzureCloudContext.getAzureResourceGroupId(), creationParameters.getName());
}
use of bio.terra.workspace.generated.model.ApiAzureDiskCreationParameters in project terra-workspace-manager by DataBiosphere.
the class CreateAzureDiskStepTest method createDisk.
@Test
void createDisk() throws InterruptedException {
final ApiAzureDiskCreationParameters creationParameters = ControlledResourceFixtures.getAzureDiskCreationParameters();
var createAzureDiskStep = new CreateAzureDiskStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureDisk(creationParameters.getName(), creationParameters.getRegion(), creationParameters.getSize()));
final StepResult stepResult = createAzureDiskStep.doStep(mockFlightContext);
// Verify step returns success
assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
// Verify Azure create call was made correctly
verify(mockDiskStage7).create(contextCaptor.capture());
Context context = contextCaptor.getValue();
Optional<CreateDiskRequestData> requestDataOpt = context.getValues().values().stream().filter(CreateDiskRequestData.class::isInstance).map(CreateDiskRequestData.class::cast).findFirst();
CreateDiskRequestData expected = CreateDiskRequestData.builder().setName(creationParameters.getName()).setRegion(Region.fromName(creationParameters.getRegion())).setSize(50).setTenantId(mockAzureCloudContext.getAzureTenantId()).setSubscriptionId(mockAzureCloudContext.getAzureSubscriptionId()).setResourceGroupName(mockAzureCloudContext.getAzureResourceGroupId()).build();
assertThat(requestDataOpt, equalTo(Optional.of(expected)));
}
use of bio.terra.workspace.generated.model.ApiAzureDiskCreationParameters in project terra-workspace-manager by DataBiosphere.
the class CreateAzureDiskStepTest method createDisk_alreadyExists.
@Test
public void createDisk_alreadyExists() throws InterruptedException {
final ApiAzureDiskCreationParameters creationParameters = ControlledResourceFixtures.getAzureDiskCreationParameters();
CreateAzureDiskStep createAzureDiskStep = new CreateAzureDiskStep(mockAzureConfig, mockCrlService, ControlledResourceFixtures.getAzureDisk(creationParameters.getName(), creationParameters.getRegion(), creationParameters.getSize()));
// Stub creation to throw Conflict exception.
when(mockDiskStage7.create(any(Context.class))).thenThrow(mockException);
final StepResult stepResult = createAzureDiskStep.doStep(mockFlightContext);
// Verify step still returns success
assertThat(stepResult, equalTo(StepResult.getStepResultSuccess()));
}
use of bio.terra.workspace.generated.model.ApiAzureDiskCreationParameters 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));
}
use of bio.terra.workspace.generated.model.ApiAzureDiskCreationParameters in project terra-workspace-manager by DataBiosphere.
the class CreateAndDeleteAzureControlledResourceFlightTest method createAzureDiskControlledResource.
@Test
public void createAzureDiskControlledResource() 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 ApiAzureDiskCreationParameters creationParameters = ControlledResourceFixtures.getAzureDiskCreationParameters();
// TODO: make this application-private resource once the POC supports it
final UUID resourceId = UUID.randomUUID();
ControlledAzureDiskResource resource = ControlledAzureDiskResource.builder().common(ControlledResourceFields.builder().workspaceId(workspaceId).resourceId(resourceId).name(getAzureName("disk")).description(getAzureName("disk-desc")).cloningInstructions(CloningInstructions.COPY_RESOURCE).accessScope(AccessScopeType.fromApi(ApiAccessScope.SHARED_ACCESS)).managedBy(ManagedByType.fromApi(ApiManagedBy.USER)).build()).diskName(creationParameters.getName()).region(creationParameters.getRegion()).size(creationParameters.getSize()).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());
// Verify controlled resource exists in the workspace.
ControlledResource res = controlledResourceService.getControlledResource(workspaceId, resourceId, userRequest);
try {
ControlledAzureDiskResource azureDiskResource = res.castByEnum(WsmResourceType.CONTROLLED_AZURE_DISK);
assertEquals(resource, azureDiskResource);
} catch (Exception e) {
fail("Failed to cast resource to ControlledAzureDiskResource", e);
}
}
Aggregations