diff --git a/pom.xml b/pom.xml
index 4208cbfe..ac4ce9b8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -156,6 +156,7 @@
com.powsybl
powsybl-ws-commons
+ 1.20.0-SNAPSHOT
org.liquibase
diff --git a/src/main/java/org/gridsuite/ds/server/controller/DynamicSimulationController.java b/src/main/java/org/gridsuite/ds/server/controller/DynamicSimulationController.java
index a2d1a55f..fd51dcff 100644
--- a/src/main/java/org/gridsuite/ds/server/controller/DynamicSimulationController.java
+++ b/src/main/java/org/gridsuite/ds/server/controller/DynamicSimulationController.java
@@ -6,13 +6,13 @@
*/
package org.gridsuite.ds.server.controller;
+import com.powsybl.ws.commons.computation.dto.ReportInfos;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.collections4.CollectionUtils;
-import com.powsybl.ws.commons.computation.dto.ReportInfos;
import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos;
import org.gridsuite.ds.server.dto.DynamicSimulationStatus;
import org.gridsuite.ds.server.service.DynamicSimulationResultService;
@@ -26,8 +26,8 @@
import java.util.List;
import java.util.UUID;
-import static org.gridsuite.ds.server.DynamicSimulationApi.API_VERSION;
import static com.powsybl.ws.commons.computation.service.NotificationService.HEADER_USER_ID;
+import static org.gridsuite.ds.server.DynamicSimulationApi.API_VERSION;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE;
@@ -62,6 +62,7 @@ public ResponseEntity run(@PathVariable("networkUuid") UUID networkUuid,
@RequestParam(name = "reporterId", required = false) String reportName,
@RequestParam(name = "reportType", required = false, defaultValue = "DynamicSimulation") String reportType,
@RequestParam(name = "provider", required = false) String provider,
+ @RequestParam(name = "debug", required = false) Boolean debug,
@RequestBody DynamicSimulationParametersInfos parameters,
@RequestHeader(HEADER_USER_ID) String userId) {
@@ -73,7 +74,8 @@ public ResponseEntity run(@PathVariable("networkUuid") UUID networkUuid,
mappingName,
ReportInfos.builder().reportUuid(reportId).reporterId(reportName).computationType(reportType).build(),
userId,
- parameters);
+ parameters,
+ debug);
UUID resultUuid = dynamicSimulationService.runAndSaveResult(dynamicSimulationRunContext);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid);
diff --git a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java
index c77cb8e7..15494eed 100644
--- a/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java
+++ b/src/main/java/org/gridsuite/ds/server/service/DynamicSimulationWorkerService.java
@@ -10,7 +10,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.io.FileUtil;
-import com.powsybl.computation.ComputationManager;
import com.powsybl.dynamicsimulation.*;
import com.powsybl.dynamicsimulation.groovy.GroovyExtension;
import com.powsybl.dynamicsimulation.groovy.GroovyOutputVariablesSupplier;
@@ -86,15 +85,6 @@ public DynamicSimulationWorkerService(NetworkStoreService networkStoreService,
this.parametersService = Objects.requireNonNull(parametersService);
}
- /**
- * Use this method to mock with DockerLocalComputationManager in case of integration tests with test container
- *
- * @return a computation manager
- */
- public ComputationManager getComputationManager() {
- return executionService.getComputationManager();
- }
-
@Override
protected DynamicSimulationResultContext fromMessage(Message message) {
return DynamicSimulationResultContext.fromMessage(message, objectMapper);
@@ -175,12 +165,8 @@ public void preRun(DynamicSimulationRunContext runContext) {
runContext.setEventModelContent(eventModel);
runContext.setCurveContent(curveModel);
- // create a working folder for this run
- Path workDir;
- workDir = createWorkingDirectory();
- runContext.setWorkDir(workDir);
-
// enrich dump parameters
+ Path workDir = runContext.getComputationManager().getLocalDir();
setupDumpParameters(workDir, parameters);
}
@@ -205,7 +191,7 @@ public CompletableFuture getCompletableFuture(DynamicSi
eventModelsSupplier,
outputVariablesSupplier,
runContext.getVariantId() != null ? runContext.getVariantId() : VariantManagerConstants.INITIAL_VARIANT_ID,
- getComputationManager(),
+ runContext.getComputationManager(),
parameters,
runContext.getReportNode());
}
@@ -225,9 +211,11 @@ public Consumer> consumeCancel() {
@Override
protected void clean(AbstractResultContext resultContext) {
super.clean(resultContext);
- // clean working directory
- Path workDir = resultContext.getRunContext().getWorkDir();
- removeWorkingDirectory(workDir);
+ if (!resultContext.getRunContext().isDebug()) {
+ // clean dump directory
+ Path dumpDir = getDumpDir(resultContext.getRunContext().getDynamicSimulationParameters());
+ removeDirectory(dumpDir);
+ }
}
// --- Dump file related methods --- //
@@ -265,27 +253,15 @@ private byte[] zipDumpFile(Path dumpDir) {
return outputState;
}
- private Path createWorkingDirectory() {
- Path workDir;
- Path localDir = getComputationManager().getLocalDir();
- try {
- workDir = Files.createTempDirectory(localDir, "dynamic_simulation_");
- } catch (IOException e) {
- throw new DynamicSimulationException(DUMP_FILE_ERROR, String.format("Error occurred while creating a working directory inside the local directory %s",
- localDir.toAbsolutePath()));
- }
- return workDir;
- }
-
- private void removeWorkingDirectory(Path workDir) {
- if (workDir != null) {
+ private void removeDirectory(Path dir) {
+ if (dir != null) {
try {
- FileUtil.removeDir(workDir);
+ FileUtil.removeDir(dir);
} catch (IOException e) {
- LOGGER.error(String.format("%s: Error occurred while cleaning working directory at %s", getComputationType(), workDir.toAbsolutePath()), e);
+ LOGGER.error(String.format("%s: Error occurred while cleaning directory at %s", getComputationType(), dir.toAbsolutePath()), e);
}
} else {
- LOGGER.info("{}: No working directory to clean", getComputationType());
+ LOGGER.info("{}: No directory to clean", getComputationType());
}
}
}
diff --git a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java
index 7cd48881..c8b02a8f 100644
--- a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java
+++ b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationResultContext.java
@@ -17,6 +17,7 @@
import java.io.UncheckedIOException;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.UUID;
import static com.powsybl.ws.commons.computation.service.NotificationService.*;
@@ -55,6 +56,7 @@ public static DynamicSimulationResultContext fromMessage(Message message
String reporterId = (String) headers.get(REPORTER_ID_HEADER);
String reportType = (String) headers.get(REPORT_TYPE_HEADER);
String userId = (String) headers.get(HEADER_USER_ID);
+ Boolean debug = (Boolean) headers.get(DEBUG_HEADER);
DynamicSimulationRunContext runContext = DynamicSimulationRunContext.builder()
.networkUuid(networkUuid)
@@ -64,6 +66,7 @@ public static DynamicSimulationResultContext fromMessage(Message message
.reportInfos(ReportInfos.builder().reportUuid(reportUuid).reporterId(reporterId).computationType(reportType).build())
.userId(userId)
.parameters(parametersInfos)
+ .debug(Optional.ofNullable(debug).orElse(false))
.build();
// specific headers for dynamic simulation
diff --git a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java
index fbe38f0b..49dfec04 100644
--- a/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java
+++ b/src/main/java/org/gridsuite/ds/server/service/contexts/DynamicSimulationRunContext.java
@@ -16,7 +16,6 @@
import lombok.Setter;
import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos;
-import java.nio.file.Path;
import java.util.List;
import java.util.UUID;
@@ -31,8 +30,6 @@ public class DynamicSimulationRunContext extends AbstractComputationRunContext dynamicModelContent;
private List eventModelContent;
@@ -43,8 +40,8 @@ public class DynamicSimulationRunContext extends AbstractComputationRunContext
- */
-public interface NotificationService {
-
- String FAIL_MESSAGE = "Dynamic simulation has failed";
-
- void emitRunDynamicSimulationMessage(Message message);
-
- void emitResultDynamicSimulationMessage(Message message);
-
- void emitCancelDynamicSimulationMessage(Message message);
-
- void emitFailDynamicSimulationMessage(Message message);
-}
diff --git a/src/main/java/org/gridsuite/ds/server/service/notification/impl/NotificationServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/notification/impl/NotificationServiceImpl.java
deleted file mode 100644
index 86b9ff7c..00000000
--- a/src/main/java/org/gridsuite/ds/server/service/notification/impl/NotificationServiceImpl.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright (c) 2022, RTE (http://www.rte-france.com)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-package org.gridsuite.ds.server.service.notification.impl;
-
-import org.gridsuite.ds.server.service.notification.NotificationService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cloud.stream.function.StreamBridge;
-import org.springframework.messaging.Message;
-import org.springframework.stereotype.Service;
-
-/**
- * @author Thang PHAM
- */
-@Service
-public class NotificationServiceImpl implements NotificationService {
- private static final String CATEGORY_BROKER_OUTPUT = NotificationService.class.getName() + ".output-broker-messages";
- private static final Logger OUTPUT_MESSAGE_LOGGER = LoggerFactory.getLogger(CATEGORY_BROKER_OUTPUT);
-
- @Autowired
- private StreamBridge publisher;
-
- private void sendMessage(Message> message, String bindingName) {
- NotificationServiceImpl.OUTPUT_MESSAGE_LOGGER.debug("Sending message : {}", message);
- publisher.send(bindingName, message);
- }
-
- @Override
- public void emitRunDynamicSimulationMessage(Message message) {
- sendMessage(message, "publishRun-out-0");
- }
-
- @Override
- public void emitResultDynamicSimulationMessage(Message message) {
- sendMessage(message, "publishResult-out-0");
- }
-
- @Override
- public void emitCancelDynamicSimulationMessage(Message message) {
- sendMessage(message, "publishCancel-out-0");
- }
-
- @Override
- public void emitFailDynamicSimulationMessage(Message message) {
- sendMessage(message, "publishFailed-out-0");
- }
-}
diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java b/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java
index 55fca09a..da40a19a 100644
--- a/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java
+++ b/src/main/java/org/gridsuite/ds/server/service/parameters/ParametersService.java
@@ -32,7 +32,7 @@ public interface ParametersService {
DynamicSimulationParameters getDynamicSimulationParameters(byte[] dynamicParams, String provider, DynamicSimulationParametersInfos inputParameters);
DynamicSimulationRunContext createRunContext(UUID networkUuid, String variantId, String receiver, String provider, String mapping,
- ReportInfos reportContext, String userId, DynamicSimulationParametersInfos parameters);
+ ReportInfos reportContext, String userId, DynamicSimulationParametersInfos parameters, Boolean debug);
List getDynamicModel(InputMapping inputMapping, Network network);
}
diff --git a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java
index aef2e481..28def57d 100644
--- a/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java
+++ b/src/main/java/org/gridsuite/ds/server/service/parameters/impl/ParametersServiceImpl.java
@@ -140,7 +140,7 @@ public DynamicSimulationParameters getDynamicSimulationParameters(byte[] dynamic
@Override
public DynamicSimulationRunContext createRunContext(UUID networkUuid, String variantId, String receiver, String provider, String mapping,
- ReportInfos reportInfos, String userId, DynamicSimulationParametersInfos parameters) {
+ ReportInfos reportInfos, String userId, DynamicSimulationParametersInfos parameters, Boolean debug) {
DynamicSimulationRunContext runContext = DynamicSimulationRunContext.builder()
.networkUuid(networkUuid)
.variantId(variantId)
@@ -148,6 +148,7 @@ public DynamicSimulationRunContext createRunContext(UUID networkUuid, String var
.reportInfos(reportInfos)
.userId(userId)
.parameters(parameters)
+ .debug(Optional.ofNullable(debug).orElse(false))
.build();
// set provider for run context
diff --git a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java
index 630ab517..b221524a 100644
--- a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java
+++ b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynamicSimulationControllerTest.java
@@ -80,10 +80,7 @@ public void setUp() throws IOException {
}
@After
- @Override
public void tearDown() throws Exception {
- super.tearDown();
-
OutputDestination output = getOutputDestination();
List destinations = List.of(dsFailedDestination, dsResultDestination, dsStoppedDestination, dsCancelFailedDestination);
@@ -104,7 +101,7 @@ public void tearDown() throws Exception {
private void initDynamicSimulationWorkerServiceSpy() {
// setup spy bean
- when(dynamicSimulationWorkerService.getComputationManager()).thenReturn(computationManager);
+ when(dynamicSimulationWorkerService.createComputationManager()).thenReturn(computationManager);
}
}
diff --git a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynawoTest.java b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynawoTest.java
index b7b645d9..a7e537af 100644
--- a/src/test/java/org/gridsuite/ds/server/controller/AbstractDynawoTest.java
+++ b/src/test/java/org/gridsuite/ds/server/controller/AbstractDynawoTest.java
@@ -10,7 +10,6 @@
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.local.test.ComputationDockerConfig;
import com.powsybl.computation.local.test.DockerLocalComputationManager;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
@@ -43,9 +42,4 @@ public void setUp() throws IOException {
Path localDir = tempFolder.getRoot().toPath();
computationManager = new DockerLocalComputationManager(localDir, dockerDir, config);
}
-
- @After
- public void tearDown() throws Exception {
- computationManager.close();
- }
}