use of com.yahoo.documentapi.VisitorSession in project vespa by vespa-engine.
the class OperationHandlerImpl method visit.
@Override
public VisitResult visit(RestUri restUri, String documentSelection, VisitOptions options) throws RestApiException {
VisitorParameters visitorParameters = createVisitorParameters(restUri, documentSelection, options);
VisitorControlHandler visitorControlHandler = new VisitorControlHandler();
visitorParameters.setControlHandler(visitorControlHandler);
LocalDataVisitorHandler localDataVisitorHandler = new LocalDataVisitorHandler();
visitorParameters.setLocalDataHandler(localDataVisitorHandler);
final VisitorSession visitorSession;
try {
visitorSession = documentAccess.createVisitorSession(visitorParameters);
// Not sure if this line is required
visitorControlHandler.setSession(visitorSession);
} catch (Exception e) {
throw new RestApiException(Response.createErrorResponse(500, "Failed during parsing of arguments for visiting: " + ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.VISITOR_ERROR));
}
try {
return doVisit(visitorControlHandler, localDataVisitorHandler, restUri);
} finally {
visitorSession.destroy();
}
}
use of com.yahoo.documentapi.VisitorSession in project vespa by vespa-engine.
the class VdsVisitor method doSearch.
@Override
public void doSearch() throws InterruptedException, ParseException, TimeoutException {
VisitorSession session = visitorSessionFactory.createVisitorSession(params);
try {
if (!session.waitUntilDone(query.getTimeout())) {
log.log(LogLevel.DEBUG, "Visitor returned from waitUntilDone without being completed for " + query + " with selection " + params.getDocumentSelection());
session.abort();
throw new TimeoutException("Query timed out in " + VdsStreamingSearcher.class.getName());
}
} finally {
session.destroy();
log.log(LogLevel.DEBUG, () -> session.getTrace().toString());
}
query.trace(session.getTrace().toString(), false, 9);
if (params.getControlHandler().getResult().code == VisitorControlHandler.CompletionCode.SUCCESS) {
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, "VdsVisitor completed successfully for " + query + " with selection " + params.getDocumentSelection());
}
} else {
throw new IllegalArgumentException(// TODO: Is it necessary to use a runtime exception?
"Query failed: " + params.getControlHandler().getResult().code + ": " + params.getControlHandler().getResult().message);
}
}
use of com.yahoo.documentapi.VisitorSession in project vespa by vespa-engine.
the class VisitorSearcherTestCase method waitUntilDoneFailureReturnsTimeoutErrorHit.
@Test
public void waitUntilDoneFailureReturnsTimeoutErrorHit() throws Exception {
VisitorSession session = mock(VisitorSession.class);
when(session.waitUntilDone(anyLong())).thenReturn(false);
factory = mock(DocumentSessionFactory.class);
when(factory.createVisitorSession(any(VisitorParameters.class))).thenReturn(session);
Result result = invokeSearcherWithUserQuery();
assertNotNull(result.hits().getErrorHit());
assertEquals(Error.TIMEOUT.code, result.hits().getErrorHit().errors().iterator().next().getCode());
}
Aggregations