use of bio.terra.stairway.FlightFilter in project terra-workspace-manager by DataBiosphere.
the class JobService method enumerateJobs.
public List<ApiJobReport> enumerateJobs(int offset, int limit, AuthenticatedUserRequest userRequest) {
List<FlightState> flightStateList;
try {
FlightFilter filter = new FlightFilter();
filter.addFilterInputParameter(JobMapKeys.SUBJECT_ID.getKeyName(), FlightFilterOp.EQUAL, userRequest.getSubjectId());
flightStateList = stairwayComponent.get().getFlights(offset, limit, filter);
} catch (StairwayException | InterruptedException stairwayEx) {
throw new InternalStairwayException(stairwayEx);
}
List<ApiJobReport> jobReportList = new ArrayList<>();
for (FlightState flightState : flightStateList) {
ApiJobReport jobReport = mapFlightStateToApiJobReport(flightState);
jobReportList.add(jobReport);
}
return jobReportList;
}
use of bio.terra.stairway.FlightFilter in project terra-workspace-manager by DataBiosphere.
the class Alpha1Service method buildFlightFilter.
private FlightFilter buildFlightFilter(UUID workspaceId, @Nullable WsmResourceFamily cloudResourceType, @Nullable StewardshipType stewardshipType, @Nullable String resourceName, @Nullable JobStateFilter jobStateFilter) {
FlightFilter filter = new FlightFilter();
// Always filter by workspace
filter.addFilterInputParameter(WorkspaceFlightMapKeys.WORKSPACE_ID, FlightFilterOp.EQUAL, workspaceId.toString());
// Add optional filters
Optional.ofNullable(cloudResourceType).map(t -> filter.addFilterInputParameter(ResourceKeys.RESOURCE_TYPE, FlightFilterOp.EQUAL, t));
Optional.ofNullable(stewardshipType).map(t -> filter.addFilterInputParameter(ResourceKeys.STEWARDSHIP_TYPE, FlightFilterOp.EQUAL, t));
Optional.ofNullable(resourceName).map(t -> filter.addFilterInputParameter(ResourceKeys.RESOURCE_NAME, FlightFilterOp.EQUAL, t));
Optional.ofNullable(jobStateFilter).map(t -> addStateFilter(filter, t));
return filter;
}
use of bio.terra.stairway.FlightFilter 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);
}
use of bio.terra.stairway.FlightFilter in project jade-data-repo by DataBiosphere.
the class JobService method enumerateJobs.
public List<JobModel> enumerateJobs(int offset, int limit, AuthenticatedUserRequest userReq) {
boolean canListAnyJob = checkUserCanListAnyJob(userReq);
// if the user has access to all jobs, then fetch everything
// otherwise, filter the jobs on the user
List<FlightState> flightStateList;
try {
FlightFilter filter = new FlightFilter();
if (!canListAnyJob) {
filter.addFilterInputParameter(JobMapKeys.SUBJECT_ID.getKeyName(), FlightFilterOp.EQUAL, userReq.getSubjectId());
}
flightStateList = stairway.getFlights(offset, limit, filter);
} catch (StairwayException stairwayEx) {
throw new InternalStairwayException(stairwayEx);
} catch (InterruptedException ex) {
throw new JobServiceShutdownException("Job service interrupted", ex);
}
List<JobModel> jobModelList = new ArrayList<>();
for (FlightState flightState : flightStateList) {
JobModel jobModel = mapFlightStateToJobModel(flightState);
jobModelList.add(jobModel);
}
return jobModelList;
}
Aggregations