Skip to content

Commit

Permalink
SearchType.Result instead of message list in the SearchJobState object
Browse files Browse the repository at this point in the history
  • Loading branch information
luk-kaminski committed Feb 7, 2025
1 parent 0fe1da4 commit fc4250e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.auto.value.AutoValue;
import org.graylog.plugins.views.search.SearchJobIdentifier;
import org.graylog.plugins.views.search.SearchType;
import org.graylog2.database.MongoEntity;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.mongojack.Id;
import org.mongojack.ObjectId;

import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;

@AutoValue
@JsonDeserialize(builder = SearchJobState.Builder.class)
Expand All @@ -40,7 +40,7 @@ public abstract class SearchJobState implements MongoEntity {
public static final String UPDATED_AT_FIELD = "updated_at";
public static final String STATUS_FIELD = "status";
public static final String TYPE_FIELD = "type";
public static final String MESSAGES_FIELD = "messages";
public static final String RESULT_FIELD = "result";

@JsonUnwrapped
public abstract SearchJobIdentifier identifier();
Expand All @@ -57,8 +57,9 @@ public abstract class SearchJobState implements MongoEntity {
@JsonProperty("progress")
public abstract int progress();

@JsonProperty(MESSAGES_FIELD)
public abstract List<Map<String, Object>> messages(); //TODO: if we decide to store search engine results as well (not only Data Lake), we would need to keep a more general SearchType.Result object here
@JsonProperty(RESULT_FIELD)
@Nullable
public abstract SearchType.Result result();

@JsonProperty(CREATED_AT_FIELD)
public abstract DateTime createdAt();
Expand Down Expand Up @@ -90,8 +91,8 @@ public abstract static class Builder {
@JsonProperty("progress")
public abstract Builder progress(final int progress);

@JsonProperty(MESSAGES_FIELD)
public abstract Builder messages(final List<Map<String, Object>> messages);
@JsonProperty(RESULT_FIELD)
public abstract Builder result(final SearchType.Result result);

@JsonProperty(CREATED_AT_FIELD)
public abstract Builder createdAt(final DateTime createdAt);
Expand All @@ -113,7 +114,7 @@ public static Builder create() {
public static SearchJobState createNewJob(final SearchJobIdentifier searchJobIdentifier) {
return SearchJobState.builder()
.identifier(searchJobIdentifier)
.messages(List.of())
.result(null)
.status(SearchJobStatus.RUNNING)
.progress(0)
.createdAt(DateTime.now(DateTimeZone.UTC))
Expand All @@ -122,9 +123,9 @@ public static SearchJobState createNewJob(final SearchJobIdentifier searchJobIde
}

public static SearchJobState createDoneJobFrom(final SearchJobState existingSearchJob,
final List<Map<String, Object>> result) {
final SearchType.Result result) {
return existingSearchJob.toBuilder()
.messages(result)
.result(result)
.status(SearchJobStatus.DONE)
.progress(100)
.updatedAt(DateTime.now(DateTimeZone.UTC))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.graylog.plugins.views.search.jobs;

import org.graylog.plugins.views.search.SearchJobIdentifier;
import org.graylog.plugins.views.search.SearchType;
import org.graylog.testing.mongodb.MongoDBInstance;
import org.graylog2.bindings.providers.MongoJackObjectMapperProvider;
import org.graylog2.database.MongoCollections;
Expand All @@ -28,7 +29,6 @@
import org.junit.Rule;
import org.junit.Test;

import java.util.List;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
Expand All @@ -54,7 +54,7 @@ public void setUp() {
public void testSaveAndGet() {
final SearchJobState toBeSaved = SearchJobState.builder()
.identifier(new SearchJobIdentifier(null, "677fd86ae6db8b71a8e10e3e", "john", "dcae52e4-777e-4e3f-8e69-61df7a607016"))
.messages(List.of())
.result(noResult())
.status(SearchJobStatus.RUNNING)
.progress(42)
.createdAt(DateTime.now(DateTimeZone.UTC))
Expand All @@ -72,7 +72,7 @@ public void testSaveAndGet() {
public void testSaveAndDelete() {
final SearchJobState toBeSaved = SearchJobState.builder()
.identifier(new SearchJobIdentifier(null, "677fd86ae6db8b71a8e10e3e", "john", "dcae52e4-777e-4e3f-8e69-61df7a607016"))
.messages(List.of())
.result(noResult())
.status(SearchJobStatus.RUNNING)
.progress(42)
.createdAt(DateTime.now(DateTimeZone.UTC))
Expand All @@ -89,7 +89,7 @@ public void testSaveAndDelete() {
public void testSaveAndUpdate() {
final SearchJobState toBeSaved = SearchJobState.builder()
.identifier(new SearchJobIdentifier(null, "677fd86ae6db8b71a8e10e3e", "john", "dcae52e4-777e-4e3f-8e69-61df7a607016"))
.messages(List.of())
.result(noResult())
.status(SearchJobStatus.RUNNING)
.progress(42)
.createdAt(DateTime.now(DateTimeZone.UTC))
Expand All @@ -111,7 +111,7 @@ public void testSaveAndUpdate() {
public void testChangeStatus() {
final SearchJobState toBeSaved = SearchJobState.builder()
.identifier(new SearchJobIdentifier(null, "677fd86ae6db8b71a8e10e3e", "john", "dcae52e4-777e-4e3f-8e69-61df7a607016"))
.messages(List.of())
.result(noResult())
.status(SearchJobStatus.RUNNING)
.progress(42)
.createdAt(DateTime.now(DateTimeZone.UTC))
Expand All @@ -137,7 +137,7 @@ public void testGetLatestForUser() {
"677fd86ae6db8b71a8e10001",
"john",
"dcae52e4-777e-4e3f-8e69-61df7a607016"))
.messages(List.of())
.result(noResult())
.status(SearchJobStatus.RUNNING)
.progress(42)
.createdAt(DateTime.parse("1999-01-01T11:11:11"))
Expand All @@ -149,7 +149,7 @@ public void testGetLatestForUser() {
"677fd86ae6db8b71a8e10002",
"john",
"dcae52e4-777e-4e3f-8e69-61df7a607016"))
.messages(List.of())
.result(noResult())
.status(SearchJobStatus.RUNNING)
.progress(42)
.createdAt(DateTime.parse("2000-01-01T11:11:11"))
Expand All @@ -161,7 +161,7 @@ public void testGetLatestForUser() {
"677fd86ae6db8b71a8e10003",
"bob",
"dcae52e4-777e-4e3f-8e69-61df7a607016"))
.messages(List.of())
.result(noResult())
.status(SearchJobStatus.RUNNING)
.progress(42)
.createdAt(DateTime.parse("2020-01-01T11:11:11"))
Expand All @@ -181,7 +181,7 @@ public void testOldJobsRemovalAndExpiration() {
"677fd86ae6db8b71a8e10001",
"john",
"dcae52e4-777e-4e3f-8e69-61df7a607016"))
.messages(List.of())
.result(noResult())
.status(SearchJobStatus.DONE)
.progress(42)
.createdAt(DateTime.parse("1999-01-01T11:11:11"))
Expand All @@ -192,7 +192,7 @@ public void testOldJobsRemovalAndExpiration() {
"677fd86ae6db8b71a8e10002",
"john",
"dcae52e4-777e-4e3f-8e69-61df7a607016"))
.messages(List.of())
.result(noResult())
.status(SearchJobStatus.DONE)
.progress(42)
.createdAt(DateTime.now(DateTimeZone.UTC).minusDays(1))
Expand All @@ -203,7 +203,7 @@ public void testOldJobsRemovalAndExpiration() {
"677fd86ae6db8b71a8e10003",
"john",
"dcae52e4-777e-4e3f-8e69-61df7a607016"))
.messages(List.of())
.result(noResult())
.status(SearchJobStatus.DONE)
.progress(42)
.createdAt(DateTime.now(DateTimeZone.UTC))
Expand All @@ -225,4 +225,8 @@ public void testOldJobsRemovalAndExpiration() {
assertEquals(0, numRemoved);

}

private SearchType.Result noResult() {
return null;
}
}

0 comments on commit fc4250e

Please sign in to comment.