Skip to content
Snippets Groups Projects
Commit a8e29618 authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Merge branch...

Merge branch 'feature/GONRG-1546_-_Audit._Implement_some_audit_events_for_Indexer_publish]' into 'integration-master'

GONRG-1546: Audit. Implement some audit events for Indexer [publish]

See merge request go3-nrg/platform/System/indexer!46
parents 108be677 4206ad85
No related branches found
No related tags found
1 merge request!74Audit Logger Implementation (GONRG-1546)
Pipeline #23266 passed
...@@ -19,6 +19,7 @@ import com.google.gson.Gson; ...@@ -19,6 +19,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import lombok.extern.java.Log; import lombok.extern.java.Log;
...@@ -28,6 +29,7 @@ import org.opengroup.osdu.core.common.model.indexer.RecordInfo; ...@@ -28,6 +29,7 @@ import org.opengroup.osdu.core.common.model.indexer.RecordInfo;
import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages;
import org.opengroup.osdu.core.common.model.search.SearchServiceRole; import org.opengroup.osdu.core.common.model.search.SearchServiceRole;
import org.opengroup.osdu.indexer.SwaggerDoc; import org.opengroup.osdu.indexer.SwaggerDoc;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.indexer.service.IndexerService; import org.opengroup.osdu.indexer.service.IndexerService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -46,6 +48,9 @@ public class CleanupIndiciesApi { ...@@ -46,6 +48,9 @@ public class CleanupIndiciesApi {
@Autowired @Autowired
private IndexerService indexerService; private IndexerService indexerService;
@Autowired
private AuditLogger auditLogger;
@PostMapping(path = "/index-cleanup", consumes = "application/json") @PostMapping(path = "/index-cleanup", consumes = "application/json")
@PreAuthorize("@authorizationFilter.hasPermission('" + SearchServiceRole.ADMIN + "')") @PreAuthorize("@authorizationFilter.hasPermission('" + SearchServiceRole.ADMIN + "')")
public ResponseEntity cleanupIndices(@NotNull(message = SwaggerDoc.REQUEST_VALIDATION_NOT_NULL_BODY) public ResponseEntity cleanupIndices(@NotNull(message = SwaggerDoc.REQUEST_VALIDATION_NOT_NULL_BODY)
...@@ -69,6 +74,10 @@ public class CleanupIndiciesApi { ...@@ -69,6 +74,10 @@ public class CleanupIndiciesApi {
return new ResponseEntity(HttpStatus.OK); return new ResponseEntity(HttpStatus.OK);
} }
indexerService.processSchemaMessages(recordInfos); indexerService.processSchemaMessages(recordInfos);
auditLogger.getIndexCleanUpJobRun(recordInfos.stream()
.map(RecordInfo::getKind)
.collect(Collectors.toList()));
return new ResponseEntity(HttpStatus.OK); return new ResponseEntity(HttpStatus.OK);
} catch (AppException e) { } catch (AppException e) {
throw e; throw e;
......
...@@ -38,6 +38,9 @@ public class AuditEvents { ...@@ -38,6 +38,9 @@ public class AuditEvents {
private static final String INDEX_PURGE_RECORD_ACTION_ID = "IN004"; private static final String INDEX_PURGE_RECORD_ACTION_ID = "IN004";
private static final String INDEX_STARTED_ACTION_ID = "IN006";
private static final String INDEX_STARTED_OPERATION = "Indexing started";
private static final String REINDEX_KIND_ACTION_ID = "IN007"; private static final String REINDEX_KIND_ACTION_ID = "IN007";
private static final String REINDEX_KIND_OPERATION = "Reindex kind"; private static final String REINDEX_KIND_OPERATION = "Reindex kind";
...@@ -151,6 +154,17 @@ public class AuditEvents { ...@@ -151,6 +154,17 @@ public class AuditEvents {
.build(); .build();
} }
public AuditPayload getIndexEvent(List<String> resources) {
return AuditPayload.builder()
.action(AuditAction.CREATE)
.status(AuditStatus.SUCCESS)
.actionId(INDEX_STARTED_ACTION_ID)
.message(INDEX_STARTED_OPERATION)
.resources(resources)
.user(this.user)
.build();
}
public AuditPayload getReindexEvent(List<String> resources) { public AuditPayload getReindexEvent(List<String> resources) {
return AuditPayload.builder() return AuditPayload.builder()
.action(AuditAction.CREATE) .action(AuditAction.CREATE)
......
...@@ -73,6 +73,10 @@ public class AuditLogger { ...@@ -73,6 +73,10 @@ public class AuditLogger {
this.writeLog(this.getAuditEvents().getIndexPurgeRecordFailEvent(resources)); this.writeLog(this.getAuditEvents().getIndexPurgeRecordFailEvent(resources));
} }
public void indexStarted(List<String> resources) {
this.writeLog(this.getAuditEvents().getIndexEvent(resources));
}
public void getReindex(List<String> resources) { public void getReindex(List<String> resources) {
this.writeLog(this.getAuditEvents().getReindexEvent(resources)); this.writeLog(this.getAuditEvents().getReindexEvent(resources));
} }
......
...@@ -125,6 +125,10 @@ public class IndexerServiceImpl implements IndexerService { ...@@ -125,6 +125,10 @@ public class IndexerServiceImpl implements IndexerService {
retryRecordIds.addAll(deleteFailureRecordIds); retryRecordIds.addAll(deleteFailureRecordIds);
} }
auditLogger.indexStarted(recordInfos.stream()
.map(RecordInfo::getKind)
.collect(Collectors.toList()));
// process schema change messages // process schema change messages
Map<String, OperationType> schemaMsgs = RecordInfo.getSchemaMsgs(recordInfos); Map<String, OperationType> schemaMsgs = RecordInfo.getSchemaMsgs(recordInfos);
if (schemaMsgs != null && !schemaMsgs.isEmpty()) { if (schemaMsgs != null && !schemaMsgs.isEmpty()) {
......
...@@ -14,6 +14,7 @@ import org.opengroup.osdu.core.common.model.http.AppException; ...@@ -14,6 +14,7 @@ import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages;
import org.opengroup.osdu.core.common.search.Config; import org.opengroup.osdu.core.common.search.Config;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.indexer.service.IndexerService; import org.opengroup.osdu.indexer.service.IndexerService;
import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
...@@ -36,6 +37,9 @@ public class CleanupIndiciesApiTest { ...@@ -36,6 +37,9 @@ public class CleanupIndiciesApiTest {
@Mock @Mock
private IndexerService indexerService; private IndexerService indexerService;
@Mock
private AuditLogger auditLogger;
@Before @Before
public void setup() { public void setup() {
initMocks(this); initMocks(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment