use of bio.terra.workspace.service.workspace.model.EnumeratedJobs 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());
}
}
}
use of bio.terra.workspace.service.workspace.model.EnumeratedJobs 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);
}
use of bio.terra.workspace.service.workspace.model.EnumeratedJobs 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);
}
Aggregations