Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize temporary and permanent limits db writings and db reading #82

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion network-store-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@Schema(description = "limits attributes")
public class LimitsInfos {

@Schema(description = "List of permeant limits")
@Schema(description = "List of permanent limits")
private List<PermanentLimitAttributes> permanentLimits = new ArrayList<>();

@Schema(description = "List of temporary limits")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.network.store.server.json;

import com.powsybl.iidm.network.LimitType;
import com.powsybl.network.store.server.dto.PermanentLimitAttributes;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
@ToString
@Builder
@AllArgsConstructor
@Getter
public class PermanentLimitSqlData {

private String operationalLimitsGroupId;
private double value;
private Integer side;
private LimitType limitType;

public PermanentLimitSqlData() {
// empty constructor for Jackson
}

public static PermanentLimitSqlData of(PermanentLimitAttributes permanentLimitAttributes) {
return PermanentLimitSqlData.builder()
.operationalLimitsGroupId(permanentLimitAttributes.getOperationalLimitsGroupId())
.value(permanentLimitAttributes.getValue())
.side(permanentLimitAttributes.getSide())
.limitType(permanentLimitAttributes.getLimitType())
.build();
}

public PermanentLimitAttributes toPermanentLimitAttributes() {
return PermanentLimitAttributes.builder()
.operationalLimitsGroupId(operationalLimitsGroupId)
.value(value)
.side(side)
.limitType(limitType)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.network.store.server.json;

import com.powsybl.iidm.network.LimitType;
import com.powsybl.network.store.model.TemporaryLimitAttributes;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
@ToString
@Builder
@AllArgsConstructor
@Getter
public class TemporaryLimitSqlData {
private String operationalLimitsGroupId;
private Integer side;
private LimitType limitType;
private String name;
private double value;
private Integer acceptableDuration;
private boolean fictitious;

public TemporaryLimitSqlData() {
// empty constructor for Jackson
}

public static TemporaryLimitSqlData of(TemporaryLimitAttributes temporaryLimit) {
return TemporaryLimitSqlData.builder()
.operationalLimitsGroupId(temporaryLimit.getOperationalLimitsGroupId())
.side(temporaryLimit.getSide())
.limitType(temporaryLimit.getLimitType())
.name(temporaryLimit.getName())
.value(temporaryLimit.getValue())
.acceptableDuration(temporaryLimit.getAcceptableDuration())
.fictitious(temporaryLimit.isFictitious())
.build();
}

public TemporaryLimitAttributes toTemporaryLimitAttributes() {
return TemporaryLimitAttributes.builder()
.operationalLimitsGroupId(operationalLimitsGroupId)
.side(side)
.limitType(limitType)
.name(name)
.value(value)
.acceptableDuration(acceptableDuration)
.fictitious(fictitious)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="2986331049275-5" author="lesoteti">
<createTable tableName="newtemporarylimits">
<column name="networkuuid" type="VARCHAR(255)">
<constraints nullable="false" primaryKey="true" primaryKeyName="newtemporarylimits_pkey"/>
</column>
<column name="variantnum" type="INTEGER">
<constraints nullable="false" primaryKey="true" primaryKeyName="newtemporarylimits_pkey"/>
</column>
<column name="equipmentid" type="VARCHAR(255)">
<constraints nullable="false" primaryKey="true" primaryKeyName="newtemporarylimits_pkey"/>
</column>
<column name="equipmenttype" type="VARCHAR(255)">
</column>
<column name="temporarylimits" type="TEXT"/>
</createTable>
<createTable tableName="newpermanentlimits">
<column name="networkuuid" type="VARCHAR(255)">
<constraints nullable="false" primaryKey="true" primaryKeyName="newpermanentlimits_pkey"/>
</column>
<column name="variantnum" type="INTEGER">
<constraints nullable="false" primaryKey="true" primaryKeyName="newpermanentlimits_pkey"/>
</column>
<column name="equipmentid" type="VARCHAR(255)">
<constraints nullable="false" primaryKey="true" primaryKeyName="newpermanentlimits_pkey"/>
</column>
<column name="equipmenttype" type="VARCHAR(255)">
</column>
<column name="permanentlimits" type="TEXT"/>
</createTable>
<createIndex indexName="permanentlimits_networkuuid_variantnum_equipmenttype_idx" tableName="newpermanentlimits">
<column name="networkuuid"/>
<column name="variantnum"/>
<column name="equipmenttype"/>
</createIndex>
<createIndex indexName="temporarylimits_networkuuid_variantnum_equipmenttype_idx" tableName="newtemporarylimits">
<column name="networkuuid"/>
<column name="variantnum"/>
<column name="equipmenttype"/>
</createIndex>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- will be used in next deployment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of doing the liquibase migration by doing a java change that just calls the same method as the one used for users

INSERT INTO newtemporarylimits (equipmentid, equipmenttype, networkuuid, variantnum, temporarylimits)
SELECT equipmentid, equipmenttype, networkuuid, variantnum,
json_agg(json_build_object(
'operationalLimitsGroupId', operationalLimitsGroupId,
'side', side,
'limitType', limitType,
'name', name,
'value', value_,
'acceptableDuration', acceptableduration,
'fictitious', fictitious
)) as temporarylimits FROM temporarylimit
GROUP BY equipmentid, equipmenttype, networkuuid, variantnum;
INSERT INTO newpermanentlimits (equipmentid, equipmenttype, networkuuid, variantnum, permanentlimits)
SELECT equipmentid, equipmenttype, networkuuid, variantnum,
json_agg(json_build_object(
'operationalLimitsGroupId', operationalLimitsGroupId,
'value', value_,
'side', side,
'limitType', limitType
)) as permanentlimits FROM permanentlimit
GROUP BY equipmentid, equipmenttype, networkuuid, variantnum;
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ databaseChangeLog:
- include:
file: changesets/changelog_20241031T110000Z.xml
relativeToChangelogFile: true

- include:
file: changesets/changelog_20241121T110000Z.xml
relativeToChangelogFile: true
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<properties>
<sirocco.version>1.0</sirocco.version>
<powsybl-ws-dependencies.version>2.16.0</powsybl-ws-dependencies.version>

<!-- FIXME : to remove when sonar version is updated on github actions -->
<!-- https://community.sonarsource.com/t/stackoverflowerror-at-defaultinputcomponent-equals/20324 -->
<!-- The versions are very different from this post. But the fix works again. Maybe a similar problem in sonar code -->
Expand Down
Loading