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