Skip to content
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
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on:
push:
branches:
- 'main'
pull_request:

jobs:
build:
uses: powsybl/github-ci/.github/workflows/build-backend-app-generic.yml@aaae75875296657028f2805e7a3fbdb1418b8b95
with:
dockerImage: docker.io/gridsuite/dynamic-margin-calculation-server
dockerUsername: gridsuiteci
eventType: dynamic_margin_calculation_server_updated
secrets:
sonar-token: ${{ secrets.SONAR_TOKEN }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
repo-token: ${{ secrets.REPO_ACCESS_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/patch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Patch

on:
workflow_dispatch:
inputs:
releaseVersion:
description: version to patch (vX.X)
required: true

jobs:
run-patch:
uses: powsybl/github-ci/.github/workflows/patch-backend-app-generic.yml@aaae75875296657028f2805e7a3fbdb1418b8b95
with:
githubappId: ${{ vars.GRIDSUITE_ACTIONS_APPID }}
dockerImage: docker.io/gridsuite/dynamic-margin-calculation-server
dockerUsername: gridsuiteci
releaseVersion: ${{ github.event.inputs.releaseVersion }}
secrets:
VERSIONBUMP_GHAPP_PRIVATE_KEY: ${{ secrets.VERSIONBUMP_GHAPP_PRIVATE_KEY }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release

on:
workflow_dispatch:
inputs:
releaseVersion:
description: Release version (vX.X)
required: true
gitReference:
description: SHA of the commit from where to release or branch name
required: true

jobs:
run-release:
uses: powsybl/github-ci/.github/workflows/release-backend-app-generic.yml@aaae75875296657028f2805e7a3fbdb1418b8b95
with:
githubappId: ${{ vars.GRIDSUITE_ACTIONS_APPID }}
dockerImage: docker.io/gridsuite/dynamic-margin-calculation-server
dockerUsername: gridsuiteci
releaseVersion: ${{ github.event.inputs.releaseVersion }}
gitReference: ${{ github.event.inputs.gitReference }}
secrets:
VERSIONBUMP_GHAPP_PRIVATE_KEY: ${{ secrets.VERSIONBUMP_GHAPP_PRIVATE_KEY }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
1 change: 1 addition & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import target/configs/powsybl-build-tools.jar!powsybl-build-tools/lombok.config
48 changes: 17 additions & 31 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2024, RTE (http://www.rte-france.com)
Copyright (c) 2025, 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/.
Expand Down Expand Up @@ -42,14 +42,16 @@
</developers>

<properties>
<gridsuite-dependencies.version>39.0.0</gridsuite-dependencies.version>
<gridsuite-dependencies.version>43.0.0</gridsuite-dependencies.version>
<!-- FIXME to remove at next upgrade of gridsuite-dependencies -->
<gridsuite-computation.version>1.3.0</gridsuite-computation.version>
<!-- FIXME to remove at next upgrade of powsybl-ws-dependencies -->
<powsybl-ws-commons.version>1.28.0</powsybl-ws-commons.version>

<jib.from.image>powsybl/java-dynawo:3.0.0</jib.from.image>
<liquibase-hibernate-package>org.gridsuite.dynamicmargincalculation.server</liquibase-hibernate-package>
<sonar.organization>gridsuite</sonar.organization>
<spring-cloud-aws.version>3.2.0</spring-cloud-aws.version>
<sonar.projectKey>org.gridsuite:dynamic-margin-calculation-server</sonar.projectKey>
<!-- FIXME: powsybl-ws-commons modules'version is overloaded in the dependencies section to be removed at next powsybl-ws-dependencies.version upgrade -->
<powsybl-ws-commons.version>1.26.0-SNAPSHOT</powsybl-ws-commons.version>
</properties>

<build>
Expand Down Expand Up @@ -89,21 +91,7 @@
<dependencyManagement>
<dependencies>
<!-- overrides of imports -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-computation-local</artifactId>
<version>6.8.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-computation</artifactId>
<version>6.8.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-api</artifactId>
<version>6.8.0-SNAPSHOT</version>
</dependency>

<!-- imports -->
<dependency>
<groupId>org.gridsuite</groupId>
Expand All @@ -119,6 +107,11 @@

<dependencies>
<!-- Compilation dependencies -->
<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-computation</artifactId>
<version>${gridsuite-computation.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -128,13 +121,12 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-starter-s3</artifactId>
<version>${spring-cloud-aws.version}</version>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
Expand All @@ -161,15 +153,9 @@
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-dynawo-margin-calculation</artifactId>
<version>2.9.0-SNAPSHOT</version>
</dependency>

<!-- runtime dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2025, 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 org.gridsuite.dynamicmargincalculation.server;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
public final class DynamicMarginCalculationApi {

private DynamicMarginCalculationApi() {
}

public static final String API_VERSION = "v1";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2025, 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 org.gridsuite.dynamicmargincalculation.server;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@SuppressWarnings("checkstyle:HideUtilityClassConstructor")
@SpringBootApplication
public class DynamicMarginCalculationApplication {

public static void main(String[] args) {
SpringApplication.run(DynamicMarginCalculationApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2025, 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 org.gridsuite.dynamicmargincalculation.server;

import lombok.Getter;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@Getter
public class DynamicMarginCalculationException extends RuntimeException {

public enum Type {
RESULT_UUID_NOT_FOUND,
}

private final Type type;

public DynamicMarginCalculationException(Type type, String message) {
super(message);
this.type = type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2025, 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 org.gridsuite.dynamicmargincalculation.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@ControllerAdvice
public class RestResponseEntityExceptionHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(RestResponseEntityExceptionHandler.class);

@ExceptionHandler(DynamicMarginCalculationException.class)
protected ResponseEntity<Object> handleDynamicSecurityAnalysisException(DynamicMarginCalculationException exception) {

Choose a reason for hiding this comment

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

Suggested change
protected ResponseEntity<Object> handleDynamicSecurityAnalysisException(DynamicMarginCalculationException exception) {
protected ResponseEntity<Object> handleDynamicMarginCalculationException(DynamicMarginCalculationException exception) {

if (LOGGER.isErrorEnabled()) {
LOGGER.error(exception.getMessage(), exception);
}

DynamicMarginCalculationException.Type type = exception.getType();
return switch (type) {
case RESULT_UUID_NOT_FOUND
-> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage());
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2025, 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 org.gridsuite.dynamicmargincalculation.server.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.gridsuite.dynamicmargincalculation.server.DynamicMarginCalculationApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@Configuration
public class SwaggerConfig {

@Bean
public OpenAPI createOpenApi() {
return new OpenAPI()
.info(new Info()
.title("Dynamic Margin Calculation Server API")
.description("This is the documentation of the Dynamic-Margin-Calculation REST API")
.version(DynamicMarginCalculationApi.API_VERSION));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2025, 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 org.gridsuite.dynamicmargincalculation.server.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.gridsuite.dynamicmargincalculation.server.DynamicMarginCalculationApi;
import org.gridsuite.dynamicmargincalculation.server.service.SupervisionService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@RestController
@RequestMapping(value = "/" + DynamicMarginCalculationApi.API_VERSION + "/supervision")
@Tag(name = "Dynamic margin calculation server - Supervision")
public class SupervisionController {
private final SupervisionService supervisionService;

public SupervisionController(SupervisionService supervisionService) {
this.supervisionService = supervisionService;
}

@GetMapping(value = "/results-count")
@Operation(summary = "Get results count")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The count of all results")})
public ResponseEntity<Integer> getResultsCount() {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getResultsCount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2025, 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 org.gridsuite.dynamicmargincalculation.server.dto;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
public enum DynamicMarginCalculationStatus {
NOT_DONE,
RUNNING,
SUCCEED,
FAILED
}
Loading