Search in sources :

Example 1 with EnumeratedJob

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

the class StairwayTestUtils method enumerateJobsDump.

public static void enumerateJobsDump(Alpha1Service alpha1Service, UUID workspaceId, AuthenticatedUserRequest userRequest) {
    EnumeratedJobs jobs = alpha1Service.enumerateJobs(workspaceId, userRequest, 1000, null, null, null, null, null);
    System.out.printf("Enumerated Jobs: total=%d, pageToken=%s%n", jobs.getTotalResults(), jobs.getPageToken());
    for (EnumeratedJob job : jobs.getResults()) {
        FlightState flightState = job.getFlightState();
        System.out.printf("  Job %s %s%n", flightState.getFlightId(), flightState.getFlightStatus());
        System.out.printf("    description: %s%n", job.getJobDescription());
        System.out.printf("    submitted  : %s%n", flightState.getSubmitted());
        System.out.printf("    completed  : %s%n", flightState.getCompleted().map(Instant::toString).orElse("<incomplete>"));
        if (flightState.getException().isPresent()) {
            System.out.printf("   error       : %s%n", flightState.getException().get().getMessage());
        }
        System.out.printf("    operation : %s%n", job.getOperationType());
        if (job.getResource().isPresent()) {
            WsmResource resource = job.getResource().get();
            System.out.println("    resource:");
            System.out.printf("      name: %s%n", resource.getName());
            System.out.printf("      id  : %s%n", resource.getResourceId());
            System.out.printf("      desc: %s%n", resource.getDescription());
            System.out.printf("      stew: %s%n", resource.getStewardshipType());
            System.out.printf("      type: %s%n", resource.getResourceType());
        }
    }
}
Also used : FlightState(bio.terra.stairway.FlightState) WsmResource(bio.terra.workspace.service.resource.model.WsmResource) Instant(java.time.Instant) EnumeratedJobs(bio.terra.workspace.service.workspace.model.EnumeratedJobs) EnumeratedJob(bio.terra.workspace.service.workspace.model.EnumeratedJob)

Example 2 with EnumeratedJob

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

the class Alpha1ApiController method enumerateJobs.

@Override
public ResponseEntity<ApiEnumerateJobsResult> enumerateJobs(UUID workspaceId, Integer limit, String pageToken, ApiResourceType resource, ApiStewardshipType stewardship, String name, ApiJobStateFilter jobState) {
    // Make sure Alpha1 is enabled
    features.alpha1EnabledCheck();
    // Prepare the inputs
    final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    ControllerValidationUtils.validatePaginationParams(0, limit);
    ResourceValidationUtils.validateOptionalResourceName(name);
    // Make sure the caller has read access to the workspace
    workspaceService.validateWorkspaceAndAction(userRequest, workspaceId, SamWorkspaceAction.READ);
    // Do the enumeration
    EnumeratedJobs enumeratedJobs = alpha1Service.enumerateJobs(workspaceId, userRequest, limit, pageToken, WsmResourceFamily.fromApiOptional(resource), StewardshipType.fromApiOptional(stewardship), name, JobStateFilter.fromApi(jobState));
    // Convert the result to API-speak
    List<ApiEnumeratedJob> apiJobList = new ArrayList<>();
    for (EnumeratedJob enumeratedJob : enumeratedJobs.getResults()) {
        ApiJobReport jobReport = jobService.mapFlightStateToApiJobReport(enumeratedJob.getFlightState());
        Optional<WsmResource> optResource = enumeratedJob.getResource();
        ApiEnumeratedJob apiJob = new ApiEnumeratedJob().jobReport(jobReport).errorReport(enumeratedJob.getFlightState().getException().map(ErrorReportUtils::buildApiErrorReport).orElse(null)).jobDescription(enumeratedJob.getJobDescription()).operationType(enumeratedJob.getOperationType().toApiModel()).resourceType(optResource.map(r -> r.getResourceType().toApiModel()).orElse(null)).resource(optResource.map(WsmResource::toApiResourceUnion).orElse(null));
        apiJobList.add(apiJob);
    }
    ApiEnumerateJobsResult result = new ApiEnumerateJobsResult().pageToken(enumeratedJobs.getPageToken()).totalResults(enumeratedJobs.getTotalResults()).results(apiJobList);
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource) WorkspaceService(bio.terra.workspace.service.workspace.WorkspaceService) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) EnumeratedJob(bio.terra.workspace.service.workspace.model.EnumeratedJob) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) JobStateFilter(bio.terra.workspace.service.workspace.model.JobStateFilter) ResourceValidationUtils(bio.terra.workspace.service.resource.ResourceValidationUtils) StewardshipType(bio.terra.workspace.service.resource.model.StewardshipType) ApiStewardshipType(bio.terra.workspace.generated.model.ApiStewardshipType) ApiJobStateFilter(bio.terra.workspace.generated.model.ApiJobStateFilter) ControllerValidationUtils(bio.terra.workspace.common.utils.ControllerValidationUtils) ApiEnumeratedJob(bio.terra.workspace.generated.model.ApiEnumeratedJob) JobService(bio.terra.workspace.service.job.JobService) WsmResource(bio.terra.workspace.service.resource.model.WsmResource) Logger(org.slf4j.Logger) Alpha1Api(bio.terra.workspace.generated.controller.Alpha1Api) UUID(java.util.UUID) SamWorkspaceAction(bio.terra.workspace.service.iam.model.SamConstants.SamWorkspaceAction) AuthenticatedUserRequestFactory(bio.terra.workspace.service.iam.AuthenticatedUserRequestFactory) EnumeratedJobs(bio.terra.workspace.service.workspace.model.EnumeratedJobs) HttpStatus(org.springframework.http.HttpStatus) Alpha1Service(bio.terra.workspace.service.workspace.Alpha1Service) List(java.util.List) ErrorReportUtils(bio.terra.workspace.common.utils.ErrorReportUtils) WsmResourceFamily(bio.terra.workspace.service.resource.model.WsmResourceFamily) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) FeatureConfiguration(bio.terra.workspace.app.configuration.external.FeatureConfiguration) ApiEnumerateJobsResult(bio.terra.workspace.generated.model.ApiEnumerateJobsResult) ApiResourceType(bio.terra.workspace.generated.model.ApiResourceType) ApiEnumeratedJob(bio.terra.workspace.generated.model.ApiEnumeratedJob) ArrayList(java.util.ArrayList) ErrorReportUtils(bio.terra.workspace.common.utils.ErrorReportUtils) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) EnumeratedJobs(bio.terra.workspace.service.workspace.model.EnumeratedJobs) ApiJobReport(bio.terra.workspace.generated.model.ApiJobReport) ResponseEntity(org.springframework.http.ResponseEntity) ApiEnumerateJobsResult(bio.terra.workspace.generated.model.ApiEnumerateJobsResult) EnumeratedJob(bio.terra.workspace.service.workspace.model.EnumeratedJob) ApiEnumeratedJob(bio.terra.workspace.generated.model.ApiEnumeratedJob)

Example 3 with EnumeratedJob

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

the class Alpha1Service method enumerateJobs.

/**
 * List Stairway flights related to a workspace. These inputs are translated into inputs to
 * Stairway's getFlights calls. The resulting flights are translated into enumerated jobs. The
 * jobs are ordered by submit time.
 *
 * @param workspaceId workspace we are listing in
 * @param userRequest authenticated user
 * @param limit max number of jobs to return
 * @param pageToken optional starting place in the result set; start at beginning if missing
 * @param cloudResourceType optional filter by cloud resource type
 * @param stewardshipType optional filter by stewardship type
 * @param resourceName optional filter by resource name
 * @param jobStateFilter optional filter by job state
 * @return POJO containing the results
 */
public EnumeratedJobs enumerateJobs(UUID workspaceId, AuthenticatedUserRequest userRequest, int limit, @Nullable String pageToken, @Nullable WsmResourceFamily cloudResourceType, @Nullable StewardshipType stewardshipType, @Nullable String resourceName, @Nullable JobStateFilter jobStateFilter) {
    features.alpha1EnabledCheck();
    // Readers can see the workspace jobs list
    workspaceService.validateWorkspaceAndAction(userRequest, workspaceId, SamConstants.SamWorkspaceAction.READ);
    FlightEnumeration flightEnumeration;
    try {
        FlightFilter filter = buildFlightFilter(workspaceId, cloudResourceType, stewardshipType, resourceName, jobStateFilter);
        flightEnumeration = stairwayComponent.get().getFlights(pageToken, limit, filter);
    } catch (StairwayException | InterruptedException stairwayEx) {
        throw new InternalStairwayException(stairwayEx);
    }
    List<EnumeratedJob> jobList = new ArrayList<>();
    for (FlightState state : flightEnumeration.getFlightStateList()) {
        FlightMap inputMap = state.getInputParameters();
        OperationType operationType = (inputMap.containsKey(WorkspaceFlightMapKeys.OPERATION_TYPE)) ? inputMap.get(WorkspaceFlightMapKeys.OPERATION_TYPE, OperationType.class) : OperationType.UNKNOWN;
        WsmResource wsmResource = (inputMap.containsKey(ResourceKeys.RESOURCE)) ? inputMap.get(ResourceKeys.RESOURCE, new TypeReference<>() {
        }) : null;
        String jobDescription = (inputMap.containsKey(JobMapKeys.DESCRIPTION.getKeyName())) ? inputMap.get(JobMapKeys.DESCRIPTION.getKeyName(), String.class) : StringUtils.EMPTY;
        EnumeratedJob enumeratedJob = new EnumeratedJob().flightState(state).jobDescription(jobDescription).operationType(operationType).resource(wsmResource);
        jobList.add(enumeratedJob);
    }
    return new EnumeratedJobs().pageToken(flightEnumeration.getNextPageToken()).totalResults(flightEnumeration.getTotalFlights()).results(jobList);
}
Also used : WsmResource(bio.terra.workspace.service.resource.model.WsmResource) FlightEnumeration(bio.terra.stairway.FlightEnumeration) ArrayList(java.util.ArrayList) EnumeratedJobs(bio.terra.workspace.service.workspace.model.EnumeratedJobs) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) FlightState(bio.terra.stairway.FlightState) FlightFilter(bio.terra.stairway.FlightFilter) InternalStairwayException(bio.terra.workspace.service.job.exception.InternalStairwayException) StairwayException(bio.terra.stairway.exception.StairwayException) FlightMap(bio.terra.stairway.FlightMap) OperationType(bio.terra.workspace.service.workspace.model.OperationType) TypeReference(com.fasterxml.jackson.core.type.TypeReference) EnumeratedJob(bio.terra.workspace.service.workspace.model.EnumeratedJob)

Aggregations

WsmResource (bio.terra.workspace.service.resource.model.WsmResource)3 EnumeratedJob (bio.terra.workspace.service.workspace.model.EnumeratedJob)3 EnumeratedJobs (bio.terra.workspace.service.workspace.model.EnumeratedJobs)3 FlightState (bio.terra.stairway.FlightState)2 ArrayList (java.util.ArrayList)2 FlightEnumeration (bio.terra.stairway.FlightEnumeration)1 FlightFilter (bio.terra.stairway.FlightFilter)1 FlightMap (bio.terra.stairway.FlightMap)1 StairwayException (bio.terra.stairway.exception.StairwayException)1 FeatureConfiguration (bio.terra.workspace.app.configuration.external.FeatureConfiguration)1 ControllerValidationUtils (bio.terra.workspace.common.utils.ControllerValidationUtils)1 ErrorReportUtils (bio.terra.workspace.common.utils.ErrorReportUtils)1 Alpha1Api (bio.terra.workspace.generated.controller.Alpha1Api)1 ApiEnumerateJobsResult (bio.terra.workspace.generated.model.ApiEnumerateJobsResult)1 ApiEnumeratedJob (bio.terra.workspace.generated.model.ApiEnumeratedJob)1 ApiJobReport (bio.terra.workspace.generated.model.ApiJobReport)1 ApiJobStateFilter (bio.terra.workspace.generated.model.ApiJobStateFilter)1 ApiResourceType (bio.terra.workspace.generated.model.ApiResourceType)1 ApiStewardshipType (bio.terra.workspace.generated.model.ApiStewardshipType)1 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)1