diff --git a/graylog2-server/src/main/java/org/graylog2/alerts/types/FieldValueAlertCondition.java b/graylog2-server/src/main/java/org/graylog2/alerts/types/FieldValueAlertCondition.java index aafccd62ff61..6a9cdb7dbe60 100644 --- a/graylog2-server/src/main/java/org/graylog2/alerts/types/FieldValueAlertCondition.java +++ b/graylog2-server/src/main/java/org/graylog2/alerts/types/FieldValueAlertCondition.java @@ -20,7 +20,7 @@ import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.AssistedInject; import org.graylog2.alerts.AbstractAlertCondition; -import org.graylog2.indexer.IndexHelper; +import org.graylog2.indexer.InvalidRangeFormatException; import org.graylog2.indexer.results.FieldStatsResult; import org.graylog2.indexer.results.ResultMessage; import org.graylog2.indexer.searches.Searches; @@ -158,7 +158,7 @@ protected CheckResult runCheck() { // cannot happen lol LOG.error("Invalid timerange.", e); return null; - } catch (IndexHelper.InvalidRangeFormatException e) { + } catch (InvalidRangeFormatException e) { // lol same here LOG.error("Invalid timerange format.", e); return null; diff --git a/graylog2-server/src/main/java/org/graylog2/alerts/types/MessageCountAlertCondition.java b/graylog2-server/src/main/java/org/graylog2/alerts/types/MessageCountAlertCondition.java index 1065825c9edf..e57d83d7c280 100644 --- a/graylog2-server/src/main/java/org/graylog2/alerts/types/MessageCountAlertCondition.java +++ b/graylog2-server/src/main/java/org/graylog2/alerts/types/MessageCountAlertCondition.java @@ -20,7 +20,7 @@ import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.AssistedInject; import org.graylog2.alerts.AbstractAlertCondition; -import org.graylog2.indexer.IndexHelper; +import org.graylog2.indexer.InvalidRangeFormatException; import org.graylog2.indexer.results.CountResult; import org.graylog2.indexer.results.ResultMessage; import org.graylog2.indexer.results.SearchResult; @@ -116,7 +116,7 @@ protected CheckResult runCheck() { // cannot happen lol LOG.error("Invalid timerange.", e); return null; - } catch (IndexHelper.InvalidRangeFormatException e) { + } catch (InvalidRangeFormatException e) { // lol same here LOG.error("Invalid timerange format.", e); return null; diff --git a/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/FieldChartWidget.java b/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/FieldChartWidget.java index 26b5c0f2fb96..01064cb2819b 100644 --- a/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/FieldChartWidget.java +++ b/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/FieldChartWidget.java @@ -18,7 +18,7 @@ import com.codahale.metrics.MetricRegistry; import com.google.common.collect.ImmutableMap; -import org.graylog2.indexer.IndexHelper; +import org.graylog2.indexer.InvalidRangeFormatException; import org.graylog2.indexer.results.HistogramResult; import org.graylog2.indexer.searches.Searches; import org.graylog2.indexer.searches.timeranges.TimeRange; @@ -99,10 +99,6 @@ protected ComputationResult compute() { String msg = "Could not calculate [" + this.getClass().getCanonicalName() + "] widget <" + getId() + ">. Not a numeric field? The field was [" + config.get("field") + "]"; LOG.error(msg, e); throw new RuntimeException(msg); - } catch (IndexHelper.InvalidRangeFormatException e) { - String msg = "Could not calculate [" + this.getClass().getCanonicalName() + "] widget <" + getId() + ">. Invalid time range."; - LOG.error(msg, e); - throw new RuntimeException(msg); } } diff --git a/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/QuickvaluesWidget.java b/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/QuickvaluesWidget.java index 1c152533fb6c..5d4691b0a354 100644 --- a/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/QuickvaluesWidget.java +++ b/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/QuickvaluesWidget.java @@ -19,7 +19,6 @@ import com.codahale.metrics.MetricRegistry; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import org.graylog2.indexer.IndexHelper; import org.graylog2.indexer.results.TermsResult; import org.graylog2.indexer.searches.Searches; import org.graylog2.indexer.searches.timeranges.TimeRange; @@ -87,21 +86,15 @@ protected ComputationResult compute() { filter = "streams:" + streamId; } - try { - final TermsResult terms = searches.terms(field, 50, query, filter, timeRange); + final TermsResult terms = searches.terms(field, 50, query, filter, timeRange); - Map result = Maps.newHashMap(); - result.put("terms", terms.getTerms()); - result.put("total", terms.getTotal()); - result.put("other", terms.getOther()); - result.put("missing", terms.getMissing()); + Map result = Maps.newHashMap(); + result.put("terms", terms.getTerms()); + result.put("total", terms.getTotal()); + result.put("other", terms.getOther()); + result.put("missing", terms.getMissing()); - return new ComputationResult(result, terms.took().millis()); - } catch (IndexHelper.InvalidRangeFormatException e) { - String msg = "Could not calculate [" + this.getClass().getCanonicalName() + "] widget <" + getId() + ">. Invalid time range."; - LOG.error(msg, e); - throw new RuntimeException(msg); - } + return new ComputationResult(result, terms.took().millis()); } private boolean checkConfig(Map config) { diff --git a/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/SearchResultChartWidget.java b/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/SearchResultChartWidget.java index 07a697809ef4..dfbe86234b8e 100644 --- a/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/SearchResultChartWidget.java +++ b/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/SearchResultChartWidget.java @@ -18,7 +18,6 @@ import com.codahale.metrics.MetricRegistry; import com.google.common.collect.ImmutableMap; -import org.graylog2.indexer.IndexHelper; import org.graylog2.indexer.results.HistogramResult; import org.graylog2.indexer.searches.Searches; import org.graylog2.indexer.searches.timeranges.TimeRange; @@ -90,11 +89,7 @@ protected ComputationResult compute() { filter = "streams:" + streamId; } - try { - HistogramResult histogram = searches.histogram(query, interval, filter, timeRange); - return new ComputationResult(histogram.getResults(), histogram.took().millis(), histogram.getHistogramBoundaries()); - } catch (IndexHelper.InvalidRangeFormatException e) { - throw new RuntimeException("Invalid timerange format.", e); - } + HistogramResult histogram = searches.histogram(query, interval, filter, timeRange); + return new ComputationResult(histogram.getResults(), histogram.took().millis(), histogram.getHistogramBoundaries()); } } diff --git a/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/SearchResultCountWidget.java b/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/SearchResultCountWidget.java index c871427f4cba..82036ee2edee 100644 --- a/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/SearchResultCountWidget.java +++ b/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/SearchResultCountWidget.java @@ -19,7 +19,6 @@ import com.codahale.metrics.MetricRegistry; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import org.graylog2.indexer.IndexHelper; import org.graylog2.indexer.results.CountResult; import org.graylog2.indexer.searches.Searches; import org.graylog2.indexer.searches.timeranges.AbsoluteRange; @@ -76,25 +75,21 @@ protected ComputationResult compute() { } protected ComputationResult computeInternal(String filter) { - try { - CountResult cr = searches.count(query, timeRange, filter); - if (trend && timeRange instanceof RelativeRange) { - DateTime toPrevious = timeRange.getFrom(); - DateTime fromPrevious = toPrevious.minus(Seconds.seconds(((RelativeRange) timeRange).getRange())); - TimeRange previousTimeRange = new AbsoluteRange(fromPrevious, toPrevious); - CountResult previousCr = searches.count(query, previousTimeRange); + CountResult cr = searches.count(query, timeRange, filter); + if (trend && timeRange instanceof RelativeRange) { + DateTime toPrevious = timeRange.getFrom(); + DateTime fromPrevious = toPrevious.minus(Seconds.seconds(((RelativeRange) timeRange).getRange())); + TimeRange previousTimeRange = new AbsoluteRange(fromPrevious, toPrevious); + CountResult previousCr = searches.count(query, previousTimeRange); - Map results = Maps.newHashMap(); - results.put("now", cr.getCount()); - results.put("previous", previousCr.getCount()); - long tookMs = cr.getTookMs() + previousCr.getTookMs(); + Map results = Maps.newHashMap(); + results.put("now", cr.getCount()); + results.put("previous", previousCr.getCount()); + long tookMs = cr.getTookMs() + previousCr.getTookMs(); - return new ComputationResult(results, tookMs); - } else { - return new ComputationResult(cr.getCount(), cr.getTookMs()); - } - } catch (IndexHelper.InvalidRangeFormatException e) { - throw new RuntimeException("Invalid timerange format.", e); + return new ComputationResult(results, tookMs); + } else { + return new ComputationResult(cr.getCount(), cr.getTookMs()); } } } diff --git a/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/StatisticalCountWidget.java b/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/StatisticalCountWidget.java index a6e7d8226d4e..3f51d1936554 100644 --- a/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/StatisticalCountWidget.java +++ b/graylog2-server/src/main/java/org/graylog2/dashboards/widgets/StatisticalCountWidget.java @@ -19,7 +19,6 @@ import com.codahale.metrics.MetricRegistry; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import org.graylog2.indexer.IndexHelper; import org.graylog2.indexer.results.FieldStatsResult; import org.graylog2.indexer.searches.Searches; import org.graylog2.indexer.searches.timeranges.AbsoluteRange; @@ -118,8 +117,6 @@ protected ComputationResult compute() { } else { return new ComputationResult(getStatisticalValue(fieldStatsResult), fieldStatsResult.took().millis()); } - } catch (IndexHelper.InvalidRangeFormatException e) { - throw new RuntimeException("Invalid timerange format.", e); } catch (Searches.FieldTypeException e) { throw new RuntimeException("Invalid field provided.", e); } diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/IndexHelper.java b/graylog2-server/src/main/java/org/graylog2/indexer/IndexHelper.java index 9707f6bad5eb..f0b1506bdad9 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/IndexHelper.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/IndexHelper.java @@ -127,6 +127,4 @@ public int compare(IndexRange o1, IndexRange o2) { return indices; } - public static class InvalidRangeFormatException extends Exception { - } } diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/InvalidRangeFormatException.java b/graylog2-server/src/main/java/org/graylog2/indexer/InvalidRangeFormatException.java new file mode 100644 index 000000000000..18be560799c9 --- /dev/null +++ b/graylog2-server/src/main/java/org/graylog2/indexer/InvalidRangeFormatException.java @@ -0,0 +1,19 @@ +package org.graylog2.indexer; + +public class InvalidRangeFormatException extends RuntimeException { + public InvalidRangeFormatException() { + super("Invalid timerange parameters provided"); + } + + public InvalidRangeFormatException(String message) { + super(message); + } + + public InvalidRangeFormatException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidRangeFormatException(Throwable cause) { + super("Invalid timerange parameters provided", cause); + } +} diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/InvalidRangeFormatExceptionMapper.java b/graylog2-server/src/main/java/org/graylog2/indexer/InvalidRangeFormatExceptionMapper.java new file mode 100644 index 000000000000..bf595030b6dd --- /dev/null +++ b/graylog2-server/src/main/java/org/graylog2/indexer/InvalidRangeFormatExceptionMapper.java @@ -0,0 +1,20 @@ +package org.graylog2.indexer; + +import org.graylog2.plugin.rest.ApiError; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +@Provider +public class InvalidRangeFormatExceptionMapper implements ExceptionMapper { + @Override + public Response toResponse(InvalidRangeFormatException exception) { + return Response + .status(Response.Status.BAD_REQUEST) + .type(MediaType.APPLICATION_JSON_TYPE) + .entity(new ApiError(exception.getMessage())) + .build(); + } +} diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/searches/Searches.java b/graylog2-server/src/main/java/org/graylog2/indexer/searches/Searches.java index 91d65b40c050..a25d4f85a91f 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/searches/Searches.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/searches/Searches.java @@ -17,8 +17,6 @@ package org.graylog2.indexer.searches; import com.google.common.collect.Sets; -import javax.inject.Inject; -import javax.inject.Singleton; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; @@ -33,7 +31,6 @@ import org.elasticsearch.index.query.QueryStringQueryBuilder; import org.elasticsearch.node.Node; import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogram; import org.elasticsearch.search.facet.FacetBuilders; import org.elasticsearch.search.facet.datehistogram.DateHistogramFacet; import org.elasticsearch.search.facet.datehistogram.DateHistogramFacetBuilder; @@ -63,6 +60,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; +import javax.inject.Singleton; import java.io.IOException; import java.util.List; import java.util.Set; @@ -131,11 +130,11 @@ public Searches(Configuration configuration, this.c = node.client(); } - public CountResult count(String query, TimeRange range) throws IndexHelper.InvalidRangeFormatException { + public CountResult count(String query, TimeRange range) { return count(query, range, null); } - public CountResult count(String query, TimeRange range, String filter) throws IndexHelper.InvalidRangeFormatException { + public CountResult count(String query, TimeRange range, String filter) { Set indices = IndexHelper.determineAffectedIndices(indexRangeService, deflector, range); SearchRequest request; @@ -150,7 +149,7 @@ public CountResult count(String query, TimeRange range, String filter) throws In return new CountResult(r.getHits().getTotalHits(), r.getTookInMillis(), r.getHits()); } - public ScrollResult scroll(String query, TimeRange range, int limit, int offset, List fields, String filter) throws IndexHelper.InvalidRangeFormatException { + public ScrollResult scroll(String query, TimeRange range, int limit, int offset, List fields, String filter) { final Set indices = IndexHelper.determineAffectedIndices(indexRangeService, deflector, range); final SearchRequestBuilder srb = standardSearchRequest(query, indices, limit, offset, range, null, false); if (range != null && filter != null) { @@ -181,11 +180,11 @@ public ScrollResult scroll(String query, TimeRange range, int limit, int offset, return new ScrollResult(c, query, request.source(), r, fields); } - public SearchResult search(String query, TimeRange range, int limit, int offset, Sorting sorting) throws IndexHelper.InvalidRangeFormatException { + public SearchResult search(String query, TimeRange range, int limit, int offset, Sorting sorting) { return search(query, null, range, limit, offset, sorting); } - public SearchResult search(String query, String filter, TimeRange range, int limit, int offset, Sorting sorting) throws IndexHelper.InvalidRangeFormatException { + public SearchResult search(String query, String filter, TimeRange range, int limit, int offset, Sorting sorting) { final SearchesConfig searchesConfig = SearchesConfigBuilder.newConfig() .setQuery(query) .setFilter(filter) @@ -198,7 +197,7 @@ public SearchResult search(String query, String filter, TimeRange range, int lim return search(searchesConfig); } - public SearchResult search(SearchesConfig config) throws IndexHelper.InvalidRangeFormatException { + public SearchResult search(SearchesConfig config) { Set indices = IndexHelper.determineAffectedIndicesWithRanges(indexRangeService, deflector, config.range()); Set indexNames = Sets.newHashSet(); @@ -212,7 +211,7 @@ public SearchResult search(SearchesConfig config) throws IndexHelper.InvalidRang return new SearchResult(r.getHits(), indices, config.query(), request.source(), r.getTook()); } - public TermsResult terms(String field, int size, String query, String filter, TimeRange range) throws IndexHelper.InvalidRangeFormatException { + public TermsResult terms(String field, int size, String query, String filter, TimeRange range) { if (size == 0) { size = 50; } @@ -244,11 +243,11 @@ public TermsResult terms(String field, int size, String query, String filter, Ti ); } - public TermsResult terms(String field, int size, String query, TimeRange range) throws IndexHelper.InvalidRangeFormatException { + public TermsResult terms(String field, int size, String query, TimeRange range) { return terms(field, size, query, null, range); } - public TermsStatsResult termsStats(String keyField, String valueField, TermsStatsOrder order, int size, String query, String filter, TimeRange range) throws IndexHelper.InvalidRangeFormatException { + public TermsStatsResult termsStats(String keyField, String valueField, TermsStatsOrder order, int size, String query, String filter, TimeRange range) { if (size == 0) { size = 50; } @@ -282,15 +281,15 @@ public TermsStatsResult termsStats(String keyField, String valueField, TermsStat ); } - public TermsStatsResult termsStats(String keyField, String valueField, TermsStatsOrder order, int size, String query, TimeRange range) throws IndexHelper.InvalidRangeFormatException { + public TermsStatsResult termsStats(String keyField, String valueField, TermsStatsOrder order, int size, String query, TimeRange range) { return termsStats(keyField, valueField, order, size, query, null, range); } - public FieldStatsResult fieldStats(String field, String query, TimeRange range) throws FieldTypeException, IndexHelper.InvalidRangeFormatException { + public FieldStatsResult fieldStats(String field, String query, TimeRange range) throws FieldTypeException { return fieldStats(field, query, null, range); } - public FieldStatsResult fieldStats(String field, String query, String filter, TimeRange range) throws FieldTypeException, IndexHelper.InvalidRangeFormatException { + public FieldStatsResult fieldStats(String field, String query, String filter, TimeRange range) throws FieldTypeException { SearchRequestBuilder srb; if (filter == null) { @@ -326,11 +325,11 @@ public FieldStatsResult fieldStats(String field, String query, String filter, Ti ); } - public HistogramResult histogram(String query, DateHistogramInterval interval, TimeRange range) throws IndexHelper.InvalidRangeFormatException { + public HistogramResult histogram(String query, DateHistogramInterval interval, TimeRange range) { return histogram(query, interval, null, range); } - public HistogramResult histogram(String query, DateHistogramInterval interval, String filter, TimeRange range) throws IndexHelper.InvalidRangeFormatException { + public HistogramResult histogram(String query, DateHistogramInterval interval, String filter, TimeRange range) { DateHistogramFacetBuilder fb = FacetBuilders.dateHistogramFacet("histogram") .field("timestamp") .interval(interval.toString().toLowerCase()); @@ -353,7 +352,7 @@ public HistogramResult histogram(String query, DateHistogramInterval interval, S interval, r.getTook()); } - public HistogramResult fieldHistogram(String query, String field, DateHistogramInterval interval, String filter, TimeRange range) throws FieldTypeException, IndexHelper.InvalidRangeFormatException { + public HistogramResult fieldHistogram(String query, String field, DateHistogramInterval interval, String filter, TimeRange range) throws FieldTypeException { DateHistogramFacetBuilder fb = FacetBuilders.dateHistogramFacet("histogram") .keyField("timestamp") .valueField(field) @@ -390,7 +389,7 @@ public SearchHit lastOfIndex(String index) { return oneOfIndex(index, matchAllQuery(), SortOrder.ASC); } - private SearchRequestBuilder searchRequest(SearchesConfig config, Set indices) throws IndexHelper.InvalidRangeFormatException { + private SearchRequestBuilder searchRequest(SearchesConfig config, Set indices) { final SearchRequestBuilder request; if (config.filter() == null) { @@ -411,11 +410,11 @@ private SearchRequestBuilder searchRequest(SearchesConfig config, Set in return request; } - private SearchRequestBuilder standardSearchRequest(String query, Set indices) throws IndexHelper.InvalidRangeFormatException { + private SearchRequestBuilder standardSearchRequest(String query, Set indices) { return standardSearchRequest(query, indices, 0, 0, null, null); } - private SearchRequestBuilder standardSearchRequest(String query, Set indices, TimeRange range) throws IndexHelper.InvalidRangeFormatException { + private SearchRequestBuilder standardSearchRequest(String query, Set indices, TimeRange range) { return standardSearchRequest(query, indices, 0, 0, range, null); } @@ -424,7 +423,7 @@ private SearchRequestBuilder standardSearchRequest(String query, int limit, int offset, TimeRange range, - Sorting sort) throws IndexHelper.InvalidRangeFormatException { + Sorting sort) { return standardSearchRequest(query, indices, limit, offset, range, sort, true); } @@ -435,7 +434,7 @@ private SearchRequestBuilder standardSearchRequest( int offset, TimeRange range, Sorting sort, - boolean highlight) throws IndexHelper.InvalidRangeFormatException { + boolean highlight) { if (query == null || query.trim().isEmpty()) { query = "*"; } @@ -473,15 +472,15 @@ private SearchRequestBuilder standardSearchRequest( return srb; } - private SearchRequestBuilder filteredSearchRequest(String query, String filter, Set indices) throws IndexHelper.InvalidRangeFormatException { + private SearchRequestBuilder filteredSearchRequest(String query, String filter, Set indices) { return filteredSearchRequest(query, filter, indices, 0, 0, null, null); } - private SearchRequestBuilder filteredSearchRequest(String query, String filter, Set indices, TimeRange range) throws IndexHelper.InvalidRangeFormatException { + private SearchRequestBuilder filteredSearchRequest(String query, String filter, Set indices, TimeRange range) { return filteredSearchRequest(query, filter, indices, 0, 0, range, null); } - private SearchRequestBuilder filteredSearchRequest(String query, String filter, Set indices, int limit, int offset, TimeRange range, Sorting sort) throws IndexHelper.InvalidRangeFormatException { + private SearchRequestBuilder filteredSearchRequest(String query, String filter, Set indices, int limit, int offset, TimeRange range, Sorting sort) { SearchRequestBuilder srb = standardSearchRequest(query, indices, limit, offset, range, sort); if (range != null && filter != null) { @@ -506,7 +505,7 @@ private SearchHit oneOfIndex(String index, QueryBuilder q, SortOrder sort) { } } - private BoolFilterBuilder standardFilters(TimeRange range, String filter) throws IndexHelper.InvalidRangeFormatException { + private BoolFilterBuilder standardFilters(TimeRange range, String filter) { BoolFilterBuilder bfb = FilterBuilders.boolFilter(); boolean set = false; diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/search/AbsoluteSearchResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/search/AbsoluteSearchResource.java index 7d7b367fba72..727c31481f45 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/search/AbsoluteSearchResource.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/search/AbsoluteSearchResource.java @@ -25,7 +25,6 @@ import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.glassfish.jersey.server.ChunkedOutput; -import org.graylog2.indexer.IndexHelper; import org.graylog2.indexer.results.ScrollResult; import org.graylog2.indexer.searches.Searches; import org.graylog2.indexer.searches.SearchesConfig; @@ -101,9 +100,6 @@ public SearchResponse searchAbsolute( try { return buildSearchResponse(searches.search(searchesConfig), timeRange); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -144,8 +140,6 @@ public ChunkedOutput searchAbsoluteChunked( return output; } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); - } catch (IndexHelper.InvalidRangeFormatException e) { - throw new BadRequestException(e); } } @@ -170,9 +164,6 @@ public TermsResult termsAbsolute( try { return buildTermsResult(searches.terms(field, size, query, filter, buildAbsoluteTimeRange(from, to))); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -198,7 +189,7 @@ public TermsStatsResult termsStatsAbsolute( @ApiParam(name = "size", value = "Maximum number of terms to return", required = false) @QueryParam("size") int size, @ApiParam(name = "from", value = "Timerange start. See search method description for date format", required = true) @QueryParam("from") String from, @ApiParam(name = "to", value = "Timerange end. See search method description for date format", required = true) @QueryParam("to") String to, - @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter) throws IndexHelper.InvalidRangeFormatException { + @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter) { checkSearchPermission(filter, RestPermissions.SEARCHES_ABSOLUTE); try { @@ -211,9 +202,6 @@ public TermsStatsResult termsStatsAbsolute( filter, buildAbsoluteTimeRange(from, to) )); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -242,9 +230,6 @@ public FieldStatsResult statsAbsolute( try { return buildFieldStatsResult(fieldStats(field, query, filter, buildAbsoluteTimeRange(from, to))); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -281,9 +266,6 @@ public HistogramResult histogramAbsolute( buildAbsoluteTimeRange(from, to) ) ); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -316,9 +298,6 @@ public HistogramResult fieldHistogramAbsolute( try { return buildHistogramResult(fieldHistogram(field, query, interval, filter, buildAbsoluteTimeRange(from, to))); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/search/KeywordSearchResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/search/KeywordSearchResource.java index e0f93a47ffbb..4b81aae8a4ab 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/search/KeywordSearchResource.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/search/KeywordSearchResource.java @@ -25,7 +25,6 @@ import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.glassfish.jersey.server.ChunkedOutput; -import org.graylog2.indexer.IndexHelper; import org.graylog2.indexer.results.ScrollResult; import org.graylog2.indexer.searches.Searches; import org.graylog2.indexer.searches.SearchesConfig; @@ -100,9 +99,6 @@ public SearchResponse searchKeyword( try { return buildSearchResponse(searches.search(searchesConfig), timeRange); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -141,8 +137,6 @@ public ChunkedOutput searchKeywordChunked( return output; } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); - } catch (IndexHelper.InvalidRangeFormatException e) { - throw new BadRequestException("Invalid timerange parameters provided", e); } } @@ -176,9 +170,6 @@ public HistogramResult histogramKeyword( buildKeywordTimeRange(keyword) ) ); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -204,9 +195,6 @@ public TermsResult termsKeyword( try { return buildTermsResult(searches.terms(field, size, query, filter, buildKeywordTimeRange(keyword))); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException(e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -231,16 +219,13 @@ public TermsStatsResult termsStatsRelative( @QueryParam("query") @NotEmpty String query, @ApiParam(name = "size", value = "Maximum number of terms to return", required = false) @QueryParam("size") int size, @ApiParam(name = "keyword", value = "Keyword timeframe", required = true) @QueryParam("keyword") String keyword, - @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter) throws IndexHelper.InvalidRangeFormatException { + @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter) { checkSearchPermission(filter, RestPermissions.SEARCHES_KEYWORD); try { return buildTermsStatsResult( searches.termsStats(keyField, valueField, Searches.TermsStatsOrder.valueOf(order.toUpperCase()), size, query, filter, buildKeywordTimeRange(keyword)) ); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -268,9 +253,6 @@ public FieldStatsResult statsKeyword( try { return buildFieldStatsResult(fieldStats(field, query, filter, buildKeywordTimeRange(keyword))); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -302,9 +284,6 @@ public HistogramResult fieldHistogramKeyword( try { return buildHistogramResult(fieldHistogram(field, query, interval, filter, buildKeywordTimeRange(keyword))); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/search/RelativeSearchResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/search/RelativeSearchResource.java index 337309d6c068..a209fbc29241 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/search/RelativeSearchResource.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/search/RelativeSearchResource.java @@ -25,7 +25,6 @@ import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.glassfish.jersey.server.ChunkedOutput; -import org.graylog2.indexer.IndexHelper; import org.graylog2.indexer.results.ScrollResult; import org.graylog2.indexer.searches.Searches; import org.graylog2.indexer.searches.SearchesConfig; @@ -82,7 +81,7 @@ public SearchResponse searchRelative( @ApiParam(name = "offset", value = "Offset", required = false) @QueryParam("offset") int offset, @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return", required = false) @QueryParam("fields") String fields, - @ApiParam(name = "sort", value = "Sorting (field:asc / field:desc)", required = false) @QueryParam("sort") String sort) throws IndexHelper.InvalidRangeFormatException { + @ApiParam(name = "sort", value = "Sorting (field:asc / field:desc)", required = false) @QueryParam("sort") String sort) { checkSearchPermission(filter, RestPermissions.SEARCHES_RELATIVE); final List fieldList = parseOptionalFields(fields); @@ -140,8 +139,6 @@ public ChunkedOutput searchRelativeChunked( return output; } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); - } catch (IndexHelper.InvalidRangeFormatException e) { - throw new BadRequestException(e); } } @@ -160,14 +157,11 @@ public TermsResult termsRelative( @QueryParam("query") @NotEmpty String query, @ApiParam(name = "size", value = "Maximum number of terms to return", required = false) @QueryParam("size") int size, @ApiParam(name = "range", value = "Relative timeframe to search in. See search method description.", required = true) @QueryParam("range") int range, - @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter) throws IndexHelper.InvalidRangeFormatException { + @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter) { checkSearchPermission(filter, RestPermissions.SEARCHES_RELATIVE); try { return buildTermsResult(searches.terms(field, size, query, filter, buildRelativeTimeRange(range))); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -192,16 +186,13 @@ public TermsStatsResult termsStatsRelative( @QueryParam("query") @NotEmpty String query, @ApiParam(name = "size", value = "Maximum number of terms to return", required = false) @QueryParam("size") int size, @ApiParam(name = "range", value = "Relative timeframe to search in. See search method description.", required = true) @QueryParam("range") int range, - @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter) throws IndexHelper.InvalidRangeFormatException { + @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter) { checkSearchPermission(filter, RestPermissions.SEARCHES_RELATIVE); try { return buildTermsStatsResult( searches.termsStats(keyField, valueField, Searches.TermsStatsOrder.valueOf(order.toUpperCase()), size, query, filter, buildRelativeTimeRange(range)) ); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException(e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -229,9 +220,6 @@ public FieldStatsResult statsRelative( try { return buildFieldStatsResult(fieldStats(field, query, filter, buildRelativeTimeRange(range))); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -267,9 +255,6 @@ public HistogramResult histogramRelative( buildRelativeTimeRange(range) ) ); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } @@ -301,9 +286,6 @@ public HistogramResult fieldHistogramRelative( try { return buildHistogramResult(fieldHistogram(field, query, interval, filter, buildRelativeTimeRange(range))); - } catch (IndexHelper.InvalidRangeFormatException e) { - LOG.warn("Invalid timerange parameters provided. Returning HTTP 400.", e); - throw new BadRequestException("Invalid timerange parameters provided", e); } catch (SearchPhaseExecutionException e) { throw createRequestExceptionForParseFailure(query, e); } diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/search/SearchResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/search/SearchResource.java index 093c7573e55d..fbd710a73bac 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/search/SearchResource.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/search/SearchResource.java @@ -25,7 +25,7 @@ import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.search.SearchParseException; import org.glassfish.jersey.server.ChunkedOutput; -import org.graylog2.indexer.IndexHelper; +import org.graylog2.indexer.InvalidRangeFormatException; import org.graylog2.indexer.results.ScrollResult; import org.graylog2.indexer.results.SearchResult; import org.graylog2.indexer.searches.Searches; @@ -101,7 +101,7 @@ protected List parseOptionalFields(String fields) { } protected org.graylog2.indexer.results.FieldStatsResult fieldStats(String field, String query, String filter, - org.graylog2.indexer.searches.timeranges.TimeRange timeRange) throws IndexHelper.InvalidRangeFormatException { + org.graylog2.indexer.searches.timeranges.TimeRange timeRange) throws InvalidRangeFormatException { try { return searches.fieldStats(field, query, filter, timeRange); } catch (Searches.FieldTypeException e) { @@ -111,7 +111,7 @@ protected org.graylog2.indexer.results.FieldStatsResult fieldStats(String field, } protected org.graylog2.indexer.results.HistogramResult fieldHistogram(String field, String query, String interval, - String filter, org.graylog2.indexer.searches.timeranges.TimeRange timeRange) throws IndexHelper.InvalidRangeFormatException { + String filter, org.graylog2.indexer.searches.timeranges.TimeRange timeRange) throws InvalidRangeFormatException { try { return searches.fieldHistogram( query, diff --git a/graylog2-server/src/main/java/org/graylog2/rest/resources/sources/SourcesResource.java b/graylog2-server/src/main/java/org/graylog2/rest/resources/sources/SourcesResource.java index ea7fcafb4d3a..ebecb29de0bb 100644 --- a/graylog2-server/src/main/java/org/graylog2/rest/resources/sources/SourcesResource.java +++ b/graylog2-server/src/main/java/org/graylog2/rest/resources/sources/SourcesResource.java @@ -26,7 +26,7 @@ import com.wordnik.swagger.annotations.ApiResponses; import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.graylog2.indexer.IndexHelper; +import org.graylog2.indexer.InvalidRangeFormatException; import org.graylog2.indexer.results.TermsResult; import org.graylog2.indexer.searches.Searches; import org.graylog2.indexer.searches.timeranges.InvalidRangeParametersException; @@ -90,7 +90,7 @@ public SourcesList list( public TermsResult call() throws Exception { try { return searches.terms("source", 5000, "*", new RelativeRange(range)); - } catch (InvalidRangeParametersException | IndexHelper.InvalidRangeFormatException e) { + } catch (InvalidRangeParametersException | InvalidRangeFormatException e) { throw new ExecutionException(e); } } diff --git a/graylog2-server/src/test/java/org/graylog2/alerts/types/FieldValueAlertConditionTest.java b/graylog2-server/src/test/java/org/graylog2/alerts/types/FieldValueAlertConditionTest.java index 2f92cd9e24ce..dc28f44bfaf0 100644 --- a/graylog2-server/src/test/java/org/graylog2/alerts/types/FieldValueAlertConditionTest.java +++ b/graylog2-server/src/test/java/org/graylog2/alerts/types/FieldValueAlertConditionTest.java @@ -17,7 +17,7 @@ package org.graylog2.alerts.types; import org.graylog2.alerts.AlertConditionTest; -import org.graylog2.indexer.IndexHelper; +import org.graylog2.indexer.InvalidRangeFormatException; import org.graylog2.indexer.results.FieldStatsResult; import org.graylog2.indexer.searches.Searches; import org.graylog2.indexer.searches.timeranges.RelativeRange; @@ -147,7 +147,7 @@ protected FieldValueAlertCondition getFieldValueAlertCondition(Map