Search in sources :

Example 16 with FlightState

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));
}
Also used : FlightDebugInfo(bio.terra.stairway.FlightDebugInfo) HashMap(java.util.HashMap) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) StepStatus(bio.terra.stairway.StepStatus) FlightState(bio.terra.stairway.FlightState) FlightMap(bio.terra.stairway.FlightMap) ControlledBigQueryDatasetResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource) Workspace(bio.terra.workspace.service.workspace.model.Workspace) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) Test(org.junit.jupiter.api.Test) DisabledIfEnvironmentVariable(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)

Example 17 with FlightState

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());
}
Also used : FlightState(bio.terra.stairway.FlightState) FlightDebugInfo(bio.terra.stairway.FlightDebugInfo) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) BaseAzureTest(bio.terra.workspace.common.BaseAzureTest)

Example 18 with FlightState

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());
}
Also used : FlightState(bio.terra.stairway.FlightState)

Example 19 with FlightState

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);
}
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) ComputeManager(com.azure.resourcemanager.compute.ComputeManager) FlightState(bio.terra.stairway.FlightState) ControlledAzureDiskResource(bio.terra.workspace.service.resource.controlled.cloud.azure.disk.ControlledAzureDiskResource) 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 20 with FlightState

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;
}
Also used : ControlledAzureIpResource(bio.terra.workspace.service.resource.controlled.cloud.azure.ip.ControlledAzureIpResource) FlightState(bio.terra.stairway.FlightState) UUID(java.util.UUID)

Aggregations

FlightState (bio.terra.stairway.FlightState)52 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)21 UUID (java.util.UUID)21 Test (org.junit.jupiter.api.Test)21 FlightMap (bio.terra.stairway.FlightMap)20 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)17 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)15 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)11 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)10 StepStatus (bio.terra.stairway.StepStatus)7 StepResult (bio.terra.stairway.StepResult)6 FlightWaitTimedOutException (bio.terra.stairway.exception.FlightWaitTimedOutException)6 StairwayException (bio.terra.stairway.exception.StairwayException)6 InternalStairwayException (bio.terra.workspace.service.job.exception.InternalStairwayException)6 HashMap (java.util.HashMap)6 BaseAzureTest (bio.terra.workspace.common.BaseAzureTest)5 WsmResource (bio.terra.workspace.service.resource.model.WsmResource)5 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)5 FlightNotFoundException (bio.terra.stairway.exception.FlightNotFoundException)4 ControlledAzureDiskResource (bio.terra.workspace.service.resource.controlled.cloud.azure.disk.ControlledAzureDiskResource)4