-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
583 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/com/powsybl/caseserver/SupervisionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* 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.caseserver; | ||
|
||
import com.powsybl.caseserver.elasticsearch.CaseInfosService; | ||
import com.powsybl.caseserver.server.CaseService; | ||
import com.powsybl.caseserver.services.SupervisionService; | ||
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.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.data.elasticsearch.client.ClientConfiguration; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* @author Jamal KHEYYAD <jamal.kheyyad at rte-international.com> | ||
*/ | ||
@RestController | ||
@RequestMapping(value = "/" + CaseConstants.API_VERSION + "/supervision") | ||
@Tag(name = "case-server - Supervision") | ||
public class SupervisionController { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionController.class); | ||
|
||
private final SupervisionService supervisionService; | ||
private final CaseService caseService; | ||
private final ClientConfiguration elasticsearchClientConfiguration; | ||
private final CaseInfosService caseInfosService; | ||
|
||
public SupervisionController(SupervisionService supervisionService, CaseService caseService, ClientConfiguration elasticsearchClientConfiguration, CaseInfosService caseInfosService) { | ||
this.supervisionService = supervisionService; | ||
this.caseService = caseService; | ||
this.elasticsearchClientConfiguration = elasticsearchClientConfiguration; | ||
this.caseInfosService = caseInfosService; | ||
} | ||
|
||
@GetMapping(value = "/elasticsearch-host") | ||
@Operation(summary = "get the elasticsearch address") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "the elasticsearch address")}) | ||
public ResponseEntity<String> getElasticsearchHost() { | ||
String host = elasticsearchClientConfiguration.getEndpoints().get(0).getHostName() | ||
+ ":" | ||
+ elasticsearchClientConfiguration.getEndpoints().get(0).getPort(); | ||
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(host); | ||
} | ||
|
||
@GetMapping(value = "/cases/index-name") | ||
@Operation(summary = "get the indexed cases index name") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Indexed directory cases index name")}) | ||
public ResponseEntity<String> getIndexedCasesFIndexName() { | ||
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(caseInfosService.getDirectoryCasesIndexName()); | ||
} | ||
|
||
@PostMapping(value = "/cases/reindex") | ||
@Operation(summary = "reindex all cases") | ||
public ResponseEntity<Void> reindexAllCases() { | ||
LOGGER.debug("reindex all cases request received"); | ||
caseInfosService.recreateAllCaseInfos(caseService.getCasesToReindex()); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@DeleteMapping(value = "/cases/indexation") | ||
@Operation(summary = "delete indexed cases") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all indexed cases have been deleted")}) | ||
public ResponseEntity<String> deleteIndexedCases() { | ||
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.deleteIndexedCases())); | ||
} | ||
|
||
@GetMapping(value = "/cases/indexation-count") | ||
@Operation(summary = "get indexed cases count") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Indexed cases count")}) | ||
public ResponseEntity<String> getIndexedCasesCount() { | ||
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.getIndexedCasesCount())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.