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);
}
}
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;
}
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);
}
}
Aggregations