Skip to content

Commit

Permalink
link up WDS record with cbas submission
Browse files Browse the repository at this point in the history
add columns to piplines table
add FK between impuation_jobs and pipelines table
rename pipeline_id to name (and subsequent changes in code/comments)
  • Loading branch information
Jose Soto committed Feb 5, 2024
1 parent edb9419 commit b255b99
Show file tree
Hide file tree
Showing 35 changed files with 588 additions and 204 deletions.
22 changes: 11 additions & 11 deletions common/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ paths:
$ref: '#/components/responses/ServerError'


/api/pipelines/v1alpha1/{pipelineId}:
/api/pipelines/v1alpha1/{pipelineName}:
parameters:
- $ref: '#/components/parameters/PipelineId'
- $ref: '#/components/parameters/PipelineName'
get:
summary: Return info about the specified pipeline
operationId: getPipeline
Expand Down Expand Up @@ -103,9 +103,9 @@ paths:
500:
$ref: '#/components/responses/ServerError'

/api/pipelines/v1alpha1/{pipelineId}/jobs:
/api/pipelines/v1alpha1/{pipelineName}/jobs:
parameters:
- $ref: '#/components/parameters/PipelineId'
- $ref: '#/components/parameters/PipelineName'
- $ref: '#/components/parameters/Limit'
- $ref: '#/components/parameters/PageToken'
get:
Expand Down Expand Up @@ -210,8 +210,8 @@ components:
schema:
type: string

PipelineId:
name: pipelineId
PipelineName:
name: pipelineName
in: path
description: A string identifier to used to identify a pipeline in the service.
required: true
Expand Down Expand Up @@ -434,12 +434,12 @@ components:

Pipeline:
description: |
Object containing the id, display name, and description of a Pipeline.
Object containing the pipeline identifier, display name, and description of a Pipeline.
type: object
required: [ pipelineId, displayName, description ]
required: [ pipelineName, displayName, description ]
properties:
pipelineId:
$ref: "#/components/schemas/PipelineId"
pipelineName:
$ref: "#/components/schemas/PipelineName"
displayName:
$ref: "#/components/schemas/PipelineDisplayName"
description:
Expand All @@ -457,7 +457,7 @@ components:
type: string
format: string

PipelineId:
PipelineName:
description: |
The identifier string for the Pipeline.
type: string
Expand Down
5 changes: 3 additions & 2 deletions scripts/write-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ case $target in
;;

local)
# for local development we will use the QA environment stuff for now to mimic our BEEs
fcenv=qa
# for local development we will use the dev environment configuration because our app is currently set up to work
# with the dev environment by default
fcenv=dev
;;

dev)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package bio.terra.pipelines.app.controller;

import static bio.terra.pipelines.common.utils.PipelinesEnum.IMPUTATION;
import static bio.terra.pipelines.common.utils.PipelinesEnum.IMPUTATION_MINIMAC4;

import bio.terra.common.exception.ApiException;
import bio.terra.common.iam.SamUser;
Expand Down Expand Up @@ -74,8 +74,9 @@ public ResponseEntity<ApiGetPipelinesResult> getPipelines() {
}

@Override
public ResponseEntity<ApiPipeline> getPipeline(@PathVariable("pipelineId") String pipelineId) {
PipelinesEnum validatedPipelineId = validatePipelineId(pipelineId);
public ResponseEntity<ApiPipeline> getPipeline(
@PathVariable("pipelineName") String pipelineName) {
PipelinesEnum validatedPipelineId = validatePipelineName(pipelineName);
Pipeline pipelineInfo = pipelinesService.getPipeline(validatedPipelineId);
ApiPipeline result = pipelineToApi(pipelineInfo);

Expand All @@ -94,7 +95,7 @@ static ApiGetPipelinesResult pipelinesToApi(List<Pipeline> pipelineList) {

static ApiPipeline pipelineToApi(Pipeline pipelineInfo) {
return new ApiPipeline()
.pipelineId(pipelineInfo.getPipelineId())
.pipelineName(pipelineInfo.getName())
.displayName(pipelineInfo.getDisplayName())
.description(pipelineInfo.getDescription());
}
Expand All @@ -108,15 +109,16 @@ static ApiPipeline pipelineToApi(Pipeline pipelineInfo) {
* <p>For now, the job will be created with a random UUID. In the future (TSPS-136), we will
* require the user to provide a job UUID.
*
* @param pipelineId the pipeline to run
* @param pipelineName the pipeline to run
* @param body the inputs for the pipeline
* @return the created job response, which includes a job report containing the job ID,
* description, status, status code, submitted timestamp, completed timestamp (if completed),
* and result URL. The response also includes an error report if the job failed.
*/
@Override
public ResponseEntity<ApiCreateJobResponse> createJob(
@PathVariable("pipelineId") String pipelineId, @RequestBody ApiCreateJobRequestBody body) {
@PathVariable("pipelineName") String pipelineName,
@RequestBody ApiCreateJobRequestBody body) {
final SamUser userRequest = getAuthenticatedInfo();
String userId = userRequest.getSubjectId();
UUID jobId = body.getJobControl().getId();
Expand All @@ -125,36 +127,34 @@ public ResponseEntity<ApiCreateJobResponse> createJob(
String pipelineVersion = body.getPipelineVersion();
Object pipelineInputs = body.getPipelineInputs();

PipelinesEnum validatedPipelineId = validatePipelineId(pipelineId);
PipelinesEnum validatedPipelineName = validatePipelineName(pipelineName);

logger.info(
"Creating {} pipeline (version {}) job (id {}) for user {} with inputs {}",
pipelineId,
pipelineName,
pipelineVersion,
jobId,
userId,
pipelineInputs);

// TSPS-136 will require that the user provide the job UUID
UUID createdJobUuid;
if (validatedPipelineId == IMPUTATION) {
if (validatedPipelineName == IMPUTATION_MINIMAC4) {
Pipeline pipeline = pipelinesService.getPipeline(IMPUTATION_MINIMAC4);
// eventually we'll expand this out to kick off the imputation pipeline flight but for
// now this is good enough.
imputationService.queryForWorkspaceApps();
imputationService.queryForWorkspaceApps(pipeline);

createdJobUuid =
imputationService.createImputationJob(
jobId, userId, description, pipelineVersion, pipelineInputs);
imputationService.createImputationJob(
jobId, userId, description, pipeline.getId(), pipelineInputs);
} else {
logger.error("Unknown validatedPipelineId {}", validatedPipelineId);
logger.error("Unknown validatedPipelineName {}", validatedPipelineName);
throw new ApiException("An internal error occurred.");
}

logger.info("Created {} job {}", validatedPipelineId.getValue(), createdJobUuid);
logger.info("Created {} job {}", validatedPipelineName.getValue(), jobId);

MetricsUtils.incrementPipelineRun(validatedPipelineId);
MetricsUtils.incrementPipelineRun(validatedPipelineName);

FlightState flightState = jobService.retrieveJob(createdJobUuid, userId);
FlightState flightState = jobService.retrieveJob(jobId, userId);
ApiJobReport jobReport = JobApiUtils.mapFlightStateToApiJobReport(flightState);
ApiCreateJobResponse createdJobResponse = new ApiCreateJobResponse().jobReport(jobReport);

Expand All @@ -164,35 +164,36 @@ public ResponseEntity<ApiCreateJobResponse> createJob(
/** Retrieves job reports for all jobs of the specified pipeline that the user has access to. */
@Override
public ResponseEntity<ApiGetJobsResponse> getPipelineJobs(
@PathVariable("pipelineId") String pipelineId, Integer limit, String pageToken) {
@PathVariable("pipelineName") String pipelineName, Integer limit, String pageToken) {
final SamUser userRequest = getAuthenticatedInfo();
String userId = userRequest.getSubjectId();
PipelinesEnum validatedPipelineId = validatePipelineId(pipelineId);
PipelinesEnum validatedPipelineName = validatePipelineName(pipelineName);
EnumeratedJobs enumeratedJobs =
jobService.enumerateJobs(userId, limit, pageToken, validatedPipelineId);
jobService.enumerateJobs(userId, limit, pageToken, validatedPipelineName);

ApiGetJobsResponse result = JobApiUtils.mapEnumeratedJobsToApi(enumeratedJobs);

return new ResponseEntity<>(result, HttpStatus.OK);
}

/**
* Validates that the pipelineId is a valid pipelineId and returns the Enum value for the
* pipelineId
* Validates that the pipelineName is a valid pipelineName and returns the Enum value for the
* pipelineName
*
* <p>Note that in PipelinesServiceTest, we check that all the pipelines in the enum exist in the
* pipelines table
*
* @param pipelineId the pipelineId to validate
* @return the Enum value for the pipelineId
* @throws InvalidPipelineException if the pipelineId is not valid
* @param pipelineName the pipelineName to validate
* @return the Enum value for the pipelineName
* @throws InvalidPipelineException if the pipelineName is not valid
*/
public PipelinesEnum validatePipelineId(String pipelineId) {
public PipelinesEnum validatePipelineName(String pipelineName) {
try {
return PipelinesEnum.valueOf(pipelineId.toUpperCase());
return PipelinesEnum.valueOf(pipelineName.toUpperCase());
} catch (IllegalArgumentException e) {
logger.error("Unknown pipeline id {}", pipelineId);
throw new InvalidPipelineException(String.format("%s is not a valid pipelineId", pipelineId));
logger.error("Unknown pipeline name {}", pipelineName);
throw new InvalidPipelineException(
String.format("%s is not a valid pipelineName", pipelineName));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bio.terra.pipelines.common.utils;

public enum PipelinesEnum {
IMPUTATION("imputation");
IMPUTATION_MINIMAC4("imputation_minimac4");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public class ImputationJob {
@Column(name = "user_id", nullable = false)
private String userId;

@Column(name = "pipeline_version", nullable = false)
private String pipelineVersion;
@Column(name = "pipeline_id", nullable = false)
private Long pipelineId;

public ImputationJob(UUID jobId, String userId, String pipelineVersion) {
public ImputationJob(UUID jobId, String userId, Long pipelineId) {
this.jobId = jobId;
this.userId = userId;
this.pipelineVersion = pipelineVersion;
this.pipelineId = pipelineId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
@NoArgsConstructor
@Table(
name = "pipelines",
uniqueConstraints = {@UniqueConstraint(columnNames = {"pipeline_id", "version"})})
uniqueConstraints = {@UniqueConstraint(columnNames = {"name", "version"})})
public class Pipeline {
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "pipeline_id", nullable = false)
private String pipelineId;
@Column(name = "name", nullable = false)
private String name;

@Column(name = "version", nullable = false)
private String version;
Expand All @@ -33,20 +33,42 @@ public class Pipeline {
@Column(name = "description")
private String description;

public Pipeline(String pipelineId, String version, String displayName, String description) {
this.pipelineId = pipelineId;
@Column(name = "pipeline_type")
private String pipelineType;

@Column(name = "wdl_url")
private String wdlUrl;

@Column(name = "wdl_method_name")
private String wdlMethodName;

public Pipeline(
String name,
String version,
String displayName,
String description,
String pipelineType,
String wdlUrl,
String wdlMethodName) {
this.name = name;
this.version = version;
this.displayName = displayName;
this.description = description;
this.pipelineType = pipelineType;
this.wdlUrl = wdlUrl;
this.wdlMethodName = wdlMethodName;
}

@Override
public String toString() {
return new StringJoiner(", ", Pipeline.class.getSimpleName() + "[", "]")
.add("pipelineId=" + pipelineId)
.add("pipelineName=" + name)
.add("version=" + version)
.add("displayName=" + displayName)
.add("description=" + description)
.add("pipelineType=" + pipelineType)
.add("wdlUrl=" + wdlUrl)
.add("wdlMethodName=" + wdlMethodName)
.toString();
}

Expand All @@ -61,10 +83,13 @@ public int hashCode() {
// two randomly chosen prime numbers
// if deriving: appendSuper(super.hashCode()).
.append(id)
.append(pipelineId)
.append(name)
.append(version)
.append(displayName)
.append(description)
.append(pipelineType)
.append(wdlUrl)
.append(wdlMethodName)
.toHashCode();
}

Expand All @@ -76,10 +101,13 @@ public boolean equals(Object obj) {
Pipeline otherObject = (Pipeline) obj;
return new EqualsBuilder()
.append(id, otherObject.id)
.append(pipelineId, otherObject.pipelineId)
.append(name, otherObject.name)
.append(version, otherObject.version)
.append(displayName, otherObject.displayName)
.append(description, otherObject.description)
.append(pipelineType, otherObject.pipelineType)
.append(wdlUrl, otherObject.wdlUrl)
.append(wdlMethodName, otherObject.wdlMethodName)
.isEquals();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface PipelinesRepository extends CrudRepository<Pipeline, Long> {
@Override
List<Pipeline> findAll();

Boolean existsByPipelineId(String pipelineId);
Boolean existsByName(String name);

Pipeline findByPipelineId(String pipelineId);
Pipeline findByName(String name);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package bio.terra.pipelines.dependencies.cbas;

import bio.terra.cbas.client.ApiException;
import bio.terra.cbas.model.MethodListResponse;
import bio.terra.cbas.model.SystemStatus;
import bio.terra.cbas.model.*;
import bio.terra.pipelines.dependencies.common.HealthCheckWorkspaceApps;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.stereotype.Service;
Expand All @@ -17,10 +16,26 @@ public CbasService(CbasClient cbasClient, RetryTemplate listenerResetRetryTempla
this.listenerResetRetryTemplate = listenerResetRetryTemplate;
}

public MethodListResponse getAllMethods(String cbasBaseUri, String accesstoken) {
public MethodListResponse getAllMethods(String cbasBaseUri, String accessToken) {
return executionWithRetryTemplate(
listenerResetRetryTemplate,
() -> cbasClient.methodsApi(cbasBaseUri, accesstoken).getMethods(null, null, null));
() -> cbasClient.methodsApi(cbasBaseUri, accessToken).getMethods(null, null, null));
}

// method used to create a method programtically
public PostMethodResponse createMethod(
String cbasBaseUri, String accessToken, PostMethodRequest postMethodRequest) {
return executionWithRetryTemplate(
listenerResetRetryTemplate,
() -> cbasClient.methodsApi(cbasBaseUri, accessToken).postMethod(postMethodRequest));
}

public RunSetStateResponse createRunset(
String cbasBaseUri, String accessToken, RunSetRequest runSetRequest) {

return executionWithRetryTemplate(
listenerResetRetryTemplate,
() -> cbasClient.runSetsApi(cbasBaseUri, accessToken).postRunSet(runSetRequest));
}

@Override
Expand Down
Loading

0 comments on commit b255b99

Please sign in to comment.