Skip to content

Commit bfcc0c8

Browse files
Leopold-Cramerjreynard-code
authored andcommitted
save workspaceFiles in s3 service instead of localStorage
changed local storage saving to s3 saving added s3 tests capabilities added integration tests for mentionned changes
1 parent 55af2a6 commit bfcc0c8

File tree

23 files changed

+349
-168
lines changed

23 files changed

+349
-168
lines changed

api/kubernetes/helm-chart/templates/_helpers.tpl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ E.g:
108108
{{- end }}
109109
{{- end }}
110110

111-
{{/*
112-
Location of the persistence data
113-
*/}}
114-
{{- define "cosmotech-api.blobPersistencePath" -}}
115-
"/var/lib/cosmotech-api/data"
116-
{{- end }}
117-
118111
{{- define "cosmotech-api.custom-rootca-path" -}}
119112
/mnt/cosmotech/certificates
120113
{{- end }}
@@ -197,8 +190,6 @@ csm:
197190
{{- else }}
198191
image-pull-secrets: []
199192
{{- end }}
200-
blobPersistence:
201-
path: {{ include "cosmotech-api.blobPersistencePath" . }}
202193
identityProvider:
203194
tls:
204195
bundle: {{ include "cosmotech-api.custom-rootca-bundle" . }}

api/kubernetes/helm-chart/templates/deployment.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ spec:
4646
- name: helm-config
4747
secret:
4848
secretName: {{ include "cosmotech-api.fullname" . }}
49-
{{if .Values.persistence.enabled}}
50-
- name: blob-storage
51-
persistentVolumeClaim:
52-
claimName: {{ include "cosmotech-api.fullname" . }}-blob-storage
53-
{{end}}
5449
{{if .Values.api.tlsTruststore.enabled}}
5550
- name: custom-rootca
5651
secret:
@@ -90,11 +85,6 @@ spec:
9085
- mountPath: /config
9186
name: helm-config
9287
readOnly: true
93-
{{if .Values.persistence.enabled}}
94-
- mountPath: {{ include "cosmotech-api.blobPersistencePath" . }}
95-
name: blob-storage
96-
readOnly: false
97-
{{end}}
9888
{{if .Values.api.tlsTruststore.enabled }}
9989
- mountPath: {{ include "cosmotech-api.custom-rootca-path" . | quote }}
10090
name: custom-rootca

api/kubernetes/helm-chart/templates/pvc.yaml

Lines changed: 0 additions & 21 deletions
This file was deleted.

api/kubernetes/helm-chart/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ config:
192192
requests:
193193
# File storage minimal claim is 100Gi for Premium classes
194194
storage: 100Gi
195+
s3:
196+
endpointUrl: "http://s3-server:9000"
197+
bucketName: "changeme"
198+
accessKeyId: "changeme"
199+
secretAccessKey: "changeme"
195200
authorization:
196201
allowed-tenants: []
197202
identityProvider:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Cosmo Tech.
2+
// Licensed under the MIT license.
3+
package com.cosmotech.api.exceptions
4+
5+
import java.net.URI
6+
import org.springframework.core.Ordered
7+
import org.springframework.core.annotation.Order
8+
import org.springframework.http.HttpStatus
9+
import org.springframework.http.ProblemDetail
10+
import org.springframework.web.bind.annotation.ExceptionHandler
11+
import org.springframework.web.bind.annotation.RestControllerAdvice
12+
import software.amazon.awssdk.awscore.exception.AwsServiceException
13+
14+
@RestControllerAdvice
15+
@Order(Ordered.HIGHEST_PRECEDENCE)
16+
internal class AwsExceptionHandling : CsmExceptionHandling() {
17+
private val httpStatusCodeTypePrefix = "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/"
18+
19+
@ExceptionHandler
20+
fun handleBlobStorageException(exception: AwsServiceException): ProblemDetail {
21+
val status = HttpStatus.INTERNAL_SERVER_ERROR
22+
23+
val problemDetail = ProblemDetail.forStatus(status)
24+
problemDetail.type = URI.create(httpStatusCodeTypePrefix + status.value())
25+
26+
if (exception.message != null) {
27+
problemDetail.detail = exception.message
28+
}
29+
return problemDetail
30+
}
31+
}

api/src/main/resources/application.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ spring:
3434
enabled: false
3535
kubernetes:
3636
enabled: false
37+
aws:
38+
credentials:
39+
access-key: ${csm.platform.s3.accessKeyId}
40+
secret-key: ${csm.platform.s3.secretAccessKey}
41+
s3:
42+
# We don't need/have a region for our local S3 service but the AWS SDK requires one to be configured
43+
region: ${csm.platform.s3.region}
44+
# Enable path-style / disable DNS-style
45+
# By default, and for AWS S3, the client crafts its URL with the bucket as sub-domain of the endpoint
46+
# which is not how our current S3 implementation works as it expects the bucket in the path
47+
# '<bucket_name>.<endpoint>/<object_key>' DNS vs Path '<endpoint>/<bucket_name>/<object_key>'
48+
path-style-access-enabled: true
49+
endpoint: ${csm.platform.s3.endpointUrl}
3750

3851
management:
3952
endpoints:
@@ -119,8 +132,11 @@ csm:
119132
sender:
120133
username: "eventbus_sender_username"
121134
password: "eventbus_sender_password"
122-
blobPersistence:
123-
path: /tmp/cosmotech-api-data
135+
s3:
136+
endpointUrl: "http://localhost:9000"
137+
bucketName: "cosmotech-api"
138+
accessKeyId: "s3_username"
139+
secretAccessKey: "s3_password"
124140
argo:
125141
base-uri: "https://localhost:2746"
126142
image-pull-secrets: []

build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ val springWebVersion = "6.2.1"
6161

6262
// Implementation
6363
val kotlinJvmTarget = 21
64-
val cosmotechApiCommonVersion = "2.1.0-SNAPSHOT"
64+
val cosmotechApiCommonVersion = "2.1.1-LCRA-store_workspace_files_in_seaweed_PROD-14290-SNAPSHOT"
6565
val jedisVersion = "4.4.6"
6666
val springOauthVersion = "6.4.2"
6767
val redisOmSpringVersion = "0.9.7"
@@ -79,6 +79,7 @@ val testNgVersion = "7.8.0"
7979
val testContainersRedisVersion = "1.6.4"
8080
val testContainersPostgreSQLVersion = "1.19.7"
8181
val commonCompressVersion = "1.27.1"
82+
val awsSpringVersion = "3.1.1"
8283

8384
// Checks
8485
val detektVersion = "1.23.7"
@@ -140,6 +141,7 @@ allprojects {
140141
configurations { all { resolutionStrategy { force("com.redis.om:redis-om-spring:0.9.1") } } }
141142

142143
repositories {
144+
mavenLocal()
143145
maven {
144146
name = "GitHubPackages"
145147
url = uri("https://maven.pkg.github.com/Cosmo-Tech/cosmotech-api-common")
@@ -312,6 +314,9 @@ subprojects {
312314

313315
implementation("org.json:json:$orgJsonVersion")
314316

317+
implementation(platform("io.awspring.cloud:spring-cloud-aws-dependencies:$awsSpringVersion"))
318+
implementation("io.awspring.cloud:spring-cloud-aws-starter-s3:$awsSpringVersion")
319+
315320
testImplementation(kotlin("test"))
316321
testImplementation(platform("org.junit:junit-bom:$jUnitBomVersion"))
317322
testImplementation("org.junit.jupiter:junit-jupiter")

config/application-dev.sample.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ spring:
4040
keycloak:
4141
truststore:
4242
certificate: "classpath:[fill-this-value].pem" # certificate file
43+
cloud:
44+
aws:
45+
credentials:
46+
access-key: "s3_username"
47+
secret-key: "s3_password"
48+
s3:
49+
region: "dummy"
50+
path-style-access-enabled: true
51+
endpoint: "http://localhost:9000"
4352

4453
csm:
4554
platform:
@@ -72,6 +81,11 @@ csm:
7281
tokenUrl: "[fill-this-value]" # eg. https://kubernetes.cosmotech.com/keycloak/realms/brewery/protocol/openid-connect/token
7382
metrics:
7483
enabled: false
84+
s3:
85+
endpointUrl: "http://localhost:9000"
86+
bucketName: "cosmotech-api"
87+
accessKeyId: "s3_username"
88+
secretAccessKey: "s3_password"
7589
argo:
7690
base-uri: "http://localhost:2746"
7791
workflows:

connector/src/integrationTest/resources/application-connector-test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,8 @@ csm:
9595
default-page-size: 5
9696
rbac:
9797
enabled: true
98-
blobPersistence:
99-
path: /tmp/cosmotech-api-connector-test-data
98+
s3:
99+
endpointUrl: "http://localhost:9000"
100+
bucketName: "test-bucket"
101+
accessKeyId: "s3_username"
102+
secretAccessKey: "s3_password"

dataset/src/integrationTest/resources/application-dataset-test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,8 @@ csm:
100100
default-page-size: 5
101101
rbac:
102102
enabled: true
103-
blobPersistence:
104-
path: /tmp/cosmotech-api-dataset-test-data
103+
s3:
104+
endpointUrl: "http://localhost:9000"
105+
bucketName: "test-bucket"
106+
accessKeyId: "s3_username"
107+
secretAccessKey: "s3_password"

0 commit comments

Comments
 (0)