private AsyncIndexer getIndexer() throws RegistryException { try { if (asyncIndexer == null) { synchronized (this) { if (asyncIndexer == null) { asyncIndexer = null;//AsyncIndexer.getInstance(); asyncIndexer = new AsyncIndexer(); new Thread(asyncIndexer).run(); } } } return asyncIndexer; } catch (SolrException e) { throw new RegistryException(e.getMessage(),e); } }
@Override public RetryPolicy getRetryPolicy(Throwable exception, SolrRequest request, SolrClient server, RetryPolicy currentPolicy) { if (exception instanceof SolrException) { SolrException sex = (SolrException) exception; if (sex.code() == ErrorCode.UNAUTHORIZED.code) { return RetryPolicyFactory.DONT_RETRY; // no point retrying that - would never succeed } if (sex.code() == ErrorCode.UNSUPPORTED_MEDIA_TYPE.code) { return RetryPolicyFactory.DONT_RETRY; // no point retrying that - would never succeed } if (sex.getMessage().startsWith("undefined field")) { // schema.xml mismatch, see IndexSchema.java return RetryPolicyFactory.DONT_RETRY; // no point retrying that - would never succeed } } if (currentPolicy == null) { return initialRetryPolicy; // init } else { return currentPolicy; // continue with current policy } }
/** * Makes sure a query throws a SolrException with the listed response code and expected message * @param failMessage The assert message to show when the query doesn't throw the expected exception * @param exceptionMessage A substring of the message expected in the exception * @param req Solr request * @param code expected error code for the query */ public static void assertQEx(String failMessage, String exceptionMessage, SolrQueryRequest req, SolrException.ErrorCode code ) { try { ignoreException("."); h.query(req); fail( failMessage ); } catch (SolrException e) { assertEquals( code.code, e.code() ); assertTrue("Unexpected error message. Expecting \"" + exceptionMessage + "\" but got \"" + e.getMessage() + "\"", e.getMessage()!= null && e.getMessage().contains(exceptionMessage)); } catch (Exception e2) { throw new RuntimeException("Exception during query", e2); } finally { unIgnoreException("."); } }
@Override public boolean execute() throws PingNotConfiguredException { try { SolrPingResponse response = server.ping(); if(response.getStatus() == 0) { return true; } } catch (SolrServerException e) { return false; } catch (IOException e) { return false; } catch (SolrException e) { if(e.getMessage().startsWith("pingQuery_not_configured")) { throw new PingNotConfiguredException("Ping command is not configured on server."); } return false; } return false; }
LOGGER.error("Caught Solr exception creating core :: " + e.getMessage());
@Override public QueryOrSearchResponse executeQuery(final String coreName, final String queryString, final String[] fields, final int maxRows) { try { final SolrQuery query = new SolrQuery() .setRows(maxRows) .setFields(fields); final ObjectMapper mapper = new ObjectMapper(); final JsonNode queryDef = mapper.readTree(queryString); for (final Iterator<Map.Entry<String, JsonNode>> iterator = queryDef.fields(); iterator.hasNext(); ) { final Map.Entry<String, JsonNode> field = iterator.next(); query.add(field.getKey(), field.getValue().asText()); } return of(proxy.query(coreName, query)) .map(response -> new QueryOrSearchResponse( response.getResults().getNumFound(), new ArrayList<Map<String, Object>>(response.getResults()))) .get(); } catch (SolrException e) { LOGGER.error("Caught Solr exception :: " + e.getMessage()); return new QueryOrSearchResponse(0, Collections.emptyList()); } catch (final Exception exception) { throw new RuntimeException(exception); } }
return rsp; } catch (SolrException e) { log.error("Solr server exception while handling suggestion request (code {}): {}",e.code(), e.getMessage(),e); throw e; } catch (final InterruptedException e) {
case SERVICE_UNAVAILABLE: case SERVER_ERROR: return new DataAccessResourceFailureException(solrException.getMessage(), solrException); case FORBIDDEN: case UNAUTHORIZED: return new PermissionDeniedDataAccessException(solrException.getMessage(), solrException); case BAD_REQUEST: return new InvalidDataAccessApiUsageException(solrException.getMessage(), solrException); case UNKNOWN: return new UncategorizedSolrException(solrException.getMessage(), solrException); default: break;
LOG.debug(e.getMessage(), e); throw new RuntimeException(e); LOG.error(e.getMessage(), e); } catch (@SuppressWarnings("unused") RuntimeException e) {
} catch (SolrException e) { if (verbose) System.err.println("error contacting client: " + e.getMessage() + "\n"); continue;