use of bio.terra.stairway.FlightState in project terra-workspace-manager by DataBiosphere.
the class WorkspaceDeleteFlightTest method deleteMcWorkspaceWithResource.
@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void deleteMcWorkspaceWithResource() throws Exception {
// Create a workspace with a controlled resource
AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
Workspace workspace = connectedTestUtils.createWorkspaceWithGcpContext(userRequest);
ControlledBigQueryDatasetResource dataset = ControlledResourceFixtures.makeDefaultControlledBigQueryBuilder(workspace.getWorkspaceId()).build();
var creationParameters = ControlledResourceFixtures.defaultBigQueryDatasetCreationParameters().datasetId(dataset.getDatasetName());
controlledResourceService.createControlledResourceSync(dataset, null, userRequest, creationParameters).castByEnum(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
ControlledBigQueryDatasetResource gotResource = controlledResourceService.getControlledResource(workspace.getWorkspaceId(), dataset.getResourceId(), userRequest).castByEnum(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
assertEquals(dataset, gotResource);
// Run the delete flight, retrying every step once
FlightMap deleteParameters = new FlightMap();
deleteParameters.put(WorkspaceFlightMapKeys.WORKSPACE_ID, workspace.getWorkspaceId().toString());
deleteParameters.put(WorkspaceFlightMapKeys.WORKSPACE_STAGE, workspace.getWorkspaceStage().name());
deleteParameters.put(JobMapKeys.AUTH_USER_INFO.getKeyName(), userRequest);
Map<String, StepStatus> doFailures = new HashMap<>();
doFailures.put(DeleteControlledSamResourcesStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
doFailures.put(DeleteGcpProjectStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
doFailures.put(DeleteWorkspaceAuthzStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
doFailures.put(DeleteWorkspaceStateStep.class.getName(), StepStatus.STEP_RESULT_FAILURE_RETRY);
FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().doStepFailures(doFailures).build();
FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), WorkspaceDeleteFlight.class, deleteParameters, DELETION_FLIGHT_TIMEOUT, debugInfo);
assertEquals(FlightStatus.SUCCESS, flightState.getFlightStatus());
// Verify the resource and workspace are not in WSM DB
assertThrows(WorkspaceNotFoundException.class, () -> controlledResourceService.getControlledResource(dataset.getWorkspaceId(), dataset.getResourceId(), userRequest));
assertThrows(WorkspaceNotFoundException.class, () -> workspaceService.getWorkspace(workspace.getWorkspaceId(), userRequest));
}
use of bio.terra.stairway.FlightState in project terra-workspace-manager by DataBiosphere.
the class CreateAzureContextFlightTest method errorRevertsChanges.
@Test
void errorRevertsChanges() throws Exception {
UUID workspaceUuid = azureTestUtils.createWorkspace(workspaceService);
AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
// There should be no cloud context initially.
assertTrue(workspaceService.getAuthorizedAzureCloudContext(workspaceUuid, userRequest).isEmpty());
// Submit a flight class that always errors.
FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().lastStepFailure(true).build();
FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateAzureContextFlight.class, azureTestUtils.createAzureContextInputParameters(workspaceUuid, userRequest), STAIRWAY_FLIGHT_TIMEOUT, debugInfo);
assertEquals(FlightStatus.ERROR, flightState.getFlightStatus());
// There should be no cloud context created.
assertTrue(workspaceService.getAuthorizedAzureCloudContext(workspaceUuid, userRequest).isEmpty());
}
use of bio.terra.stairway.FlightState in project terra-workspace-manager by DataBiosphere.
the class CreateAndDeleteAzureControlledResourceFlightTest method submitControlledResourceDeletionFlight.
private <T extends ControlledResource, R> void submitControlledResourceDeletionFlight(UUID workspaceUuid, AuthenticatedUserRequest userRequest, T controlledResource, String azureResourceGroupId, String resourceName, BiFunction<String, String, R> findResource) throws InterruptedException {
FlightState deleteControlledResourceFlightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), DeleteControlledResourceFlight.class, azureTestUtils.deleteControlledResourceInputParameters(workspaceUuid, controlledResource.getResourceId(), userRequest, controlledResource), STAIRWAY_FLIGHT_TIMEOUT, null);
assertEquals(FlightStatus.SUCCESS, deleteControlledResourceFlightState.getFlightStatus());
TimeUnit.SECONDS.sleep(5);
com.azure.core.exception.HttpResponseException exception = assertThrows(com.azure.core.exception.HttpResponseException.class, () -> findResource.apply(azureResourceGroupId, resourceName));
assertEquals(404, exception.getResponse().getStatusCode());
}
use of bio.terra.stairway.FlightState in project terra-workspace-manager by DataBiosphere.
the class CreateAndDeleteAzureControlledResourceFlightTest method createAndDeleteAzureVmControlledResourceWithCustomScriptExtension.
@Test
public void createAndDeleteAzureVmControlledResourceWithCustomScriptExtension() throws InterruptedException {
// Setup workspace and cloud context
UUID workspaceUuid = azureTestUtils.createWorkspace(workspaceService);
AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
createCloudContext(workspaceUuid, userRequest);
// Create ip
ControlledAzureIpResource ipResource = createIp(workspaceUuid, userRequest);
// Create disk
ControlledAzureDiskResource diskResource = createDisk(workspaceUuid, userRequest);
// Create network
ControlledAzureNetworkResource networkResource = createNetwork(workspaceUuid, userRequest);
final ApiAzureVmCreationParameters creationParameters = ControlledResourceFixtures.getAzureVmCreationParametersWithCustomScriptExtension();
// TODO: make this application-private resource once the POC supports it
final UUID resourceId = UUID.randomUUID();
ControlledAzureVmResource resource = ControlledAzureVmResource.builder().common(ControlledResourceFields.builder().workspaceUuid(workspaceUuid).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()).vmImage(AzureVmUtils.getImageData(creationParameters.getVmImage())).region(creationParameters.getRegion()).ipId(ipResource.getResourceId()).diskId(diskResource.getResourceId()).networkId(networkResource.getResourceId()).build();
// Submit a VM creation flight and verify the resource exists in the workspace.
createVMResource(workspaceUuid, userRequest, resource, creationParameters);
// Exercise resource enumeration for the underlying resources.
// Verify that the resources we created are in the enumeration.
List<WsmResource> resourceList = wsmResourceService.enumerateResources(workspaceUuid, null, null, 0, 100, userRequest);
checkForResource(resourceList, ipResource);
checkForResource(resourceList, diskResource);
checkForResource(resourceList, networkResource);
checkForResource(resourceList, resource);
ComputeManager computeManager = azureTestUtils.getComputeManager();
final VirtualMachine resolvedVm = getVirtualMachine(creationParameters, computeManager);
// Submit a VM deletion flight.
FlightState deleteFlightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), DeleteControlledResourceFlight.class, azureTestUtils.deleteControlledResourceInputParameters(workspaceUuid, 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()));
// clean up resources - vm deletion flight doesn't remove network and ip resources, so we need
// to remove them;
submitControlledResourceDeletionFlight(workspaceUuid, userRequest, networkResource, azureTestUtils.getAzureCloudContext().getAzureResourceGroupId(), networkResource.getNetworkName(), azureTestUtils.getComputeManager().networkManager().networks()::getByResourceGroup);
submitControlledResourceDeletionFlight(workspaceUuid, userRequest, ipResource, azureTestUtils.getAzureCloudContext().getAzureResourceGroupId(), ipResource.getIpName(), azureTestUtils.getComputeManager().networkManager().publicIpAddresses()::getByResourceGroup);
// we need to create data disk as well
submitControlledResourceDeletionFlight(workspaceUuid, userRequest, diskResource, azureTestUtils.getAzureCloudContext().getAzureResourceGroupId(), diskResource.getDiskName(), azureTestUtils.getComputeManager().disks()::getByResourceGroup);
}
use of bio.terra.stairway.FlightState in project terra-workspace-manager by DataBiosphere.
the class CreateAndDeleteAzureControlledResourceFlightTest method createIp.
ControlledAzureIpResource createIp(UUID workspaceUuid, AuthenticatedUserRequest userRequest) throws InterruptedException {
final ApiAzureIpCreationParameters ipCreationParameters = ControlledResourceFixtures.getAzureIpCreationParameters();
// TODO: make this application-private resource once the POC supports it
final UUID resourceId = UUID.randomUUID();
ControlledAzureIpResource resource = ControlledAzureIpResource.builder().common(ControlledResourceFields.builder().workspaceUuid(workspaceUuid).resourceId(resourceId).name(getAzureName("ip")).description(getAzureName("ip-desc")).cloningInstructions(CloningInstructions.COPY_RESOURCE).accessScope(AccessScopeType.fromApi(ApiAccessScope.SHARED_ACCESS)).managedBy(ManagedByType.fromApi(ApiManagedBy.USER)).build()).ipName(ipCreationParameters.getName()).region(ipCreationParameters.getRegion()).build();
// Submit an IP creation flight.
FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateControlledResourceFlight.class, azureTestUtils.createControlledResourceInputParameters(workspaceUuid, userRequest, resource), STAIRWAY_FLIGHT_TIMEOUT, null);
assertEquals(FlightStatus.SUCCESS, flightState.getFlightStatus());
return resource;
}
Aggregations