Skip to content

Commit

Permalink
Remove hack and update report management (#531)
Browse files Browse the repository at this point in the history
Signed-off-by: Ayoub LABIDI <[email protected]>
  • Loading branch information
ayolab authored Sep 26, 2024
1 parent b3c9198 commit 977b4d1
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ public ResponseEntity<Optional<NetworkModificationResult>> handleNetworkModifica
@RequestBody List<UUID> modificationsUuidList) {
switch (action) {
case COPY:
return ResponseEntity.ok().body(networkModificationService.duplicateModifications(targetGroupUuid, networkUuid, variantId, new ReportInfos(reportUuid, reporterId.toString()), modificationsUuidList));
return ResponseEntity.ok().body(networkModificationService.duplicateModifications(targetGroupUuid, networkUuid, variantId, new ReportInfos(reportUuid, reporterId), modificationsUuidList));
case INSERT:
return ResponseEntity.ok().body(networkModificationService.insertCompositeModifications(targetGroupUuid, networkUuid, variantId, new ReportInfos(reportUuid, reporterId.toString()), modificationsUuidList));
return ResponseEntity.ok().body(networkModificationService.insertCompositeModifications(targetGroupUuid, networkUuid, variantId, new ReportInfos(reportUuid, reporterId), modificationsUuidList));
case MOVE:
UUID sourceGroupUuid = originGroupUuid == null ? targetGroupUuid : originGroupUuid;
boolean canBuildNode = build;
if (sourceGroupUuid.equals(targetGroupUuid)) {
canBuildNode = false;
}
return ResponseEntity.ok().body(networkModificationService.moveModifications(targetGroupUuid, sourceGroupUuid, beforeModificationUuid, networkUuid, variantId, new ReportInfos(reportUuid, reporterId.toString()), modificationsUuidList, canBuildNode));
return ResponseEntity.ok().body(networkModificationService.moveModifications(targetGroupUuid, sourceGroupUuid, beforeModificationUuid, networkUuid, variantId, new ReportInfos(reportUuid, reporterId), modificationsUuidList, canBuildNode));
default:
throw new NetworkModificationException(TYPE_MISMATCH);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public ResponseEntity<Optional<NetworkModificationResult>> createNetworkModifica
@Parameter(description = "Reporter ID") @RequestParam("reporterId") String reporterId,
@RequestBody ModificationInfos modificationInfos) {
modificationInfos.check();
return ResponseEntity.ok().body(networkModificationService.createNetworkModification(networkUuid, variantId, groupUuid, new ReportInfos(reportUuid, reporterId), modificationInfos));
return ResponseEntity.ok().body(networkModificationService.createNetworkModification(networkUuid, variantId, groupUuid, new ReportInfos(reportUuid, UUID.fromString(reporterId)), modificationInfos));
}

@PutMapping(value = "/network-modifications/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down Expand Up @@ -261,7 +261,7 @@ public ResponseEntity<Optional<NetworkModificationResult>> duplicateModification
@Parameter(description = "the reporter id", required = true) @RequestParam(value = "reporterId") UUID reporterId,
@Parameter(description = "the variant id", required = true) @RequestParam(value = "variantId") String variantId,
@Parameter(description = "origin group UUID, from where modifications are copied") @RequestParam(value = "duplicateFrom") UUID originGroupUuid) {
return ResponseEntity.ok().body(networkModificationService.duplicateModificationsInGroup(targetGroupUuid, networkUuid, variantId, new ReportInfos(reportUuid, reporterId.toString()), originGroupUuid));
return ResponseEntity.ok().body(networkModificationService.duplicateModificationsInGroup(targetGroupUuid, networkUuid, variantId, new ReportInfos(reportUuid, reporterId), originGroupUuid));
}

@DeleteMapping(value = "/groups/{groupUuid}/stashed-modifications")
Expand All @@ -288,6 +288,6 @@ public ResponseEntity<Optional<NetworkModificationResult>> applyModifications(@P
@Parameter(description = "the report uuid") @RequestParam(value = "reportUuid", required = false) UUID reportUuid,
@Parameter(description = "the reporter id") @RequestParam(value = "reporterId", required = false) String reporterId,
@RequestBody List<UUID> modificationsUuidList) {
return ResponseEntity.ok().body(networkModificationService.applyModificationsFromUuids(networkUuid, variantId, new ReportInfos(reportUuid, reporterId), modificationsUuidList));
return ResponseEntity.ok().body(networkModificationService.applyModificationsFromUuids(networkUuid, variantId, new ReportInfos(reportUuid, UUID.fromString(reporterId)), modificationsUuidList));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ public class BuildInfos {

private String destinationVariantId;

private UUID reportUuid;

private List<UUID> modificationGroupUuids = new ArrayList<>();

private List<String> reporterIds = new ArrayList<>();
private List<ReportInfos> reportsInfos = new ArrayList<>();

private Set<UUID> modificationsToExclude = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
public class ReportInfos {
private UUID reportUuid;

private String reporterId;
private UUID nodeUuid;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
public class NetworkModificationApplicator {
private static final Logger LOGGER = LoggerFactory.getLogger(NetworkModificationApplicator.class);

public static final String NETWORK_MODIFICATION_TYPE_REPORT = "NetworkModification";

private final NetworkStoreService networkStoreService;

private final EquipmentInfosService equipmentInfosService;
Expand Down Expand Up @@ -126,7 +124,7 @@ private NetworkModificationResult processApplication(List<ModificationInfos> mod
* Note : it is possible that the rabbitmq consumer threads here will be blocked by modifications applied directly in the other applyModifications method
* and no more builds can go through. If this causes problems we should put them in separate rabbitmq queues.
*/
public NetworkModificationResult applyModifications(List<Pair<String, List<ModificationInfos>>> modificationInfosGroups, NetworkInfos networkInfos, UUID reportUuid) {
public NetworkModificationResult applyModifications(List<Pair<ReportInfos, List<ModificationInfos>>> modificationInfosGroups, NetworkInfos networkInfos) {
PreloadingStrategy preloadingStrategy = modificationInfosGroups.stream()
.map(Pair::getRight)
.flatMap(List::stream)
Expand All @@ -135,19 +133,19 @@ public NetworkModificationResult applyModifications(List<Pair<String, List<Modif
.map(ModificationType::getStrategy)
.orElse(PreloadingStrategy.NONE);
if (preloadingStrategy == PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW) {
CompletableFuture<NetworkModificationResult> future = CompletableFuture.supplyAsync(() -> processApplication(modificationInfosGroups, networkInfos, reportUuid), applicationExecutor);
CompletableFuture<NetworkModificationResult> future = CompletableFuture.supplyAsync(() -> processApplication(modificationInfosGroups, networkInfos), applicationExecutor);
return future.join();
} else {
return processApplication(modificationInfosGroups, networkInfos, reportUuid);
return processApplication(modificationInfosGroups, networkInfos);
}
}

// used for building a variant
private NetworkModificationResult processApplication(List<Pair<String, List<ModificationInfos>>> modificationInfosGroups, NetworkInfos networkInfos, UUID reportUuid) {
private NetworkModificationResult processApplication(List<Pair<ReportInfos, List<ModificationInfos>>> modificationInfosGroups, NetworkInfos networkInfos) {
NetworkStoreListener listener = NetworkStoreListener.create(networkInfos.getNetwork(), networkInfos.getNetworkUuuid(), networkStoreService, equipmentInfosService, collectionThreshold);
List<ApplicationStatus> groupsApplicationStatuses =
modificationInfosGroups.stream()
.map(g -> apply(g.getRight(), listener.getNetwork(), new ReportInfos(reportUuid, g.getLeft())))
.map(g -> apply(g.getRight(), listener.getNetwork(), g.getLeft()))
.toList();
List<AbstractBaseImpact> networkImpacts = listener.flushNetworkModifications();
return NetworkModificationResult.builder()
Expand All @@ -159,9 +157,9 @@ private NetworkModificationResult processApplication(List<Pair<String, List<Modi

private ApplicationStatus apply(List<ModificationInfos> modificationInfosList, Network network, ReportInfos reportInfos) {
ReportNode reportNode;
if (reportInfos.getReporterId() != null) {
String rootReporterId = reportInfos.getReporterId() + "@" + NETWORK_MODIFICATION_TYPE_REPORT;
reportNode = ReportNode.newRootReportNode().withMessageTemplate(rootReporterId, rootReporterId).build();
if (reportInfos.getNodeUuid() != null) {
UUID nodeUuid = reportInfos.getNodeUuid();
reportNode = ReportNode.newRootReportNode().withMessageTemplate(nodeUuid.toString(), nodeUuid.toString()).build();
} else {
reportNode = ReportNode.NO_OP;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public Network cloneNetworkVariant(UUID networkUuid,
@Transactional(readOnly = true)
public NetworkModificationResult buildVariant(@NonNull UUID networkUuid, @NonNull BuildInfos buildInfos) {
// Apply all modifications belonging to the modification groups uuids in buildInfos
List<Pair<String, List<ModificationInfos>>> modificationInfos = new ArrayList<>();
List<Pair<ReportInfos, List<ModificationInfos>>> modificationInfos = new ArrayList<>();

Streams.forEachPair(buildInfos.getModificationGroupUuids().stream(), buildInfos.getReporterIds().stream(),
Streams.forEachPair(buildInfos.getModificationGroupUuids().stream(), buildInfos.getReportsInfos().stream(),
(groupUuid, reporterId) -> {
List<ModificationInfos> modificationsByGroup = List.of();
try {
Expand Down Expand Up @@ -199,7 +199,7 @@ public NetworkModificationResult buildVariant(@NonNull UUID networkUuid, @NonNul
Network network = cloneNetworkVariant(networkUuid, buildInfos.getOriginVariantId(), buildInfos.getDestinationVariantId(), preloadingStrategy);
NetworkInfos networkInfos = new NetworkInfos(network, networkUuid, true);

return modificationApplicator.applyModifications(modificationInfos, networkInfos, buildInfos.getReportUuid());
return modificationApplicator.applyModifications(modificationInfos, networkInfos);
}

public void buildVariantRequest(UUID networkUuid, BuildInfos buildInfos, String receiver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ public void testApplyModificationsFromUuids() throws Exception {
// apply the modification on the network
mvcResult = mockMvc.perform(
put("/v1/networks/" + TEST_NETWORK_ID + "/apply"
+ "?variantId=" + NetworkCreation.VARIANT_ID)
+ "?variantId=" + NetworkCreation.VARIANT_ID + "&reporterId=" + UUID.randomUUID().toString())
.content(objectWriter.writeValueAsString(modificationUuidList))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andReturn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void testVoltageInitDuplicationLogs(final ApplicationStatus resultStatus, final
assertThat(networkModificationApplicator.applyModifications(
List.of(modificationInfos),
new NetworkInfos(network, networkUuuid, true),
new ReportInfos(reportUuid, "99999999-9999-9999-9999-999999999999")))
new ReportInfos(reportUuid, UUID.fromString("99999999-9999-9999-9999-999999999999"))))
.as("network modifications results")
.isNotNull()
.extracting(NetworkModificationResult::getApplicationStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ public class CompositeModificationsTest extends AbstractNetworkModificationTest
@Before
public void specificSetUp() {
// Currently we never apply composite modifications (apply mocked)
NetworkModificationResult networkModificationResultMock =
NetworkModificationResult.builder()
.applicationStatus(NetworkModificationResult.ApplicationStatus.ALL_OK)
.lastGroupApplicationStatus(NetworkModificationResult.ApplicationStatus.ALL_OK)
.networkImpacts(List.of())
.build();
when(networkModificationApplicator.applyModifications(any(), any(), any(ReportInfos.class))).then((Answer<NetworkModificationResult>) invocation -> networkModificationResultMock);
when(networkModificationApplicator.applyModifications(any(), any(), any(UUID.class))).then((Answer<NetworkModificationResult>) invocation -> networkModificationResultMock);
NetworkModificationResult networkModificationResultMock = NetworkModificationResult.builder()
.applicationStatus(NetworkModificationResult.ApplicationStatus.ALL_OK)
.lastGroupApplicationStatus(NetworkModificationResult.ApplicationStatus.ALL_OK)
.networkImpacts(List.of())
.build();
when(networkModificationApplicator.applyModifications(any(), any(), any(ReportInfos.class)))
.then((Answer<NetworkModificationResult>) invocation -> networkModificationResultMock);
when(networkModificationApplicator.applyModifications(any(), any(), any(ReportInfos.class)))
.then((Answer<NetworkModificationResult>) invocation -> networkModificationResultMock);
}

@Override
Expand All @@ -66,10 +67,10 @@ protected Network createNetwork(UUID networkUuid) {
@Override
protected ModificationInfos buildModification() {
List<ModificationInfos> modifications = List.of(
ModificationCreation.getCreationGenerator("v1", "idGenerator", "nameGenerator", "1B", "v2load", "LOAD", "v1"),
ModificationCreation.getCreationGenerator("v1", "idGenerator", "nameGenerator", "1B", "v2load", "LOAD",
"v1"),
ModificationCreation.getCreationLoad("v1", "idLoad", "nameLoad", "1.1", LoadType.UNDEFINED),
ModificationCreation.getCreationBattery("v1", "idBattery", "nameBattry", "1.1")
);
ModificationCreation.getCreationBattery("v1", "idBattery", "nameBattry", "1.1"));
return CompositeModificationInfos.builder()
.modifications(modifications)
.stashed(false)
Expand Down Expand Up @@ -107,7 +108,7 @@ public void testCheckSqlRequestsCount() throws Exception {
SQLStatementCountValidator.reset();

mockMvc.perform(get("/v1/network-modifications/{uuid}", modificationUuid)).andExpectAll(
status().isOk(), content().contentType(MediaType.APPLICATION_JSON))
status().isOk(), content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
assertSelectCount(7);
SQLStatementCountValidator.reset();
Expand Down
Loading

0 comments on commit 977b4d1

Please sign in to comment.