@@ -49,12 +49,12 @@ public class ConsumerService {
49
49
50
50
private static final Logger LOGGER = LoggerFactory .getLogger (ConsumerService .class );
51
51
52
- static final String RESULT_UUID = "resultUuid" ;
53
- static final String NETWORK_UUID = "networkUuid" ;
54
- static final String NETWORK_ID = "networkId" ;
55
- static final String HEADER_CASE_FORMAT = "caseFormat" ;
56
- static final String HEADER_CASE_NAME = "caseName" ;
57
- static final String HEADER_WITH_RATIO_TAP_CHANGERS = "withRatioTapChangers" ;
52
+ private static final String RESULT_UUID = "resultUuid" ;
53
+ private static final String NETWORK_UUID = "networkUuid" ;
54
+ private static final String NETWORK_ID = "networkId" ;
55
+ private static final String HEADER_CASE_FORMAT = "caseFormat" ;
56
+ private static final String HEADER_CASE_NAME = "caseName" ;
57
+ private static final String HEADER_WITH_RATIO_TAP_CHANGERS = "withRatioTapChangers" ;
58
58
59
59
private final ObjectMapper objectMapper ;
60
60
@@ -134,7 +134,7 @@ private void handleBuildResultWorkflow(UUID studyUuid, UUID nodeUuid, UUID rootN
134
134
WorkflowType workflowType = WorkflowType .valueOf (workflowTypeStr );
135
135
if (WorkflowType .RERUN_LOAD_FLOW .equals (workflowType )) {
136
136
RerunLoadFlowInfos workflowInfos = objectMapper .readValue (URLDecoder .decode (workflowInfosStr , StandardCharsets .UTF_8 ), RerunLoadFlowInfos .class );
137
- studyService .sendLoadflowRequest (studyUuid , nodeUuid , rootNetworkUuid , workflowInfos .getLoadflowResultUuid (), workflowInfos .isWithRatioTapChangers (), workflowInfos .getUserId ());
137
+ studyService .sendLoadflowRequest (studyUuid , nodeUuid , rootNetworkUuid , workflowInfos .getLoadflowResultUuid (), workflowInfos .isWithRatioTapChangers (), false , workflowInfos .getUserId ());
138
138
}
139
139
}
140
140
}
@@ -226,54 +226,59 @@ public Consumer<Message<String>> consumeCaseImportSucceeded() {
226
226
return ;
227
227
}
228
228
229
- UUID caseUuid = receiver .getCaseUuid ();
230
- UUID studyUuid = receiver .getStudyUuid ();
231
- String userId = receiver .getUserId ();
232
- Long startTime = receiver .getStartTime ();
233
- UUID importReportUuid = receiver .getReportUuid ();
234
- UUID rootNetworkUuid = receiver .getRootNetworkUuid ();
235
- CaseImportAction caseImportAction = receiver .getCaseImportAction ();
236
-
237
- CaseInfos caseInfos = new CaseInfos (caseUuid , receiver .getOriginalCaseUuid (), caseName , caseFormat );
238
- NetworkInfos networkInfos = new NetworkInfos (networkUuid , networkId );
239
- try {
240
- switch (caseImportAction ) {
241
- case STUDY_CREATION ->
242
- insertStudy (studyUuid , userId , networkInfos , caseInfos , importParameters , importReportUuid );
243
- case ROOT_NETWORK_CREATION ->
244
- studyService .createRootNetwork (studyUuid , RootNetworkInfos .builder ()
245
- .id (rootNetworkUuid )
246
- .caseInfos (caseInfos )
247
- .reportUuid (importReportUuid )
248
- .networkInfos (networkInfos )
249
- .importParameters (importParameters )
250
- .build ());
251
- case NETWORK_RECREATION ->
252
- studyService .updateNetwork (studyUuid , rootNetworkUuid , networkInfos , userId );
253
- case ROOT_NETWORK_MODIFICATION ->
254
- studyService .modifyRootNetwork (studyUuid , RootNetworkInfos .builder ()
255
- .id (rootNetworkUuid )
256
- .networkInfos (networkInfos )
257
- .caseInfos (caseInfos )
258
- .importParameters (importParameters )
259
- .reportUuid (importReportUuid )
260
- .build (), true );
261
- }
262
- caseService .disableCaseExpiration (caseUuid );
263
- } catch (Exception e ) {
264
- LOGGER .error ("Error while importing case" , e );
265
- } finally {
266
- // if studyEntity is already existing, we don't delete anything in the end of the process
267
- if (caseImportAction == CaseImportAction .STUDY_CREATION ) {
268
- studyService .deleteStudyIfNotCreationInProgress (studyUuid );
269
- }
270
- LOGGER .trace ("{} for study uuid '{}' : {} seconds" , caseImportAction .getLabel (), studyUuid ,
271
- TimeUnit .NANOSECONDS .toSeconds (System .nanoTime () - startTime ));
272
- }
229
+ handleConsumeCaseImportSucceeded (receiver , networkUuid , networkId , caseName , caseFormat , importParameters );
273
230
}
274
231
};
275
232
}
276
233
234
+ private void handleConsumeCaseImportSucceeded (CaseImportReceiver receiver , UUID networkUuid , String networkId , String caseName , String caseFormat , Map <String , String > importParameters ) {
235
+ UUID caseUuid = receiver .getCaseUuid ();
236
+ UUID studyUuid = receiver .getStudyUuid ();
237
+ String userId = receiver .getUserId ();
238
+ Long startTime = receiver .getStartTime ();
239
+ UUID importReportUuid = receiver .getReportUuid ();
240
+ UUID rootNetworkUuid = receiver .getRootNetworkUuid ();
241
+ CaseImportAction caseImportAction = receiver .getCaseImportAction ();
242
+
243
+ CaseInfos caseInfos = new CaseInfos (caseUuid , receiver .getOriginalCaseUuid (), caseName , caseFormat );
244
+ NetworkInfos networkInfos = new NetworkInfos (networkUuid , networkId );
245
+ try {
246
+ switch (caseImportAction ) {
247
+ case STUDY_CREATION ->
248
+ insertStudy (studyUuid , userId , networkInfos , caseInfos , importParameters , importReportUuid );
249
+ case ROOT_NETWORK_CREATION -> studyService .createRootNetwork (studyUuid , RootNetworkInfos .builder ()
250
+ .id (rootNetworkUuid )
251
+ .caseInfos (caseInfos )
252
+ .reportUuid (importReportUuid )
253
+ .networkInfos (networkInfos )
254
+ .importParameters (importParameters )
255
+ .build ());
256
+ case NETWORK_RECREATION -> studyService .updateNetwork (studyUuid , rootNetworkUuid , networkInfos , userId );
257
+ case ROOT_NETWORK_MODIFICATION -> studyService .modifyRootNetwork (studyUuid , RootNetworkInfos .builder ()
258
+ .id (rootNetworkUuid )
259
+ .networkInfos (networkInfos )
260
+ .caseInfos (caseInfos )
261
+ .importParameters (importParameters )
262
+ .reportUuid (importReportUuid )
263
+ .build ());
264
+ }
265
+ caseService .disableCaseExpiration (caseUuid );
266
+ } catch (Exception e ) {
267
+ LOGGER .error ("Error while importing case" , e );
268
+ } finally {
269
+ // if studyEntity is already existing, we don't delete anything in the end of the process
270
+ if (caseImportAction == CaseImportAction .STUDY_CREATION ) {
271
+ studyService .deleteStudyIfNotCreationInProgress (studyUuid );
272
+ }
273
+ if (caseImportAction == CaseImportAction .ROOT_NETWORK_MODIFICATION ) {
274
+ UUID rootNodeUuid = networkModificationTreeService .getStudyRootNodeUuid (studyUuid );
275
+ networkModificationTreeService .invalidateBlockedBuildNodeTree (rootNetworkUuid , rootNodeUuid );
276
+ }
277
+ LOGGER .trace ("{} for study uuid '{}' : {} seconds" , caseImportAction .getLabel (), studyUuid ,
278
+ TimeUnit .NANOSECONDS .toSeconds (System .nanoTime () - startTime ));
279
+ }
280
+ }
281
+
277
282
private void insertStudy (UUID studyUuid , String userId , NetworkInfos networkInfos , CaseInfos caseInfos ,
278
283
Map <String , String > importParameters , UUID importReportUuid ) {
279
284
UserProfileInfos userProfileInfos = getUserProfile (userId );
@@ -521,7 +526,7 @@ public void consumeCalculationFailed(Message<String> msg, ComputationType comput
521
526
}
522
527
}
523
528
if (!Strings .isBlank (receiver )) {
524
- NodeReceiver receiverObj ;
529
+ NodeReceiver receiverObj = null ;
525
530
try {
526
531
receiverObj = objectMapper .readValue (URLDecoder .decode (receiver , StandardCharsets .UTF_8 ), NodeReceiver .class );
527
532
@@ -530,24 +535,18 @@ public void consumeCalculationFailed(Message<String> msg, ComputationType comput
530
535
// delete computation results from the databases
531
536
// ==> will probably be removed soon because it prevents the front from recovering the resultId ; or 'null' parameter will be replaced by null like in VOLTAGE_INITIALIZATION
532
537
rootNetworkNodeInfoService .updateComputationResultUuid (receiverObj .getNodeUuid (), receiverObj .getRootNetworkUuid (), resultUuid , computationType );
533
-
534
- UUID studyUuid = networkModificationTreeService .getStudyUuidForNodeId (receiverObj .getNodeUuid ());
535
-
536
- if (computationType == LOAD_FLOW ) {
537
- // since running loadflow impacts the network linked to the node "nodeUuid", we need to invalidate its children nodes to prevent inconsistencies
538
- studyService .invalidateNodeTree (studyUuid , receiverObj .getNodeUuid (), receiverObj .getRootNetworkUuid (), InvalidateNodeTreeParameters .ONLY_CHILDREN );
539
- }
540
-
541
- // send notification for failed computation
542
- notificationService .emitStudyError (
543
- studyUuid ,
544
- receiverObj .getNodeUuid (),
545
- receiverObj .getRootNetworkUuid (),
546
- computationType .getUpdateFailedType (),
547
- errorMessage ,
548
- userId );
549
538
} catch (JsonProcessingException e ) {
550
539
LOGGER .error (e .toString ());
540
+ } finally {
541
+ if (receiverObj != null ) {
542
+ if (computationType == LOAD_FLOW ) {
543
+ networkModificationTreeService .invalidateBlockedBuildNodeTree (receiverObj .getRootNetworkUuid (), receiverObj .getNodeUuid ());
544
+ }
545
+
546
+ // send notification for failed computation
547
+ UUID studyUuid = networkModificationTreeService .getStudyUuidForNodeId (receiverObj .getNodeUuid ());
548
+ notificationService .emitStudyError (studyUuid , receiverObj .getNodeUuid (), receiverObj .getRootNetworkUuid (), computationType .getUpdateFailedType (), errorMessage , userId );
549
+ }
551
550
}
552
551
}
553
552
}
@@ -601,22 +600,22 @@ private void consumeLoadFlowResult(Message<String> msg, boolean withRatioTapChan
601
600
Optional .ofNullable (msg .getHeaders ().get (RESULT_UUID , String .class ))
602
601
.map (UUID ::fromString )
603
602
.ifPresent (resultUuid -> getNodeReceiver (msg ).ifPresent (receiverObj -> {
604
- LOGGER .info ("{} result '{}' available for node '{}'" ,
605
- LOAD_FLOW .getLabel (),
606
- resultUuid ,
607
- receiverObj .getNodeUuid ());
608
-
609
- // update DB
610
- rootNetworkNodeInfoService .updateLoadflowResultUuid (receiverObj .getNodeUuid (), receiverObj .getRootNetworkUuid (), resultUuid , withRatioTapChangers );
611
-
612
- UUID studyUuid = networkModificationTreeService .getStudyUuidForNodeId (receiverObj .getNodeUuid ());
603
+ try {
604
+ LOGGER .info ("{} result '{}' available for node '{}'" ,
605
+ LOAD_FLOW .getLabel (),
606
+ resultUuid ,
607
+ receiverObj .getNodeUuid ());
613
608
614
- // since running loadflow impacts the network linked to the node "nodeUuid", we need to invalidate its children nodes to prevent inconsistencies
615
- studyService .invalidateNodeTree (studyUuid , receiverObj .getNodeUuid (), receiverObj .getRootNetworkUuid (), InvalidateNodeTreeParameters .ONLY_CHILDREN );
609
+ // update DB
610
+ rootNetworkNodeInfoService .updateLoadflowResultUuid (receiverObj .getNodeUuid (), receiverObj .getRootNetworkUuid (), resultUuid , withRatioTapChangers );
611
+ } finally {
612
+ networkModificationTreeService .invalidateBlockedBuildNodeTree (receiverObj .getRootNetworkUuid (), receiverObj .getNodeUuid ());
616
613
617
- // send notifications
618
- notificationService .emitStudyChanged (studyUuid , receiverObj .getNodeUuid (), receiverObj .getRootNetworkUuid (), LOAD_FLOW .getUpdateStatusType ());
619
- notificationService .emitStudyChanged (studyUuid , receiverObj .getNodeUuid (), receiverObj .getRootNetworkUuid (), LOAD_FLOW .getUpdateResultType ());
614
+ // send notifications
615
+ UUID studyUuid = networkModificationTreeService .getStudyUuidForNodeId (receiverObj .getNodeUuid ());
616
+ notificationService .emitStudyChanged (studyUuid , receiverObj .getNodeUuid (), receiverObj .getRootNetworkUuid (), LOAD_FLOW .getUpdateStatusType ());
617
+ notificationService .emitStudyChanged (studyUuid , receiverObj .getNodeUuid (), receiverObj .getRootNetworkUuid (), LOAD_FLOW .getUpdateResultType ());
618
+ }
620
619
}));
621
620
}
622
621
0 commit comments