-
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.
feat(reindex): Initiate Full Reindex (#642)
* feat(reindex): Initiate Full Reindex 1. Truncate tables: instance, item, holding, ranges (merge and upload), status 2. Request counts of records from mod-inventory-storage (do this for each member in ECS) 3. Construct records' ID ranges and fill Merge Range table (do this for each member in ECS) 4. Call mod-inventory-storage's POST /inventory-reindex-records/publish for constructed records' ranges (do this for each member in ECS) Do not allow running full reindex from member tenants in ECS Closes: MSEARCH-794
- Loading branch information
1 parent
baee716
commit d5fcc26
Showing
69 changed files
with
1,777 additions
and
422 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
26 changes: 26 additions & 0 deletions
26
src/main/java/org/folio/search/client/ConsortiumTenantsClient.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,26 @@ | ||
package org.folio.search.client; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
|
||
import java.util.List; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@FeignClient("consortia") | ||
public interface ConsortiumTenantsClient { | ||
|
||
/** | ||
* Get tenants by consortium id. | ||
* | ||
* @return consortium tenants if executed under consortium central 'tenantId' context | ||
* */ | ||
@GetMapping(value = "/{consortiumId}/tenants", produces = APPLICATION_JSON_VALUE) | ||
ConsortiumTenants getConsortiumTenants(@PathVariable("consortiumId") String consortiumId, | ||
@RequestParam("limit") int limit); | ||
|
||
record ConsortiumTenants(List<ConsortiumTenant> tenants) { } | ||
|
||
record ConsortiumTenant(String id, boolean isCentral) { } | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/folio/search/client/InventoryInstanceClient.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,22 @@ | ||
package org.folio.search.client; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
|
||
import java.net.URI; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
@FeignClient("instance-storage") | ||
public interface InventoryInstanceClient { | ||
|
||
/** | ||
* Retrieves Inventory Records count with given URI. | ||
* | ||
* @param uri URI to retrieve count of inventory record | ||
* @return count represented as {@link InventoryRecordsCountDto} | ||
*/ | ||
@GetMapping(produces = APPLICATION_JSON_VALUE) | ||
InventoryRecordsCountDto getInventoryRecordsCount(URI uri); | ||
|
||
record InventoryRecordsCountDto(int totalRecords) { } | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/folio/search/client/InventoryReindexRecordsClient.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,17 @@ | ||
package org.folio.search.client; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
|
||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
|
||
@FeignClient("inventory-reindex-records") | ||
public interface InventoryReindexRecordsClient { | ||
|
||
@PostMapping(path = "/publish", consumes = APPLICATION_JSON_VALUE) | ||
void publishReindexRecords(ReindexRecords reindexRecords); | ||
|
||
record ReindexRecords(String id, String recordType, ReindexRecordsRange recordIdsRange) {} | ||
|
||
record ReindexRecordsRange(String from, String to) {} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/org/folio/search/exception/FolioIntegrationException.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,28 @@ | ||
package org.folio.search.exception; | ||
|
||
import static org.folio.search.model.types.ErrorCode.INTEGRATION_ERROR; | ||
|
||
/** | ||
* Handles exceptional cases of module integration with other Folio modules. | ||
*/ | ||
public class FolioIntegrationException extends BaseSearchException { | ||
|
||
/** | ||
* Initialize exception with provided message and error code. | ||
* | ||
* @param message exception message | ||
*/ | ||
public FolioIntegrationException(String message) { | ||
super(message, INTEGRATION_ERROR); | ||
} | ||
|
||
/** | ||
* Initialize exception with provided message and error code. | ||
* | ||
* @param message exception message | ||
* @param cause cause Exception | ||
*/ | ||
public FolioIntegrationException(String message, Throwable cause) { | ||
super(message, cause, INTEGRATION_ERROR); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/org/folio/search/integration/InventoryService.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,71 @@ | ||
package org.folio.search.integration; | ||
|
||
import lombok.extern.log4j.Log4j2; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.folio.search.client.InventoryInstanceClient; | ||
import org.folio.search.client.InventoryReindexRecordsClient; | ||
import org.folio.search.exception.FolioIntegrationException; | ||
import org.folio.search.model.reindex.MergeRangeEntity; | ||
import org.folio.search.model.types.InventoryRecordType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
@Service | ||
@Log4j2 | ||
public class InventoryService { | ||
|
||
private final InventoryInstanceClient inventoryInstanceClient; | ||
private final InventoryReindexRecordsClient reindexRecordsClient; | ||
|
||
public InventoryService(InventoryInstanceClient inventoryInstanceClient, | ||
InventoryReindexRecordsClient reindexRecordsClient) { | ||
this.inventoryInstanceClient = inventoryInstanceClient; | ||
this.reindexRecordsClient = reindexRecordsClient; | ||
} | ||
|
||
public int fetchInventoryRecordsCount(InventoryRecordType recordType) { | ||
if (recordType == null) { | ||
log.warn("No Inventory Record Type was provided to fetch Inventory Count"); | ||
return 0; | ||
} | ||
|
||
try { | ||
var countPath = "%s?limit=0&totalRecords=exact".formatted(recordType.getPath()); | ||
var uri = UriComponentsBuilder.fromUriString(countPath).build().toUri(); | ||
var result = inventoryInstanceClient.getInventoryRecordsCount(uri); | ||
|
||
if (result == null) { | ||
log.warn("Failed to retrieve Inventory Records count"); | ||
return 0; | ||
} | ||
|
||
return result.totalRecords(); | ||
} catch (Exception e) { | ||
log.warn("Failed to fetch Inventory record counts for {}", recordType); | ||
throw new FolioIntegrationException( | ||
"Failed to fetch inventory record counts for %s : %s".formatted(recordType.name(), e.getMessage())); | ||
} | ||
} | ||
|
||
public void publishReindexRecordsRange(MergeRangeEntity rangeEntity) { | ||
if (rangeEntity == null | ||
|| ObjectUtils.anyNull(rangeEntity.getId(), rangeEntity.getLowerId(), rangeEntity.getUpperId())) { | ||
log.warn("Invalid Range Entity: [rangeEntity: {}]", rangeEntity); | ||
return; | ||
} | ||
|
||
var from = rangeEntity.getLowerId().toString(); | ||
var to = rangeEntity.getUpperId().toString(); | ||
var recordsRange = new InventoryReindexRecordsClient.ReindexRecords( | ||
rangeEntity.getId().toString(), | ||
rangeEntity.getEntityType().getType(), | ||
new InventoryReindexRecordsClient.ReindexRecordsRange(from, to)); | ||
|
||
try { | ||
reindexRecordsClient.publishReindexRecords(recordsRange); | ||
} catch (Exception e) { | ||
log.warn("Failed to publish reindex records range {} : {}", recordsRange, e.getMessage()); | ||
throw new FolioIntegrationException("Failed to publish reindex records range", e); | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/folio/search/model/reindex/MergeRangeEntity.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,27 @@ | ||
package org.folio.search.model.reindex; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.UUID; | ||
import lombok.Data; | ||
import org.folio.search.model.types.ReindexEntityType; | ||
|
||
@Data | ||
public class MergeRangeEntity { | ||
|
||
public static final String ID_COLUMN = "id"; | ||
public static final String ENTITY_TYPE_COLUMN = "entity_type"; | ||
public static final String TENANT_ID_COLUMN = "tenant_id"; | ||
public static final String RANGE_LOWER_COLUMN = "lower"; | ||
public static final String RANGE_UPPER_COLUMN = "upper"; | ||
public static final String CREATED_AT_COLUMN = "created_at"; | ||
public static final String FINISHED_AT_COLUMN = "finished_at"; | ||
|
||
private final UUID id; | ||
private final ReindexEntityType entityType; | ||
private final String tenantId; | ||
private final UUID lowerId; | ||
private final UUID upperId; | ||
private final Timestamp createdAt; | ||
private Timestamp finishedAt; | ||
|
||
} |
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
32 changes: 32 additions & 0 deletions
32
src/main/java/org/folio/search/model/types/InventoryRecordType.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.model.types; | ||
|
||
import java.util.Locale; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum InventoryRecordType { | ||
INSTANCE("instance", "http://instance-storage/instances"), | ||
ITEM("item", "http://item-storage/items"), | ||
HOLDING("holding", "http://holdings-storage/holdings"); | ||
|
||
|
||
/** | ||
* record name. | ||
*/ | ||
private final String recordName; | ||
|
||
/** | ||
* Request path for the record. | ||
*/ | ||
private final String path; | ||
|
||
InventoryRecordType(String recordName, String path) { | ||
this.recordName = recordName; | ||
this.path = path; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name().toLowerCase(Locale.ROOT); | ||
} | ||
} |
Oops, something went wrong.