-
Notifications
You must be signed in to change notification settings - Fork 10
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
21 changed files
with
421 additions
and
17 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
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
8 changes: 8 additions & 0 deletions
8
src/main/java/org/folio/search/exception/ReindexException.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,8 @@ | ||
package org.folio.search.exception; | ||
|
||
public class ReindexException extends RuntimeException { | ||
|
||
public ReindexException(String errorMessage) { | ||
super(errorMessage); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/folio/search/integration/ReindexKafkaListener.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,32 @@ | ||
package org.folio.search.integration; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.folio.search.model.event.ReindexRangeIndexEvent; | ||
import org.folio.search.service.consortium.ConsortiumTenantExecutor; | ||
import org.folio.search.service.reindex.ReindexService; | ||
import org.folio.search.utils.KafkaConstants; | ||
import org.folio.spring.service.SystemUserScopedExecutionService; | ||
import org.springframework.kafka.annotation.KafkaListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Log4j2 | ||
@Component | ||
@RequiredArgsConstructor | ||
public class ReindexKafkaListener { | ||
|
||
private final ReindexService reindexService; | ||
private final ConsortiumTenantExecutor executionService; | ||
private final SystemUserScopedExecutionService systemUserScopedExecutionService; | ||
|
||
@KafkaListener( | ||
id = KafkaConstants.REINDEX_RANGE_INDEX_LISTENER_ID, | ||
containerFactory = "rangeIndexListenerContainerFactory", | ||
topicPattern = "#{folioKafkaProperties.listener['reindex-range-index'].topicPattern}", | ||
groupId = "#{folioKafkaProperties.listener['reindex-range-index'].groupId}", | ||
concurrency = "#{folioKafkaProperties.listener['reindex-range-index'].concurrency}") | ||
public void handleInstanceEvents(ReindexRangeIndexEvent event) { | ||
systemUserScopedExecutionService.executeSystemUserScoped(event.getTenant(), | ||
() -> executionService.execute(() -> reindexService.process(event))); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/folio/search/model/event/ReindexRangeIndexEvent.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 |
---|---|---|
@@ -1,16 +1,27 @@ | ||
package org.folio.search.model.event; | ||
|
||
import java.util.UUID; | ||
import lombok.Data; | ||
import org.folio.search.model.types.ReindexEntityType; | ||
import org.folio.spring.tools.kafka.BaseKafkaMessage; | ||
|
||
@Data | ||
public class ReindexRangeIndexEvent implements BaseKafkaMessage { | ||
|
||
private UUID id; | ||
private ReindexEntityType entityType; | ||
private int offset; | ||
private int limit; | ||
|
||
private String tenant; | ||
private String ts; | ||
} | ||
|
||
//{ | ||
// "id": "8b00efbd-07e0-48c1-a691-d259d9c67e37", | ||
// "entityType": "SUBJECT", | ||
// "offset": 0, | ||
// "limit": 10, | ||
// "tenant": "test_tenant" | ||
//} | ||
|
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
29 changes: 29 additions & 0 deletions
29
src/main/java/org/folio/search/service/reindex/ReindexService.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,29 @@ | ||
package org.folio.search.service.reindex; | ||
|
||
import java.util.Collection; | ||
import lombok.RequiredArgsConstructor; | ||
import org.folio.search.domain.dto.FolioIndexOperationResponse; | ||
import org.folio.search.exception.ReindexException; | ||
import org.folio.search.model.event.ReindexRangeIndexEvent; | ||
import org.folio.search.repository.PrimaryResourceRepository; | ||
import org.folio.search.service.converter.MultiTenantSearchDocumentConverter; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReindexService { | ||
|
||
private final ReindexRangeIndexService rangeIndexService; | ||
private final PrimaryResourceRepository elasticRepository; | ||
private final MultiTenantSearchDocumentConverter documentConverter; | ||
|
||
public boolean process(ReindexRangeIndexEvent event) { | ||
var resourceEvents = rangeIndexService.fetchRecordRange(event); | ||
var documents = documentConverter.convert(resourceEvents).values().stream().flatMap(Collection::stream).toList(); | ||
var folioIndexOperationResponse = elasticRepository.indexResources(documents); | ||
if (folioIndexOperationResponse.getStatus() == FolioIndexOperationResponse.StatusEnum.ERROR) { | ||
throw new ReindexException(folioIndexOperationResponse.getErrorMessage()); | ||
} | ||
return true; | ||
} | ||
} |
24 changes: 22 additions & 2 deletions
24
src/main/java/org/folio/search/service/reindex/jdbc/ClassificationJdbcRepository.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
25 changes: 23 additions & 2 deletions
25
src/main/java/org/folio/search/service/reindex/jdbc/ContributorJdbcRepository.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
34 changes: 32 additions & 2 deletions
34
src/main/java/org/folio/search/service/reindex/jdbc/InstanceJdbcRepository.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
Oops, something went wrong.