Search in sources :

Example 1 with ApiResourceMetadata

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

the class MakeApiResourceDescriptionTest method validateWsmResource.

public void validateWsmResource(ApiResourceDescription resourceDescription) {
    ApiResourceMetadata metadata = resourceDescription.getMetadata();
    assertEquals(metadata.getWorkspaceId(), workspaceId);
    assertEquals(metadata.getResourceId(), resourceId);
    assertEquals(metadata.getName(), resourceName);
    assertEquals(metadata.getDescription(), description);
    assertEquals(metadata.getCloningInstructions(), cloning.toApiModel());
}
Also used : ApiResourceMetadata(bio.terra.workspace.generated.model.ApiResourceMetadata)

Example 2 with ApiResourceMetadata

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

the class ResourceController method makeApiResourceDescription.

// Convert a WsmResource into the API format for enumeration
@VisibleForTesting
public ApiResourceDescription makeApiResourceDescription(WsmResource wsmResource) {
    ApiResourceMetadata common = wsmResource.toApiMetadata();
    ApiResourceAttributesUnion union = wsmResource.toApiAttributesUnion();
    return new ApiResourceDescription().metadata(common).resourceAttributes(union);
}
Also used : ApiResourceMetadata(bio.terra.workspace.generated.model.ApiResourceMetadata) ApiResourceDescription(bio.terra.workspace.generated.model.ApiResourceDescription) ApiResourceAttributesUnion(bio.terra.workspace.generated.model.ApiResourceAttributesUnion) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ApiResourceMetadata

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

the class AwaitCloneControlledGcpBigQueryDatasetResourceFlightStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    // wait for the flight
    try {
        final FlightState subflightState = context.getStairway().waitForFlight(subflightId, FLIGHT_POLL_SECONDS, FLIGHT_POLL_CYCLES);
        final WsmResourceCloneDetails cloneDetails = new WsmResourceCloneDetails();
        final WsmCloneResourceResult cloneResult = WorkspaceCloneUtils.flightStatusToCloneResult(subflightState.getFlightStatus(), resource);
        cloneDetails.setResult(cloneResult);
        final FlightMap resultMap = FlightUtils.getResultMapRequired(subflightState);
        final var clonedDataset = resultMap.get(JobMapKeys.RESPONSE.getKeyName(), ApiClonedControlledGcpBigQueryDataset.class);
        cloneDetails.setStewardshipType(StewardshipType.CONTROLLED);
        cloneDetails.setResourceType(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
        cloneDetails.setCloningInstructions(resource.getCloningInstructions());
        cloneDetails.setSourceResourceId(resource.getResourceId());
        cloneDetails.setDestinationResourceId(Optional.ofNullable(clonedDataset).map(ApiClonedControlledGcpBigQueryDataset::getDataset).map(ApiGcpBigQueryDatasetResource::getMetadata).map(ApiResourceMetadata::getResourceId).orElse(null));
        String errorMessage = FlightUtils.getFlightErrorMessage(subflightState);
        cloneDetails.setErrorMessage(errorMessage);
        cloneDetails.setName(resource.getName());
        cloneDetails.setDescription(resource.getDescription());
        // add to the map
        final var resourceIdToResult = Optional.ofNullable(context.getWorkingMap().get(ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT, new TypeReference<Map<UUID, WsmResourceCloneDetails>>() {
        })).orElseGet(HashMap::new);
        resourceIdToResult.put(resource.getResourceId(), cloneDetails);
        context.getWorkingMap().put(ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT, resourceIdToResult);
    } catch (DatabaseOperationException | FlightWaitTimedOutException e) {
        // Retry for database issues or expired wait loop
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    }
    validateRequiredEntries(context.getWorkingMap(), ControlledResourceKeys.RESOURCE_ID_TO_CLONE_RESULT);
    return StepResult.getStepResultSuccess();
}
Also used : WsmResourceCloneDetails(bio.terra.workspace.service.workspace.model.WsmResourceCloneDetails) ApiResourceMetadata(bio.terra.workspace.generated.model.ApiResourceMetadata) WsmCloneResourceResult(bio.terra.workspace.service.workspace.model.WsmCloneResourceResult) HashMap(java.util.HashMap) FlightWaitTimedOutException(bio.terra.stairway.exception.FlightWaitTimedOutException) ApiClonedControlledGcpBigQueryDataset(bio.terra.workspace.generated.model.ApiClonedControlledGcpBigQueryDataset) FlightState(bio.terra.stairway.FlightState) DatabaseOperationException(bio.terra.stairway.exception.DatabaseOperationException) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult) HashMap(java.util.HashMap) Map(java.util.Map) FlightMap(bio.terra.stairway.FlightMap)

Example 4 with ApiResourceMetadata

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

the class ControlledResource method toApiMetadata.

@Override
public ApiResourceMetadata toApiMetadata() {
    ApiResourceMetadata metadata = super.toApiMetadata();
    var controlled = new ApiControlledResourceMetadata().accessScope(accessScope.toApiModel()).managedBy(managedBy.toApiModel()).privateResourceUser(// TODO: PF-616 figure out how to supply the assigned user's role
    new ApiPrivateResourceUser().userName(assignedUser)).privateResourceState(getPrivateResourceState().map(PrivateResourceState::toApiModel).orElse(null));
    metadata.controlledResourceMetadata(controlled);
    return metadata;
}
Also used : ApiControlledResourceMetadata(bio.terra.workspace.generated.model.ApiControlledResourceMetadata) ApiResourceMetadata(bio.terra.workspace.generated.model.ApiResourceMetadata) ApiPrivateResourceUser(bio.terra.workspace.generated.model.ApiPrivateResourceUser)

Aggregations

ApiResourceMetadata (bio.terra.workspace.generated.model.ApiResourceMetadata)4 FlightMap (bio.terra.stairway.FlightMap)1 FlightState (bio.terra.stairway.FlightState)1 StepResult (bio.terra.stairway.StepResult)1 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)1 FlightWaitTimedOutException (bio.terra.stairway.exception.FlightWaitTimedOutException)1 ApiClonedControlledGcpBigQueryDataset (bio.terra.workspace.generated.model.ApiClonedControlledGcpBigQueryDataset)1 ApiControlledResourceMetadata (bio.terra.workspace.generated.model.ApiControlledResourceMetadata)1 ApiPrivateResourceUser (bio.terra.workspace.generated.model.ApiPrivateResourceUser)1 ApiResourceAttributesUnion (bio.terra.workspace.generated.model.ApiResourceAttributesUnion)1 ApiResourceDescription (bio.terra.workspace.generated.model.ApiResourceDescription)1 WsmCloneResourceResult (bio.terra.workspace.service.workspace.model.WsmCloneResourceResult)1 WsmResourceCloneDetails (bio.terra.workspace.service.workspace.model.WsmResourceCloneDetails)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1