Skip to content

Commit b05ba83

Browse files
committed
Dynamic Margin Calculation (DMC) - First implementation
Signed-off-by: Thang PHAM <[email protected]>
1 parent f692e44 commit b05ba83

21 files changed

+651
-13
lines changed

lombok.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import target/configs/powsybl-build-tools.jar!powsybl-build-tools/lombok.config

pom.xml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@
4242
</developers>
4343

4444
<properties>
45-
<gridsuite-dependencies.version>39.0.0</gridsuite-dependencies.version>
45+
<gridsuite-dependencies.version>41.0.0</gridsuite-dependencies.version>
4646
<jib.from.image>powsybl/java-dynawo:3.0.0</jib.from.image>
4747
<liquibase-hibernate-package>org.gridsuite.dynamicmargincalculation.server</liquibase-hibernate-package>
4848
<sonar.organization>gridsuite</sonar.organization>
49-
<spring-cloud-aws.version>3.2.0</spring-cloud-aws.version>
5049
<sonar.projectKey>org.gridsuite:dynamic-margin-calculation-server</sonar.projectKey>
51-
<!-- FIXME: powsybl-ws-commons modules'version is overloaded in the dependencies section to be removed at next powsybl-ws-dependencies.version upgrade -->
52-
<powsybl-ws-commons.version>1.26.0-SNAPSHOT</powsybl-ws-commons.version>
5350
</properties>
5451

5552
<build>
@@ -92,17 +89,17 @@
9289
<dependency>
9390
<groupId>com.powsybl</groupId>
9491
<artifactId>powsybl-computation-local</artifactId>
95-
<version>6.8.0-SNAPSHOT</version>
92+
<version>6.8.0</version>
9693
</dependency>
9794
<dependency>
9895
<groupId>com.powsybl</groupId>
9996
<artifactId>powsybl-computation</artifactId>
100-
<version>6.8.0-SNAPSHOT</version>
97+
<version>6.8.0</version>
10198
</dependency>
10299
<dependency>
103100
<groupId>com.powsybl</groupId>
104101
<artifactId>powsybl-iidm-api</artifactId>
105-
<version>6.8.0-SNAPSHOT</version>
102+
<version>6.8.0</version>
106103
</dependency>
107104
<!-- imports -->
108105
<dependency>
@@ -131,11 +128,6 @@
131128
<groupId>org.springframework.cloud</groupId>
132129
<artifactId>spring-cloud-stream</artifactId>
133130
</dependency>
134-
<dependency>
135-
<groupId>io.awspring.cloud</groupId>
136-
<artifactId>spring-cloud-aws-starter-s3</artifactId>
137-
<version>${spring-cloud-aws.version}</version>
138-
</dependency>
139131
<dependency>
140132
<groupId>org.springdoc</groupId>
141133
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
@@ -152,7 +144,6 @@
152144
<dependency>
153145
<groupId>com.powsybl</groupId>
154146
<artifactId>powsybl-ws-commons</artifactId>
155-
<version>${powsybl-ws-commons.version}</version>
156147
</dependency>
157148
<dependency>
158149
<groupId>com.powsybl</groupId>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
package org.gridsuite.dynamicmargincalculation.server;
9+
10+
/**
11+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
12+
*/
13+
public final class DynamicMarginCalculationApi {
14+
15+
private DynamicMarginCalculationApi() {
16+
}
17+
18+
public static final String API_VERSION = "v1";
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.dynamicmargincalculation.server;
8+
9+
import org.springframework.boot.SpringApplication;
10+
import org.springframework.boot.autoconfigure.SpringBootApplication;
11+
12+
/**
13+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
14+
*/
15+
@SuppressWarnings("checkstyle:HideUtilityClassConstructor")
16+
@SpringBootApplication
17+
public class DynamicMarginCalculationApplication {
18+
19+
public static void main(String[] args) {
20+
SpringApplication.run(DynamicMarginCalculationApplication.class, args);
21+
}
22+
23+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.dynamicmargincalculation.server;
8+
9+
import lombok.Getter;
10+
11+
/**
12+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
13+
*/
14+
@Getter
15+
public class DynamicMarginCalculationException extends RuntimeException {
16+
17+
public enum Type {
18+
RESULT_UUID_NOT_FOUND,
19+
}
20+
21+
private final Type type;
22+
23+
public DynamicMarginCalculationException(Type type, String message) {
24+
super(message);
25+
this.type = type;
26+
}
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.dynamicmargincalculation.server;
8+
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
import org.springframework.http.HttpStatus;
12+
import org.springframework.http.ResponseEntity;
13+
import org.springframework.web.bind.annotation.ControllerAdvice;
14+
import org.springframework.web.bind.annotation.ExceptionHandler;
15+
16+
/**
17+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
18+
*/
19+
@ControllerAdvice
20+
public class RestResponseEntityExceptionHandler {
21+
22+
private static final Logger LOGGER = LoggerFactory.getLogger(RestResponseEntityExceptionHandler.class);
23+
24+
@ExceptionHandler(DynamicMarginCalculationException.class)
25+
protected ResponseEntity<Object> handleDynamicSecurityAnalysisException(DynamicMarginCalculationException exception) {
26+
if (LOGGER.isErrorEnabled()) {
27+
LOGGER.error(exception.getMessage(), exception);
28+
}
29+
30+
DynamicMarginCalculationException.Type type = exception.getType();
31+
return switch (type) {
32+
case RESULT_UUID_NOT_FOUND
33+
-> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage());
34+
};
35+
}
36+
37+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.dynamicmargincalculation.server.config;
8+
9+
import io.swagger.v3.oas.models.OpenAPI;
10+
import io.swagger.v3.oas.models.info.Info;
11+
import org.gridsuite.dynamicmargincalculation.server.DynamicMarginCalculationApi;
12+
import org.springframework.context.annotation.Bean;
13+
import org.springframework.context.annotation.Configuration;
14+
15+
/**
16+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
17+
*/
18+
@Configuration
19+
public class SwaggerConfig {
20+
21+
@Bean
22+
public OpenAPI createOpenApi() {
23+
return new OpenAPI()
24+
.info(new Info()
25+
.title("Dynamic Margin Calculation Server API")
26+
.description("This is the documentation of the Dynamic-Margin-Calculation REST API")
27+
.version(DynamicMarginCalculationApi.API_VERSION));
28+
}
29+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
package org.gridsuite.dynamicmargincalculation.server.controller;
8+
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
12+
import io.swagger.v3.oas.annotations.tags.Tag;
13+
import org.gridsuite.dynamicmargincalculation.server.DynamicMarginCalculationApi;
14+
import org.gridsuite.dynamicmargincalculation.server.service.SupervisionService;
15+
import org.springframework.http.MediaType;
16+
import org.springframework.http.ResponseEntity;
17+
import org.springframework.web.bind.annotation.GetMapping;
18+
import org.springframework.web.bind.annotation.RequestMapping;
19+
import org.springframework.web.bind.annotation.RestController;
20+
21+
/**
22+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
23+
*/
24+
@RestController
25+
@RequestMapping(value = "/" + DynamicMarginCalculationApi.API_VERSION + "/supervision")
26+
@Tag(name = "Dynamic margin calculation server - Supervision")
27+
public class SupervisionController {
28+
private final SupervisionService supervisionService;
29+
30+
public SupervisionController(SupervisionService supervisionService) {
31+
this.supervisionService = supervisionService;
32+
}
33+
34+
@GetMapping(value = "/results-count")
35+
@Operation(summary = "Get results count")
36+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The count of all results")})
37+
public ResponseEntity<Integer> getResultsCount() {
38+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getResultsCount());
39+
}
40+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
package org.gridsuite.dynamicmargincalculation.server.dto;
9+
10+
/**
11+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
12+
*/
13+
public enum DynamicMarginCalculationStatus {
14+
NOT_DONE,
15+
RUNNING,
16+
SUCCEED,
17+
FAILED
18+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
package org.gridsuite.dynamicmargincalculation.server.entities;
9+
10+
import jakarta.persistence.*;
11+
import lombok.Getter;
12+
import lombok.NoArgsConstructor;
13+
import lombok.Setter;
14+
import org.gridsuite.dynamicmargincalculation.server.dto.DynamicMarginCalculationStatus;
15+
16+
import java.util.UUID;
17+
18+
/**
19+
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
20+
*/
21+
@Getter
22+
@Setter
23+
@Table(name = "dynamic_margin_calculation_result")
24+
@NoArgsConstructor
25+
@Entity
26+
public class DynamicMarginCalculationResultEntity {
27+
28+
public DynamicMarginCalculationResultEntity(UUID id, DynamicMarginCalculationStatus status) {
29+
this.id = id;
30+
this.status = status;
31+
}
32+
33+
@Id
34+
@Column(name = "result_uuid")
35+
private UUID id;
36+
37+
@Column(name = "status")
38+
@Enumerated(EnumType.STRING)
39+
private DynamicMarginCalculationStatus status;
40+
41+
}

0 commit comments

Comments
 (0)