From 3d22478701db1c8f789534c7e380b2ef872db7bc Mon Sep 17 00:00:00 2001 From: SCHWITZGUEBEL Marc Ext Date: Thu, 25 Jul 2024 13:41:03 +0200 Subject: [PATCH] Add interrupt pending feature --- ...nfiguration.java => UrlConfiguration.java} | 11 ++++- .../app/services/CseExportRunner.java | 27 ++++++++++- .../app/services/FileImporter.java | 10 ++-- .../app/services/RaoRunnerService.java | 7 +-- .../app/services/CseExportRunnerTest.java | 40 ++++++++++++++++ .../app/services/RaoRunnerServiceTest.java | 7 ++- .../app/services/RequestServiceTest.java | 4 +- .../src/test/resources/application.yml | 1 + ...nfiguration.java => UrlConfiguration.java} | 11 ++++- .../app/dichotomy/DichotomyRunner.java | 4 +- .../app/dichotomy/RaoRunnerValidator.java | 14 +++--- .../import_runner/app/services/CseRunner.java | 35 +++++++++++++- .../app/services/FileImporter.java | 10 ++-- .../app/services/UrlValidationService.java | 10 ++-- ...ionTest.java => UrlConfigurationTest.java} | 8 ++-- .../MultipleDichotomyRunnerTest.java | 1 + .../app/dichotomy/RaoRunnerValidatorTest.java | 23 +++++++--- .../app/services/CseRunnerTest.java | 46 +++++++++++++++++++ .../app/services/RequestServiceTest.java | 9 ++-- .../src/test/resources/application.yml | 1 + .../runner/api/resource/CseExportRequest.java | 7 +++ .../cse/runner/api/resource/CseRequest.java | 13 +++++- .../runner/api/resource/CseRequestTest.java | 4 ++ pom.xml | 2 +- 24 files changed, 251 insertions(+), 54 deletions(-) rename cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/configurations/{UrlWhitelistConfiguration.java => UrlConfiguration.java} (76%) rename cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/configurations/{UrlWhitelistConfiguration.java => UrlConfiguration.java} (76%) rename cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/configurations/{UrlWhitelistConfigurationTest.java => UrlConfigurationTest.java} (70%) diff --git a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/configurations/UrlWhitelistConfiguration.java b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/configurations/UrlConfiguration.java similarity index 76% rename from cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/configurations/UrlWhitelistConfiguration.java rename to cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/configurations/UrlConfiguration.java index cdf4c3bd..cb2bfb6e 100644 --- a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/configurations/UrlWhitelistConfiguration.java +++ b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/configurations/UrlConfiguration.java @@ -19,10 +19,19 @@ @Configuration @EnableConfigurationProperties @ConfigurationProperties("cse-cc-runner") -public class UrlWhitelistConfiguration { +public class UrlConfiguration { private final List whitelist = new ArrayList<>(); + private String interruptServerUrl; public List getWhitelist() { return whitelist; } + + public String getInterruptServerUrl() { + return interruptServerUrl; + } + + public void setInterruptServerUrl(String interruptServerUrl) { + this.interruptServerUrl = interruptServerUrl; + } } diff --git a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/CseExportRunner.java b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/CseExportRunner.java index 40439219..7872da5f 100644 --- a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/CseExportRunner.java +++ b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/CseExportRunner.java @@ -8,6 +8,7 @@ import com.farao_community.farao.cse.export_runner.app.FileUtil; import com.farao_community.farao.cse.export_runner.app.configurations.ProcessConfiguration; +import com.farao_community.farao.cse.export_runner.app.configurations.UrlConfiguration; import com.farao_community.farao.cse.network_processing.CracCreationParametersService; import com.farao_community.farao.cse.network_processing.busbar_change.BusBarChangePostProcessor; import com.farao_community.farao.cse.network_processing.busbar_change.BusBarChangePreProcessor; @@ -31,6 +32,9 @@ import com.powsybl.openrao.data.raoresultapi.RaoResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import java.io.InputStream; @@ -60,8 +64,10 @@ public class CseExportRunner { private final Logger businessLogger; private final ProcessConfiguration processConfiguration; private final MerchantLineService merchantLineService; + private final RestTemplateBuilder restTemplateBuilder; + private final UrlConfiguration urlConfiguration; - public CseExportRunner(FileImporter fileImporter, FileExporter fileExporter, PiSaService pisaService, RaoRunnerService raoRunnerService, TtcRaoService ttcRaoService, Logger businessLogger, ProcessConfiguration processConfiguration, MerchantLineService merchantLineService) { + public CseExportRunner(FileImporter fileImporter, FileExporter fileExporter, PiSaService pisaService, RaoRunnerService raoRunnerService, TtcRaoService ttcRaoService, Logger businessLogger, ProcessConfiguration processConfiguration, MerchantLineService merchantLineService, RestTemplateBuilder restTemplateBuilder, UrlConfiguration urlConfiguration) { this.fileImporter = fileImporter; this.fileExporter = fileExporter; this.pisaService = pisaService; @@ -70,11 +76,19 @@ public CseExportRunner(FileImporter fileImporter, FileExporter fileExporter, PiS this.businessLogger = businessLogger; this.processConfiguration = processConfiguration; this.merchantLineService = merchantLineService; + this.restTemplateBuilder = restTemplateBuilder; + this.urlConfiguration = urlConfiguration; } public CseExportResponse run(CseExportRequest cseExportRequest) { String logsFileUrl = ""; //TODO + if (checkIsInterrupted(cseExportRequest)) { + businessLogger.warn("Computation has been interrupted for timestamp {}", cseExportRequest.getTargetProcessDateTime()); + LOGGER.info("Response sent for timestamp {} : run has been interrupted", cseExportRequest.getTargetProcessDateTime()); + return new CseExportResponse(cseExportRequest.getId(), ttcRaoService.saveFailedTtcRao(cseExportRequest), "", logsFileUrl, true); + } + // Check on cgm file name FileUtil.checkCgmFileName(cseExportRequest.getCgmUrl(), cseExportRequest.getProcessType()); @@ -102,7 +116,7 @@ public CseExportResponse run(CseExportRequest cseExportRequest) { cseExportRequest.getTargetProcessDateTime()); String artefactDestinationPath = fileExporter.getDestinationPath(cseExportRequest.getTargetProcessDateTime(), cseExportRequest.getProcessType(), GridcapaFileGroup.ARTIFACT); try { - RaoResponse raoResponse = raoRunnerService.run(cseExportRequest.getId(), initialNetworkUrl, cracInJsonFormatUrl, raoParametersUrl, artefactDestinationPath); + RaoResponse raoResponse = raoRunnerService.run(cseExportRequest.getId(), cseExportRequest.getCurrentRunId(), initialNetworkUrl, cracInJsonFormatUrl, raoParametersUrl, artefactDestinationPath); Network networkWithPra = fileImporter.importNetwork(raoResponse.getNetworkWithPraFileUrl()); BusBarChangePostProcessor.process(networkWithPra, busBarChangeSwitchesSet); @@ -146,4 +160,13 @@ private void runLoadFlow(Network network) { throw new CseInternalException(String.format("Loadflow computation diverged on network %s", network.getId())); } } + + private boolean checkIsInterrupted(CseExportRequest cseExportRequest) { + ResponseEntity responseEntity = restTemplateBuilder.build().getForEntity(getInterruptedUrl(cseExportRequest.getCurrentRunId()), Boolean.class); + return responseEntity.getBody() != null && responseEntity.getStatusCode() == HttpStatus.OK && responseEntity.getBody(); + } + + private String getInterruptedUrl(String runId) { + return urlConfiguration.getInterruptServerUrl() + runId; + } } diff --git a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileImporter.java b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileImporter.java index b441d0ee..c7003083 100644 --- a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileImporter.java +++ b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileImporter.java @@ -8,7 +8,7 @@ import com.farao_community.farao.cse.data.CseDataException; import com.farao_community.farao.cse.export_runner.app.FileUtil; -import com.farao_community.farao.cse.export_runner.app.configurations.UrlWhitelistConfiguration; +import com.farao_community.farao.cse.export_runner.app.configurations.UrlConfiguration; import com.farao_community.farao.cse.runner.api.exception.CseInvalidDataException; import com.powsybl.openrao.data.cracapi.Crac; @@ -30,11 +30,11 @@ */ @Service public class FileImporter { - private final UrlWhitelistConfiguration urlWhitelistConfiguration; + private final UrlConfiguration urlConfiguration; private final Logger businessLogger; - public FileImporter(UrlWhitelistConfiguration urlWhitelistConfiguration, Logger businessLogger) { - this.urlWhitelistConfiguration = urlWhitelistConfiguration; + public FileImporter(UrlConfiguration urlConfiguration, Logger businessLogger) { + this.urlConfiguration = urlConfiguration; this.businessLogger = businessLogger; } @@ -54,7 +54,7 @@ public RaoResult importRaoResult(String raoResultUrl, Crac crac) { private InputStream openUrlStream(String urlString) { try { - if (urlWhitelistConfiguration.getWhitelist().stream().noneMatch(urlString::startsWith)) { + if (urlConfiguration.getWhitelist().stream().noneMatch(urlString::startsWith)) { throw new CseInvalidDataException(String.format("URL '%s' is not part of application's whitelisted url's.", urlString)); } URL url = new URL(urlString); diff --git a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerService.java b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerService.java index 6ad5ab40..a6ed530a 100644 --- a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerService.java +++ b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerService.java @@ -29,8 +29,8 @@ public RaoRunnerService(RaoRunnerClient raoRunnerClient) { this.raoRunnerClient = raoRunnerClient; } - public RaoResponse run(String id, String networkPresignedUrl, String cracInJsonFormatUrl, String raoParametersUrl, String artifactDestinationPath) throws CseInternalException, RaoInterruptionException { - RaoRequest raoRequest = buildRaoRequest(id, networkPresignedUrl, cracInJsonFormatUrl, raoParametersUrl, artifactDestinationPath); + public RaoResponse run(String id, String runId, String networkPresignedUrl, String cracInJsonFormatUrl, String raoParametersUrl, String artifactDestinationPath) throws CseInternalException, RaoInterruptionException { + RaoRequest raoRequest = buildRaoRequest(id, runId, networkPresignedUrl, cracInJsonFormatUrl, raoParametersUrl, artifactDestinationPath); try { LOGGER.info("RAO request sent: {}", raoRequest); RaoResponse raoResponse = raoRunnerClient.runRao(raoRequest); @@ -45,9 +45,10 @@ public RaoResponse run(String id, String networkPresignedUrl, String cracInJsonF } } - private RaoRequest buildRaoRequest(String id, String networkPresignedUrl, String cracUrl, String raoParametersUrl, String artifactDestinationPath) { + private RaoRequest buildRaoRequest(String id, String runId, String networkPresignedUrl, String cracUrl, String raoParametersUrl, String artifactDestinationPath) { return new RaoRequest.RaoRequestBuilder() .withId(id) + .withRunId(runId) .withNetworkFileUrl(networkPresignedUrl) .withCracFileUrl(cracUrl) .withRaoParametersFileUrl(raoParametersUrl) diff --git a/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/CseExportRunnerTest.java b/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/CseExportRunnerTest.java index 52bfca19..17a0d679 100644 --- a/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/CseExportRunnerTest.java +++ b/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/CseExportRunnerTest.java @@ -6,14 +6,27 @@ */ package com.farao_community.farao.cse.export_runner.app.services; +import com.farao_community.farao.cse.runner.api.resource.CseExportRequest; +import com.farao_community.farao.cse.runner.api.resource.CseExportResponse; import com.farao_community.farao.cse.runner.api.resource.ProcessType; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; import java.time.OffsetDateTime; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * @author Amira Kahya {@literal } @@ -24,6 +37,12 @@ class CseExportRunnerTest { @Autowired private CseExportRunner cseExportRunner; + @MockBean + private RestTemplateBuilder restTemplateBuilder; + + @MockBean + private TtcRaoService ttcRaoService; + @Test void getFinalNetworkFilenameTest() { OffsetDateTime processTargetDate = OffsetDateTime.parse("2022-10-20T16:30Z"); @@ -33,4 +52,25 @@ void getFinalNetworkFilenameTest() { assertEquals(expectedFilenameWithoutExtension, actualFilenameWithoutExtension); } + + @Test + void runInterruptPendingCase() { + CseExportRequest request = Mockito.mock(CseExportRequest.class); + Mockito.when(request.getId()).thenReturn("ID"); + Mockito.when(request.getCurrentRunId()).thenReturn("RUNID"); + Mockito.when(request.getProcessType()).thenReturn(ProcessType.D2CC); + Mockito.when(request.getTargetProcessDateTime()).thenReturn(OffsetDateTime.now()); + Mockito.when(request.getCgmUrl()).thenReturn("testCgmUrl"); + + RestTemplate restTemplate = mock(RestTemplate.class); + ResponseEntity responseEntity = mock(ResponseEntity.class); + when(restTemplateBuilder.build()).thenReturn(restTemplate); + when(restTemplate.getForEntity(anyString(), eq(Boolean.class))).thenReturn(responseEntity); + when(responseEntity.getStatusCode()).thenReturn(HttpStatus.OK); + when(responseEntity.getBody()).thenReturn(true); + + CseExportResponse cseExportResponse = cseExportRunner.run(request); + assertTrue(cseExportResponse.isInterrupted()); + assertEquals("ID", cseExportResponse.getId()); + } } diff --git a/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerServiceTest.java b/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerServiceTest.java index 44b21dc2..19825089 100644 --- a/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerServiceTest.java +++ b/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerServiceTest.java @@ -33,6 +33,7 @@ class RaoRunnerServiceTest { private RaoRunnerService raoRunnerService; private final String id = "testId"; + private final String runId = "testRunId"; private final String networkPresignedUrl = "http://network.url"; private final String cracInJsonFormatUrl = "http://crac.url"; private final String raoParametersUrl = "http://parameters.url"; @@ -44,7 +45,7 @@ void testRunSuccessful() throws CseInternalException, RaoInterruptionException { when(raoRunnerClient.runRao(any(RaoRequest.class))).thenReturn(expectedResponse); - RaoResponse actualResponse = raoRunnerService.run(id, networkPresignedUrl, cracInJsonFormatUrl, raoParametersUrl, artifactDestinationPath); + RaoResponse actualResponse = raoRunnerService.run(id, runId, networkPresignedUrl, cracInJsonFormatUrl, raoParametersUrl, artifactDestinationPath); assertEquals(expectedResponse, actualResponse); } @@ -54,7 +55,7 @@ void testRunThrowsCseInternalException() { when(raoRunnerClient.runRao(any())).thenThrow(new RuntimeException("Test exception")); Exception exception = assertThrows(CseInternalException.class, () -> { - raoRunnerService.run(id, networkPresignedUrl, cracInJsonFormatUrl, raoParametersUrl, artifactDestinationPath); + raoRunnerService.run(id, runId, networkPresignedUrl, cracInJsonFormatUrl, raoParametersUrl, artifactDestinationPath); }); String expectedMessage = "RAO run failed"; @@ -67,6 +68,7 @@ void testRunThrowsCseInternalException() { void testRaoRequestValues() { RaoRequest raoRequest = new RaoRequest.RaoRequestBuilder() .withId(id) + .withRunId(runId) .withNetworkFileUrl(networkPresignedUrl) .withCracFileUrl(cracInJsonFormatUrl) .withRaoParametersFileUrl(raoParametersUrl) @@ -74,6 +76,7 @@ void testRaoRequestValues() { .build(); assertEquals("testId", raoRequest.getId()); + assertEquals("testRunId", raoRequest.getRunId()); assertEquals("http://network.url", raoRequest.getNetworkFileUrl()); assertEquals("http://crac.url", raoRequest.getCracFileUrl()); assertEquals("http://parameters.url", raoRequest.getRaoParametersFileUrl()); diff --git a/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/RequestServiceTest.java b/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/RequestServiceTest.java index 22e8b787..ce4b12f2 100644 --- a/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/RequestServiceTest.java +++ b/cse-cc-export-runner-app/src/test/java/com/farao_community/farao/cse/export_runner/app/services/RequestServiceTest.java @@ -44,7 +44,7 @@ class RequestServiceTest { @Test void testSuccessRequestService() { - CseExportRequest cseRequest = new CseExportRequest(UUID.randomUUID().toString(), null, null, "", ""); + CseExportRequest cseRequest = new CseExportRequest(UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, null, "", ""); CseExportResponse cseResponse = new CseExportResponse(cseRequest.getId(), "", "", "", false); byte[] req = jsonApiConverter.toJsonMessage(cseRequest, CseExportRequest.class); byte[] resp = jsonApiConverter.toJsonMessage(cseResponse, CseExportResponse.class); @@ -63,7 +63,7 @@ void testSuccessRequestService() { @Test void testInterruptedRequestService() { - CseExportRequest cseRequest = new CseExportRequest(UUID.randomUUID().toString(), null, null, "", ""); + CseExportRequest cseRequest = new CseExportRequest(UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, null, "", ""); CseExportResponse cseResponse = new CseExportResponse(cseRequest.getId(), "", "", "", true); byte[] request = jsonApiConverter.toJsonMessage(cseRequest, CseExportRequest.class); byte[] expectedResponse = jsonApiConverter.toJsonMessage(cseResponse, CseExportResponse.class); diff --git a/cse-cc-export-runner-app/src/test/resources/application.yml b/cse-cc-export-runner-app/src/test/resources/application.yml index 942e80a2..417c4aa1 100644 --- a/cse-cc-export-runner-app/src/test/resources/application.yml +++ b/cse-cc-export-runner-app/src/test/resources/application.yml @@ -39,3 +39,4 @@ cse-cc-runner: whitelist: - http://minio:9000/ - http://localhost:9000/ + interrupt-server-url: http://testUrl/interrupted/ diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlWhitelistConfiguration.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlConfiguration.java similarity index 76% rename from cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlWhitelistConfiguration.java rename to cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlConfiguration.java index 670e534d..b8fb349c 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlWhitelistConfiguration.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlConfiguration.java @@ -19,10 +19,19 @@ @Configuration @EnableConfigurationProperties @ConfigurationProperties("cse-cc-runner") -public class UrlWhitelistConfiguration { +public class UrlConfiguration { private final List whitelist = new ArrayList<>(); + private String interruptServerUrl; public List getWhitelist() { return whitelist; } + + public String getInterruptServerUrl() { + return interruptServerUrl; + } + + public void setInterruptServerUrl(String interruptServerUrl) { + this.interruptServerUrl = interruptServerUrl; + } } diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/DichotomyRunner.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/DichotomyRunner.java index 94fa6d54..1d2fc316 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/DichotomyRunner.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/DichotomyRunner.java @@ -87,9 +87,7 @@ public DichotomyResult runDichotomy(CseRequest cseRequest, private NetworkValidator getNetworkValidator(CseRequest request, CseData cseData, Set forcedPrasIds) { final boolean isImportEcProcess = request.isImportEcProcess(); return new RaoRunnerValidator( - request.getProcessType(), - request.getId(), - request.getTargetProcessDateTime(), + request, cseData.getJsonCracUrl(), fileExporter.saveRaoParameters(request.getTargetProcessDateTime(), request.getProcessType(), isImportEcProcess), raoRunnerClient, diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java index a1657b02..54dcae4c 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java @@ -11,6 +11,7 @@ import com.farao_community.farao.cse.import_runner.app.services.ForcedPrasHandler; import com.farao_community.farao.cse.import_runner.app.util.FlowEvaluator; import com.farao_community.farao.cse.import_runner.app.util.MinioStorageHelper; +import com.farao_community.farao.cse.runner.api.resource.CseRequest; import com.farao_community.farao.cse.runner.api.resource.ProcessType; import com.farao_community.farao.dichotomy.api.exceptions.RaoInterruptionException; import com.powsybl.openrao.commons.Unit; @@ -43,6 +44,7 @@ public class RaoRunnerValidator implements NetworkValidator forcedPrasIds, boolean isImportEcProcess) { - this.processType = processType; - this.requestId = requestId; - this.processTargetDateTime = processTargetDateTime; + this.processType = cseRequest.getProcessType(); + this.requestId = cseRequest.getId(); + this.currentRunId = cseRequest.getCurrentRunId(); + this.processTargetDateTime = cseRequest.getTargetProcessDateTime(); this.cracUrl = cracUrl; this.raoParametersUrl = raoParametersUrl; this.raoRunnerClient = raoRunnerClient; @@ -130,6 +131,7 @@ private Set applyForcedPras(Crac crac, Network network) { public RaoRequest buildRaoRequest(String networkPreSignedUrl, String baseDirPathForCurrentStep, List appliedRemedialActionInPreviousStep) { RaoRequest.RaoRequestBuilder builder = new RaoRequest.RaoRequestBuilder() .withId(requestId) + .withRunId(currentRunId) .withNetworkFileUrl(networkPreSignedUrl) .withCracFileUrl(cracUrl) .withResultsDestination(baseDirPathForCurrentStep); diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/CseRunner.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/CseRunner.java index a420c29d..7190db02 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/CseRunner.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/CseRunner.java @@ -10,6 +10,7 @@ import com.farao_community.farao.cse.data.ttc_res.TtcResult; import com.farao_community.farao.cse.import_runner.app.CseData; import com.farao_community.farao.cse.import_runner.app.configurations.ProcessConfiguration; +import com.farao_community.farao.cse.import_runner.app.configurations.UrlConfiguration; import com.farao_community.farao.cse.import_runner.app.dichotomy.DichotomyRaoResponse; import com.farao_community.farao.cse.import_runner.app.dichotomy.MultipleDichotomyResult; import com.farao_community.farao.cse.import_runner.app.dichotomy.MultipleDichotomyRunner; @@ -34,6 +35,9 @@ import com.powsybl.openrao.data.craccreation.creator.cse.parameters.BusBarChangeSwitches; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import java.io.IOException; @@ -59,11 +63,14 @@ public class CseRunner { private final ProcessConfiguration processConfiguration; private final Logger businessLogger; private final InitialShiftService initialShiftService; + private final RestTemplateBuilder restTemplateBuilder; + private final UrlConfiguration urlConfiguration; private static final String CRAC_CREATION_PARAMETERS_JSON = "/crac/cseCracCreationParameters.json"; public CseRunner(FileImporter fileImporter, FileExporter fileExporter, MultipleDichotomyRunner multipleDichotomyRunner, TtcResultService ttcResultService, PiSaService piSaService, MerchantLineService merchantLineService, - ProcessConfiguration processConfiguration, Logger businessLogger, InitialShiftService initialShiftService) { + ProcessConfiguration processConfiguration, Logger businessLogger, InitialShiftService initialShiftService, + RestTemplateBuilder restTemplateBuilder, UrlConfiguration urlConfiguration) { this.fileImporter = fileImporter; this.fileExporter = fileExporter; this.multipleDichotomyRunner = multipleDichotomyRunner; @@ -73,9 +80,25 @@ public CseRunner(FileImporter fileImporter, FileExporter fileExporter, MultipleD this.processConfiguration = processConfiguration; this.businessLogger = businessLogger; this.initialShiftService = initialShiftService; + this.restTemplateBuilder = restTemplateBuilder; + this.urlConfiguration = urlConfiguration; } public CseResponse run(CseRequest cseRequest) throws IOException { + String firstShiftNetworkName = fileExporter.getFirstShiftNetworkName(cseRequest.getTargetProcessDateTime(), cseRequest.getProcessType()); + + if (checkIsInterrupted(cseRequest)) { + businessLogger.warn("Computation has been interrupted for timestamp {}", cseRequest.getTargetProcessDateTime()); + LOGGER.info("Response sent for timestamp {} : run has been interrupted", cseRequest.getTargetProcessDateTime()); + String interruptedTtc = ttcResultService.saveFailedTtcResult( + cseRequest, + firstShiftNetworkName, + TtcResult.FailedProcessData.FailedProcessReason.OTHER); + String interruptedCgm = firstShiftNetworkName; + + return new CseResponse(cseRequest.getId(), interruptedTtc, interruptedCgm, true); + } + final boolean importEcProcess = cseRequest.isImportEcProcess(); CseData cseData = new CseData(cseRequest, fileImporter); // CRAC import and network pre-processing @@ -117,7 +140,6 @@ public CseResponse run(CseRequest cseRequest) throws IOException { NetworkShifterUtil.getReferenceExchanges(cseData), ntcsByEic); - String firstShiftNetworkName = fileExporter.getFirstShiftNetworkName(cseRequest.getTargetProcessDateTime(), cseRequest.getProcessType()); String ttcResultUrl; String finalCgmUrl; DichotomyResult dichotomyResult; @@ -171,4 +193,13 @@ private CracImportData(CseCracCreationContext cseCracCreationContext, Set responseEntity = restTemplateBuilder.build().getForEntity(getInterruptedUrl(cseRequest.getCurrentRunId()), Boolean.class); + return responseEntity.getBody() != null && responseEntity.getStatusCode() == HttpStatus.OK && responseEntity.getBody(); + } + + private String getInterruptedUrl(String runId) { + return urlConfiguration.getInterruptServerUrl() + runId; + } } diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileImporter.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileImporter.java index 81e40b95..a6969356 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileImporter.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileImporter.java @@ -15,7 +15,7 @@ import com.farao_community.farao.cse.data.target_ch.LineFixedFlows; import com.farao_community.farao.cse.data.xsd.NTCAnnualDocument; import com.farao_community.farao.cse.data.xsd.NTCReductionsDocument; -import com.farao_community.farao.cse.import_runner.app.configurations.UrlWhitelistConfiguration; +import com.farao_community.farao.cse.import_runner.app.configurations.UrlConfiguration; import com.farao_community.farao.cse.import_runner.app.util.FileUtil; import com.farao_community.farao.cse.import_runner.app.util.Ntc2Util; import com.farao_community.farao.cse.runner.api.resource.ProcessType; @@ -51,11 +51,11 @@ public class FileImporter { public static final String IMPOSSIBLE_TO_CREATE_NTC = "Impossible to create NTC"; - private final UrlWhitelistConfiguration urlWhitelistConfiguration; + private final UrlConfiguration urlConfiguration; private final Logger businessLogger; - public FileImporter(UrlWhitelistConfiguration urlWhitelistConfiguration, Logger businessLogger) { - this.urlWhitelistConfiguration = urlWhitelistConfiguration; + public FileImporter(UrlConfiguration urlConfiguration, Logger businessLogger) { + this.urlConfiguration = urlConfiguration; this.businessLogger = businessLogger; } @@ -160,7 +160,7 @@ public LineFixedFlows importLineFixedFlowFromTargetChFile(OffsetDateTime targetP InputStream openUrlStream(String urlString) { try { - if (urlWhitelistConfiguration.getWhitelist().stream().noneMatch(urlString::startsWith)) { + if (urlConfiguration.getWhitelist().stream().noneMatch(urlString::startsWith)) { throw new CseInvalidDataException(String.format("URL '%s' is not part of application's whitelisted url's.", urlString)); } URL url = new URL(urlString); diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/UrlValidationService.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/UrlValidationService.java index d722213b..b8fed6ea 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/UrlValidationService.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/UrlValidationService.java @@ -6,7 +6,7 @@ */ package com.farao_community.farao.cse.import_runner.app.services; -import com.farao_community.farao.cse.import_runner.app.configurations.UrlWhitelistConfiguration; +import com.farao_community.farao.cse.import_runner.app.configurations.UrlConfiguration; import com.farao_community.farao.cse.runner.api.exception.CseInvalidDataException; import org.springframework.stereotype.Component; @@ -19,14 +19,14 @@ */ @Component public class UrlValidationService { - private final UrlWhitelistConfiguration urlWhitelistConfiguration; + private final UrlConfiguration urlConfiguration; - public UrlValidationService(UrlWhitelistConfiguration urlWhitelistConfiguration) { - this.urlWhitelistConfiguration = urlWhitelistConfiguration; + public UrlValidationService(UrlConfiguration urlConfiguration) { + this.urlConfiguration = urlConfiguration; } public InputStream openUrlStream(String urlString) throws IOException { - if (urlWhitelistConfiguration.getWhitelist().stream().noneMatch(urlString::startsWith)) { + if (urlConfiguration.getWhitelist().stream().noneMatch(urlString::startsWith)) { throw new CseInvalidDataException(String.format("URL '%s' is not part of application's whitelisted url's.", urlString)); } URL url = new URL(urlString); diff --git a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlWhitelistConfigurationTest.java b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlConfigurationTest.java similarity index 70% rename from cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlWhitelistConfigurationTest.java rename to cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlConfigurationTest.java index 3a894660..60082479 100644 --- a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlWhitelistConfigurationTest.java +++ b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/configurations/UrlConfigurationTest.java @@ -15,14 +15,14 @@ * @author Amira Kahya {@literal } */ @SpringBootTest -class UrlWhitelistConfigurationTest { +class UrlConfigurationTest { @Autowired - public UrlWhitelistConfiguration urlWhitelistConfiguration; + public UrlConfiguration urlConfiguration; @Test void checkUrlWhiteListIsRetrievedCorrectly() { - Assertions.assertEquals(2, urlWhitelistConfiguration.getWhitelist().size()); - Assertions.assertEquals("http://localhost:9000", urlWhitelistConfiguration.getWhitelist().get(0)); + Assertions.assertEquals(2, urlConfiguration.getWhitelist().size()); + Assertions.assertEquals("http://localhost:9000", urlConfiguration.getWhitelist().get(0)); } } diff --git a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/dichotomy/MultipleDichotomyRunnerTest.java b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/dichotomy/MultipleDichotomyRunnerTest.java index fde9c9da..3f2e1e89 100644 --- a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/dichotomy/MultipleDichotomyRunnerTest.java +++ b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/dichotomy/MultipleDichotomyRunnerTest.java @@ -93,6 +93,7 @@ private CseRequest getCseRequest(Map>> automatedForcedP null, null, null, + null, Collections.emptyList(), automatedForcedPras, dichotomyNumber, diff --git a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidatorTest.java b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidatorTest.java index d9c67f8a..3715d866 100644 --- a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidatorTest.java +++ b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidatorTest.java @@ -9,6 +9,7 @@ import com.farao_community.farao.cse.import_runner.app.services.FileExporter; import com.farao_community.farao.cse.import_runner.app.services.FileImporter; import com.farao_community.farao.cse.import_runner.app.services.ForcedPrasHandler; +import com.farao_community.farao.cse.runner.api.resource.CseRequest; import com.farao_community.farao.cse.runner.api.resource.ProcessType; import com.farao_community.farao.dichotomy.api.exceptions.RaoInterruptionException; import com.farao_community.farao.dichotomy.api.exceptions.ValidationException; @@ -41,6 +42,7 @@ class RaoRunnerValidatorTest { private static final String BASE_DIR_PATH = "/base/dir/path"; private static final String RAO_PARAMETERS_URL = "http://parameters.url"; private static final String REQUEST_ID = "requestId"; + private static final String RUN_ID = "runId"; private static final String CRAC_URL = "http://crac.url"; @MockBean @@ -53,7 +55,7 @@ class RaoRunnerValidatorTest { void buildRaoRequestWithEmptyPreviousActionsShouldNotSaveParameters() { List previousActions = Collections.singletonList("Action1"); - RaoRunnerValidator raoRunnerValidator = new RaoRunnerValidator(ProcessType.D2CC, REQUEST_ID, null, CRAC_URL, RAO_PARAMETERS_URL, null, null, null, null, null, false); + RaoRunnerValidator raoRunnerValidator = new RaoRunnerValidator(getCseRequest(ProcessType.D2CC, null), CRAC_URL, RAO_PARAMETERS_URL, null, null, null, null, null, false); RaoRequest result = raoRunnerValidator.buildRaoRequest(NETWORK_PRE_SIGNED_URL, BASE_DIR_PATH, previousActions); verify(fileExporter, never()).saveRaoParameters(anyString(), anyList(), any(), any(), anyBoolean()); @@ -70,9 +72,8 @@ void validateNetworkInterruptionException() { Set forcedPrasIds = Set.of(); Network network = mock(Network.class); - RaoRunnerValidator raoRunnerValidator = new RaoRunnerValidator(processType, - REQUEST_ID, - processTargetDateTime, + RaoRunnerValidator raoRunnerValidator = new RaoRunnerValidator( + getCseRequest(processType, processTargetDateTime), CRAC_URL, RAO_PARAMETERS_URL, raoRunnerClient, @@ -106,9 +107,8 @@ void validateNetworkValidationException() { Set forcedPrasIds = Set.of(); // Network network = mock(Network.class); - RaoRunnerValidator raoRunnerValidator = new RaoRunnerValidator(processType, - REQUEST_ID, - processTargetDateTime, + RaoRunnerValidator raoRunnerValidator = new RaoRunnerValidator( + getCseRequest(processType, processTargetDateTime), CRAC_URL, RAO_PARAMETERS_URL, raoRunnerClient, @@ -127,4 +127,13 @@ void validateNetworkValidationException() { when(fileImporter.importCracFromJson(CRAC_URL, network)).thenThrow(RuntimeException.class); assertThrows(ValidationException.class, () -> raoRunnerValidator.validateNetwork(network, null)); } + + private CseRequest getCseRequest(ProcessType type, OffsetDateTime timestamp) { + CseRequest cseRequest = mock(CseRequest.class); + when(cseRequest.getId()).thenReturn(REQUEST_ID); + when(cseRequest.getCurrentRunId()).thenReturn(RUN_ID); + when(cseRequest.getTargetProcessDateTime()).thenReturn(timestamp); + when(cseRequest.getProcessType()).thenReturn(type); + return cseRequest; + } } diff --git a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/CseRunnerTest.java b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/CseRunnerTest.java index a5b7e451..ca6b47f2 100644 --- a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/CseRunnerTest.java +++ b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/CseRunnerTest.java @@ -24,6 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; import java.io.IOException; import java.net.MalformedURLException; @@ -61,6 +65,9 @@ class CseRunnerTest { @MockBean private TtcResultService ttcResultService; + @MockBean + private RestTemplateBuilder restTemplateBuilder; + @Test void testCracImportAndBusbarPreprocess() { String cracUrl = Objects.requireNonNull(getClass().getResource("20210901_2230_213_CRAC_CO_CSE1_busbar.xml")).toString(); @@ -101,6 +108,13 @@ void testRun() { when(dichotomyResult.getBestDichotomyResult()).thenReturn(raoResponse); when(raoResponse.hasValidStep()).thenReturn(false); + RestTemplate restTemplate = mock(RestTemplate.class); + ResponseEntity responseEntity = mock(ResponseEntity.class); + when(restTemplateBuilder.build()).thenReturn(restTemplate); + when(restTemplate.getForEntity(anyString(), eq(Boolean.class))).thenReturn(responseEntity); + when(responseEntity.getStatusCode()).thenReturn(HttpStatus.OK); + when(responseEntity.getBody()).thenReturn(false); + when(fileExporter.getFinalNetworkFilePath(any(OffsetDateTime.class), any(ProcessType.class), anyBoolean())).thenReturn("AnyString"); when(fileExporter.exportAndUploadNetwork(any(Network.class), anyString(), any(GridcapaFileGroup.class), anyString(), anyString(), any(OffsetDateTime.class), any(ProcessType.class), anyBoolean())).thenReturn("file:/AnyString/IMPORT_EC/test"); when(ttcResultService.saveFailedTtcResult(any(), any(), any())).thenReturn("file:/AnyTTCfilepath/IMPORT_EC/test"); @@ -133,6 +147,13 @@ void testRunInterrupted() throws IOException, URISyntaxException { any(Map.class) )).thenReturn(dichotomyResult); + RestTemplate restTemplate = mock(RestTemplate.class); + ResponseEntity responseEntity = mock(ResponseEntity.class); + when(restTemplateBuilder.build()).thenReturn(restTemplate); + when(restTemplate.getForEntity(anyString(), eq(Boolean.class))).thenReturn(responseEntity); + when(responseEntity.getStatusCode()).thenReturn(HttpStatus.OK); + when(responseEntity.getBody()).thenReturn(false); + when(dichotomyResult.isInterrupted()).thenReturn(true); when(dichotomyResult.getBestDichotomyResult()).thenThrow(new IndexOutOfBoundsException()); @@ -148,9 +169,34 @@ void testRunInterrupted() throws IOException, URISyntaxException { assertTrue(response.isInterrupted()); } + @Test + void testRunPendingInterrupted() throws IOException, URISyntaxException { + + CseRequest cseRequest = buildTestCseRequest(); + + RestTemplate restTemplate = mock(RestTemplate.class); + ResponseEntity responseEntity = mock(ResponseEntity.class); + when(restTemplateBuilder.build()).thenReturn(restTemplate); + when(restTemplate.getForEntity(anyString(), eq(Boolean.class))).thenReturn(responseEntity); + when(responseEntity.getStatusCode()).thenReturn(HttpStatus.OK); + when(responseEntity.getBody()).thenReturn(true); + + when(ttcResultService.saveFailedTtcResult(any(), any(), any())).thenReturn("interruptedTTCFilePath"); + + // WHEN + CseResponse response = cseRunner.run(cseRequest); + + // THEN + verify(ttcResultService, times(1)).saveFailedTtcResult(eq(cseRequest), any(), eq(TtcResult.FailedProcessData.FailedProcessReason.OTHER)); + assertNotNull(response); + assertEquals("interruptedTTCFilePath", response.getTtcFileUrl()); + assertTrue(response.isInterrupted()); + } + private CseRequest buildTestCseRequest() throws MalformedURLException, URISyntaxException { return new CseRequest( "ID1", + "RUNID1", ProcessType.IDCC, OffsetDateTime.parse("2021-09-01T20:30Z"), getClass().getResource("20210901_2230_test_network_pisa_test_both_links_connected_setpoint_and_emulation_ok_for_run.uct").toURI().toURL().toString(), diff --git a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/RequestServiceTest.java b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/RequestServiceTest.java index 0df5dc4d..5ee99596 100644 --- a/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/RequestServiceTest.java +++ b/cse-cc-import-runner-app/src/test/java/com/farao_community/farao/cse/import_runner/app/services/RequestServiceTest.java @@ -47,7 +47,8 @@ class RequestServiceTest { @Test void testRequestService() throws IOException { String id = UUID.randomUUID().toString(); - CseRequest cseRequest = new CseRequest(id, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0.0, 0.0, null, false); + String runId = UUID.randomUUID().toString(); + CseRequest cseRequest = new CseRequest(id, runId, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0.0, 0.0, null, false); CseResponse cseResponse = new CseResponse(cseRequest.getId(), "null", "null", false); byte[] req = jsonApiConverter.toJsonMessage(cseRequest, CseRequest.class); byte[] resp = jsonApiConverter.toJsonMessage(cseResponse, CseResponse.class); @@ -66,7 +67,8 @@ void testRequestService() throws IOException { @Test void testInterruptedRequestService() throws IOException { String id = UUID.randomUUID().toString(); - CseRequest cseRequest = new CseRequest(id, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0.0, 0.0, null, false); + String runId = UUID.randomUUID().toString(); + CseRequest cseRequest = new CseRequest(id, runId, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0.0, 0.0, null, false); CseResponse cseResponse = new CseResponse(cseRequest.getId(), "null", "null", true); byte[] req = jsonApiConverter.toJsonMessage(cseRequest, CseRequest.class); byte[] resp = jsonApiConverter.toJsonMessage(cseResponse, CseResponse.class); @@ -85,8 +87,9 @@ void testInterruptedRequestService() throws IOException { @Test void testErrorRequestService() throws IOException { String id = UUID.randomUUID().toString(); + String runId = UUID.randomUUID().toString(); Exception except = new IOException("Mocked exception"); - CseRequest cseRequest = new CseRequest(id, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0.0, 0.0, null, false); + CseRequest cseRequest = new CseRequest(id, runId, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 0, 0.0, 0.0, null, false); byte[] req = jsonApiConverter.toJsonMessage(cseRequest, CseRequest.class); when(cseServer.run(any())).thenThrow(except); byte[] expectedResult = jsonApiConverter.toJsonMessage(new CseInternalException("CSE run failed", except)); diff --git a/cse-cc-import-runner-app/src/test/resources/application.yml b/cse-cc-import-runner-app/src/test/resources/application.yml index d6430a2d..bafadee8 100644 --- a/cse-cc-import-runner-app/src/test/resources/application.yml +++ b/cse-cc-import-runner-app/src/test/resources/application.yml @@ -43,3 +43,4 @@ cse-cc-runner: whitelist: - http://localhost:9000 - file:/ + interrupt-server-url: http://testUrl/interrupted/ diff --git a/cse-runner-api/src/main/java/com/farao_community/farao/cse/runner/api/resource/CseExportRequest.java b/cse-runner-api/src/main/java/com/farao_community/farao/cse/runner/api/resource/CseExportRequest.java index 893df29a..ed4a28ac 100644 --- a/cse-runner-api/src/main/java/com/farao_community/farao/cse/runner/api/resource/CseExportRequest.java +++ b/cse-runner-api/src/main/java/com/farao_community/farao/cse/runner/api/resource/CseExportRequest.java @@ -21,6 +21,7 @@ public class CseExportRequest { @Id private final String id; + private final String currentRunId; private final ProcessType processType; private final OffsetDateTime targetProcessDateTime; private final String cgmUrl; @@ -28,11 +29,13 @@ public class CseExportRequest { @JsonCreator public CseExportRequest(@JsonProperty("id") String id, + @JsonProperty("currentRunId") String currentRunId, @JsonProperty("targetProcessDateTime") OffsetDateTime targetProcessDateTime, @JsonProperty("processType") ProcessType processType, @JsonProperty("cgmUrl") String cgmUrl, @JsonProperty("mergedCracUrl") String mergedCracUrl) { this.id = id; + this.currentRunId = currentRunId; this.targetProcessDateTime = targetProcessDateTime; this.processType = processType; this.cgmUrl = cgmUrl; @@ -43,6 +46,10 @@ public String getId() { return id; } + public String getCurrentRunId() { + return currentRunId; + } + public String getCgmUrl() { return cgmUrl; } diff --git a/cse-runner-api/src/main/java/com/farao_community/farao/cse/runner/api/resource/CseRequest.java b/cse-runner-api/src/main/java/com/farao_community/farao/cse/runner/api/resource/CseRequest.java index 9194fc36..c09d0264 100644 --- a/cse-runner-api/src/main/java/com/farao_community/farao/cse/runner/api/resource/CseRequest.java +++ b/cse-runner-api/src/main/java/com/farao_community/farao/cse/runner/api/resource/CseRequest.java @@ -24,6 +24,7 @@ public class CseRequest { @Id private final String id; + private final String currentRunId; private final ProcessType processType; private final OffsetDateTime targetProcessDateTime; private final String cgmUrl; @@ -48,6 +49,7 @@ public class CseRequest { @JsonCreator public CseRequest(@JsonProperty("id") String id, + @JsonProperty("currentRunId") String currentRunId, @JsonProperty("processType") ProcessType processType, @JsonProperty("targetProcessDateTime") OffsetDateTime targetProcessDateTime, @JsonProperty("cgmUrl") String cgmUrl, @@ -69,6 +71,7 @@ public CseRequest(@JsonProperty("id") String id, @JsonProperty("initialDichotomyIndex") Double initialDichotomyIndex, @JsonProperty("importEcProcess") boolean isImportEcProcess) { this.id = id; + this.currentRunId = currentRunId; this.processType = processType; this.targetProcessDateTime = targetProcessDateTime; this.cgmUrl = cgmUrl; @@ -92,6 +95,7 @@ public CseRequest(@JsonProperty("id") String id, } public static CseRequest d2ccProcess(String id, + String currentRunId, OffsetDateTime targetProcessDateTime, String cgmUrl, String mergedCracUrl, @@ -108,12 +112,13 @@ public static CseRequest d2ccProcess(String id, Double initialDichotomyIndex, boolean isImportEc) { return new CseRequest( - id, ProcessType.D2CC, targetProcessDateTime, cgmUrl, mergedCracUrl, mergedGlskUrl, ntcReductionsUrl, null, + id, currentRunId, ProcessType.D2CC, targetProcessDateTime, cgmUrl, mergedCracUrl, mergedGlskUrl, ntcReductionsUrl, null, null, null, null, targetChUrl, vulcanusUrl, yearlyNtcUrl, manualFrcedPrasIds, automatedForcedPras, maximumDichotomiesNumber, dichotomyPrecision, initialDichotomyStep, initialDichotomyIndex, isImportEc); } public static CseRequest idccProcess(String id, + String currentRunId, OffsetDateTime targetProcessDateTime, String cgmUrl, String mergedCracUrl, @@ -132,7 +137,7 @@ public static CseRequest idccProcess(String id, double initialDichotomyStep, Double initialDichotomyIndex, boolean isImportEc) { - return new CseRequest(id, ProcessType.IDCC, targetProcessDateTime, cgmUrl, mergedCracUrl, mergedGlskUrl, ntcReductionsUrl, + return new CseRequest(id, currentRunId, ProcessType.IDCC, targetProcessDateTime, cgmUrl, mergedCracUrl, mergedGlskUrl, ntcReductionsUrl, ntc2AtItUrl, ntc2ChItUrl, ntc2FrItUrl, ntc2SiItUrl, null, vulcanusUrl, yearlyNtcUrl, manualForcedPrasIds, automatedForcedPras, maximumDichotomiesNumber, dichotomyPrecision, initialDichotomyStep, initialDichotomyIndex, isImportEc); } @@ -141,6 +146,10 @@ public String getId() { return id; } + public String getCurrentRunId() { + return currentRunId; + } + public ProcessType getProcessType() { return processType; } diff --git a/cse-runner-api/src/test/java/com/farao_community/farao/cse/runner/api/resource/CseRequestTest.java b/cse-runner-api/src/test/java/com/farao_community/farao/cse/runner/api/resource/CseRequestTest.java index a1971e11..ca5c2792 100644 --- a/cse-runner-api/src/test/java/com/farao_community/farao/cse/runner/api/resource/CseRequestTest.java +++ b/cse-runner-api/src/test/java/com/farao_community/farao/cse/runner/api/resource/CseRequestTest.java @@ -22,6 +22,7 @@ class CseRequestTest { void checkCseRequestForD2ccProcess() { CseRequest cseRequest = CseRequest.d2ccProcess( "id", + "runId", OffsetDateTime.parse("2017-07-18T08:18Z"), "cgmUrl", "mergedCracUrl", @@ -52,6 +53,7 @@ void checkCseRequestForD2ccProcess() { void checkCseRequestForIdccProcess() { CseRequest cseRequest = CseRequest.idccProcess( "id", + "runId", OffsetDateTime.parse("2017-07-18T08:18Z"), "cgmUrl", "mergedCracUrl", @@ -85,6 +87,7 @@ void checkCseRequestForIdccProcess() { void checkCseRequestForD2ccAdaptedProcess() { CseRequest cseRequest = CseRequest.d2ccProcess( "id", + "runId", OffsetDateTime.parse("2017-07-18T08:18Z"), "cgmUrl", "mergedCracUrl", @@ -108,6 +111,7 @@ void checkCseRequestForD2ccAdaptedProcess() { void checkCseRequestForIdccAdaptedProcess() { CseRequest cseRequest = CseRequest.idccProcess( "id", + "runId", OffsetDateTime.parse("2017-07-18T08:18Z"), "cgmUrl", "mergedCracUrl", diff --git a/pom.xml b/pom.xml index 57d337a0..53263744 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ 1.32.1 4.17.1 - 1.23.1 + 1.23.4-SNAPSHOT 1.26.1 1.1.2