Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9773494
initial work, still broken
zloery Jan 27, 2021
f8e7cd0
fix name and run spotless
jaycarlton Jan 27, 2021
ea5233b
progress
jaycarlton Jan 27, 2021
de2f9ba
add basic reference validation. still needs testing and cleanup
zloery Jan 29, 2021
8e912c0
use shared UIDs for cloud resources, tests
zloery Feb 1, 2021
2a1ef38
move controller translation to util, rename createCow methods
zloery Feb 1, 2021
0d74bc6
merge from dev
zloery Feb 1, 2021
0226124
formatting
zloery Feb 1, 2021
9235d98
update other crl versions
zloery Feb 1, 2021
9bdadf3
review comments
zloery Feb 2, 2021
fc7d63a
add logging for invalid references
zloery Feb 2, 2021
950fdfd
remove commented out yaml
zloery Feb 2, 2021
4a2f918
merge dev changes
zloery Feb 2, 2021
2e5ac95
add bucket/bq name validation, return values in errors
zloery Feb 3, 2021
a2f3c49
remove typeMap
zloery Feb 3, 2021
c2a9dd9
merge dev changes
zloery Feb 4, 2021
b22c01a
major refactoring of endpoints to per-reference type
zloery Feb 8, 2021
eaae8be
add controller annotations
zloery Feb 8, 2021
6b17d85
updated endpoint locations to remove ambiguity
zloery Feb 8, 2021
84afee2
make endpoints plural
zloery Feb 9, 2021
f792853
remove per-type delete endpoints
zloery Feb 10, 2021
5ebcc69
merge changes from dev
zloery Feb 10, 2021
26bfe9a
factor out common ReferenceController, proper description wiring
zloery Feb 10, 2021
c40e94a
logging formatting
zloery Feb 10, 2021
7937bf1
formatting, fix swagger-ui interaction with remote yaml
zloery Feb 11, 2021
51c06c0
merge dev changes
zloery Feb 11, 2021
ac1f476
bump version, responses to comments
zloery Feb 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sourceCompatibility = JavaVersion.VERSION_11

allprojects {
group = "bio.terra"
version = "0.11.0-SNAPSHOT"
version = "0.12.0-SNAPSHOT"
ext {
artifactGroup = "${group}.workspace"
swaggerOutputDir = "${buildDir}/swagger-code"
Expand All @@ -36,6 +36,7 @@ allprojects {
entry "opencensus-impl"
}

dependency group: "bio.terra.cloud-resource-lib", name: "cloud-resource-schema", version: "0.4.0"
dependency group: "io.swagger.core.v3", name: "swagger-annotations", version: "2.1.6"
dependency group: "io.swagger.codegen.v3", name: "swagger-codegen-cli", version: "3.0.23"
}
Expand Down Expand Up @@ -69,9 +70,11 @@ dependencies {
implementation group: "bio.terra", name: "datarepo-client", version: "1.0.1-SNAPSHOT"
implementation group: "bio.terra", name: "stairway", version: "0.0.36-SNAPSHOT"
implementation group: "bio.terra", name: "terra-common-lib", version: "0.0.13-SNAPSHOT"
implementation group: 'bio.terra.cloud-resource-lib', name: 'google-billing', version: '0.0.4-SNAPSHOT'
implementation group: 'bio.terra.cloud-resource-lib', name: 'google-cloudresourcemanager', version: '0.0.8-SNAPSHOT'
implementation group: 'bio.terra.cloud-resource-lib', name: 'google-serviceusage', version: '0.0.4-SNAPSHOT'
implementation group: 'bio.terra.cloud-resource-lib', name: 'google-billing', version: '0.4.0'
implementation group: 'bio.terra.cloud-resource-lib', name: 'google-bigquery', version: '0.4.0'
implementation group: 'bio.terra.cloud-resource-lib', name: 'google-cloudresourcemanager', version: '0.4.0'
implementation group: 'bio.terra.cloud-resource-lib', name: 'google-serviceusage', version: '0.4.0'
implementation group: 'bio.terra.cloud-resource-lib', name: 'google-storage', version: '0.4.0'
implementation group: "org.broadinstitute.dsde.workbench", name: "sam-client_2.12", version: "0.1-61135c7"
implementation group: "bio.terra", name: "terra-resource-buffer-client", version: "0.4.3-SNAPSHOT"

Expand Down Expand Up @@ -125,6 +128,20 @@ if (hasProperty("buildScan")) {
}
}

// CRL schema extraction
configurations {
cloudResourceSchema { transitive = false }
}
dependencies {
cloudResourceSchema group: 'bio.terra.cloud-resource-lib', name: 'cloud-resource-schema'
}
task unzipCloudResourceSchema(type: Copy) {
from zipTree(configurations.cloudResourceSchema.singleFile).matching {
include 'cloud_resources_uid.yaml'
}
into "${resourceDir}/api/common"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to unpack this into the source tree?
Is an alternative to copy our resources into the build tree?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to deploy our yaml file into a build dir so we could use relative (non-upward) paths.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I unpacked it into the source tree so that our swagger-ui (also in the source dir) can parse references to it. otherwise, those schemas won't show up in swagger-ui, which breaks example values.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave it for now. I'll make a ticket.
Another approach might be to move all of the parts into a build subdirectory and do the codegen from there.
I'll make a ticket.

}

// Defs

def generatedResourceDir = "${resourceDir}/generated"
Expand Down Expand Up @@ -230,9 +247,11 @@ jib {
}
}

// Internal dependencies

sourceSets.main.java.srcDir "${swaggerOutputDir}/src/main/java"
compileJava.dependsOn swaggerSources.server.code, spotlessApply, setGitVersion

// Internal dependencies
// Note The Open API schema depends on an external library - cloud-resource-schema, so need to unzip it first.
swaggerSources.server.code.dependsOn tasks.unzipCloudResourceSchema
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the swagger client tasks?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This took longer to investigate and fix than I want to admit, but you're right that swagger client tasks didn't depend on this. Should be fixed now

swaggerSources.server.ui.dependsOn tasks.unzipCloudResourceSchema
compileJava.dependsOn swaggerSources.server.code, spotlessApply, setGitVersion
clean.dependsOn cleanSetGitVersion
24 changes: 17 additions & 7 deletions gradle.lockfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
bio.terra.cloud-resource-lib:cloud-resource-schema:0.0.2-SNAPSHOT=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:common:0.0.9-SNAPSHOT=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:google-api-services-common:0.0.5-SNAPSHOT=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:google-billing:0.0.4-SNAPSHOT=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:google-cloudresourcemanager:0.0.8-SNAPSHOT=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:google-serviceusage:0.0.4-SNAPSHOT=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:cloud-resource-schema:0.4.0=cloudResourceSchema,productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:common:0.4.0=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:google-api-services-common:0.4.0=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:google-bigquery:0.4.0=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:google-billing:0.4.0=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:google-cloudresourcemanager:0.4.0=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:google-serviceusage:0.4.0=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.cloud-resource-lib:google-storage:0.4.0=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra.janitor:terra-resource-janitor-client:0.0.2-SNAPSHOT=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
bio.terra:datarepo-client:1.0.1-SNAPSHOT=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
bio.terra:stairway:0.0.36-SNAPSHOT=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -45,8 +47,11 @@ com.google.api:gax-grpc:1.60.0=compileClasspath,testCompileClasspath
com.google.api:gax-httpjson:0.73.0=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.api:gax:1.56.0=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
com.google.api:gax:1.60.0=compileClasspath,testCompileClasspath
com.google.apis:google-api-services-bigquery:v2-rev20200324-1.30.9=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
com.google.apis:google-api-services-bigquery:v2-rev20200429-1.30.9=compileClasspath,testCompileClasspath
com.google.apis:google-api-services-cloudresourcemanager:v1-rev20200810-1.30.10=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.apis:google-api-services-serviceusage:v1-rev20200821-1.30.10=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.apis:google-api-services-storage:v1-rev20200326-1.30.9=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.auth:google-auth-library-credentials:0.20.0=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
com.google.auth:google-auth-library-credentials:0.22.0=compileClasspath
com.google.auth:google-auth-library-credentials:0.22.1=testCompileClasspath
Expand All @@ -55,6 +60,8 @@ com.google.auth:google-auth-library-oauth2-http:0.22.0=compileClasspath
com.google.auth:google-auth-library-oauth2-http:0.22.1=testCompileClasspath,testRuntimeClasspath
com.google.auto.value:auto-value-annotations:1.7.4=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.google.auto.value:auto-value:1.7.4=annotationProcessor
com.google.cloud:google-cloud-bigquery:1.111.1=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-bigquery:1.116.0=compileClasspath,testCompileClasspath
com.google.cloud:google-cloud-billing:1.0.2=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-billing:1.1.1=compileClasspath,testCompileClasspath
com.google.cloud:google-cloud-core-grpc:1.93.4=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
Expand All @@ -68,6 +75,8 @@ com.google.cloud:google-cloud-logging-logback:0.118.3-alpha=compileClasspath,tes
com.google.cloud:google-cloud-logging:1.101.1=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-logging:1.102.0=compileClasspath,testCompileClasspath
com.google.cloud:google-cloud-pubsub:1.105.0=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-storage:1.107.0=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
com.google.cloud:google-cloud-storage:1.108.0=compileClasspath,testCompileClasspath
com.google.cloud:google-cloud-trace:0.100.0-beta=compileClasspath,testCompileClasspath
com.google.cloud:google-cloud-trace:1.0.3=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
com.google.cloud:libraries-bom:5.3.0=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -100,6 +109,7 @@ com.squareup.okio:okio:1.17.2=compileClasspath,productionRuntimeClasspath,runtim
com.vaadin.external.google:android-json:0.0.20131108.vaadin1=testCompileClasspath,testRuntimeClasspath
com.zaxxer:HikariCP:3.4.5=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
commons-codec:commons-codec:1.15=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
commons-logging:commons-logging:1.2=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
io.github.classgraph:classgraph:4.8.69=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
io.grpc:grpc-alts:1.29.0=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
io.grpc:grpc-alts:1.32.2=compileClasspath,testCompileClasspath
Expand Down Expand Up @@ -185,7 +195,7 @@ org.bouncycastle:bcpkix-jdk15on:1.66=productionRuntimeClasspath,runtimeClasspath
org.bouncycastle:bcprov-ext-jdk15on:1.66=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
org.bouncycastle:bcprov-jdk15on:1.66=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
org.broadinstitute.dsde.workbench:sam-client_2.12:0.1-61135c7=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.checkerframework:checker-compat-qual:2.5.5=compileClasspath,testCompileClasspath
org.checkerframework:checker-compat-qual:2.5.5=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.checkerframework:checker-qual:3.5.0=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.codehaus.mojo:animal-sniffer-annotations:1.18=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
org.conscrypt:conscrypt-openjdk-uber:2.2.1=compileClasspath,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package bio.terra.workspace.app.controller;

import bio.terra.workspace.app.controller.common.ReferenceController;
import bio.terra.workspace.common.utils.ControllerTranslationUtils;
import bio.terra.workspace.generated.controller.DataRepoReferenceApi;
import bio.terra.workspace.generated.model.CreateDataRepoSnapshotReferenceRequestBody;
import bio.terra.workspace.generated.model.DataRepoSnapshotReference;
import bio.terra.workspace.generated.model.UpdateDataReferenceRequestBody;
import bio.terra.workspace.service.datareference.DataReferenceService;
import bio.terra.workspace.service.datareference.model.DataReference;
import bio.terra.workspace.service.datareference.model.DataReferenceType;
import bio.terra.workspace.service.datareference.model.SnapshotReference;
import bio.terra.workspace.service.datareference.utils.DataReferenceValidationUtils;
import bio.terra.workspace.service.iam.AuthenticatedUserRequest;
import bio.terra.workspace.service.iam.AuthenticatedUserRequestFactory;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

@Controller
public class DataRepoReferenceController extends ReferenceController
implements DataRepoReferenceApi {

private final DataReferenceValidationUtils dataReferenceValidation;
private final DataReferenceService dataReferenceService;
private final AuthenticatedUserRequestFactory authenticatedUserRequestFactory;
private final HttpServletRequest request;

@Autowired
public DataRepoReferenceController(
DataReferenceValidationUtils dataReferenceValidation,
DataReferenceService dataReferenceService,
AuthenticatedUserRequestFactory authenticatedUserRequestFactory,
HttpServletRequest request) {
this.dataReferenceValidation = dataReferenceValidation;
this.dataReferenceService = dataReferenceService;
this.authenticatedUserRequestFactory = authenticatedUserRequestFactory;
this.request = request;
}

private AuthenticatedUserRequest getAuthenticatedInfo() {
return authenticatedUserRequestFactory.from(request);
}

@Override
public ResponseEntity<DataRepoSnapshotReference> createDataRepoSnapshotReference(
UUID id, @Valid CreateDataRepoSnapshotReferenceRequestBody body) {
SnapshotReference referenceObject =
SnapshotReference.create(
body.getSnapshot().getInstanceName(), body.getSnapshot().getSnapshot());
DataReference reference =
createDataReference(
id,
body.getMetadata(),
DataReferenceType.DATA_REPO_SNAPSHOT,
referenceObject,
getAuthenticatedInfo(),
dataReferenceValidation,
dataReferenceService);

DataRepoSnapshotReference response =
new DataRepoSnapshotReference()
.metadata(ControllerTranslationUtils.metadataFromDataReference(reference))
.snapshot(((SnapshotReference) reference.referenceObject()).toApiModel());
return new ResponseEntity<>(response, HttpStatus.OK);
}

@Override
public ResponseEntity<DataRepoSnapshotReference> getDataRepoSnapshotReference(
UUID id, UUID referenceId) {
DataReference ref = getReference(id, referenceId, getAuthenticatedInfo(), dataReferenceService);

DataRepoSnapshotReference response =
new DataRepoSnapshotReference()
.snapshot(((SnapshotReference) ref.referenceObject()).toApiModel())
.metadata(ControllerTranslationUtils.metadataFromDataReference(ref));
return new ResponseEntity<>(response, HttpStatus.OK);
}

@Override
public ResponseEntity<DataRepoSnapshotReference> getDataRepoSnapshotReferenceByName(
UUID id, String name) {
DataReference ref =
getReferenceByName(
id,
DataReferenceType.DATA_REPO_SNAPSHOT,
name,
getAuthenticatedInfo(),
dataReferenceService);
DataRepoSnapshotReference response =
new DataRepoSnapshotReference()
.snapshot(((SnapshotReference) ref.referenceObject()).toApiModel())
.metadata(ControllerTranslationUtils.metadataFromDataReference(ref));
return new ResponseEntity<>(response, HttpStatus.OK);
}

@Override
public ResponseEntity<Void> updateDataRepoSnapshotReference(
@PathVariable("id") UUID id,
@PathVariable("referenceId") UUID referenceId,
@RequestBody UpdateDataReferenceRequestBody body) {
updateReference(id, referenceId, body, getAuthenticatedInfo(), dataReferenceService);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also from #221 this needs to include updateDataReference(...)

Loading