Java Code Examples for org.apache.solr.client.solrj.impl.HttpSolrClient#RemoteSolrException

The following examples show how to use org.apache.solr.client.solrj.impl.HttpSolrClient#RemoteSolrException . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPutSolrContentStream.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoteSolrExceptionShouldRouteToFailure() throws IOException, SolrServerException {
    final Throwable throwable = new HttpSolrClient.RemoteSolrException(
            "host", 401, "error", new NumberFormatException());
    final ExceptionThrowingProcessor proc = new ExceptionThrowingProcessor(throwable);

    final TestRunner runner = createDefaultTestRunner(proc);

    try (FileInputStream fileIn = new FileInputStream(CUSTOM_JSON_SINGLE_DOC_FILE)) {
        runner.enqueue(fileIn);
        runner.run();

        runner.assertAllFlowFilesTransferred(PutSolrContentStream.REL_FAILURE, 1);
        verify(proc.getSolrClient(), times(1)).request(any(SolrRequest.class), eq((String)null));
    }
}
 
Example 2
Source File: Solr6Index.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void commitChanges(String collectionName,
                           Collection<SolrInputDocument> documents) throws SolrServerException, IOException {
    if (documents.size() == 0) return;

    try {
        solrClient.request(newUpdateRequest().add(documents), collectionName);
    } catch (final HttpSolrClient.RemoteSolrException rse) {
        logger.error("Unable to save documents to Solr as one of the shape objects stored were not compatible with Solr.", rse);
        logger.error("Details in failed document batch: ");
        for (final SolrInputDocument d : documents) {
            final Collection<String> fieldNames = d.getFieldNames();
            for (final String name : fieldNames) {
                logger.error(name + ":" + d.getFieldValue(name));
            }
        }

        throw rse;
    }
}
 
Example 3
Source File: MarcSolrClient.java    From metadata-qa-marc with GNU General Public License v3.0 6 votes vote down vote up
public void indexMap(String id, Map<String, List<String>> objectMap)
    throws IOException, SolrServerException {
  SolrInputDocument document = new SolrInputDocument();
  document.addField("id", (trimId ? id.trim() : id));
  for (Map.Entry<String, List<String>> entry : objectMap.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    if (value != null) {
      if (!key.endsWith("_sni") && !key.endsWith("_ss"))
        key += "_ss";
      document.addField(key, value);
    }
  }

  try {
    UpdateResponse response = solr.add(document);
  } catch (HttpSolrClient.RemoteSolrException ex) {
    System.err.printf("document: %s", document);
    System.err.printf("Commit exception: %s%n", ex.getMessage());
  }
}
 
Example 4
Source File: MarcSolrClient.java    From metadata-qa-marc with GNU General Public License v3.0 6 votes vote down vote up
public void indexDuplumKey(String id, Map<String, Object> objectMap)
    throws IOException, SolrServerException {
  SolrInputDocument document = new SolrInputDocument();
  document.addField("id", id);
  for (Map.Entry<String, Object> entry : objectMap.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    if (value != null) {
      if (!key.endsWith("_sni") && !key.endsWith("_ss"))
        key += "_ss";
      document.addField(key, value);
    }
  }

  try {
    UpdateResponse response = solr.add(document);
  } catch (HttpSolrClient.RemoteSolrException ex) {
    System.err.printf("document: %s", document);
    System.err.printf("Commit exception: %s%n", ex.getMessage());
  }
}
 
Example 5
Source File: Solr5Index.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void commitDocumentChanges(String collectionName, Collection<SolrInputDocument> documents) throws SolrServerException, IOException {
    if (documents.size() == 0) return;

    try {
        solrClient.request(newUpdateRequest().add(documents), collectionName);
    } catch (HttpSolrClient.RemoteSolrException rse) {
        logger.error("Unable to save documents to Solr as one of the shape objects stored were not compatible with Solr.", rse);
        logger.error("Details in failed document batch: ");
        for (SolrInputDocument d : documents) {
            Collection<String> fieldNames = d.getFieldNames();
            for (String name : fieldNames) {
                logger.error(name + ":" + d.getFieldValue(name).toString());
            }
        }

        throw rse;
    }
}
 
Example 6
Source File: SolrTarget07.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void add(List<Map<String, Object>> fieldMaps) throws StageException {
  List<SolrInputDocument> documents = new ArrayList();
  for (Map<String, Object> fieldMap : fieldMaps) {
    SolrInputDocument document = createDocument(fieldMap);
    documents.add(document);
  }

  try {
    this.solrClient.add(documents);
  } catch (SolrServerException | IOException | HttpSolrClient.RemoteSolrException ex) {
    throw new StageException(Errors.SOLR_04, ex.toString(), ex);
  }
}
 
Example 7
Source File: SolrTarget06.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void add(List<Map<String, Object>> fieldMaps) throws StageException {
  List<SolrInputDocument> documents = new ArrayList();
  for(Map<String, Object> fieldMap : fieldMaps) {
    SolrInputDocument document = createDocument(fieldMap);
    documents.add(document);
  }

  try {
    this.solrClient.add(documents);
  } catch (SolrServerException | IOException | HttpSolrClient.RemoteSolrException ex) {
    throw new StageException(Errors.SOLR_04, ex.toString(), ex);
  }
}
 
Example 8
Source File: SolrWriter.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
public BulkWriterResponse write(String sourceType, WriterConfiguration configurations, List<BulkMessage<JSONObject>> messages) throws Exception {
  String collection = getCollection(sourceType, configurations);
  BulkWriterResponse bulkResponse = new BulkWriterResponse();
  Collection<SolrInputDocument> docs = toDocs(messages);
  Set<MessageId> ids = messages.stream().map(BulkMessage::getId).collect(Collectors.toSet());
  try {
    Optional<SolrException> exceptionOptional = fromUpdateResponse(solr.add(collection, docs));
    // Solr commits the entire batch or throws an exception for it.  There's no way to get partial failures.
    if(exceptionOptional.isPresent()) {
      bulkResponse.addAllErrors(exceptionOptional.get(), ids);
    }
    else {
      if (shouldCommit) {
        exceptionOptional = fromUpdateResponse(solr.commit(collection, waitFlush, waitSearcher, softCommit));
        if(exceptionOptional.isPresent()) {
          bulkResponse.addAllErrors(exceptionOptional.get(), ids);
        }
      }
      if(!exceptionOptional.isPresent()) {
        bulkResponse.addAllSuccesses(ids);
      }
    }
  }
  catch(HttpSolrClient.RemoteSolrException sse) {
    bulkResponse.addAllErrors(sse, ids);
  }

  return bulkResponse;
}