Search in sources :

Example 41 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)

Example 42 with UpdateResponse

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

the class BackupCommandTest method getMockOptimizationResponse.

private UpdateResponse getMockOptimizationResponse(int status) {
    UpdateResponse mockOptimizationResponse = mock(UpdateResponse.class);
    when(mockOptimizationResponse.getStatus()).thenReturn(status);
    return mockOptimizationResponse;
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse)

Example 43 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)

Aggregations

UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)43 SolrInputDocument (org.apache.solr.common.SolrInputDocument)17 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)16 IOException (java.io.IOException)13 SolrServerException (org.apache.solr.client.solrj.SolrServerException)12 ArrayList (java.util.ArrayList)10 SolrClient (org.apache.solr.client.solrj.SolrClient)8 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)8 SolrDocument (org.apache.solr.common.SolrDocument)8 NamedList (org.apache.solr.common.util.NamedList)7 Future (java.util.concurrent.Future)6 Test (org.junit.Test)6 ExecutorService (java.util.concurrent.ExecutorService)5 SolrException (org.apache.solr.common.SolrException)5 DefaultSolrThreadFactory (org.apache.solr.util.DefaultSolrThreadFactory)5 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)4 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)3 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)3 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2