diff --git a/core/src/main/java/fr/sncf/osrd/api/InfraCacheStatusEndpoint.java b/core/src/main/java/fr/sncf/osrd/api/InfraCacheStatusEndpoint.java deleted file mode 100644 index c5baf8d1c7b..00000000000 --- a/core/src/main/java/fr/sncf/osrd/api/InfraCacheStatusEndpoint.java +++ /dev/null @@ -1,90 +0,0 @@ -package fr.sncf.osrd.api; - -import com.squareup.moshi.Json; -import com.squareup.moshi.JsonAdapter; -import com.squareup.moshi.Moshi; -import com.squareup.moshi.Types; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import fr.sncf.osrd.api.InfraManager.InfraCacheEntry; -import fr.sncf.osrd.api.InfraManager.InfraStatus; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import org.takes.Request; -import org.takes.Response; -import org.takes.Take; -import org.takes.rq.RqPrint; -import org.takes.rs.RsJson; -import org.takes.rs.RsWithBody; - -public final class InfraCacheStatusEndpoint implements Take { - private final InfraManager infraManager; - - public static final JsonAdapter adapterRequest = - new Moshi.Builder().build().adapter(InfraCacheRequest.class); - - public static final JsonAdapter> adapter; - - static { - Moshi moshi = new Moshi.Builder().build(); - var type = Types.newParameterizedType(Map.class, String.class, SerializedInfraCache.class); - adapter = moshi.adapter(type); - } - - public InfraCacheStatusEndpoint(InfraManager infraManager) { - this.infraManager = infraManager; - } - - @Override - public Response act(Request req) throws IOException { - - Map res = new HashMap<>(); - // Parse request input - try { - var body = new RqPrint(req).printBody(); - String infra = null; - if (!body.equals("")) { - infra = adapterRequest.fromJson(body).infra; - } - if (infra != null) { - var request = adapterRequest.fromJson(body); - var infraCacheEntry = infraManager.getInfraCache(request.infra); - if (infraCacheEntry != null) res.put(request.infra, SerializedInfraCache.from(infraCacheEntry)); - } else { - infraManager.forEach((infraId, infraCacheEntry) -> { - res.put(infraId, SerializedInfraCache.from(infraCacheEntry)); - }); - } - return new RsJson(new RsWithBody(adapter.toJson(res))); - } catch (Throwable ex) { - // TODO: include warnings in the response - return ExceptionHandler.handle(ex); - } - } - - @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") - public static final class SerializedInfraCache { - public InfraStatus status; - - @Json(name = "last_status") - public InfraStatus lastStatus; - - public SerializedInfraCache(InfraStatus status, InfraStatus lastStatus) { - this.status = status; - this.lastStatus = lastStatus; - } - - static SerializedInfraCache from(InfraCacheEntry entry) { - return new SerializedInfraCache(entry.status, entry.lastStatus); - } - } - - public static final class InfraCacheRequest { - /** Infra id */ - public String infra; - - public InfraCacheRequest(String infra) { - this.infra = infra; - } - } -} diff --git a/core/src/main/java/fr/sncf/osrd/cli/ApiServerCommand.java b/core/src/main/java/fr/sncf/osrd/cli/ApiServerCommand.java index db8c8db4200..b70246a4893 100644 --- a/core/src/main/java/fr/sncf/osrd/cli/ApiServerCommand.java +++ b/core/src/main/java/fr/sncf/osrd/cli/ApiServerCommand.java @@ -91,7 +91,6 @@ public int run() { new FkRegex("/v2/signal_projection", new SignalProjectionEndpointV2(infraManager)), new FkRegex("/detect_conflicts", new ConflictDetectionEndpoint()), new FkRegex("/v2/conflict_detection", new ConflictDetectionEndpointV2(infraManager)), - new FkRegex("/cache_status", new InfraCacheStatusEndpoint(infraManager)), new FkRegex("/version", new VersionEndpoint()), new FkRegex("/stdcm", new STDCMEndpoint(infraManager)), new FkRegex("/v2/stdcm", new STDCMEndpointV2(infraManager)), diff --git a/core/src/main/java/fr/sncf/osrd/cli/WorkerCommand.kt b/core/src/main/java/fr/sncf/osrd/cli/WorkerCommand.kt index 2fae8929157..295f8ecf51b 100644 --- a/core/src/main/java/fr/sncf/osrd/cli/WorkerCommand.kt +++ b/core/src/main/java/fr/sncf/osrd/cli/WorkerCommand.kt @@ -112,7 +112,6 @@ class WorkerCommand : CliCommand { SimulationEndpoint(infraManager, electricalProfileSetManager), "/v2/signal_projection" to SignalProjectionEndpointV2(infraManager), "/v2/conflict_detection" to ConflictDetectionEndpointV2(infraManager), - "/cache_status" to InfraCacheStatusEndpoint(infraManager), "/version" to VersionEndpoint(), "/v2/stdcm" to STDCMEndpointV2(infraManager), "/infra_load" to InfraLoadEndpoint(infraManager), diff --git a/core/src/test/java/fr/sncf/osrd/api/InfraCacheStatusTest.java b/core/src/test/java/fr/sncf/osrd/api/InfraCacheStatusTest.java deleted file mode 100644 index 0c7af63c55e..00000000000 --- a/core/src/test/java/fr/sncf/osrd/api/InfraCacheStatusTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package fr.sncf.osrd.api; - -import static fr.sncf.osrd.utils.takes.TakesUtils.readBodyResponse; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import fr.sncf.osrd.reporting.warnings.DiagnosticRecorderImpl; -import java.io.IOException; -import java.util.Map; -import org.junit.jupiter.api.Test; -import org.takes.rq.RqFake; - -public class InfraCacheStatusTest extends ApiTest { - - /** */ - public Map runInfraCacheStatus( - InfraCacheStatusEndpoint.InfraCacheRequest request) throws IOException { - // serialize the request - var requestBody = InfraCacheStatusEndpoint.adapterRequest.toJson(request); - - // process it - var rawResponse = readBodyResponse( - new InfraCacheStatusEndpoint(infraManager).act(new RqFake("POST", "/cache_status", requestBody))); - - // parse the response - var response = InfraCacheStatusEndpoint.adapter.fromJson(rawResponse); - assertNotNull(response); - return response; - } - - @Test - public void simple() throws Exception { - var recorder = new DiagnosticRecorderImpl(false); - var query = new InfraCacheStatusEndpoint.InfraCacheRequest("tiny_infra/infra.json"); - infraManager.load("tiny_infra/infra.json", "1", recorder); - var res = runInfraCacheStatus(query); - var response = res.get("tiny_infra/infra.json"); - assertEquals(InfraManager.InfraStatus.CACHED, response.status); - } -} diff --git a/editoast/src/views/infra/mod.rs b/editoast/src/views/infra/mod.rs index 0e12f47ab9b..d7d76461047 100644 --- a/editoast/src/views/infra/mod.rs +++ b/editoast/src/views/infra/mod.rs @@ -957,17 +957,8 @@ pub mod tests { #[rstest] async fn infra_get() { let db_pool = DbConnectionPoolV2::for_tests(); - let mut core = MockingClient::new(); - core.stub("/cache_status") - .method(reqwest::Method::POST) - .response(StatusCode::OK) - .body("{}") - .finish(); - let app = TestAppBuilder::new() - .db_pool(db_pool.clone()) - .core_client(core.into()) - .build(); + let app = TestAppBuilder::new().db_pool(db_pool.clone()).build(); let empty_infra = create_empty_infra(&mut db_pool.get_ok()).await; let req = app.get(format!("/infra/{}", empty_infra.id).as_str()); @@ -1160,17 +1151,8 @@ pub mod tests { #[rstest] async fn infra_lock() { let db_pool = DbConnectionPoolV2::for_tests(); - let mut core = MockingClient::new(); - core.stub("/cache_status") - .method(reqwest::Method::POST) - .response(StatusCode::OK) - .body("{}") - .finish(); - let app = TestAppBuilder::new() - .db_pool(db_pool.clone()) - .core_client(core.into()) - .build(); + let app = TestAppBuilder::new().db_pool(db_pool.clone()).build(); let empty_infra = create_empty_infra(&mut db_pool.get_ok()).await; // Lock infra