Search in sources :

Example 16 with WsmResource

use of bio.terra.workspace.service.resource.model.WsmResource in project terra-workspace-manager by DataBiosphere.

the class StoreControlledResourceMetadataStepTest method testEntersInfo.

@Test
public void testEntersInfo() throws InterruptedException, RetryException {
    // Generate a fake workspace and cloud context so that the
    // database insert will pass FK constraints.
    UUID workspaceId = UUID.randomUUID();
    Workspace workspace = Workspace.builder().workspaceStage(WorkspaceStage.RAWLS_WORKSPACE).workspaceId(workspaceId).build();
    workspaceDao.createWorkspace(workspace);
    gcpCloudContextService.createGcpCloudContext(workspaceId, new GcpCloudContext("fake-project"), "flight-testentersinfo");
    StoreMetadataStep storeGoogleBucketMetadataStep = new StoreMetadataStep(resourceDao);
    // Stub the flight map as of this step
    ControlledGcsBucketResource bucketResource = ControlledResourceFixtures.makeDefaultControlledGcsBucketBuilder(workspaceId).build();
    final FlightMap inputFlightMap = new FlightMap();
    inputFlightMap.put(ResourceKeys.RESOURCE, bucketResource);
    inputFlightMap.makeImmutable();
    doReturn(inputFlightMap).when(mockFlightContext).getInputParameters();
    final StepResult result = storeGoogleBucketMetadataStep.doStep(mockFlightContext);
    assertThat(result, equalTo(StepResult.getStepResultSuccess()));
    WsmResource daoResource = resourceDao.getResource(bucketResource.getWorkspaceId(), bucketResource.getResourceId());
    assertThat(daoResource.getResourceType(), equalTo(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET));
    ControlledGcsBucketResource daoBucket = (ControlledGcsBucketResource) daoResource;
    assertThat(bucketResource, equalTo(daoBucket));
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource) StoreMetadataStep(bio.terra.workspace.service.resource.controlled.flight.create.StoreMetadataStep) FlightMap(bio.terra.stairway.FlightMap) UUID(java.util.UUID) StepResult(bio.terra.stairway.StepResult) GcpCloudContext(bio.terra.workspace.service.workspace.model.GcpCloudContext) ControlledGcsBucketResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest)

Example 17 with WsmResource

use of bio.terra.workspace.service.resource.model.WsmResource in project terra-workspace-manager by DataBiosphere.

the class ResourceController method enumerateResources.

@Override
public ResponseEntity<ApiResourceList> enumerateResources(UUID workspaceId, @Valid @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset, @Valid @RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit, @Valid ApiResourceType resource, @Valid ApiStewardshipType stewardship) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    ControllerValidationUtils.validatePaginationParams(offset, limit);
    workspaceService.validateWorkspaceAndAction(userRequest, workspaceId, SamConstants.SamWorkspaceAction.READ);
    List<WsmResource> wsmResources = resourceService.enumerateResources(workspaceId, WsmResourceFamily.fromApiOptional(resource), StewardshipType.fromApiOptional(stewardship), offset, limit, userRequest);
    List<ApiResourceDescription> apiResourceDescriptionList = wsmResources.stream().map(r -> makeApiResourceDescription(r)).collect(Collectors.toList());
    var apiResourceList = new ApiResourceList().resources(apiResourceDescriptionList);
    return new ResponseEntity<>(apiResourceList, HttpStatus.OK);
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource) RequestParam(org.springframework.web.bind.annotation.RequestParam) WorkspaceService(bio.terra.workspace.service.workspace.WorkspaceService) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) Valid(javax.validation.Valid) SamConstants(bio.terra.workspace.service.iam.model.SamConstants) ReferencedResourceService(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResourceService) HttpServletRequest(javax.servlet.http.HttpServletRequest) ApiResourceAttributesUnion(bio.terra.workspace.generated.model.ApiResourceAttributesUnion) StewardshipType(bio.terra.workspace.service.resource.model.StewardshipType) ApiStewardshipType(bio.terra.workspace.generated.model.ApiStewardshipType) ControllerValidationUtils(bio.terra.workspace.common.utils.ControllerValidationUtils) ApiResourceMetadata(bio.terra.workspace.generated.model.ApiResourceMetadata) WsmResource(bio.terra.workspace.service.resource.model.WsmResource) ApiResourceList(bio.terra.workspace.generated.model.ApiResourceList) ApiResourceDescription(bio.terra.workspace.generated.model.ApiResourceDescription) Logger(org.slf4j.Logger) UUID(java.util.UUID) ResourceApi(bio.terra.workspace.generated.controller.ResourceApi) Collectors(java.util.stream.Collectors) WsmResourceService(bio.terra.workspace.service.resource.WsmResourceService) AuthenticatedUserRequestFactory(bio.terra.workspace.service.iam.AuthenticatedUserRequestFactory) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) WsmResourceFamily(bio.terra.workspace.service.resource.model.WsmResourceFamily) ResponseEntity(org.springframework.http.ResponseEntity) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ApiResourceType(bio.terra.workspace.generated.model.ApiResourceType) ResponseEntity(org.springframework.http.ResponseEntity) ApiResourceDescription(bio.terra.workspace.generated.model.ApiResourceDescription) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ApiResourceList(bio.terra.workspace.generated.model.ApiResourceList)

Example 18 with WsmResource

use of bio.terra.workspace.service.resource.model.WsmResource in project terra-workspace-manager by DataBiosphere.

the class SetCreateResponseStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
    WsmResource responseResource = resourceDao.getResource(resource.getWorkspaceId(), resource.getResourceId());
    flightContext.getWorkingMap().put(JobMapKeys.RESPONSE.getKeyName(), responseResource);
    return StepResult.getStepResultSuccess();
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource)

Aggregations

WsmResource (bio.terra.workspace.service.resource.model.WsmResource)18 UUID (java.util.UUID)6 Test (org.junit.jupiter.api.Test)4 FlightState (bio.terra.stairway.FlightState)3 StepResult (bio.terra.stairway.StepResult)3 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)3 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)3 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)3 EnumeratedJob (bio.terra.workspace.service.workspace.model.EnumeratedJob)3 EnumeratedJobs (bio.terra.workspace.service.workspace.model.EnumeratedJobs)3 FlightMap (bio.terra.stairway.FlightMap)2 ControllerValidationUtils (bio.terra.workspace.common.utils.ControllerValidationUtils)2 ApiResourceType (bio.terra.workspace.generated.model.ApiResourceType)2 ApiStewardshipType (bio.terra.workspace.generated.model.ApiStewardshipType)2 AuthenticatedUserRequestFactory (bio.terra.workspace.service.iam.AuthenticatedUserRequestFactory)2 StewardshipType (bio.terra.workspace.service.resource.model.StewardshipType)2 WsmResourceFamily (bio.terra.workspace.service.resource.model.WsmResourceFamily)2 WorkspaceService (bio.terra.workspace.service.workspace.WorkspaceService)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2