Skip to content

Commit 4c3af0e

Browse files
committed
move validation to service
1 parent c4ce429 commit 4c3af0e

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

graylog2-server/src/main/java/org/graylog2/indexer/indices/OutdatedIndexService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import jakarta.inject.Inject;
2323
import jakarta.inject.Singleton;
2424
import jakarta.validation.constraints.NotNull;
25+
import jakarta.ws.rs.NotFoundException;
2526
import org.graylog2.indexer.ElasticsearchException;
2627
import org.graylog2.indexer.cluster.Cluster;
2728
import org.graylog2.indexer.indexset.registry.IndexSetRegistry;
@@ -67,7 +68,11 @@ public List<OutdatedIndex> getOutdatedIndices() {
6768
}
6869

6970
public void reindex(String index, boolean withReplicas) {
70-
HealthStatus sourceStatus = indicesAdapter.waitForRecovery(index, 2);
71+
OutdatedIndex outdatedIndex = getOutdatedIndices().stream()
72+
.filter(OutdatedIndex::isSystemIndex)
73+
.filter(i -> i.indexName().equals(index))
74+
.findAny().orElseThrow(() -> new NotFoundException("Index " + index + " not found or is no system index"));
75+
HealthStatus sourceStatus = indicesAdapter.waitForRecovery(outdatedIndex.indexName(), 2);
7176
if (sourceStatus != HealthStatus.Green) {
7277
throw new IllegalStateException("Index " + index + " state is not healthy: " + sourceStatus);
7378
}
@@ -151,6 +156,10 @@ private Map<String, Object> cleanIndexSettings(Map<String, Object> settings, boo
151156
}
152157

153158
public void delete(@NotNull String index) {
154-
indicesAdapter.delete(index);
159+
OutdatedIndex outdatedIndex = getOutdatedIndices().stream()
160+
.filter(i -> !i.managedIndex())
161+
.filter(i -> i.indexName().equals(index))
162+
.findAny().orElseThrow(() -> new NotFoundException("Index " + index + " not found or is an index managed by Graylog"));
163+
indicesAdapter.delete(outdatedIndex.indexName());
155164
}
156165
}

graylog2-server/src/main/java/org/graylog2/rest/resources/system/indexer/IndicesResource.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,6 @@ public List<OutdatedIndex> getOutdatedIndices() {
332332
@AuditEvent(type = AuditEventTypes.ES_INDEX_REINDEX)
333333
public void reindex(@Parameter(name = "index") @PathParam("index") @NotNull String index,
334334
@Parameter(name = "withReplication") @QueryParam("withReplication") @DefaultValue("true") boolean withReplication) {
335-
outdatedIndexService.getOutdatedIndices().stream()
336-
.filter(OutdatedIndex::isSystemIndex)
337-
.filter(i -> i.indexName().equals(index))
338-
.findAny().orElseThrow(() -> new NotFoundException("Index " + index + " not found or is no system index"));
339335
outdatedIndexService.reindex(index, withReplication);
340336
}
341337

@@ -346,10 +342,6 @@ public void reindex(@Parameter(name = "index") @PathParam("index") @NotNull Stri
346342
@Produces(MediaType.APPLICATION_JSON)
347343
@AuditEvent(type = AuditEventTypes.ES_INDEX_DELETE)
348344
public void deleteOutdated(@Parameter(name = "index") @PathParam("index") @NotNull String index) {
349-
outdatedIndexService.getOutdatedIndices().stream()
350-
.filter(i -> !i.managedIndex())
351-
.filter(i -> i.indexName().equals(index))
352-
.findAny().orElseThrow(() -> new NotFoundException("Index " + index + " not found or is an index managed by Graylog"));
353345
outdatedIndexService.delete(index);
354346
}
355347

0 commit comments

Comments
 (0)