Skip to content

Commit e37b50e

Browse files
committed
editoast: log stdcm requests
Signed-off-by: hamz2a <atrari.hamza@gmail.com>
1 parent 02ccfc8 commit e37b50e

File tree

11 files changed

+188
-22
lines changed

11 files changed

+188
-22
lines changed

editoast/editoast_models/src/tables.rs

+17
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,21 @@ diesel::table! {
597597
}
598598
}
599599

600+
diesel::table! {
601+
use diesel::sql_types::*;
602+
use postgis_diesel::sql_types::*;
603+
604+
stdcm_logs (id) {
605+
id -> Int8,
606+
#[max_length = 32]
607+
trace_id -> Varchar,
608+
request -> Jsonb,
609+
response -> Jsonb,
610+
created -> Timestamptz,
611+
user_id -> Nullable<Int8>,
612+
}
613+
}
614+
600615
diesel::table! {
601616
use diesel::sql_types::*;
602617
use postgis_diesel::sql_types::*;
@@ -799,6 +814,7 @@ diesel::joinable!(search_project -> project (id));
799814
diesel::joinable!(search_scenario -> scenario (id));
800815
diesel::joinable!(search_signal -> infra_object_signal (id));
801816
diesel::joinable!(search_study -> study (id));
817+
diesel::joinable!(stdcm_logs -> authn_user (user_id));
802818
diesel::joinable!(stdcm_search_environment -> electrical_profile_set (electrical_profile_set_id));
803819
diesel::joinable!(stdcm_search_environment -> infra (infra_id));
804820
diesel::joinable!(stdcm_search_environment -> temporary_speed_limit_group (temporary_speed_limit_group_id));
@@ -852,6 +868,7 @@ diesel::allow_tables_to_appear_in_same_query!(
852868
search_signal,
853869
search_study,
854870
search_track,
871+
stdcm_logs,
855872
stdcm_search_environment,
856873
study,
857874
temporary_speed_limit,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE stdcm_logs;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE TABLE stdcm_logs (
2+
id int8 PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
3+
trace_id VARCHAR(32) UNIQUE NOT NULL,
4+
request jsonb NOT NULL,
5+
response jsonb NOT NULL,
6+
created timestamptz NOT NULL DEFAULT NOW(),
7+
user_id bigint REFERENCES authn_user ON DELETE CASCADE
8+
);

editoast/openapi.yaml

+64
Original file line numberDiff line numberDiff line change
@@ -8621,6 +8621,45 @@ components:
86218621
type: integer
86228622
format: int64
86238623
nullable: true
8624+
Response:
8625+
oneOf:
8626+
- type: object
8627+
required:
8628+
- simulation
8629+
- path
8630+
- departure_time
8631+
- status
8632+
properties:
8633+
departure_time:
8634+
type: string
8635+
format: date-time
8636+
path:
8637+
$ref: '#/components/schemas/PathfindingResultSuccess'
8638+
simulation:
8639+
$ref: '#/components/schemas/SimulationResponse'
8640+
status:
8641+
type: string
8642+
enum:
8643+
- success
8644+
- type: object
8645+
required:
8646+
- status
8647+
properties:
8648+
status:
8649+
type: string
8650+
enum:
8651+
- path_not_found
8652+
- type: object
8653+
required:
8654+
- error
8655+
- status
8656+
properties:
8657+
error:
8658+
$ref: '#/components/schemas/SimulationResponse'
8659+
status:
8660+
type: string
8661+
enum:
8662+
- preprocessing_simulation_error
86248663
RjsPowerRestrictionRange:
86258664
type: object
86268665
description: A range along the train path where a power restriction is applied.
@@ -10232,6 +10271,31 @@ components:
1023210271
type: array
1023310272
items:
1023410273
$ref: '#/components/schemas/RangeAllowance'
10274+
StdcmLog:
10275+
type: object
10276+
required:
10277+
- id
10278+
- trace_id
10279+
- request
10280+
- response
10281+
- created
10282+
properties:
10283+
created:
10284+
type: string
10285+
format: date-time
10286+
id:
10287+
type: integer
10288+
format: int64
10289+
request:
10290+
$ref: '#/components/schemas/Request'
10291+
response:
10292+
$ref: '#/components/schemas/Response'
10293+
trace_id:
10294+
type: string
10295+
user_id:
10296+
type: integer
10297+
format: int64
10298+
nullable: true
1023510299
StdcmSearchEnvironment:
1023610300
type: object
1023710301
required:

editoast/src/core/conflict_detection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct ConflictDetectionRequest {
2929
pub work_schedules: Option<WorkSchedulesRequest>,
3030
}
3131

32-
#[derive(Debug, Clone, Serialize)]
32+
#[derive(Debug, Clone, Serialize, Deserialize)]
3333
pub struct TrainRequirements {
3434
pub start_time: DateTime<Utc>,
3535
pub spacing_requirements: Vec<SpacingRequirement>,

editoast/src/core/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ editoast_common::schemas! {
3636
simulation::schemas(),
3737
pathfinding::schemas(),
3838
conflict_detection::schemas(),
39+
stdcm::schemas(),
3940
}
4041

4142
#[derive(Debug, Clone)]

editoast/src/core/simulation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ editoast_common::schemas! {
3333
SimulationResponse,
3434
}
3535

36-
#[derive(Debug, Serialize, Derivative)]
36+
#[derive(Debug, Clone, Serialize, Deserialize, Derivative)]
3737
#[derivative(Hash)]
3838
pub struct PhysicsConsist {
3939
pub effort_curves: EffortCurves,

editoast/src/core/stdcm.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ use super::simulation::SimulationResponse;
1919
use crate::core::AsCoreRequest;
2020
use crate::core::Json;
2121

22-
#[derive(Debug, Serialize)]
22+
editoast_common::schemas! {
23+
Response,
24+
}
25+
26+
#[derive(Debug, Clone, Serialize, Deserialize)]
2327
pub struct Request {
2428
/// Infrastructure id
2529
pub infra: i64,
@@ -61,7 +65,7 @@ pub struct Request {
6165
pub temporary_speed_limits: Vec<TemporarySpeedLimit>,
6266
}
6367

64-
#[derive(Debug, Serialize)]
68+
#[derive(Debug, Clone, Serialize, Deserialize)]
6569
pub struct PathItem {
6670
/// The track offsets of the path item
6771
pub locations: Vec<TrackOffset>,
@@ -72,7 +76,7 @@ pub struct PathItem {
7276
}
7377

7478
/// Contains the data of a step timing, when it is specified
75-
#[derive(Debug, Serialize)]
79+
#[derive(Debug, Clone, Serialize, Deserialize)]
7680
pub struct StepTimingData {
7781
/// Time the train should arrive at this point
7882
pub arrival_time: DateTime<Utc>,
@@ -83,7 +87,7 @@ pub struct StepTimingData {
8387
}
8488

8589
/// Lighter description of a work schedule, with only the relevant information for core
86-
#[derive(Debug, Serialize)]
90+
#[derive(Debug, Clone, Serialize, Deserialize)]
8791
pub struct WorkSchedule {
8892
/// Start time as a time delta from the stdcm start time in ms
8993
pub start_time: u64,
@@ -94,7 +98,7 @@ pub struct WorkSchedule {
9498
}
9599

96100
/// Lighter description of a work schedule with only the relevant information for core
97-
#[derive(Debug, Serialize)]
101+
#[derive(Debug, Clone, Serialize, Deserialize)]
98102
pub struct TemporarySpeedLimit {
99103
/// Speed limitation in m/s
100104
pub speed_limit: f64,
@@ -114,7 +118,7 @@ pub struct UndirectedTrackRange {
114118
pub end: u64,
115119
}
116120

117-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
121+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, ToSchema)]
118122
#[serde(tag = "status", rename_all = "snake_case")]
119123
// We accepted the difference of memory size taken by variants
120124
// Since there is only on success and others are error cases

editoast/src/models/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod fixtures;
66
pub mod infra;
77
pub mod infra_objects;
88
pub mod layers;
9+
pub mod stdcm_log;
910
// We allow unused until models is moved to a separate crate
1011
pub mod auth;
1112
pub mod pagination;
@@ -41,6 +42,7 @@ editoast_common::schemas! {
4142
infra::schemas(),
4243
projects::schemas(),
4344
rolling_stock_model::schemas(),
45+
stdcm_log::schemas(),
4446
}
4547

4648
#[cfg(test)]

editoast/src/models/stdcm_log.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use chrono::DateTime;
2+
use chrono::Utc;
3+
use editoast_derive::Model;
4+
use serde::Deserialize;
5+
use serde::Serialize;
6+
use utoipa::ToSchema;
7+
8+
use crate::core::stdcm::Request;
9+
use crate::core::stdcm::Response;
10+
11+
editoast_common::schemas! {
12+
StdcmLog,
13+
}
14+
15+
#[derive(Clone, Debug, Serialize, Deserialize, Model, ToSchema)]
16+
#[model(table = editoast_models::tables::stdcm_logs)]
17+
#[model(gen(ops = c))]
18+
pub struct StdcmLog {
19+
pub id: i64,
20+
pub trace_id: String,
21+
#[model(json)]
22+
pub request: Request,
23+
#[model(json)]
24+
pub response: Response,
25+
pub created: DateTime<Utc>,
26+
pub user_id: Option<i64>,
27+
}

0 commit comments

Comments
 (0)