Skip to content

Commit 3005b87

Browse files
committed
core: save loaded infras to s3 when available
Signed-off-by: Eloi Charpentier <eloi.charpentier.42@gmail.com>
1 parent 5678a65 commit 3005b87

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

core/src/main/java/fr/sncf/osrd/api/InfraManager.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fr.sncf.osrd.parseRJSInfra
44
import fr.sncf.osrd.railjson.schema.infra.RJSInfra
55
import fr.sncf.osrd.reporting.exceptions.ErrorType
66
import fr.sncf.osrd.reporting.exceptions.OSRDError
7+
import fr.sncf.osrd.utils.compressToZip
78
import fr.sncf.osrd.utils.jacoco.ExcludeFromGeneratedCodeCoverage
89
import io.opentelemetry.api.trace.SpanKind
910
import io.opentelemetry.instrumentation.annotations.WithSpan
@@ -14,8 +15,12 @@ import okhttp3.OkHttpClient
1415
import org.slf4j.Logger
1516
import org.slf4j.LoggerFactory
1617

17-
class InfraManager(baseUrl: String, authorizationToken: String?, httpClient: OkHttpClient) :
18-
APIClient(baseUrl, authorizationToken, httpClient), InfraProvider {
18+
class InfraManager(
19+
baseUrl: String,
20+
authorizationToken: String?,
21+
httpClient: OkHttpClient,
22+
val s3Context: S3Context? = null,
23+
) : APIClient(baseUrl, authorizationToken, httpClient), InfraProvider {
1924
private val infraCache = ConcurrentHashMap<String, InfraCacheEntry>()
2025
private val signalingSimulator = makeSignalingSimulator()
2126

@@ -118,6 +123,16 @@ class InfraManager(baseUrl: String, authorizationToken: String?, httpClient: OkH
118123
cacheEntry.version = version
119124
checkNotNull(response.body) { "missing body in railjson response" }
120125
rjsInfra = RJSInfra.adapter.fromJson(response.body.source())!!
126+
127+
// Save railjson to s3 if available, for better reproducibility.
128+
// This is done on a different thread while the infra is parsed (on a single
129+
// thread), it should not take any extra time.
130+
s3Context?.writeFileIfMissing("stdcm/infras/$infraId-$version.railjson.zip") {
131+
RJSInfra.adapter
132+
.toJson(rjsInfra)
133+
.encodeToByteArray()
134+
.compressToZip("$infraId-$version.railjson")
135+
}
121136
}
122137

123138
// Parse railjson into a proper infra

core/src/main/java/fr/sncf/osrd/cli/WorkerCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class WorkerCommand : CliCommand {
122122

123123
val infraId = WORKER_KEY.split("-").first()
124124
val timetableId = WORKER_KEY.split("-").getOrNull(1)?.toInt()
125-
val infraManager = InfraManager(editoastUrl!!, editoastAuthorization, httpClient)
125+
val infraManager = InfraManager(editoastUrl!!, editoastAuthorization, httpClient, s3Context)
126126
val timetableCache =
127127
TimetableCacheManager(
128128
TimetableDownloader(

0 commit comments

Comments
 (0)