-
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.
add indexed attribute index only elements marked for indexation (#39)
Signed-off-by: jamal-khey <myjamal89@gmail.com>
- Loading branch information
Showing
14 changed files
with
475 additions
and
79 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
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
82 changes: 82 additions & 0 deletions
82
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,82 @@ | ||
/** | ||
* 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.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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/powsybl/caseserver/services/SupervisionService.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,43 @@ | ||
/** | ||
* 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.services; | ||
|
||
import com.powsybl.caseserver.elasticsearch.CaseInfosRepository; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
/** | ||
* @author Jamal KHEYYAD <jamal.kheyyad at rte-international.com> | ||
*/ | ||
@Service | ||
public class SupervisionService { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionService.class); | ||
|
||
private final CaseInfosRepository caseInfosRepository; | ||
|
||
public SupervisionService(CaseInfosRepository caseInfosRepository) { | ||
this.caseInfosRepository = caseInfosRepository; | ||
} | ||
|
||
public long deleteIndexedCases() { | ||
AtomicReference<Long> startTime = new AtomicReference<>(); | ||
startTime.set(System.nanoTime()); | ||
|
||
long nbIndexesToDelete = getIndexedCasesCount(); | ||
caseInfosRepository.deleteAll(); | ||
LOGGER.trace("Indexed cases deletion : {} seconds", TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime.get())); | ||
return nbIndexesToDelete; | ||
} | ||
|
||
public long getIndexedCasesCount() { | ||
return caseInfosRepository.count(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/resources/db/changelog/changesets/changelog_20240726T144717Z.xml
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,10 @@ | ||
<?xml version="1.1" encoding="UTF-8" standalone="no"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||
<changeSet author="jamalk (generated)" id="1722005243703-1"> | ||
<addColumn tableName="case_metadata"> | ||
<column defaultValueBoolean="false" name="indexed" type="boolean"> | ||
<constraints nullable="false"/> | ||
</column> | ||
</addColumn> | ||
</changeSet> | ||
</databaseChangeLog> |
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.