diff --git a/docs/context/architecture.md b/docs/context/architecture.md index 3ddb248d..f2967c2b 100644 --- a/docs/context/architecture.md +++ b/docs/context/architecture.md @@ -79,7 +79,7 @@ Authorization-sensitive logic appears in `ClaimUtils`, `AnalysisService`, `DataM - `SpecificationsService` fetches inputdata, preprocessing, and algorithm specifications from Exaflow per request. - `AnalysisService` executes preview/run synchronously through `AnalysisExecutionService`. Preview stores nothing; successful runs retain owner-only drafts. Save copies a retained result without execution. - Data model and algorithm metadata are fetched through `HTTPUtil` using configured Exaflow URLs. -- Analysis execution runs exclusively over RabbitMQ. `AnalysisExecutionService` publishes the JSON request body to Exaflow's request queue via `ExaflowAmqpClient` and waits on a backend-owned reply queue. Specifications and metadata stay on `EXAFLOW_URL`. It requires an Exaflow build that includes madgik/exaflow#673 and madgik/exaflow#681 with its RabbitMQ consumer enabled. Replies are at-least-once; a duplicate or late reply is acked and dropped. Transient previews (`POST /analyses/preview`) check `consumer_count == 0` and fail fast with HTTP 503; normal runs (`POST /analyses/runs`) queue in RabbitMQ and rely on `mandatory` return for a missing request queue. A confirmed publish that gets no reply within the reply timeout is HTTP 504. Both use a fixed message. `RABBITMQ_URL` is parsed with the RabbitMQ client's `setUri` so `%2F` and encoded passwords match Exaflow. +- Analysis execution runs exclusively over RabbitMQ. `AnalysisExecutionService` publishes the JSON request body to Exaflow's request queue via `ExaflowAmqpClient` and waits on a backend-owned reply queue. Specifications and metadata stay on `EXAFLOW_URL`. It requires an Exaflow build that includes madgik/exaflow#673, madgik/exaflow#681 and madgik/exaflow#687 with its RabbitMQ consumer enabled. Replies are at-least-once; a duplicate or late reply is acked and dropped. Transient previews (`POST /analyses/preview`) check `consumer_count == 0` and fail fast with HTTP 503; normal runs (`POST /analyses/runs`) queue in RabbitMQ and rely on `mandatory` return for a missing request queue. A confirmed publish that gets no reply within the reply timeout is HTTP 504. Both use a fixed message. `RABBITMQ_URL` is parsed with the RabbitMQ client's `setUri` so `%2F` and encoded passwords match Exaflow. ## Config and Environment Model - All runtime config is in `src/main/resources/application.yml` with `${ENV:default}` placeholders. diff --git a/src/main/java/hbp/mip/algorithm/AnalysisExecutionService.java b/src/main/java/hbp/mip/algorithm/AnalysisExecutionService.java index 8fdb65c0..1e7e0b2d 100644 --- a/src/main/java/hbp/mip/algorithm/AnalysisExecutionService.java +++ b/src/main/java/hbp/mip/algorithm/AnalysisExecutionService.java @@ -64,7 +64,7 @@ private AnalysisResultDTO execute(UUID requestId, AnalysisRequestDTO analysisReq static Object convertResponseToAnalysisResult(Logger logger, int code, String responseBody) { return switch (code) { case 200 -> new RawJson(responseBody); - case 400, 413, 422, 460, 461, 512, 513 -> convertExaflowResponseToAnalysisResult(responseBody); + case 400, 413, 422, 460, 461, 462, 512, 513 -> convertExaflowResponseToAnalysisResult(responseBody); case 500 -> convertExaflowResponseToAnalysisResult(GENERIC_ERROR_MESSAGE); // Exaflow is at its concurrent-analysis limit; its own message names internal components, // so it goes to the log and the user gets a retry message. diff --git a/src/main/java/hbp/mip/algorithm/ExaflowAmqpClient.java b/src/main/java/hbp/mip/algorithm/ExaflowAmqpClient.java index 0acf53c5..5904cf7e 100644 --- a/src/main/java/hbp/mip/algorithm/ExaflowAmqpClient.java +++ b/src/main/java/hbp/mip/algorithm/ExaflowAmqpClient.java @@ -374,6 +374,7 @@ private static int httpCode(String errorCode) { case "invalid_request" -> 422; case "BadUserInput", "DataModelUnavailable", "DatasetUnavailable" -> 460; case "insufficient_data" -> 461; + case "AnalysisExecutionError" -> 462; case "WorkerUnresponsiveError" -> 512; case "WorkerTaskTimeoutError" -> 513; case "GlobalWorkerUnavailableError" -> 503; diff --git a/src/test/java/hbp/mip/algorithm/AnalysisExecutionServiceContractTest.java b/src/test/java/hbp/mip/algorithm/AnalysisExecutionServiceContractTest.java index 50995d99..c38719bb 100644 --- a/src/test/java/hbp/mip/algorithm/AnalysisExecutionServiceContractTest.java +++ b/src/test/java/hbp/mip/algorithm/AnalysisExecutionServiceContractTest.java @@ -78,6 +78,22 @@ void errorReplyGoesThroughExistingConverter() { assertThat(response.code()).isEqualTo(461); } + @Test + void analysisExecutionErrorReplyKeepsItsMessage() { + ExaflowAmqpClient amqp = mock(ExaflowAmqpClient.class); + when(amqp.submit(anyString(), anyString(), eq(false), any())) + .thenReturn(new ExaflowAmqpClient.ExaflowReply( + 462, "Logistic regression could not converge to a stable solution.")); + + var response = new AnalysisExecutionService(amqp) + .runAnalysis(UUID.randomUUID(), analysisRequest(), new Logger("user", "test")); + + assertThat(response.body()).isEqualTo(Map.of( + "data", "Logistic regression could not converge to a stable solution.", + "type", "text/plain+error")); + assertThat(response.code()).isEqualTo(462); + } + private static AnalysisRequestDTO analysisRequest() { return new AnalysisRequestDTO("original-request-id", new AnalysisRequestDTO.AnalysisInputDataDTO("dm:1", List.of("ds1"), List.of("validation"), diff --git a/src/test/java/hbp/mip/algorithm/ExaflowAmqpReplyMappingTest.java b/src/test/java/hbp/mip/algorithm/ExaflowAmqpReplyMappingTest.java index d6ce6df8..165b9676 100644 --- a/src/test/java/hbp/mip/algorithm/ExaflowAmqpReplyMappingTest.java +++ b/src/test/java/hbp/mip/algorithm/ExaflowAmqpReplyMappingTest.java @@ -35,6 +35,7 @@ static Stream mappingRows() { Arguments.of(failed("DataModelUnavailable", "model"), 460, "model"), Arguments.of(failed("DatasetUnavailable", "dataset"), 460, "dataset"), Arguments.of(failed("insufficient_data", "not enough"), 461, "not enough"), + Arguments.of(failed("AnalysisExecutionError", "could not converge"), 462, "could not converge"), Arguments.of(failed("SMPCUsageError", "smpc"), 500, "smpc"), Arguments.of(failed("WorkerUnresponsiveError", "unresponsive"), 512, "unresponsive"), Arguments.of(failed("WorkerTaskTimeoutError", "task timeout"), 513, "task timeout"),