From 24f8a2d8a54cc1f77c7a4ac27b2e6b1111755cbe Mon Sep 17 00:00:00 2001 From: MZhu9 <ujr7dj3ljx3fpstxflyytui5kziqgnbscv3po6mrm3ikbn52frqq> Date: Sun, 11 Jun 2023 22:45:10 -0500 Subject: [PATCH] 1. add new audit event for reindex records API 2. switch from storage query/records:batch API to query/records API --- .../opengroup/osdu/indexer/api/ReindexApi.java | 2 +- .../osdu/indexer/logging/AuditEvents.java | 16 +++++++++++++++- .../osdu/indexer/logging/AuditLogger.java | 6 +++++- .../osdu/indexer/service/StorageServiceImpl.java | 3 +-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java index 625442ac4..c4ea75f99 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java @@ -82,7 +82,7 @@ public class ReindexApi { Records records = this.reIndexService.reindexRecords(reindexRecordsRequest.getRecordIds()); List<String> reindexedRecords = records.getRecords().stream().map(Records.Entity::getId).collect(Collectors.toList()); if (!reindexedRecords.isEmpty()) { - this.auditLogger.getReindex(reindexedRecords); + this.auditLogger.getReindexRecords(reindexedRecords); } return new ResponseEntity<>(ReindexRecordsResponse.builder().reIndexedRecords(records.getRecords().stream().map(Records.Entity::getId).collect(Collectors.toList())).notFoundRecords(records.getNotFound()).build(), HttpStatus.ACCEPTED); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditEvents.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditEvents.java index ad0a6cc98..9a183e80d 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditEvents.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditEvents.java @@ -63,6 +63,9 @@ public class AuditEvents { private static final String INDEX_DELETE_SUCCESS = "Successfully deleted index"; private static final String INDEX_DELETE_FAILURE = "Failed deleting index"; + private static final String REINDEX_RECORDS_ACTION_ID = "IN0014"; + private static final String REINDEX_RECORDS_OPERATION = "Reindex records"; + private final String user; public AuditEvents(String user) { @@ -204,6 +207,17 @@ public class AuditEvents { .build(); } + public AuditPayload getReindexRecordsEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.CREATE) + .status(AuditStatus.SUCCESS) + .actionId(REINDEX_RECORDS_ACTION_ID) + .message(REINDEX_RECORDS_OPERATION) + .resources(resources) + .user(this.user) + .build(); + } + public AuditPayload getCopyIndexEvent(List<String> resources) { return AuditPayload.builder() .action(AuditAction.CREATE) @@ -269,4 +283,4 @@ public class AuditEvents { .build(); } } -} \ No newline at end of file +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditLogger.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditLogger.java index e02f7a2ea..792f46de6 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditLogger.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditLogger.java @@ -89,6 +89,10 @@ public class AuditLogger { this.writeLog(this.getAuditEvents().getReindexEvent(resources)); } + public void getReindexRecords(List<String> resources) { + this.writeLog(this.getAuditEvents().getReindexRecordsEvent(resources)); + } + public void copyIndex(List<String> resources) { this.writeLog(this.getAuditEvents().getCopyIndexEvent(resources)); } @@ -116,4 +120,4 @@ public class AuditLogger { private void writeLog(AuditPayload log) { this.logger.audit(log); } -} \ No newline at end of file +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java index 38c405d7a..cce0297f2 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java @@ -137,8 +137,7 @@ public class StorageServiceImpl implements StorageService { protected Records getRecords(List<String> ids) throws URISyntaxException { String body = this.gson.toJson(RecordIds.builder().records(ids).build()); DpsHeaders headers = this.requestInfo.getHeaders(); - headers.put(FRAME_OF_REFERENCE, SLB_FRAME_OF_REFERENCE_VALUE); - URIBuilder builder = new URIBuilder(configurationProperties.getStorageQueryRecordForConversionHost()); + URIBuilder builder = new URIBuilder(configurationProperties.getStorageQueryRecordHost()); HttpPost request = new HttpPost(builder.build()); request.setEntity(new StringEntity(body, StandardCharsets.UTF_8)); // we do not need retry on storage based on not found record -- GitLab