@@ -106,13 +106,19 @@ private Mono<Network> getNetwork(UUID networkUuid) {
106106 .subscribeOn (Schedulers .boundedElastic ());
107107 }
108108
109- private Mono <Network > getNetwork (UUID networkUuid , List <UUID > otherNetworkUuids ) {
109+ private Mono <Network > getNetwork (UUID networkUuid , List <UUID > otherNetworkUuids , UUID resultUuid ) {
110110 Mono <Network > network = getNetwork (networkUuid );
111111 if (otherNetworkUuids .isEmpty ()) {
112112 return network ;
113113 } else {
114114 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+ })
116122 .collectList ();
117123 return Mono .zip (network , otherNetworks )
118124 .map (t -> {
@@ -136,7 +142,19 @@ private Mono<SecurityAnalysisResult> run(SecurityAnalysisRunContext context, UUI
136142
137143 LOGGER .info ("Run security analysis on contingency lists: {}" , context .getContingencyListNames ().stream ().map (SecurityAnalysisWorkerService ::sanitizeParam ).collect (Collectors .toList ()));
138144
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" );
140158
141159 Mono <List <Contingency >> contingencies = Flux .fromIterable (context .getContingencyListNames ())
142160 .flatMap (contingencyListName -> actionsService .getContingencyList (contingencyListName , context .getNetworkUuid ())
@@ -153,6 +171,7 @@ private Mono<SecurityAnalysisResult> run(SecurityAnalysisRunContext context, UUI
153171 if (resultUuid != null ) {
154172 futures .put (resultUuid , future );
155173 }
174+ LOGGER .info ("Starting security analysis computation" );
156175 return Mono .fromCompletionStage (future );
157176 }
158177 });
@@ -173,6 +192,11 @@ public Consumer<Flux<Message<String>>> consumeRun() {
173192 if (result != null ) { // result available
174193 resultPublisherService .publish (resultContext .getResultUuid (), resultContext .getRunContext ().getReceiver ());
175194 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+ }
176200 }
177201 })
178202 .doFinally (s -> {
0 commit comments