Channel/Config hasher

This commit is contained in:
Fabian Märki
2017-12-01 08:50:20 +01:00
parent 7b71a2a394
commit 92710685d6
5 changed files with 121 additions and 10 deletions

View File

@ -50,6 +50,7 @@ import ch.psi.daq.domain.query.DAQQueryElement;
import ch.psi.daq.domain.query.backend.BackendQuery;
import ch.psi.daq.domain.query.channels.ChannelConfigurationsRequest;
import ch.psi.daq.domain.query.channels.ChannelsRequest;
import ch.psi.daq.domain.query.channels.LongHash;
import ch.psi.daq.domain.query.operation.Aggregation;
import ch.psi.daq.domain.query.operation.AggregationType;
import ch.psi.daq.domain.query.operation.Compression;
@ -123,6 +124,14 @@ public class QueryRestController implements ApplicationContextAware {
}
}
@RequestMapping(
value = DomainConfig.PATH_CHANNELS_HASH,
method = {RequestMethod.GET},
produces = {MediaType.APPLICATION_JSON_VALUE})
public LongHash getChannelsHash() throws Throwable {
return queryManager.getChannelsHash();
}
@RequestMapping(
value = DomainConfig.PATH_CHANNELS,
method = {RequestMethod.GET, RequestMethod.POST},
@ -148,6 +157,14 @@ public class QueryRestController implements ApplicationContextAware {
getChannels(new ChannelsRequest(channelName), res);
}
@RequestMapping(
value = DomainConfig.PATH_CHANNELS_CONFIG_HASH,
method = {RequestMethod.GET},
produces = {MediaType.APPLICATION_JSON_VALUE})
public LongHash getChannelConfigurationsHash() throws Throwable {
return queryManager.getChannelConfigurationsHash();
}
@RequestMapping(
value = DomainConfig.PATH_CHANNELS_CONFIG,
method = {RequestMethod.GET, RequestMethod.POST},

View File

@ -17,17 +17,24 @@ import ch.psi.daq.domain.query.channels.ChannelConfigurationsRequest;
import ch.psi.daq.domain.query.channels.ChannelConfigurationsResponse;
import ch.psi.daq.domain.query.channels.ChannelsRequest;
import ch.psi.daq.domain.query.channels.ChannelsResponse;
import ch.psi.daq.domain.query.channels.LongHash;
public interface QueryManager {
LongHash getChannelsHash();
Stream<ChannelsResponse> getChannels(final ChannelsRequest request) throws Exception;
Stream<ChannelConfigurationsResponse> getChannelConfigurations(final ChannelConfigurationsRequest request) throws Exception;
LongHash getChannelConfigurationsHash();
Stream<ChannelConfigurationsResponse> getChannelConfigurations(final ChannelConfigurationsRequest request)
throws Exception;
ChannelConfiguration getChannelConfiguration(final ChannelName channel) throws Exception;
Entry<DAQConfigQueryElement, Stream<Triple<BackendQuery, ChannelName, ?>>> queryConfigs(final DAQConfigQuery query) throws Exception;
Entry<DAQConfigQueryElement, Stream<Triple<BackendQuery, ChannelName, ?>>> queryConfigs(final DAQConfigQuery query)
throws Exception;
List<Entry<DAQQueryElement, Stream<Triple<BackendQuery, ChannelName, ?>>>> queryEvents(final DAQQueries queries)
throws Exception;
}
}

View File

@ -33,6 +33,7 @@ import ch.psi.daq.domain.query.channels.ChannelConfigurationsRequest;
import ch.psi.daq.domain.query.channels.ChannelConfigurationsResponse;
import ch.psi.daq.domain.query.channels.ChannelsRequest;
import ch.psi.daq.domain.query.channels.ChannelsResponse;
import ch.psi.daq.domain.query.channels.LongHash;
import ch.psi.daq.domain.query.processor.QueryProcessor;
import ch.psi.daq.query.config.QueryConfig;
import ch.psi.daq.queryrest.config.QueryRestConfig;
@ -47,13 +48,19 @@ public class QueryManagerImpl implements QueryManager, ApplicationContextAware {
final Backend backend = context.getBean(DomainConfig.BEAN_NAME_BACKEND_DEFAULT, Backend.class);
context = backend.getApplicationContext();
channelsCache = context.getBean(QueryConfig.BEAN_NAME_HISTORIC_CHANNELS_CACHE, BackendsChannelConfigurationCache.class);
channelsCache =
context.getBean(QueryConfig.BEAN_NAME_HISTORIC_CHANNELS_CACHE, BackendsChannelConfigurationCache.class);
queryAnalizerFactory = context.getBean(QueryRestConfig.BEAN_NAME_QUERY_ANALIZER_FACTORY, Function.class);
}
@PreDestroy
public void destroy() {}
@Override
public LongHash getChannelsHash() {
return channelsCache.getChannelsHash();
}
@Override
public Stream<ChannelsResponse> getChannels(ChannelsRequest request) {
// in case not specified use defaults (e.g. GET)
@ -64,6 +71,11 @@ public class QueryManagerImpl implements QueryManager, ApplicationContextAware {
return channelsCache.getChannels(request);
}
@Override
public LongHash getChannelConfigurationsHash() {
return channelsCache.getChannelConfigurationsHash();
}
@Override
public Stream<ChannelConfigurationsResponse> getChannelConfigurations(ChannelConfigurationsRequest request) {
// in case not specified use defaults (e.g. GET)
@ -100,7 +112,7 @@ public class QueryManagerImpl implements QueryManager, ApplicationContextAware {
return channelToConfig.entrySet().stream()
.map(entry -> {
return Triple.of(
query,
query,
new ChannelName(entry.getKey(), query.getBackend()),
entry.getValue());
});

View File

@ -19,6 +19,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
@ -32,6 +33,7 @@ import ch.psi.daq.domain.query.DAQQueries;
import ch.psi.daq.domain.query.DAQQuery;
import ch.psi.daq.domain.query.DAQQueryElement;
import ch.psi.daq.domain.query.channels.ChannelsRequest;
import ch.psi.daq.domain.query.channels.LongHash;
import ch.psi.daq.domain.query.operation.Aggregation;
import ch.psi.daq.domain.query.operation.AggregationDescriptor;
import ch.psi.daq.domain.query.operation.AggregationType;
@ -72,6 +74,8 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest implements
private Backend backend;
private Backend backend2;
private Backend backend3;
private ObjectMapper objectMapper = new ObjectMapper();
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
@ -122,6 +126,41 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest implements
.andExpect(MockMvcResultMatchers.jsonPath("$[2].channels[1]").value("BoolWaveform"));
}
@Test
public void testChannelsHash() throws Exception {
MvcResult result = this.mockMvc
.perform(
MockMvcRequestBuilders
.get(DomainConfig.PATH_CHANNELS_HASH)
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String response = result.getResponse().getContentAsString();
System.out.println("Response: " + response);
LongHash hash1 =
objectMapper.readValue(response, LongHash.class);
result = this.mockMvc
.perform(
MockMvcRequestBuilders
.get(DomainConfig.PATH_CHANNELS_HASH)
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
response = result.getResponse().getContentAsString();
System.out.println("Response: " + response);
LongHash hash2 =
objectMapper.readValue(response, LongHash.class);
assertEquals(hash1.getHash(), hash2.getHash());
}
@Test
public void testSpecificChannelSearch() throws Exception {

View File

@ -33,6 +33,7 @@ import ch.psi.daq.domain.json.ChannelConfigurationsList;
import ch.psi.daq.domain.query.DAQConfigQuery;
import ch.psi.daq.domain.query.channels.ChannelConfigurationsRequest;
import ch.psi.daq.domain.query.channels.ChannelConfigurationsResponse;
import ch.psi.daq.domain.query.channels.LongHash;
import ch.psi.daq.domain.request.range.RequestRangePulseId;
import ch.psi.daq.test.queryrest.AbstractDaqRestTest;
@ -49,6 +50,41 @@ public class QueryRestControllerChannelConfigurationTest extends AbstractDaqRest
@After
public void tearDown() throws Exception {}
@Test
public void testChannelConfigurationsHash() throws Exception {
MvcResult result = this.mockMvc
.perform(
MockMvcRequestBuilders
.get(DomainConfig.PATH_CHANNELS_CONFIG_HASH)
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
String response = result.getResponse().getContentAsString();
System.out.println("Response: " + response);
LongHash hash1 =
objectMapper.readValue(response, LongHash.class);
result = this.mockMvc
.perform(
MockMvcRequestBuilders
.get(DomainConfig.PATH_CHANNELS_CONFIG_HASH)
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();
response = result.getResponse().getContentAsString();
System.out.println("Response: " + response);
LongHash hash2 =
objectMapper.readValue(response, LongHash.class);
assertEquals(hash1.getHash(), hash2.getHash());
}
@Test
public void testChannelConfigurationQuery_01() throws Exception {
DAQConfigQuery query = new DAQConfigQuery(