@@ -104,13 +104,19 @@ private Mono<Network> getNetwork(UUID networkUuid) {
104104 .subscribeOn (Schedulers .boundedElastic ());
105105 }
106106
107- private Mono <Network > getNetwork (UUID networkUuid , List <UUID > otherNetworkUuids ) {
107+ private Mono <Network > getNetwork (UUID networkUuid , List <UUID > otherNetworkUuids , UUID resultUuid ) {
108108 Mono <Network > network = getNetwork (networkUuid );
109109 if (otherNetworkUuids .isEmpty ()) {
110110 return network ;
111111 } else {
112112 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+ })
114120 .collectList ();
115121 return Mono .zip (network , otherNetworks )
116122 .map (t -> {
@@ -134,7 +140,19 @@ private Mono<SecurityAnalysisResult> run(SecurityAnalysisRunContext context, UUI
134140
135141 LOGGER .info ("Run security analysis on contingency lists: {}" , context .getContingencyListNames ().stream ().map (SecurityAnalysisWorkerService ::sanitizeParam ).collect (Collectors .toList ()));
136142
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" );
138156
139157 Mono <List <Contingency >> contingencies = Flux .fromIterable (context .getContingencyListNames ())
140158 .flatMap (contingencyListName -> actionsService .getContingencyList (contingencyListName , context .getNetworkUuid ()))
@@ -150,6 +168,7 @@ private Mono<SecurityAnalysisResult> run(SecurityAnalysisRunContext context, UUI
150168 if (resultUuid != null ) {
151169 futures .put (resultUuid , future );
152170 }
171+ LOGGER .info ("Starting security analysis computation" );
153172 return Mono .fromCompletionStage (future );
154173 }
155174 });
@@ -170,6 +189,11 @@ public Consumer<Flux<Message<String>>> consumeRun() {
170189 if (result != null ) { // result available
171190 resultPublisherService .publish (resultContext .getResultUuid (), resultContext .getRunContext ().getReceiver ());
172191 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+ }
173197 }
174198 })
175199 .onErrorResume (throwable -> {
0 commit comments