ATEST-246
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
#Wed Sep 16 07:23:26 CEST 2015
|
#Thu Oct 29 09:13:22 CET 2015
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
@ -30,7 +30,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
|
||||||
import ch.psi.daq.cassandra.util.test.CassandraDataGen;
|
import ch.psi.daq.cassandra.util.test.CassandraDataGen;
|
||||||
import ch.psi.daq.common.json.deserialize.AttributeBasedDeserializer;
|
|
||||||
import ch.psi.daq.common.statistic.StorelessStatistics;
|
import ch.psi.daq.common.statistic.StorelessStatistics;
|
||||||
import ch.psi.daq.domain.DataEvent;
|
import ch.psi.daq.domain.DataEvent;
|
||||||
import ch.psi.daq.query.analyzer.QueryAnalyzer;
|
import ch.psi.daq.query.analyzer.QueryAnalyzer;
|
||||||
@ -39,7 +38,6 @@ import ch.psi.daq.query.config.QueryConfig;
|
|||||||
import ch.psi.daq.query.model.Aggregation;
|
import ch.psi.daq.query.model.Aggregation;
|
||||||
import ch.psi.daq.query.model.Query;
|
import ch.psi.daq.query.model.Query;
|
||||||
import ch.psi.daq.query.model.QueryField;
|
import ch.psi.daq.query.model.QueryField;
|
||||||
import ch.psi.daq.query.model.impl.AbstractQuery;
|
|
||||||
import ch.psi.daq.queryrest.controller.validator.QueryValidator;
|
import ch.psi.daq.queryrest.controller.validator.QueryValidator;
|
||||||
import ch.psi.daq.queryrest.model.PropertyFilterMixin;
|
import ch.psi.daq.queryrest.model.PropertyFilterMixin;
|
||||||
import ch.psi.daq.queryrest.response.JsonByteArraySerializer;
|
import ch.psi.daq.queryrest.response.JsonByteArraySerializer;
|
||||||
@ -77,15 +75,6 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter {
|
|||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
// add deserializers to ObjectMapper
|
|
||||||
String packageName = AbstractQuery.class.getPackage().getName();
|
|
||||||
Class<AbstractQuery> abstractQueryClass = AbstractQuery.class;
|
|
||||||
AttributeBasedDeserializer<AbstractQuery> abstractQueryDeserializer =
|
|
||||||
new AttributeBasedDeserializer<AbstractQuery>(abstractQueryClass).register(packageName);
|
|
||||||
SimpleModule module = new SimpleModule("PolymorphicAbstractQuery", Version.unknownVersion());
|
|
||||||
module.addDeserializer(abstractQueryClass, abstractQueryDeserializer);
|
|
||||||
objectMapper.registerModule(module);
|
|
||||||
|
|
||||||
// only include non-null values
|
// only include non-null values
|
||||||
objectMapper.setSerializationInclusion(Include.NON_NULL);
|
objectMapper.setSerializationInclusion(Include.NON_NULL);
|
||||||
// Mixin which is used dynamically to filter out which properties get serialised and which
|
// Mixin which is used dynamically to filter out which properties get serialised and which
|
||||||
@ -95,7 +84,7 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter {
|
|||||||
objectMapper.addMixIn(EnumMap.class, PropertyFilterMixin.class);
|
objectMapper.addMixIn(EnumMap.class, PropertyFilterMixin.class);
|
||||||
|
|
||||||
// defines how to writer inner Streams (i.e. Stream<Entry<String, Stream<?>>> toSerialize)
|
// defines how to writer inner Streams (i.e. Stream<Entry<String, Stream<?>>> toSerialize)
|
||||||
module = new SimpleModule("Streams API", Version.unknownVersion());
|
SimpleModule module = new SimpleModule("Streams API", Version.unknownVersion());
|
||||||
module.addSerializer(new JsonStreamSerializer());
|
module.addSerializer(new JsonStreamSerializer());
|
||||||
objectMapper.registerModule(module);
|
objectMapper.registerModule(module);
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@ import ch.psi.daq.query.model.Aggregation;
|
|||||||
import ch.psi.daq.query.model.DBMode;
|
import ch.psi.daq.query.model.DBMode;
|
||||||
import ch.psi.daq.query.model.Query;
|
import ch.psi.daq.query.model.Query;
|
||||||
import ch.psi.daq.query.model.QueryField;
|
import ch.psi.daq.query.model.QueryField;
|
||||||
import ch.psi.daq.query.model.impl.AbstractQuery;
|
import ch.psi.daq.query.model.impl.DAQQuery;
|
||||||
import ch.psi.daq.query.processor.QueryProcessor;
|
import ch.psi.daq.query.processor.QueryProcessor;
|
||||||
|
import ch.psi.daq.query.request.ChannelsRequest;
|
||||||
import ch.psi.daq.queryrest.config.QueryRestConfig;
|
import ch.psi.daq.queryrest.config.QueryRestConfig;
|
||||||
import ch.psi.daq.queryrest.model.ChannelsRequest;
|
|
||||||
import ch.psi.daq.queryrest.response.ResponseStreamWriter;
|
import ch.psi.daq.queryrest.response.ResponseStreamWriter;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -117,17 +117,17 @@ public class QueryRestController {
|
|||||||
/**
|
/**
|
||||||
* Catch-all query method for getting data from the backend.
|
* Catch-all query method for getting data from the backend.
|
||||||
* <p>
|
* <p>
|
||||||
* The {@link AbstractQuery} object will be a concrete subclass based on the combination of
|
* The {@link DAQQuery} object will be a concrete subclass based on the combination of
|
||||||
* fields defined in the user's query. The {@link AttributeBasedDeserializer} decides which class
|
* fields defined in the user's query. The {@link AttributeBasedDeserializer} decides which class
|
||||||
* to deserialize the information into and has been configured (see
|
* to deserialize the information into and has been configured (see
|
||||||
* QueryRestConfig#afterPropertiesSet) accordingly.
|
* QueryRestConfig#afterPropertiesSet) accordingly.
|
||||||
*
|
*
|
||||||
* @param query concrete implementation of {@link AbstractQuery}
|
* @param query concrete implementation of {@link DAQQuery}
|
||||||
* @param res the {@link HttpServletResponse} instance associated with this request
|
* @param res the {@link HttpServletResponse} instance associated with this request
|
||||||
* @throws IOException thrown if writing to the output stream fails
|
* @throws IOException thrown if writing to the output stream fails
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value = QUERY, method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE})
|
@RequestMapping(value = QUERY, method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE})
|
||||||
public void executeQuery(@RequestBody @Valid AbstractQuery query, HttpServletResponse res) throws IOException {
|
public void executeQuery(@RequestBody @Valid DAQQuery query, HttpServletResponse res) throws IOException {
|
||||||
try {
|
try {
|
||||||
LOGGER.debug("Executing query '{}'", query.toString());
|
LOGGER.debug("Executing query '{}'", query.toString());
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ public class QueryRestController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<Entry<String, ?>> executeQuery(AbstractQuery query) {
|
public Stream<Entry<String, ?>> executeQuery(DAQQuery query) {
|
||||||
QueryAnalyzer queryAnalizer = queryAnalizerFactory.apply(query);
|
QueryAnalyzer queryAnalizer = queryAnalizerFactory.apply(query);
|
||||||
|
|
||||||
// all the magic happens here
|
// all the magic happens here
|
||||||
|
@ -12,7 +12,7 @@ import org.springframework.validation.Validator;
|
|||||||
import ch.psi.daq.query.model.Aggregation;
|
import ch.psi.daq.query.model.Aggregation;
|
||||||
import ch.psi.daq.query.model.DBMode;
|
import ch.psi.daq.query.model.DBMode;
|
||||||
import ch.psi.daq.query.model.QueryField;
|
import ch.psi.daq.query.model.QueryField;
|
||||||
import ch.psi.daq.query.model.impl.AbstractQuery;
|
import ch.psi.daq.query.model.impl.DAQQuery;
|
||||||
import ch.psi.daq.cassandra.request.Request;
|
import ch.psi.daq.cassandra.request.Request;
|
||||||
import ch.psi.daq.cassandra.request.range.RequestRangeTime;
|
import ch.psi.daq.cassandra.request.range.RequestRangeTime;
|
||||||
import ch.psi.daq.queryrest.config.QueryRestConfig;
|
import ch.psi.daq.queryrest.config.QueryRestConfig;
|
||||||
@ -30,7 +30,7 @@ public class QueryValidator implements Validator {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(Class<?> clazz) {
|
public boolean supports(Class<?> clazz) {
|
||||||
return AbstractQuery.class.isAssignableFrom(clazz);
|
return DAQQuery.class.isAssignableFrom(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +39,7 @@ public class QueryValidator implements Validator {
|
|||||||
@Override
|
@Override
|
||||||
public void validate(Object target, Errors errors) {
|
public void validate(Object target, Errors errors) {
|
||||||
|
|
||||||
AbstractQuery query = (AbstractQuery) target;
|
DAQQuery query = (DAQQuery) target;
|
||||||
|
|
||||||
Request request = query.getRequest();
|
Request request = query.getRequest();
|
||||||
|
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
package ch.psi.daq.queryrest.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
|
||||||
|
|
||||||
import ch.psi.daq.query.model.DBMode;
|
|
||||||
|
|
||||||
// as RequestBody due to special chars in regex
|
|
||||||
@JsonInclude(Include.NON_DEFAULT)
|
|
||||||
public class ChannelsRequest {
|
|
||||||
private DBMode dbMode = DBMode.databuffer;
|
|
||||||
// null for no regex
|
|
||||||
private String regex = null;
|
|
||||||
|
|
||||||
public ChannelsRequest() {}
|
|
||||||
|
|
||||||
public ChannelsRequest(String regex) {
|
|
||||||
this(DBMode.databuffer, regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChannelsRequest(DBMode dbMode, String regex) {
|
|
||||||
this.regex = regex;
|
|
||||||
this.dbMode = dbMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DBMode getDbMode() {
|
|
||||||
return dbMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDbMode(DBMode dbMode) {
|
|
||||||
this.dbMode = dbMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRegex() {
|
|
||||||
return regex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRegex(String regex) {
|
|
||||||
this.regex = regex;
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,7 +24,7 @@ import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
|
|||||||
|
|
||||||
import ch.psi.daq.query.model.Aggregation;
|
import ch.psi.daq.query.model.Aggregation;
|
||||||
import ch.psi.daq.query.model.QueryField;
|
import ch.psi.daq.query.model.QueryField;
|
||||||
import ch.psi.daq.query.model.impl.AbstractQuery;
|
import ch.psi.daq.query.model.impl.DAQQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a Java 8 stream and writes it to the output stream provided by the {@link ServletResponse}
|
* Takes a Java 8 stream and writes it to the output stream provided by the {@link ServletResponse}
|
||||||
@ -45,11 +45,11 @@ public class ResponseStreamWriter {
|
|||||||
* {@link ServletResponse}.
|
* {@link ServletResponse}.
|
||||||
*
|
*
|
||||||
* @param stream Mapping from channel name to data
|
* @param stream Mapping from channel name to data
|
||||||
* @param query concrete instance of {@link AbstractQuery}
|
* @param query concrete instance of {@link DAQQuery}
|
||||||
* @param response {@link ServletResponse} instance given by the current HTTP request
|
* @param response {@link ServletResponse} instance given by the current HTTP request
|
||||||
* @throws IOException thrown if writing to the output stream fails
|
* @throws IOException thrown if writing to the output stream fails
|
||||||
*/
|
*/
|
||||||
public void respond(Stream<Entry<String, ?>> stream, AbstractQuery query,
|
public void respond(Stream<Entry<String, ?>> stream, DAQQuery query,
|
||||||
ServletResponse response) throws IOException {
|
ServletResponse response) throws IOException {
|
||||||
|
|
||||||
Set<QueryField> queryFields = query.getFields();
|
Set<QueryField> queryFields = query.getFields();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<Pattern>.%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n
|
<Pattern>.%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n
|
||||||
</Pattern>
|
</Pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
|
@ -10,12 +10,14 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|||||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||||
|
|
||||||
|
import ch.psi.daq.cassandra.request.range.RequestRangeDate;
|
||||||
|
import ch.psi.daq.cassandra.request.range.RequestRangePulseId;
|
||||||
|
import ch.psi.daq.cassandra.request.range.RequestRangeTime;
|
||||||
import ch.psi.daq.cassandra.util.test.CassandraDataGen;
|
import ch.psi.daq.cassandra.util.test.CassandraDataGen;
|
||||||
import ch.psi.daq.common.ordering.Ordering;
|
import ch.psi.daq.common.ordering.Ordering;
|
||||||
import ch.psi.daq.query.model.AggregationType;
|
import ch.psi.daq.query.model.AggregationType;
|
||||||
import ch.psi.daq.query.model.impl.PulseRangeQuery;
|
import ch.psi.daq.query.model.Query;
|
||||||
import ch.psi.daq.query.model.impl.TimeRangeQuery;
|
import ch.psi.daq.query.model.impl.DAQQuery;
|
||||||
import ch.psi.daq.query.model.impl.TimeRangeQueryDate;
|
|
||||||
import ch.psi.daq.queryrest.controller.QueryRestController;
|
import ch.psi.daq.queryrest.controller.QueryRestController;
|
||||||
import ch.psi.daq.test.cassandra.admin.CassandraTestAdmin;
|
import ch.psi.daq.test.cassandra.admin.CassandraTestAdmin;
|
||||||
import ch.psi.daq.test.queryrest.AbstractDaqRestTest;
|
import ch.psi.daq.test.queryrest.AbstractDaqRestTest;
|
||||||
@ -67,9 +69,10 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPulseRangeQuery() throws Exception {
|
public void testPulseRangeQuery() throws Exception {
|
||||||
PulseRangeQuery request = new PulseRangeQuery(
|
Query request = new DAQQuery(
|
||||||
|
new RequestRangePulseId(
|
||||||
100,
|
100,
|
||||||
101,
|
101),
|
||||||
TEST_CHANNEL_NAMES);
|
TEST_CHANNEL_NAMES);
|
||||||
|
|
||||||
String content = mapper.writeValueAsString(request);
|
String content = mapper.writeValueAsString(request);
|
||||||
@ -100,9 +103,10 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTimeRangeQuery() throws Exception {
|
public void testTimeRangeQuery() throws Exception {
|
||||||
TimeRangeQuery request = new TimeRangeQuery(
|
Query request = new DAQQuery(
|
||||||
|
new RequestRangeTime(
|
||||||
100,
|
100,
|
||||||
101,
|
101),
|
||||||
TEST_CHANNEL_NAMES);
|
TEST_CHANNEL_NAMES);
|
||||||
|
|
||||||
String content = mapper.writeValueAsString(request);
|
String content = mapper.writeValueAsString(request);
|
||||||
@ -129,11 +133,12 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDateRangeQuery() throws Exception {
|
public void testDateRangeQuery() throws Exception {
|
||||||
String startDate = TimeRangeQueryDate.format(100);
|
String startDate = RequestRangeDate.format(100);
|
||||||
String endDate = TimeRangeQueryDate.format(101);
|
String endDate = RequestRangeDate.format(101);
|
||||||
TimeRangeQueryDate request = new TimeRangeQueryDate(
|
Query request = new DAQQuery(
|
||||||
|
new RequestRangeDate(
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate),
|
||||||
TEST_CHANNEL_NAMES);
|
TEST_CHANNEL_NAMES);
|
||||||
|
|
||||||
String content = mapper.writeValueAsString(request);
|
String content = mapper.writeValueAsString(request);
|
||||||
@ -163,9 +168,10 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtremaAggregation() throws Exception {
|
public void testExtremaAggregation() throws Exception {
|
||||||
PulseRangeQuery request = new PulseRangeQuery(
|
Query request = new DAQQuery(
|
||||||
|
new RequestRangePulseId(
|
||||||
100,
|
100,
|
||||||
101,
|
101),
|
||||||
false,
|
false,
|
||||||
Ordering.asc,
|
Ordering.asc,
|
||||||
AggregationType.extrema,
|
AggregationType.extrema,
|
||||||
|
Reference in New Issue
Block a user