Skip to content

Commit

Permalink
V2.11 limits migration: apply changeset and clean v211 code (#91)
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Homer <[email protected]>
  • Loading branch information
etiennehomer authored Jan 29, 2025
1 parent 63ca2ab commit 1279d22
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import com.powsybl.network.store.server.exceptions.UncheckedSqlException;
import com.powsybl.network.store.server.json.PermanentLimitSqlData;
import com.powsybl.network.store.server.json.TemporaryLimitSqlData;
import com.powsybl.network.store.server.migration.v211limits.V211LimitsMigration;
import com.powsybl.network.store.server.migration.v211limits.V211LimitsQueryCatalog;
import com.powsybl.ws.commons.LogUtils;
import lombok.Getter;
import org.apache.commons.lang3.mutable.MutableInt;
Expand All @@ -46,7 +44,6 @@
import static com.powsybl.network.store.server.QueryCatalog.*;
import static com.powsybl.network.store.server.Utils.bindAttributes;
import static com.powsybl.network.store.server.Utils.bindValues;
import static com.powsybl.network.store.server.migration.v211limits.V211LimitsMigration.*;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand Down Expand Up @@ -284,23 +281,11 @@ public void deleteNetwork(UUID uuid) {
preparedStmt.execute();
}
}
// Delete of the temporary limits (which are not Identifiables objects)
//TODO: to be removed when limits are fully migrated — should be after v2.13 deployment
try (var preparedStmt = connection.prepareStatement(V211LimitsQueryCatalog.buildDeleteV211TemporaryLimitsQuery())) {
preparedStmt.setObject(1, uuid.toString());
preparedStmt.executeUpdate();
}
try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeleteTemporaryLimitsQuery())) {
preparedStmt.setObject(1, uuid.toString());
preparedStmt.executeUpdate();
}

// Delete permanent limits (which are not Identifiables objects)
//TODO: to be removed when limits are fully migrated — should be after v2.13 deployment
try (var preparedStmt = connection.prepareStatement(V211LimitsQueryCatalog.buildDeleteV211PermanentLimitsQuery())) {
preparedStmt.setObject(1, uuid.toString());
preparedStmt.executeUpdate();
}
try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeletePermanentLimitsQuery())) {
preparedStmt.setObject(1, uuid.toString());
preparedStmt.executeUpdate();
Expand Down Expand Up @@ -354,26 +339,12 @@ public void deleteNetwork(UUID uuid, int variantNum) {
preparedStmt.execute();
}
}
// Delete of the temporary limits (which are not Identifiables objects)
//TODO: to be removed when limits are fully migrated — should be after v2.13 deployment
try (var preparedStmt = connection.prepareStatement(V211LimitsQueryCatalog.buildDeleteV211TemporaryLimitsVariantQuery())) {
preparedStmt.setObject(1, uuid.toString());
preparedStmt.setInt(2, variantNum);
preparedStmt.executeUpdate();
}
try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeleteTemporaryLimitsVariantQuery())) {
preparedStmt.setObject(1, uuid.toString());
preparedStmt.setInt(2, variantNum);
preparedStmt.executeUpdate();
}

// Delete permanent limits (which are not Identifiables objects)
//TODO: to be removed when limits are fully migrated — should be after v2.13 deployment
try (var preparedStmt = connection.prepareStatement(V211LimitsQueryCatalog.buildDeleteV211PermanentLimitsVariantQuery())) {
preparedStmt.setObject(1, uuid.toString());
preparedStmt.setInt(2, variantNum);
preparedStmt.executeUpdate();
}
try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeletePermanentLimitsVariantQuery())) {
preparedStmt.setObject(1, uuid.toString());
preparedStmt.setInt(2, variantNum);
Expand Down Expand Up @@ -481,17 +452,6 @@ public void cloneNetworkElements(Connection connection, UUID uuid, UUID targetUu
}
}
// Copy of the temporary limits (which are not Identifiables objects)
//TODO: to be removed when limits are fully migrated — should be after v2.13 deployment
///////////////////////////////////////////////////////////////////////////////////////
int insertedRows = 0;
try (var preparedStmt = connection.prepareStatement(V211LimitsQueryCatalog.buildCloneV211TemporaryLimitsQuery())) {
preparedStmt.setString(1, targetUuid.toString());
preparedStmt.setInt(2, targetVariantNum);
preparedStmt.setString(3, uuid.toString());
preparedStmt.setInt(4, sourceVariantNum);
insertedRows += preparedStmt.executeUpdate();
}
///////////////////////////////////////////////////////////////////////////////////////
try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildCloneTemporaryLimitsQuery())) {
preparedStmt.setString(1, targetUuid.toString());
preparedStmt.setInt(2, targetVariantNum);
Expand All @@ -501,16 +461,6 @@ public void cloneNetworkElements(Connection connection, UUID uuid, UUID targetUu
}

// Copy of the permanent limits (which are not Identifiables objects)
//TODO: to be removed when limits are fully migrated — should be after v2.13 deployment
///////////////////////////////////////////////////////////////////////////////////////
try (var preparedStmt = connection.prepareStatement(V211LimitsQueryCatalog.buildCloneV211PermanentLimitsQuery())) {
preparedStmt.setString(1, targetUuid.toString());
preparedStmt.setInt(2, targetVariantNum);
preparedStmt.setString(3, uuid.toString());
preparedStmt.setInt(4, sourceVariantNum);
insertedRows += preparedStmt.executeUpdate();
}
///////////////////////////////////////////////////////////////////////////////////////
try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildClonePermanentLimitsQuery())) {
preparedStmt.setString(1, targetUuid.toString());
preparedStmt.setInt(2, targetVariantNum);
Expand All @@ -519,13 +469,6 @@ public void cloneNetworkElements(Connection connection, UUID uuid, UUID targetUu
preparedStmt.execute();
}

//TODO: to be removed when limits are fully migrated — should be after v2.13 deployment
// We don't want the V2.12 code to create V2.11 limits in the database and to inflate the remainder of the limits to migrate.
// So after the clone of the V2.11 limits, if some v2.11 limits were cloned, we migrate them.
if (insertedRows > 0) {
V211LimitsMigration.migrateV211Limits(this, targetUuid, targetVariantNum);
}

// Copy of the reactive capability curve points (which are not Identifiables objects)
try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildCloneReactiveCapabilityCurvePointsQuery())) {
preparedStmt.setString(1, targetUuid.toString());
Expand Down Expand Up @@ -1854,30 +1797,12 @@ public Map<OwnerInfo, List<PermanentLimitAttributes>> getPermanentLimitsWithInCl
}

public Map<OwnerInfo, LimitsInfos> getLimitsInfos(UUID networkUuid, int variantNum, String columnNameForWhereClause, String valueForWhereClause) {
//TODO: to be removed when limits are fully migrated — should be after v2.13 deployment
///////////////////////////////////////////////////////////////////////////////////////
Map<OwnerInfo, List<TemporaryLimitAttributes>> v211TemporaryLimits = getV211TemporaryLimits(this, networkUuid, variantNum, columnNameForWhereClause, valueForWhereClause);
Map<OwnerInfo, List<PermanentLimitAttributes>> v211PermanentLimits = getV211PermanentLimits(this, networkUuid, variantNum, columnNameForWhereClause, valueForWhereClause);
if (!v211TemporaryLimits.isEmpty() || !v211PermanentLimits.isEmpty()) {
return mergeLimitsIntoLimitsInfos(v211TemporaryLimits, v211PermanentLimits);
}
///////////////////////////////////////////////////////////////////////////////////////

Map<OwnerInfo, List<TemporaryLimitAttributes>> temporaryLimits = getTemporaryLimits(networkUuid, variantNum, columnNameForWhereClause, valueForWhereClause);
Map<OwnerInfo, List<PermanentLimitAttributes>> permanentLimits = getPermanentLimits(networkUuid, variantNum, columnNameForWhereClause, valueForWhereClause);
return mergeLimitsIntoLimitsInfos(temporaryLimits, permanentLimits);
}

public Map<OwnerInfo, LimitsInfos> getLimitsInfosWithInClause(UUID networkUuid, int variantNum, String columnNameForWhereClause, List<String> valuesForInClause) {
//TODO: to be removed when limits are fully migrated — should be after v2.13 deployment
///////////////////////////////////////////////////////////////////////////////////////
Map<OwnerInfo, List<TemporaryLimitAttributes>> v211TemporaryLimits = getV211TemporaryLimitsWithInClause(this, networkUuid, variantNum, columnNameForWhereClause, valuesForInClause);
Map<OwnerInfo, List<PermanentLimitAttributes>> v211PermanentLimits = getV211PermanentLimitsWithInClause(this, networkUuid, variantNum, columnNameForWhereClause, valuesForInClause);
if (!v211TemporaryLimits.isEmpty() || !v211PermanentLimits.isEmpty()) {
return mergeLimitsIntoLimitsInfos(v211TemporaryLimits, v211PermanentLimits);
}
///////////////////////////////////////////////////////////////////////////////////////

Map<OwnerInfo, List<TemporaryLimitAttributes>> temporaryLimits = getTemporaryLimitsWithInClause(networkUuid, variantNum, columnNameForWhereClause, valuesForInClause);
Map<OwnerInfo, List<PermanentLimitAttributes>> permanentLimits = getPermanentLimitsWithInClause(networkUuid, variantNum, columnNameForWhereClause, valuesForInClause);
return mergeLimitsIntoLimitsInfos(temporaryLimits, permanentLimits);
Expand Down Expand Up @@ -2099,9 +2024,6 @@ private <T extends LimitHolder> void insertPermanentLimitInEquipment(T equipment

private void deleteTemporaryLimits(UUID networkUuid, int variantNum, List<String> equipmentIds) {
try (var connection = dataSource.getConnection()) {
//TODO: To be removed when limits are fully migrated — should be after v2.13 deployment
deleteV211TemporaryLimits(connection, networkUuid, variantNum, equipmentIds);

try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeleteTemporaryLimitsVariantEquipmentINQuery(equipmentIds.size()))) {
preparedStmt.setString(1, networkUuid.toString());
preparedStmt.setInt(2, variantNum);
Expand All @@ -2117,9 +2039,6 @@ private void deleteTemporaryLimits(UUID networkUuid, int variantNum, List<String

private void deletePermanentLimits(UUID networkUuid, int variantNum, List<String> equipmentIds) {
try (var connection = dataSource.getConnection()) {
//TODO: To be removed when limits are fully migrated — should be after v2.13 deployment
deleteV211PermanentLimits(connection, networkUuid, variantNum, equipmentIds);

try (var preparedStmt = connection.prepareStatement(QueryCatalog.buildDeletePermanentLimitsVariantEquipmentINQuery(equipmentIds.size()))) {
preparedStmt.setString(1, networkUuid.toString());
preparedStmt.setInt(2, variantNum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public final class QueryCatalog {
static final String INDEX_COLUMN = "index";
static final String TAPCHANGER_TYPE_COLUMN = "tapChangerType";
static final String ALPHA_COLUMN = "alpha";
public static final String V211_TEMPORARY_LIMIT_TABLE = "v211temporarylimit";
public static final String V211_PERMANENT_LIMIT_TABLE = "v211permanentlimit";
static final String TEMPORARY_LIMITS_TABLE = "temporarylimits";
static final String TEMPORARY_LIMITS_COLUMN = "temporarylimits";
static final String PERMANENT_LIMITS_TABLE = "permanentlimits";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
public final class V211LimitsQueryCatalog {
public static final String MINIMAL_VALUE_REQUIREMENT_ERROR = "Function should not be called without at least one value.";
static final String LIMIT_TYPE_COLUMN = "limitType";
public static final String V211_TEMPORARY_LIMIT_TABLE = "v211temporarylimit";
public static final String V211_PERMANENT_LIMIT_TABLE = "v211permanentlimit";

private V211LimitsQueryCatalog() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet author="homereti" id="8428118131015-1">
<customChange class="com.powsybl.network.store.server.migration.V211LimitsMigration"/>
<customChange class="com.powsybl.network.store.server.migration.v211limits.V211LimitsMigration"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ databaseChangeLog:
file: changesets/changelog_20241121T110000Z.xml
relativeToChangelogFile: true

# Migration of V2.11 limits. To be added before tag v2.13.0 is deployed
# - include:
# file: changesets/changelog_20241223T130000Z.xml
# relativeToChangelogFile: true
- include:
file: changesets/changelog_20241223T130000Z.xml
relativeToChangelogFile: true

# Deletion of V2.11 limits tables. To be added before tag v2.14.0 is deployed
# - include:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import static com.powsybl.network.store.server.NetworkStoreRepository.BATCH_SIZE;
import static com.powsybl.network.store.server.QueryCatalog.*;
import static com.powsybl.network.store.server.Utils.bindValues;
import static com.powsybl.network.store.server.migration.v211limits.V211LimitsQueryCatalog.V211_PERMANENT_LIMIT_TABLE;
import static com.powsybl.network.store.server.migration.v211limits.V211LimitsQueryCatalog.V211_TEMPORARY_LIMIT_TABLE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down

0 comments on commit 1279d22

Please sign in to comment.