Skip to content

Commit ca689a3

Browse files
committed
Small additions
Signed-off-by: Sébastien Murgey <sebastien.murgey@rte-france.com>
1 parent 7bc6e6a commit ca689a3

5 files changed

Lines changed: 60 additions & 10 deletions

File tree

data/crac/crac-api/src/main/java/com/powsybl/openrao/data/cracapi/Crac.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,16 @@ default State getState(String contingencyId, Instant instant) {
549549
* @param inputStream CRAC data
550550
* @param cracFactory CRAC factory
551551
* @param network the network on which the CRAC data is based
552+
* @param reportNode
552553
* @return CRAC object
553554
*/
554-
private static Crac read(List<Importer> importers, InputStream inputStream, CracFactory cracFactory, Network network) throws IOException {
555+
private static Crac read(List<Importer> importers, InputStream inputStream, CracFactory cracFactory, Network network, ReportNode reportNode) throws IOException {
555556
byte[] bytes = getBytesFromInputStream(inputStream);
556557
return importers.stream()
557558
.filter(importer -> importer.exists(new ByteArrayInputStream(bytes)))
558559
.findAny()
559560
.orElseThrow(() -> new OpenRaoException("No suitable CRAC importer found."))
560-
.importData(new ByteArrayInputStream(bytes), cracFactory, network, ReportNode.NO_OP);
561+
.importData(new ByteArrayInputStream(bytes), cracFactory, network, reportNode);
561562
}
562563

563564
/**
@@ -566,10 +567,11 @@ private static Crac read(List<Importer> importers, InputStream inputStream, Crac
566567
* @param inputStream CRAC data
567568
* @param cracFactory CRAC factory
568569
* @param network the network on which the CRAC data is based
570+
* @param reportNode
569571
* @return CRAC object
570572
*/
571-
static Crac read(InputStream inputStream, CracFactory cracFactory, Network network) throws IOException {
572-
return read(new ServiceLoaderCache<>(Importer.class).getServices(), inputStream, cracFactory, network);
573+
static Crac read(InputStream inputStream, CracFactory cracFactory, Network network, ReportNode reportNode) throws IOException {
574+
return read(new ServiceLoaderCache<>(Importer.class).getServices(), inputStream, cracFactory, network, reportNode);
573575
}
574576

575577
/**
@@ -580,7 +582,19 @@ static Crac read(InputStream inputStream, CracFactory cracFactory, Network netwo
580582
* @return CRAC object
581583
*/
582584
static Crac read(InputStream inputStream, Network network) throws IOException {
583-
return read(inputStream, CracFactory.findDefault(), network);
585+
return read(inputStream, CracFactory.findDefault(), network, ReportNode.NO_OP);
586+
}
587+
588+
/**
589+
* Import CRAC from a file
590+
*
591+
* @param inputStream CRAC data
592+
* @param network the network on which the CRAC data is based
593+
* @param reportNode
594+
* @return CRAC object
595+
*/
596+
static Crac read(InputStream inputStream, Network network, ReportNode reportNode) throws IOException {
597+
return read(inputStream, CracFactory.findDefault(), network, reportNode);
584598
}
585599

586600
private static byte[] getBytesFromInputStream(InputStream inputStream) throws IOException {

data/native-crac/native-crac-io-api/src/main/java/com/powsybl/openrao/data/nativecracioapi/NativeCracImporters.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static NativeCrac importData(String fileName, InputStream inputStream, Re
7777
try {
7878
byte[] bytes = getBytesFromInputStream(inputStream);
7979

80-
NativeCracImporter importer = findImporter(fileName, new ByteArrayInputStream(bytes));
80+
NativeCracImporter importer = findImporter(fileName, new ByteArrayInputStream(bytes), reportNode);
8181
if (importer == null) {
8282
throw new OpenRaoException("No importer found for this file");
8383
}
@@ -94,12 +94,23 @@ public static NativeCrac importData(String fileName, InputStream inputStream, Re
9494
* @return the importer if one exists for the given file or <code>null</code> otherwise.
9595
*/
9696
public static NativeCracImporter findImporter(String fileName, InputStream inputStream) {
97+
return findImporter(fileName, inputStream, ReportNode.NO_OP);
98+
}
99+
100+
/**
101+
* Find an importer for a specified file, trying to guess its format
102+
* @param fileName name of the native CRAC file
103+
* @param inputStream input stream of the native CRAC file
104+
* @param reportNode
105+
* @return the importer if one exists for the given file or <code>null</code> otherwise.
106+
*/
107+
public static NativeCracImporter findImporter(String fileName, InputStream inputStream, ReportNode reportNode) {
97108
try {
98109
byte[] bytes = getBytesFromInputStream(inputStream);
99110

100111
for (NativeCracImporter importer : NATIVE_CRAC_IMPORTERS.get()) {
101112
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
102-
if (importer.exists(fileName, bais)) {
113+
if (importer.exists(fileName, bais, reportNode)) {
103114
return importer;
104115
}
105116
}

monitoring/angle-monitoring/src/main/java/com/powsybl/openrao/monitoring/anglemonitoring/AngleMonitoring.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
import java.util.concurrent.ForkJoinTask;
3939
import java.util.stream.Collectors;
4040

41-
import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.*;
42-
4341
/**
4442
* Monitors AngleCnecs' angles.
4543
* To remedy AngleCnecs with angles past their thresholds, corresponding remedial actions are applied.
@@ -162,7 +160,7 @@ private ReportNode runPostContingencyTask(String loadFlowProvider, LoadFlowParam
162160
applyOptimalRemedialActionsOnContingencyState(state, networkClone);
163161
stateSpecificResults.add(monitorAngleCnecsAndLog(loadFlowProvider, loadFlowParameters, state, networkClone, scenarioReportNode));
164162
} catch (Exception e) {
165-
BUSINESS_WARNS.warn(e.getMessage()); // TODO: The thread is interrupted in the Voltage monitoring and there is no business warn
163+
AngleMonitoringReports.reportExceptionInAngleMonitoring(scenarioReportNode, e); // TODO: The thread is interrupted in the Voltage monitoring and there is no business warn
166164
stateSpecificResults.add(catchAngleMonitoringResult(state, AngleMonitoringResult.Status.UNKNOWN, scenarioReportNode));
167165
}
168166
networkPool.releaseUsedNetwork(networkClone);

monitoring/angle-monitoring/src/main/java/com/powsybl/openrao/monitoring/anglemonitoring/AngleMonitoringReports.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,15 @@ public static ReportNode reportRedispatchingFailed(ReportNode reportNode, double
139139
BUSINESS_WARNS.warn("Redispatching failed: asked={} MW, applied={} MW", powerToRedispatch, redispatchedPower);
140140
return addedNode;
141141
}
142+
143+
public static ReportNode reportExceptionInAngleMonitoring(ReportNode reportNode, Exception exception) {
144+
String exceptionMessage = exception.getMessage();
145+
ReportNode addedNode = reportNode.newReportNode()
146+
.withMessageTemplate("reportExceptionInAngleMonitoring", "Exception thrown during angle monitoring: ${exceptionMessage}")
147+
.withUntypedValue("exceptionMessage", exceptionMessage)
148+
.withSeverity(TypedValue.ERROR_SEVERITY)
149+
.add();
150+
BUSINESS_WARNS.warn(exceptionMessage);
151+
return addedNode;
152+
}
142153
}

ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonRaoParameters.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ public static ExtensionProviders<ExtensionSerializer> getExtensionSerializers()
6161
private JsonRaoParameters() {
6262
}
6363

64+
/**
65+
* @param jsonFile Path where the RaoParameters should be read from
66+
* @return parameters from a JSON file (will NOT rely on platform config).
67+
*/
68+
public static RaoParameters read(Path jsonFile) {
69+
return update(new RaoParameters(ReportNode.NO_OP), jsonFile, ReportNode.NO_OP);
70+
}
71+
72+
/**
73+
* @param jsonStream InputStream where the RaoParameters are
74+
* @return parameters from a JSON file (will NOT rely on platform config).
75+
*/
76+
public static RaoParameters read(InputStream jsonStream) {
77+
return update(new RaoParameters(ReportNode.NO_OP), jsonStream, ReportNode.NO_OP);
78+
}
79+
6480
/**
6581
* @param jsonFile Path where the RaoParameters should be read from
6682
* @param reportNode

0 commit comments

Comments
 (0)