-
Notifications
You must be signed in to change notification settings - Fork 3
MODLD-907: Reindex job status endpoint introduced #462
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
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
62 changes: 62 additions & 0 deletions
62
src/main/java/org/folio/linked/data/mapper/dto/ReindexJobStatusMapper.java
This file contains hidden or 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,62 @@ | ||
| package org.folio.linked.data.mapper.dto; | ||
|
|
||
| import static java.util.Objects.isNull; | ||
| import static java.util.Optional.ofNullable; | ||
| import static org.folio.linked.data.configuration.batch.BatchConfig.REINDEX_STEP_NAME; | ||
| import static org.folio.linked.data.domain.dto.ReindexJobStatusDto.ReindexTypeEnum.FULL; | ||
| import static org.folio.linked.data.domain.dto.ReindexJobStatusDto.ReindexTypeEnum.INCREMENTAL; | ||
| import static org.mapstruct.MappingConstants.ComponentModel.SPRING; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.time.OffsetDateTime; | ||
| import java.time.ZoneOffset; | ||
| import java.util.Set; | ||
| import org.folio.linked.data.domain.dto.ReindexJobStatusDto; | ||
| import org.folio.linked.data.domain.dto.ReindexJobStatusDto.ReindexTypeEnum; | ||
| import org.folio.linked.data.model.entity.batch.BatchJobExecution; | ||
| import org.folio.linked.data.model.entity.batch.BatchStepExecution; | ||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.Mapping; | ||
|
|
||
| @Mapper(componentModel = SPRING) | ||
| public interface ReindexJobStatusMapper { | ||
|
|
||
| @Mapping(target = "startDate", source = "startTime") | ||
| @Mapping(target = "endDate", source = "endTime") | ||
| @Mapping(target = "reindexType", source = "isFullReindex") | ||
| @Mapping(target = "linesRead", expression = "java(linesRead(execution.getStepExecutions()))") | ||
| @Mapping(target = "linesSent", expression = "java(linesSent(execution.getStepExecutions()))") | ||
| ReindexJobStatusDto toDto(BatchJobExecution execution); | ||
|
|
||
| default OffsetDateTime toOffsetDateTime(LocalDateTime localDateTime) { | ||
| return ofNullable(localDateTime).map(ldt -> ldt.atOffset(ZoneOffset.UTC)).orElse(null); | ||
| } | ||
|
|
||
| default ReindexTypeEnum toReindexType(String isFullReindex) { | ||
| return ofNullable(isFullReindex) | ||
| .map(Boolean::parseBoolean) | ||
| .map(full -> full ? FULL : INCREMENTAL) | ||
| .orElse(null); | ||
| } | ||
|
|
||
| default Long linesRead(Set<BatchStepExecution> steps) { | ||
| return getReindexStepCount(steps, true); | ||
| } | ||
|
|
||
| default Long linesSent(Set<BatchStepExecution> steps) { | ||
| return getReindexStepCount(steps, false); | ||
| } | ||
|
|
||
| private Long getReindexStepCount(Set<BatchStepExecution> steps, boolean read) { | ||
| if (isNull(steps)) { | ||
| return 0L; | ||
| } | ||
| return steps.stream() | ||
| .filter(s -> REINDEX_STEP_NAME.equals(s.getStepName())) | ||
| .findFirst() | ||
| .map(s -> read | ||
| ? ofNullable(s.getReadCount()).orElse(0L) | ||
| : ofNullable(s.getWriteCount()).orElse(0L)) | ||
| .orElse(0L); | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/folio/linked/data/model/entity/batch/BatchJobExecution.java
This file contains hidden or 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,39 @@ | ||
| package org.folio.linked.data.model.entity.batch; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.OneToMany; | ||
| import java.time.LocalDateTime; | ||
| import java.util.Set; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import org.hibernate.annotations.Formula; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @EqualsAndHashCode(of = "jobExecutionId") | ||
| @Entity | ||
| public class BatchJobExecution { | ||
|
PBobylev marked this conversation as resolved.
|
||
|
|
||
| @Id | ||
| private Long jobExecutionId; | ||
|
|
||
| private LocalDateTime startTime; | ||
|
|
||
| private LocalDateTime endTime; | ||
|
|
||
| private String status; | ||
|
|
||
| @Formula("(SELECT p.parameter_value FROM batch_job_execution_params p" | ||
| + " WHERE p.job_execution_id = job_execution_id AND p.parameter_name = 'startedBy')") | ||
| private String startedBy; | ||
|
|
||
|
PBobylev marked this conversation as resolved.
|
||
| @Formula("(SELECT p.parameter_value FROM batch_job_execution_params p" | ||
| + " WHERE p.job_execution_id = job_execution_id AND p.parameter_name = 'isFullReindex')") | ||
| private String isFullReindex; | ||
|
|
||
| @OneToMany(mappedBy = "jobExecution", fetch = FetchType.EAGER) | ||
|
PBobylev marked this conversation as resolved.
|
||
| private Set<BatchStepExecution> stepExecutions; | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
src/main/java/org/folio/linked/data/model/entity/batch/BatchStepExecution.java
This file contains hidden or 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,30 @@ | ||
| package org.folio.linked.data.model.entity.batch; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.ManyToOne; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @EqualsAndHashCode(of = "stepExecutionId") | ||
| @Entity | ||
| public class BatchStepExecution { | ||
|
PBobylev marked this conversation as resolved.
|
||
|
|
||
| @Id | ||
| private Long stepExecutionId; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "job_execution_id") | ||
| private BatchJobExecution jobExecution; | ||
|
|
||
| private String stepName; | ||
|
|
||
| private Long readCount; | ||
|
|
||
| private Long writeCount; | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
src/main/java/org/folio/linked/data/repo/BatchJobExecutionRepository.java
This file contains hidden or 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.linked.data.repo; | ||
|
|
||
| import org.folio.linked.data.model.entity.batch.BatchJobExecution; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface BatchJobExecutionRepository extends JpaRepository<BatchJobExecution, Long> { | ||
| } | ||
|
|
4 changes: 4 additions & 0 deletions
4
src/main/java/org/folio/linked/data/service/batch/ReindexJobService.java
This file contains hidden or 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,6 +1,10 @@ | ||
| package org.folio.linked.data.service.batch; | ||
|
|
||
| import org.folio.linked.data.domain.dto.ReindexJobStatusDto; | ||
|
|
||
| public interface ReindexJobService { | ||
|
|
||
| Long start(boolean isFullReindex, String resourceType); | ||
|
|
||
| ReindexJobStatusDto getStatus(Long jobExecutionId); | ||
| } |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.