@@ -4,6 +4,7 @@ import fr.sncf.osrd.parseRJSInfra
44import fr.sncf.osrd.railjson.schema.infra.RJSInfra
55import fr.sncf.osrd.reporting.exceptions.ErrorType
66import fr.sncf.osrd.reporting.exceptions.OSRDError
7+ import fr.sncf.osrd.utils.compressToZip
78import fr.sncf.osrd.utils.jacoco.ExcludeFromGeneratedCodeCoverage
89import io.opentelemetry.api.trace.SpanKind
910import io.opentelemetry.instrumentation.annotations.WithSpan
@@ -14,8 +15,12 @@ import okhttp3.OkHttpClient
1415import org.slf4j.Logger
1516import 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
0 commit comments