@@ -106,13 +106,19 @@ private Mono<Network> getNetwork(UUID networkUuid) {
106
106
.subscribeOn (Schedulers .boundedElastic ());
107
107
}
108
108
109
- private Mono <Network > getNetwork (UUID networkUuid , List <UUID > otherNetworkUuids ) {
109
+ private Mono <Network > getNetwork (UUID networkUuid , List <UUID > otherNetworkUuids , UUID resultUuid ) {
110
110
Mono <Network > network = getNetwork (networkUuid );
111
111
if (otherNetworkUuids .isEmpty ()) {
112
112
return network ;
113
113
} else {
114
114
Mono <List <Network >> otherNetworks = Flux .fromIterable (otherNetworkUuids )
115
- .flatMap (this ::getNetwork )
115
+ .flatMap (uuid -> {
116
+ if (resultUuid != null && cancelComputationRequests .get (resultUuid ) != null ) {
117
+ return Mono .empty ();
118
+ } else {
119
+ return getNetwork (uuid );
120
+ }
121
+ })
116
122
.collectList ();
117
123
return Mono .zip (network , otherNetworks )
118
124
.map (t -> {
@@ -136,7 +142,19 @@ private Mono<SecurityAnalysisResult> run(SecurityAnalysisRunContext context, UUI
136
142
137
143
LOGGER .info ("Run security analysis on contingency lists: {}" , context .getContingencyListNames ().stream ().map (SecurityAnalysisWorkerService ::sanitizeParam ).collect (Collectors .toList ()));
138
144
139
- Mono <Network > network = getNetwork (context .getNetworkUuid (), context .getOtherNetworkUuids ());
145
+ if (resultUuid != null && cancelComputationRequests .get (resultUuid ) != null ) {
146
+ return Mono .empty ();
147
+ }
148
+
149
+ LOGGER .info ("Loading networks" );
150
+
151
+ Mono <Network > network = getNetwork (context .getNetworkUuid (), context .getOtherNetworkUuids (), resultUuid );
152
+
153
+ if (resultUuid != null && cancelComputationRequests .get (resultUuid ) != null ) {
154
+ return Mono .empty ();
155
+ }
156
+
157
+ LOGGER .info ("Loading contingencies" );
140
158
141
159
Mono <List <Contingency >> contingencies = Flux .fromIterable (context .getContingencyListNames ())
142
160
.flatMap (contingencyListName -> actionsService .getContingencyList (contingencyListName , context .getNetworkUuid ())
@@ -153,6 +171,7 @@ private Mono<SecurityAnalysisResult> run(SecurityAnalysisRunContext context, UUI
153
171
if (resultUuid != null ) {
154
172
futures .put (resultUuid , future );
155
173
}
174
+ LOGGER .info ("Starting security analysis computation" );
156
175
return Mono .fromCompletionStage (future );
157
176
}
158
177
});
@@ -173,6 +192,11 @@ public Consumer<Flux<Message<String>>> consumeRun() {
173
192
if (result != null ) { // result available
174
193
resultPublisherService .publish (resultContext .getResultUuid (), resultContext .getRunContext ().getReceiver ());
175
194
LOGGER .info ("Security analysis complete (resultUuid='{}')" , resultContext .getResultUuid ());
195
+ } else { // result not available : stop computation request
196
+ if (cancelComputationRequests .get (resultContext .getResultUuid ()) != null ) {
197
+ stoppedPublisherService .publish (resultContext .getResultUuid (), cancelComputationRequests .get (resultContext .getResultUuid ()).getReceiver ());
198
+ LOGGER .info ("Security analysis stopped (resultUuid='{}')" , resultContext .getResultUuid ());
199
+ }
176
200
}
177
201
})
178
202
.doFinally (s -> {
0 commit comments