Search in sources :

Example 46 with UpdateResponse

use of org.apache.solr.client.solrj.response.UpdateResponse in project ddf by codice.

the class BackupCommandTest method setupMockSolrClientForBackup.

/**
     * See https://cwiki.apache.org/confluence/display/solr/Collections+API#CollectionsAPI-BACKUP:BackupCollection for
     * requests and responses.
     */
private void setupMockSolrClientForBackup(String collection, int optimizationStatusCode, int backupStatusCode, NamedList<String> backupErrorMessages) throws Exception {
    UpdateResponse optimizationResponse = getMockOptimizationResponse(optimizationStatusCode);
    when(mockSolrClient.optimize(eq(collection))).thenReturn(optimizationResponse);
    NamedList<Object> responseHeader = getResponseHeader(backupStatusCode);
    NamedList<Object> mockResponse = new NamedList<>();
    mockResponse.add("responseHeader", responseHeader);
    if (backupErrorMessages != null) {
        mockResponse.add("failure", backupErrorMessages);
    } else {
        mockResponse.add("success", new Object());
    }
    if (collection != null) {
        when(mockSolrClient.request(any(SolrRequest.class), eq(collection))).thenReturn(mockResponse);
    }
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest)

Example 47 with UpdateResponse

use of org.apache.solr.client.solrj.response.UpdateResponse in project ddf by codice.

the class PersistentStoreImpl method add.

@Override
public // Input Map is expected to have the suffixes on the key names
void add(String type, Map<String, Object> properties) throws PersistenceException {
    LOGGER.debug("type = {}", type);
    if (type == null || type.isEmpty()) {
        throw new PersistenceException("The type of object(s) to retrieve must be non-null and not blank, e.g., notification, metacard, etc.");
    }
    if (properties == null || properties.isEmpty() || properties.containsValue("guest")) {
        return;
    }
    LOGGER.debug("Adding entry of type {}", type);
    // Set Solr Core name to type and create solr client
    SolrClient solrClient = getSolrClient(type);
    if (solrClient == null) {
        throw new PersistenceException("Unable to create Solr client.");
    }
    Date now = new Date();
    //DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    //String createdDate = df.format(now);
    SolrInputDocument solrInputDocument = new SolrInputDocument();
    solrInputDocument.addField("createddate_tdt", now);
    for (Map.Entry<String, Object> entry : properties.entrySet()) {
        solrInputDocument.addField(entry.getKey(), entry.getValue());
    }
    try {
        UpdateResponse response = solrClient.add(solrInputDocument);
        LOGGER.debug("UpdateResponse from add of SolrInputDocument:  {}", response);
    } catch (SolrServerException e) {
        LOGGER.info("SolrServerException while adding Solr index for persistent type {}", type, e);
        doRollback(solrClient, type);
        throw new PersistenceException("SolrServerException while adding Solr index for persistent type " + type, e);
    } catch (IOException e) {
        LOGGER.info("IOException while adding Solr index for persistent type {}", type, e);
        doRollback(solrClient, type);
        throw new PersistenceException("IOException while adding Solr index for persistent type " + type, e);
    } catch (RuntimeException e) {
        LOGGER.info("RuntimeException while adding Solr index for persistent type {}", type, e);
        doRollback(solrClient, type);
        throw new PersistenceException("RuntimeException while adding Solr index for persistent type " + type, e);
    }
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrServerException(org.apache.solr.client.solrj.SolrServerException) PersistenceException(org.codice.ddf.persistence.PersistenceException) IOException(java.io.IOException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Date(java.util.Date)

Aggregations

UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)47 SolrInputDocument (org.apache.solr.common.SolrInputDocument)20 IOException (java.io.IOException)16 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)16 SolrServerException (org.apache.solr.client.solrj.SolrServerException)15 ArrayList (java.util.ArrayList)10 SolrClient (org.apache.solr.client.solrj.SolrClient)9 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)8 SolrDocument (org.apache.solr.common.SolrDocument)8 NamedList (org.apache.solr.common.util.NamedList)7 SolrException (org.apache.solr.common.SolrException)6 Test (org.junit.Test)6 Future (java.util.concurrent.Future)5 ExecutorService (java.util.concurrent.ExecutorService)4 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)4 DefaultSolrThreadFactory (org.apache.solr.util.DefaultSolrThreadFactory)4 HashMap (java.util.HashMap)3 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)3 SolrException (com.odysseusinc.arachne.portal.model.solr.SolrException)2 MalformedURLException (java.net.MalformedURLException)2