use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class SearchResource method search.
protected SearchResponse search(String query, int limit, String filter, boolean decorate, SearchUser searchUser, List<String> fieldList, Sort sorting, TimeRange timeRange) {
final Search search = createSearch(query, limit, filter, fieldList, sorting, timeRange);
final Optional<String> streamId = Searches.extractStreamId(filter);
final SearchJob searchJob = searchExecutor.execute(search, searchUser, ExecutionState.empty());
return extractSearchResponse(searchJob, query, decorate, fieldList, timeRange, streamId);
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class SearchResourceExecutionTest method executeSyncJobTriggersEvent.
@Test
public void executeSyncJobTriggersEvent() {
mockCurrentUserName("peterchen");
final SearchDTO search = mockSearchDTO();
final SearchJob searchJob = new SearchJob("deadbeef", search.toSearch(), "peterchen");
searchJob.addQueryResultFuture("query", CompletableFuture.completedFuture(QueryResult.emptyResult()));
searchJob.seal();
when(queryEngine.execute(any())).thenReturn(searchJob);
final Response response = this.searchResource.executeSyncJob(search, 100, searchUser);
final ArgumentCaptor<SearchJobExecutionEvent> eventCaptor = ArgumentCaptor.forClass(SearchJobExecutionEvent.class);
verify(this.eventBus, times(1)).post(eventCaptor.capture());
final SearchJobExecutionEvent searchJobExecutionEvent = eventCaptor.getValue();
assertThat(searchJobExecutionEvent.user()).isEqualTo(currentUser);
assertThat(searchJobExecutionEvent.searchJob().getId()).isEqualTo("deadbeef");
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class SearchExecutor method execute.
public SearchJob execute(Search search, SearchUser searchUser, ExecutionState executionState) {
final Search searchWithStreams = search.addStreamsToQueriesWithoutStreams(() -> searchUser.streams().loadAll());
final Search searchWithExecutionState = searchWithStreams.applyExecutionState(objectMapper, firstNonNull(executionState, ExecutionState.empty()));
authorize(searchWithExecutionState, searchUser);
final SearchJob searchJob = queryEngine.execute(searchJobService.create(searchWithExecutionState, searchUser.username()));
try {
Uninterruptibles.getUninterruptibly(searchJob.getResultFuture(), 60000, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
LOG.error("Error executing search job <{}>", searchJob.getId(), e);
throw new InternalServerErrorException("Error executing search job: " + e.getMessage(), e);
} catch (TimeoutException e) {
throw new InternalServerErrorException("Timeout while executing search job");
} catch (Exception e) {
LOG.error("Other error", e);
throw e;
}
return searchJob;
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class SearchResource method executeQuery.
@POST
@ApiOperation(value = "Execute the referenced search query asynchronously", notes = "Starts a new search, irrespective whether or not another is already running", response = SearchJobDTO.class)
@Path("{id}/execute")
@NoAuditEvent("Creating audit event manually in method body.")
@Produces({ MediaType.APPLICATION_JSON, SEARCH_FORMAT_V1 })
public Response executeQuery(@ApiParam(name = "id") @PathParam("id") String id, @ApiParam ExecutionState executionState, @Context SearchUser searchUser) {
final SearchJob searchJob = searchExecutor.execute(id, searchUser, executionState);
postAuditEvent(searchJob);
final SearchJobDTO searchJobDTO = SearchJobDTO.fromSearchJob(searchJob);
return Response.created(URI.create(BASE_PATH + "/status/" + searchJobDTO.id())).entity(searchJob).build();
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class SearchExecutorTest method addsStreamsToSearchWithoutStreams.
@Test
public void addsStreamsToSearchWithoutStreams() {
final Search search = mockSearch();
final SearchUser searchUser = mock(SearchUser.class);
when(searchUser.canReadView(any())).thenReturn(true);
when(searchUser.canReadStream(any())).thenReturn(true);
when(searchUser.username()).thenReturn("frank-drebin");
final SearchJob searchJob = mock(SearchJob.class);
when(searchJobService.create(search, "frank-drebin")).thenReturn(searchJob);
when(searchJob.getResultFuture()).thenReturn(CompletableFuture.completedFuture(null));
when(queryEngine.execute(searchJob)).thenReturn(searchJob);
when(searchDomain.getForUser(eq("search1"), eq(searchUser))).thenReturn(Optional.of(search));
this.searchExecutor.execute("search1", searchUser, ExecutionState.empty());
verify(search, times(1)).addStreamsToQueriesWithoutStreams(any());
}
Aggregations