ATEST-81:
- added dummy write method for REST interface
This commit is contained in:
@ -3,11 +3,13 @@ package ch.psi.daq.rest;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import ch.psi.daq.cassandra.writer.CassandraWriter;
|
||||||
|
import ch.psi.daq.cassandra.writer.CassandraWriterImpl;
|
||||||
import ch.psi.daq.common.statistic.StorelessStatistics;
|
import ch.psi.daq.common.statistic.StorelessStatistics;
|
||||||
import ch.psi.daq.domain.cassandra.ChannelEvent;
|
import ch.psi.daq.domain.cassandra.ChannelEvent;
|
||||||
import ch.psi.daq.hazelcast.query.processor.QueryProcessor;
|
import ch.psi.daq.hazelcast.query.processor.QueryProcessor;
|
||||||
|
import ch.psi.daq.hazelcast.query.processor.cassandra.CassandraQueryProcessorLocal;
|
||||||
import ch.psi.daq.rest.model.PropertyFilterMixin;
|
import ch.psi.daq.rest.model.PropertyFilterMixin;
|
||||||
import ch.psi.daq.test.rest.query.DummyQueryProcessor;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
@ -18,9 +20,15 @@ public class DaqRestConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public QueryProcessor queryProcessor() {
|
public QueryProcessor queryProcessor() {
|
||||||
return new DummyQueryProcessor();
|
// return new DummyQueryProcessor();
|
||||||
|
return new CassandraQueryProcessorLocal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CassandraWriter cassandraWriter() {
|
||||||
|
return new CassandraWriterImpl();
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JsonFactory jsonFactory() {
|
public JsonFactory jsonFactory() {
|
||||||
return new JsonFactory();
|
return new JsonFactory();
|
||||||
|
@ -2,6 +2,8 @@ package ch.psi.daq.rest;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@ -13,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import ch.psi.daq.cassandra.writer.CassandraWriter;
|
||||||
|
import ch.psi.daq.domain.cassandra.ChannelEvent;
|
||||||
import ch.psi.daq.domain.cassandra.DataEvent;
|
import ch.psi.daq.domain.cassandra.DataEvent;
|
||||||
import ch.psi.daq.hazelcast.query.processor.QueryProcessor;
|
import ch.psi.daq.hazelcast.query.processor.QueryProcessor;
|
||||||
import ch.psi.daq.rest.queries.AbstractQuery;
|
import ch.psi.daq.rest.queries.AbstractQuery;
|
||||||
@ -23,11 +27,13 @@ import ch.psi.daq.rest.queries.TimeRangeQuery;
|
|||||||
public class DaqRestController {
|
public class DaqRestController {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DaqRestController.class);
|
private static final Logger logger = LoggerFactory.getLogger(DaqRestController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CassandraWriter cassandraWriter;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ResponseStreamWriter responseStreamWriter;
|
private ResponseStreamWriter responseStreamWriter;
|
||||||
|
|
||||||
// TODO: just a dummy test implementation - remove when the real processor is ready
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private QueryProcessor queryProcessor;
|
private QueryProcessor queryProcessor;
|
||||||
|
|
||||||
@ -67,6 +73,7 @@ public class DaqRestController {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void executeQuery(AbstractQuery query, HttpServletResponse res) throws IOException {
|
private void executeQuery(AbstractQuery query, HttpServletResponse res) throws IOException {
|
||||||
|
|
||||||
// all the magic happens here
|
// all the magic happens here
|
||||||
Map<String, Stream<? extends DataEvent>> process = queryProcessor.process(query);
|
Map<String, Stream<? extends DataEvent>> process = queryProcessor.process(query);
|
||||||
|
|
||||||
@ -77,4 +84,21 @@ public class DaqRestController {
|
|||||||
// write the response back to the client using java 8 streams
|
// write the response back to the client using java 8 streams
|
||||||
responseStreamWriter.respond(flatStreams, query, res);
|
responseStreamWriter.respond(flatStreams, query, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/write")
|
||||||
|
public void writeDummyEntry() {
|
||||||
|
int pulseId = 100;
|
||||||
|
ChannelEvent event = new ChannelEvent(
|
||||||
|
"dummy-test",
|
||||||
|
pulseId,
|
||||||
|
0,
|
||||||
|
pulseId,
|
||||||
|
pulseId,
|
||||||
|
0,
|
||||||
|
"data_" + UUID.randomUUID().toString());
|
||||||
|
|
||||||
|
CompletableFuture<Void> future = cassandraWriter.writeAsync(3, 0, event);
|
||||||
|
future.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,12 +57,9 @@ public class ResponseStreamWriter {
|
|||||||
.stream()
|
.stream()
|
||||||
.map(a -> {
|
.map(a -> {
|
||||||
return a.getType().toString();
|
return a.getType().toString();
|
||||||
})
|
}).collect(Collectors.toSet()));
|
||||||
.collect(Collectors.toSet()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectWriter writer = configureWriter(includedFields);
|
ObjectWriter writer = configureWriter(includedFields);
|
||||||
|
|
||||||
respondInternal(stream, response, writer);
|
respondInternal(stream, response, writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import com.google.common.collect.Sets;
|
|||||||
/**
|
/**
|
||||||
* Tests the {@link DaqController} implementation.
|
* Tests the {@link DaqController} implementation.
|
||||||
*/
|
*/
|
||||||
public class DaqControllerTest extends AbstractDaqRestTest {
|
public class DaqRestControllerTest extends AbstractDaqRestTest {
|
||||||
|
|
||||||
private static final List<String> DEFAULT_PROPERTIES = Lists.newArrayList("channel", "pulseId");
|
private static final List<String> DEFAULT_PROPERTIES = Lists.newArrayList("channel", "pulseId");
|
||||||
|
|
@ -60,3 +60,7 @@ curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"timerange"
|
|||||||
|
|
||||||
curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"timerange","ordering":"ASC","channels":["test"],"fields":["channel","pulseId"],"aggregateChannels":false,"aggregationType":"index","queryRange":{"startMillis":1435049709091,"startNanos":0,"endMillis":1435049710091,"endNanos":0,"startPulseId":9223372036854775807,"endPulseId":9223372036854775807},"binningStrategyEnum":"bincount"}' http://localhost:8080/timerange
|
curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"timerange","ordering":"ASC","channels":["test"],"fields":["channel","pulseId"],"aggregateChannels":false,"aggregationType":"index","queryRange":{"startMillis":1435049709091,"startNanos":0,"endMillis":1435049710091,"endNanos":0,"startPulseId":9223372036854775807,"endPulseId":9223372036854775807},"binningStrategyEnum":"bincount"}' http://localhost:8080/timerange
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"pulserange","ordering":"ASC","channels":["dummy-test"],"fields":["channel","pulseId","globalMillis","globalNanos","dbValueBytes"],"binningStrategy":"bincount","binDuration":100,"aggregateChannels":"false","aggregationType":"index","aggregations":[{"fieldRef":"e_val","type":"max","resultFieldName":"maximum"},{"fieldRef":"e_val","type":"min","resultFieldName":"minimum"}], "queryRange":{"startPulseId":100,"endPulseId":100}}' http://localhost:8080/pulserange
|
Reference in New Issue
Block a user