Search in sources :

Example 16 with InvalidRangeParametersException

use of org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException in project graylog2-server by Graylog2.

the class DashboardWidgetCreator method fromRequest.

public DashboardWidget fromRequest(String widgetId, AddWidgetRequest awr, String userId) throws DashboardWidget.NoSuchWidgetTypeException, InvalidRangeParametersException, InvalidWidgetConfigurationException {
    final String id = isNullOrEmpty(widgetId) ? UUID.randomUUID().toString() : widgetId;
    // Build timerange.
    final Map<String, Object> timerangeConfig = (Map<String, Object>) awr.config().get("timerange");
    final TimeRange timeRange = timeRangeFactory.create(timerangeConfig);
    return buildDashboardWidget(awr.type(), id, awr.description(), 0, awr.config(), timeRange, userId);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) BasicDBObject(com.mongodb.BasicDBObject) Map(java.util.Map)

Example 17 with InvalidRangeParametersException

use of org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException in project graylog2-server by Graylog2.

the class ValueReferenceTypeIdResolverTest method testSerialization.

@Test
public void testSerialization() throws IOException, InvalidRangeParametersException {
    final RelativeRangeEntity relativeRange = RelativeRangeEntity.of(RelativeRange.create(300));
    final String json = objectMapper.writeValueAsString(relativeRange);
    assertThat(json).isNotNull();
}
Also used : RelativeRangeEntity(org.graylog2.contentpacks.model.entities.RelativeRangeEntity) Test(org.junit.Test)

Example 18 with InvalidRangeParametersException

use of org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException in project graylog2-server by Graylog2.

the class QueryEffectiveTimeRangeTest method returnQueryTimeRangeIfNoSearchTypeTimeRangeAndNoGlobalOverride.

@Test
public void returnQueryTimeRangeIfNoSearchTypeTimeRangeAndNoGlobalOverride() throws InvalidRangeParametersException {
    final SearchType searchType = mock(SearchType.class);
    when(searchType.timerange()).thenReturn(Optional.empty());
    final Query queryWithTimeRange = query.toBuilder().timerange(RelativeRange.create(3600)).build();
    final TimeRange result = queryWithTimeRange.effectiveTimeRange(searchType);
    assertThat(result).isEqualTo(RelativeRange.create(3600));
}
Also used : DerivedTimeRange(org.graylog.plugins.views.search.timeranges.DerivedTimeRange) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Test(org.junit.Test)

Example 19 with InvalidRangeParametersException

use of org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException in project graylog2-server by Graylog2.

the class QueryEffectiveTimeRangeTest method returnGlobalOverrideTimeRangeIfPresent.

@Test
public void returnGlobalOverrideTimeRangeIfPresent() throws InvalidRangeParametersException {
    final SearchType searchType = mock(SearchType.class);
    when(searchType.timerange()).thenReturn(Optional.of(DerivedTimeRange.of(RelativeRange.create(7200))));
    final Query queryWithTimeRange = query.toBuilder().timerange(RelativeRange.create(3600)).globalOverride(GlobalOverride.builder().timerange(RelativeRange.create(600)).build()).build();
    final TimeRange result = queryWithTimeRange.effectiveTimeRange(searchType);
    assertThat(result).isEqualTo(RelativeRange.create(600));
}
Also used : DerivedTimeRange(org.graylog.plugins.views.search.timeranges.DerivedTimeRange) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Test(org.junit.Test)

Example 20 with InvalidRangeParametersException

use of org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException in project graylog2-server by Graylog2.

the class ESTimeHandlerTest method timeSpecIntervalIsCalculatedOnPivotTimerangeIfOverridden.

@Test
public void timeSpecIntervalIsCalculatedOnPivotTimerangeIfOverridden() throws InvalidRangeParametersException {
    final ArgumentCaptor<TimeRange> timeRangeCaptor = ArgumentCaptor.forClass(TimeRange.class);
    when(interval.toDateInterval(timeRangeCaptor.capture())).thenReturn(DateInterval.days(1));
    when(pivot.timerange()).thenReturn(Optional.of(DerivedTimeRange.of(RelativeRange.create(4242))));
    this.esTimeHandler.doCreateAggregation("foobar", pivot, time, esPivot, queryContext, query);
    final TimeRange argumentTimeRange = timeRangeCaptor.getValue();
    assertThat(argumentTimeRange).isEqualTo(RelativeRange.create(4242));
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DerivedTimeRange(org.graylog.plugins.views.search.timeranges.DerivedTimeRange) Test(org.junit.Test)

Aggregations

TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)13 DerivedTimeRange (org.graylog.plugins.views.search.timeranges.DerivedTimeRange)10 Test (org.junit.Test)9 InvalidRangeParametersException (org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException)8 BasicDBObject (com.mongodb.BasicDBObject)3 DashboardWidget (org.graylog2.dashboards.widgets.DashboardWidget)3 InvalidWidgetConfigurationException (org.graylog2.dashboards.widgets.InvalidWidgetConfigurationException)3 ResultMessage (org.graylog2.indexer.results.ResultMessage)3 Message (org.graylog2.plugin.Message)3 MessageSummary (org.graylog2.plugin.MessageSummary)3 Timed (com.codahale.metrics.annotation.Timed)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 BadRequestException (javax.ws.rs.BadRequestException)2 Produces (javax.ws.rs.Produces)2 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)2 SearchConfig (org.graylog.plugins.views.search.engine.SearchConfig)2