-
Notifications
You must be signed in to change notification settings - Fork 1
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
disable auto case indexation #39
Merged
Merged
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
49f5a76
add indexed attribute
jamal-khey eb50035
index only elements marked for indexation
jamal-khey 3faccb1
fix syles
jamal-khey 397d9c4
add delete index
jamal-khey 4fb0ead
renaming endpoints
jamal-khey dff6051
add tests
jamal-khey f8761fa
fix old tests
jamal-khey 82643ee
add tests for supervision controller
jamal-khey eab35af
Merge branch 'refs/heads/main' into jamalkhey/disable-auto-case-index…
jamal-khey 66fafa8
clean conde
jamal-khey 571a851
check styles
jamal-khey 4abc90c
split test
jamal-khey d787751
split test
jamal-khey 51bbe76
split test
jamal-khey 11f42d1
assert queues are empty after each test
jamal-khey 809b620
clean code
jamal-khey cb26803
impove test and coverage
jamal-khey 5524154
fix review comments
jamal-khey 9f80c67
fix review comments
jamal-khey d4f5b02
remove any ref to elements
jamal-khey 08a7a2d
throw NOT_Found
jamal-khey e821fe6
extract getCaseMetaDataEntity into a function
jamal-khey 0f911ae
Review
jamal-khey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 directory elements index name") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Indexed directory elements index name")}) | ||
public ResponseEntity<String> getIndexedDirectoryElementsIndexName() { | ||
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(caseInfosService.getDirectoryElementsIndexName()); | ||
} | ||
|
||
@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 elements") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all indexed elements have been deleted")}) | ||
public ResponseEntity<String> deleteIndexedDirectoryElements() { | ||
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.deleteIndexedDirectoryElements())); | ||
} | ||
|
||
@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 deleteIndexedDirectoryElements() { | ||
AtomicReference<Long> startTime = new AtomicReference<>(); | ||
startTime.set(System.nanoTime()); | ||
|
||
long nbIndexesToDelete = getIndexedCasesCount(); | ||
caseInfosRepository.deleteAll(); | ||
LOGGER.trace("Indexed directory elements 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throws
NO_FOUND
exception likedisableCaseExpiration