From 1f5543e07dd0d3d265d0103eafeb04021dd6952c Mon Sep 17 00:00:00 2001 From: Whitney O'Meara Date: Tue, 16 Jul 2024 22:03:54 +0000 Subject: [PATCH 1/3] 1.0.1 --- pom.xml | 12 ++++----- .../QueryLogicFactoryConfiguration.java | 3 +-- .../RabbitMQQueryResultsPublisher.java | 14 ++++++++++- .../query/util/GeometryDeserializer.java | 25 +++++++++++++++++++ .../query/util/GeometrySerializer.java | 16 ++++++++++++ .../storage/QueryTaskCheckpointTest.java | 6 ++--- 6 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 src/main/java/datawave/microservice/query/util/GeometryDeserializer.java create mode 100644 src/main/java/datawave/microservice/query/util/GeometrySerializer.java diff --git a/pom.xml b/pom.xml index 6f4c25e3..14d12f60 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ ../../microservice-service-parent/pom.xml spring-boot-starter-datawave-query - 1.0.1-SNAPSHOT + 1.0.1 https://github.com/NationalSecurityAgency/datawave-spring-boot-starter-query @@ -24,12 +24,12 @@ http://webservice.datawave/v1 - 7.0.0 + 7.1.2 31.0.1-jre - 4.0.0 - 4.0.0 - 3.0.0 - 3.0.0 + 4.0.1 + 4.0.1 + 3.0.1 + 3.0.2 diff --git a/src/main/java/datawave/microservice/query/logic/config/QueryLogicFactoryConfiguration.java b/src/main/java/datawave/microservice/query/logic/config/QueryLogicFactoryConfiguration.java index 56aa467b..81440fef 100644 --- a/src/main/java/datawave/microservice/query/logic/config/QueryLogicFactoryConfiguration.java +++ b/src/main/java/datawave/microservice/query/logic/config/QueryLogicFactoryConfiguration.java @@ -11,7 +11,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -35,7 +34,7 @@ public class QueryLogicFactoryConfiguration { private final Logger log = LoggerFactory.getLogger(this.getClass()); @Bean - @ConditionalOnMissingBean + @ConditionalOnProperty(name = "datawave.defaults.ResponseObjectFactory.enabled", havingValue = "true", matchIfMissing = true) public ResponseObjectFactory responseObjectFactory() { return new DefaultResponseObjectFactory(); } diff --git a/src/main/java/datawave/microservice/query/messaging/rabbitmq/RabbitMQQueryResultsPublisher.java b/src/main/java/datawave/microservice/query/messaging/rabbitmq/RabbitMQQueryResultsPublisher.java index 249e1197..fae05f74 100644 --- a/src/main/java/datawave/microservice/query/messaging/rabbitmq/RabbitMQQueryResultsPublisher.java +++ b/src/main/java/datawave/microservice/query/messaging/rabbitmq/RabbitMQQueryResultsPublisher.java @@ -8,6 +8,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.locationtech.jts.geom.Geometry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.amqp.core.MessageProperties; @@ -16,11 +17,15 @@ import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; import datawave.microservice.query.messaging.ClaimCheck; import datawave.microservice.query.messaging.QueryResultsPublisher; import datawave.microservice.query.messaging.Result; import datawave.microservice.query.messaging.config.MessagingProperties; +import datawave.microservice.query.util.GeometryDeserializer; +import datawave.microservice.query.util.GeometrySerializer; class RabbitMQQueryResultsPublisher implements QueryResultsPublisher { private final Logger log = LoggerFactory.getLogger(this.getClass()); @@ -52,7 +57,14 @@ public RabbitMQQueryResultsPublisher(MessagingProperties.RabbitMQProperties rabb latchMap.get(correlationData.getId()).countDown(); } }); - this.rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter()); + + // set a custom module for (de)serializing Geometry objects + ObjectMapper objectMapper = new ObjectMapper(); + SimpleModule geometryModule = new SimpleModule(Geometry.class.getName()); + geometryModule.addSerializer(Geometry.class, new GeometrySerializer()); + geometryModule.addDeserializer(Geometry.class, new GeometryDeserializer()); + + this.rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter(objectMapper)); } @Override diff --git a/src/main/java/datawave/microservice/query/util/GeometryDeserializer.java b/src/main/java/datawave/microservice/query/util/GeometryDeserializer.java new file mode 100644 index 00000000..2154eb91 --- /dev/null +++ b/src/main/java/datawave/microservice/query/util/GeometryDeserializer.java @@ -0,0 +1,25 @@ +package datawave.microservice.query.util; + +import java.io.IOException; + +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.io.ParseException; +import org.locationtech.jts.io.WKTReader; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +public class GeometryDeserializer extends JsonDeserializer { + private WKTReader wktReader = new WKTReader(); + + @Override + public Geometry deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException { + try { + return wktReader.read(jsonParser.getValueAsString()); + } catch (ParseException e) { + throw new IOException("Failed to deserialize wkt to Geometry: " + jsonParser.getValueAsString(), e); + } + } +} diff --git a/src/main/java/datawave/microservice/query/util/GeometrySerializer.java b/src/main/java/datawave/microservice/query/util/GeometrySerializer.java new file mode 100644 index 00000000..58f28f77 --- /dev/null +++ b/src/main/java/datawave/microservice/query/util/GeometrySerializer.java @@ -0,0 +1,16 @@ +package datawave.microservice.query.util; + +import java.io.IOException; + +import org.locationtech.jts.geom.Geometry; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +public class GeometrySerializer extends JsonSerializer { + @Override + public void serialize(Geometry geometry, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + jsonGenerator.writeString(geometry.toText()); + } +} diff --git a/src/test/java/datawave/microservice/query/storage/QueryTaskCheckpointTest.java b/src/test/java/datawave/microservice/query/storage/QueryTaskCheckpointTest.java index e9b03c40..eaff36c4 100644 --- a/src/test/java/datawave/microservice/query/storage/QueryTaskCheckpointTest.java +++ b/src/test/java/datawave/microservice/query/storage/QueryTaskCheckpointTest.java @@ -118,7 +118,7 @@ public void testCheckpoint() { query.setQuery("foo == bar"); ShardQueryConfiguration config = new ShardQueryConfiguration(); config.setQuery(query); - QueryData queryData = new QueryData("table", "logic", Collections.singletonList(new Range()), + QueryData queryData = new QueryData("table", "logic", Collections.singletonList(new Range()), Collections.emptyList(), Collections.singletonList(new IteratorSetting(10, "test", "test"))); config.setQueries(Collections.singletonList(queryData)); QueryCheckpoint qcp = new QueryCheckpoint(queryPool, uuid, queryLogic, config.getQueries()); @@ -169,7 +169,7 @@ public void testTask() { query.setQuery("foo == bar"); ShardQueryConfiguration config = new ShardQueryConfiguration(); config.setQuery(query); - QueryData queryData = new QueryData("table", "logic", Collections.singletonList(new Range()), + QueryData queryData = new QueryData("table", "logic", Collections.singletonList(new Range()), Collections.emptyList(), Collections.singletonList(new IteratorSetting(10, "test", "test"))); config.setQueries(Collections.singletonList(queryData)); QueryCheckpoint qcp = new QueryCheckpoint(queryPool, uuid, queryLogic, config.getQueries()); @@ -220,7 +220,7 @@ public void testTaskDescription() throws JsonProcessingException { config.setQuery(query); QueryData queryData = new QueryData("table", "logic", Collections.singletonList(new Range(new Key("row1", "cf1", "cq1", "(FOO)"), true, new Key("row2", "cf2", "cq2", "(BAR)"), false)), - Collections.singletonList(new IteratorSetting(10, "test", "test", Collections.singletonMap("key", "value")))); + Collections.emptyList(), Collections.singletonList(new IteratorSetting(10, "test", "test", Collections.singletonMap("key", "value")))); config.setQueries(Collections.singletonList(queryData)); TaskDescription desc = new TaskDescription(key, config.getQueries()); From 9ea65e98781c2ca5b8e067c16f433a8a9b9d212b Mon Sep 17 00:00:00 2001 From: Whitney O'Meara Date: Tue, 16 Jul 2024 22:05:20 +0000 Subject: [PATCH 2/3] 1.0.2-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 14d12f60..e728304f 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ ../../microservice-service-parent/pom.xml spring-boot-starter-datawave-query - 1.0.1 + 1.0.2-SNAPSHOT https://github.com/NationalSecurityAgency/datawave-spring-boot-starter-query From 970847bd06e4c49d9ad7aafdeefd63bec4a6e4a1 Mon Sep 17 00:00:00 2001 From: Whitney O'Meara Date: Thu, 18 Jul 2024 20:57:59 +0000 Subject: [PATCH 3/3] added serialVersionUID to serializable classes --- .../query/mapreduce/status/MapReduceQueryStatus.java | 3 ++- .../java/datawave/microservice/query/storage/QueryStatus.java | 2 ++ .../java/datawave/microservice/query/storage/TaskStates.java | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/datawave/microservice/query/mapreduce/status/MapReduceQueryStatus.java b/src/main/java/datawave/microservice/query/mapreduce/status/MapReduceQueryStatus.java index d8c310ed..8675c4a0 100644 --- a/src/main/java/datawave/microservice/query/mapreduce/status/MapReduceQueryStatus.java +++ b/src/main/java/datawave/microservice/query/mapreduce/status/MapReduceQueryStatus.java @@ -22,7 +22,8 @@ import datawave.webservice.results.mr.MapReduceInfoResponse; public class MapReduceQueryStatus implements Serializable { - + private static final long serialVersionUID = -8731070243293603952L; + public enum MapReduceQueryState { DEFINED, SUBMITTED, RUNNING, SUCCEEDED, CLOSED, CANCELED, FAILED } diff --git a/src/main/java/datawave/microservice/query/storage/QueryStatus.java b/src/main/java/datawave/microservice/query/storage/QueryStatus.java index 94a17be8..93d3c5cb 100644 --- a/src/main/java/datawave/microservice/query/storage/QueryStatus.java +++ b/src/main/java/datawave/microservice/query/storage/QueryStatus.java @@ -27,6 +27,8 @@ import datawave.webservice.query.exception.DatawaveErrorCode; public class QueryStatus implements Serializable { + private static final long serialVersionUID = -1633953472983032183L; + /** * These are the possible query states correlating with the activity that the user is requesting.
* DEFINE: define a query
diff --git a/src/main/java/datawave/microservice/query/storage/TaskStates.java b/src/main/java/datawave/microservice/query/storage/TaskStates.java index 5ba2a37a..752ee07f 100644 --- a/src/main/java/datawave/microservice/query/storage/TaskStates.java +++ b/src/main/java/datawave/microservice/query/storage/TaskStates.java @@ -23,6 +23,8 @@ import datawave.util.StringUtils; public class TaskStates implements Serializable { + private static final long serialVersionUID = 1361359960334155427L; + /** * The possible task states:
* READY: ready to run
@@ -30,7 +32,7 @@ public class TaskStates implements Serializable { * COMPLETED: completed successfully
* FAILED: failed to execute successfully
*/ - public enum TASK_STATE implements Serializable { + public enum TASK_STATE { READY, RUNNING, COMPLETED, FAILED }