Search in sources :

Example 46 with FlightState

use of bio.terra.stairway.FlightState in project jade-data-repo by DataBiosphere.

the class FlightStates method makeFlightRunningState.

public static FlightState makeFlightRunningState() {
    DatasetSummaryModel req = buildMinimalDatasetSummary();
    FlightMap resultMap = new FlightMap();
    resultMap.put(JobMapKeys.RESPONSE.getKeyName(), req);
    resultMap.put(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.I_AM_A_TEAPOT);
    resultMap.put(JobMapKeys.DESCRIPTION.getKeyName(), req.getDescription());
    FlightState flightState = new FlightState();
    flightState.setFlightId(testFlightId);
    flightState.setFlightStatus(FlightStatus.RUNNING);
    flightState.setSubmitted(submittedTime);
    flightState.setInputParameters(resultMap);
    flightState.setResultMap(resultMap);
    return flightState;
}
Also used : FlightState(bio.terra.stairway.FlightState) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) FlightMap(bio.terra.stairway.FlightMap)

Example 47 with FlightState

use of bio.terra.stairway.FlightState in project jade-data-repo by DataBiosphere.

the class FlightStates method makeFlightSimpleState.

public static FlightState makeFlightSimpleState() {
    // Construct a mock FlightState
    FlightMap resultMap = new FlightMap();
    resultMap.put(JobMapKeys.RESPONSE.getKeyName(), buildMinimalDatasetSummary());
    resultMap.put(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.I_AM_A_TEAPOT);
    FlightState flightState = new FlightState();
    flightState.setFlightId(testFlightId);
    flightState.setFlightStatus(FlightStatus.SUCCESS);
    flightState.setSubmitted(Instant.now());
    // unused
    flightState.setInputParameters(resultMap);
    flightState.setResultMap(resultMap);
    flightState.setCompleted(Instant.now());
    return flightState;
}
Also used : FlightState(bio.terra.stairway.FlightState) FlightMap(bio.terra.stairway.FlightMap)

Example 48 with FlightState

use of bio.terra.stairway.FlightState in project stairway by DataBiosphere.

the class TestUtil method makeStairwayValidateRecovery.

// For cases where we want to validate recovery of a single stairway instance and that
// that a specific flight is READY and unowned.
public static Stairway makeStairwayValidateRecovery(String stairwayName, String flightId) throws DatabaseOperationException, QueueException, MigrateException, StairwayExecutionException, InterruptedException, DatabaseSetupException {
    DataSource dataSource = makeDataSource();
    Stairway stairway = Stairway.newBuilder().stairwayClusterName("stairway-cluster").stairwayName(stairwayName).workQueueProjectId(null).maxParallelFlights(2).build();
    List<String> recordedStairways = stairway.initialize(dataSource, false, false);
    assertThat("one stairway to recover", recordedStairways.size(), equalTo(1));
    assertThat("stairway name matches", recordedStairways.get(0), equalTo(stairwayName));
    FlightState state = stairway.getFlightState(flightId);
    assertThat("State is ready", state.getFlightStatus(), equalTo(FlightStatus.READY));
    assertNull(state.getStairwayId(), "Flight is unowned");
    stairway.recoverAndStart(recordedStairways);
    return stairway;
}
Also used : FlightState(bio.terra.stairway.FlightState) Stairway(bio.terra.stairway.Stairway) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) DataSource(javax.sql.DataSource)

Example 49 with FlightState

use of bio.terra.stairway.FlightState in project terra-workspace-manager by DataBiosphere.

the class CreateGcpContextFlightTest method createsProjectAndContext_noBillingAccount_flightFailsAndGcpProjectNotCreated.

@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void createsProjectAndContext_noBillingAccount_flightFailsAndGcpProjectNotCreated() throws Exception {
    UUID workspaceId = createWorkspace(spendUtils.noBillingAccount());
    AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
    assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
    FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateGcpContextFlight.class, createInputParameters(workspaceId, userRequest), STAIRWAY_FLIGHT_TIMEOUT, FlightDebugInfo.newBuilder().build());
    assertEquals(FlightStatus.ERROR, flightState.getFlightStatus());
    assertEquals(NoBillingAccountException.class, flightState.getException().get().getClass());
    assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
    assertFalse(flightState.getResultMap().get().containsKey(WorkspaceFlightMapKeys.GCP_PROJECT_ID));
}
Also used : FlightState(bio.terra.stairway.FlightState) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) DisabledIfEnvironmentVariable(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)

Example 50 with FlightState

use of bio.terra.stairway.FlightState in project terra-workspace-manager by DataBiosphere.

the class CreateGcpContextFlightTest method createsProjectAndContext_unauthorizedSpendProfile_flightFailsAndGcpProjectNotCreated.

@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void createsProjectAndContext_unauthorizedSpendProfile_flightFailsAndGcpProjectNotCreated() throws Exception {
    Mockito.when(mockSamService.isAuthorized(Mockito.any(), Mockito.eq(SamResource.SPEND_PROFILE), Mockito.any(), Mockito.eq(SamSpendProfileAction.LINK))).thenReturn(false);
    UUID workspaceId = createWorkspace(spendUtils.defaultSpendId());
    AuthenticatedUserRequest unauthorizedUserRequest = userAccessUtils.secondUserAuthRequest();
    FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateGcpContextFlight.class, createInputParameters(workspaceId, unauthorizedUserRequest), STAIRWAY_FLIGHT_TIMEOUT, FlightDebugInfo.newBuilder().build());
    assertEquals(FlightStatus.ERROR, flightState.getFlightStatus());
    assertEquals(SpendUnauthorizedException.class, flightState.getException().get().getClass());
    assertFalse(flightState.getResultMap().get().containsKey(WorkspaceFlightMapKeys.GCP_PROJECT_ID));
}
Also used : FlightState(bio.terra.stairway.FlightState) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) DisabledIfEnvironmentVariable(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)

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