use of org.apache.solr.client.solrj.SolrServerException in project dataverse by IQSS.
the class SolrIndexServiceBean method reindexFilesInBatches.
private String reindexFilesInBatches(List<DataFile> filesToReindexPermissionsFor) {
List<SolrInputDocument> docs = new ArrayList<>();
Map<Long, List<Long>> byParentId = new HashMap<>();
Map<Long, List<String>> permStringByDatasetVersion = new HashMap<>();
for (DataFile file : filesToReindexPermissionsFor) {
Dataset dataset = (Dataset) file.getOwner();
Map<DatasetVersion.VersionState, Boolean> desiredCards = searchPermissionsService.getDesiredCards(dataset);
for (DatasetVersion datasetVersionFileIsAttachedTo : datasetVersionsToBuildCardsFor(dataset)) {
boolean cardShouldExist = desiredCards.get(datasetVersionFileIsAttachedTo.getVersionState());
if (cardShouldExist) {
List<String> cachedPermission = permStringByDatasetVersion.get(datasetVersionFileIsAttachedTo.getId());
if (cachedPermission == null) {
logger.fine("no cached permission! Looking it up...");
List<DvObjectSolrDoc> fileSolrDocs = constructDatafileSolrDocs((DataFile) file, permStringByDatasetVersion);
for (DvObjectSolrDoc fileSolrDoc : fileSolrDocs) {
Long datasetVersionId = fileSolrDoc.getDatasetVersionId();
if (datasetVersionId != null) {
permStringByDatasetVersion.put(datasetVersionId, fileSolrDoc.getPermissions());
SolrInputDocument solrDoc = SearchUtil.createSolrDoc(fileSolrDoc);
docs.add(solrDoc);
}
}
} else {
logger.fine("cached permission is " + cachedPermission);
List<DvObjectSolrDoc> fileSolrDocsBasedOnCachedPermissions = constructDatafileSolrDocs((DataFile) file, permStringByDatasetVersion);
for (DvObjectSolrDoc fileSolrDoc : fileSolrDocsBasedOnCachedPermissions) {
SolrInputDocument solrDoc = SearchUtil.createSolrDoc(fileSolrDoc);
docs.add(solrDoc);
}
}
}
}
Long parent = file.getOwner().getId();
List<Long> existingList = byParentId.get(parent);
if (existingList == null) {
List<Long> empty = new ArrayList<>();
byParentId.put(parent, empty);
} else {
List<Long> updatedList = existingList;
updatedList.add(file.getId());
byParentId.put(parent, updatedList);
}
}
try {
persistToSolr(docs);
return " " + filesToReindexPermissionsFor.size() + " files indexed across " + docs.size() + " Solr documents ";
} catch (SolrServerException | IOException ex) {
return " tried to reindex " + filesToReindexPermissionsFor.size() + " files indexed across " + docs.size() + " Solr documents but caught exception: " + ex;
}
}
use of org.apache.solr.client.solrj.SolrServerException in project dataverse by IQSS.
the class IndexAllServiceBean method indexAllOrSubset.
public Future<String> indexAllOrSubset(long numPartitions, long partitionId, boolean skipIndexed) {
long indexAllTimeBegin = System.currentTimeMillis();
String status;
String resultOfClearingIndexTimes;
/**
* @todo Should we allow sysadmins to request that the Solr index and
* related timestamps in the database be cleared as part of "index all"?
* If so, we can make this boolean a parameter that's passed into this
* method. A method to do this clearing has been added as a separate API
* endpoint.
*/
boolean clearSolrAndTimestamps = false;
/**
* We only allow clearing of Solr and database index timestamps if we
* are operating on the entire index ("index all") and if we are not
* running in "continue" mode.
*/
if (numPartitions == 1 && !skipIndexed && clearSolrAndTimestamps) {
logger.info("attempting to delete all Solr documents before a complete re-index");
try {
JsonObject response = solrIndexService.deleteAllFromSolrAndResetIndexTimes().build();
String message = response.getString(SolrIndexServiceBean.messageString);
int numRowsCleared = response.getInt(SolrIndexServiceBean.numRowsClearedByClearAllIndexTimes);
resultOfClearingIndexTimes = message + " Database rows from which index timestamps were cleared: " + numRowsCleared;
} catch (SolrServerException | IOException ex) {
resultOfClearingIndexTimes = "Solr index and database timestamps were not cleared: " + ex;
}
} else {
resultOfClearingIndexTimes = "Solr index was not cleared before indexing.";
}
// List<Dataverse> dataverses = dataverseService.findAllOrSubset(numPartitions, partitionId, skipIndexed);
// Note: no support for "partitions" in this experimental branch.
// The method below returns the ids of all the unindexed dataverses.
List<Long> dataverseIds = dataverseIds = dataverseService.findDataverseIdsForIndexing(skipIndexed);
int dataverseIndexCount = 0;
int dataverseFailureCount = 0;
// for (Dataverse dataverse : dataverses) {
for (Long id : dataverseIds) {
try {
dataverseIndexCount++;
Dataverse dataverse = dataverseService.find(id);
logger.info("indexing dataverse " + dataverseIndexCount + " of " + dataverseIds.size() + " (id=" + id + ", persistentId=" + dataverse.getAlias() + ")");
Future<String> result = indexService.indexDataverseInNewTransaction(dataverse);
dataverse = null;
} catch (Exception e) {
// We want to keep running even after an exception so throw some more info into the log
dataverseFailureCount++;
logger.info("FAILURE indexing dataverse " + dataverseIndexCount + " of " + dataverseIds.size() + " (id=" + id + ") Exception info: " + e.getMessage());
}
}
int datasetIndexCount = 0;
int datasetFailureCount = 0;
List<Long> datasetIds = datasetService.findAllOrSubset(numPartitions, partitionId, skipIndexed);
for (Long id : datasetIds) {
try {
datasetIndexCount++;
logger.info("indexing dataset " + datasetIndexCount + " of " + datasetIds.size() + " (id=" + id + ")");
Future<String> result = indexService.indexDatasetInNewTransaction(id);
} catch (Exception e) {
// We want to keep running even after an exception so throw some more info into the log
datasetFailureCount++;
logger.info("FAILURE indexing dataset " + datasetIndexCount + " of " + datasetIds.size() + " (id=" + id + ") Exception info: " + e.getMessage());
}
}
logger.info("done iterating through all datasets");
long indexAllTimeEnd = System.currentTimeMillis();
String timeElapsed = "index all took " + (indexAllTimeEnd - indexAllTimeBegin) + " milliseconds";
logger.info(timeElapsed);
if (datasetFailureCount + dataverseFailureCount > 0) {
String failureMessage = "There were index failures. " + dataverseFailureCount + " dataverse(s) and " + datasetFailureCount + " dataset(s) failed to index. Please check the log for more information.";
logger.info(failureMessage);
}
status = dataverseIndexCount + " dataverses and " + datasetIndexCount + " datasets indexed. " + timeElapsed + ". " + resultOfClearingIndexTimes + "\n";
logger.info(status);
return new AsyncResult<>(status);
}
use of org.apache.solr.client.solrj.SolrServerException in project nextprot-api by calipho-sib.
the class SolrIndexer method addRemaing.
public void addRemaing() {
try {
if (docs.size() > 0) // There are some prepared docs not yet sent to solr server
{
solrServer.add(docs);
docs.clear();
}
} catch (SolrServerException | IOException e) {
throw new NextProtException(e);
}
}
use of org.apache.solr.client.solrj.SolrServerException in project nextprot-api by calipho-sib.
the class SolrIndexer method add.
public void add(T t) {
try {
SolrInputDocument doc = this.convertToSolrDocument(t);
if (doc == null)
return;
docs.add(doc);
if (docs.size() % BATCH_SIZE == 0) {
// System.err.println("sent " +docs.size() + " docs to solr so far");
this.solrServer.add(docs);
docs.clear();
}
} catch (SolrServerException | IOException e) {
throw new NextProtException(e);
}
}
use of org.apache.solr.client.solrj.SolrServerException in project streamline by hortonworks.
the class AmbariInfraWithStormLogSearch method searchEvent.
@Override
public EventSearchResult searchEvent(EventSearchCriteria criteria) {
SolrQuery query = new SolrQuery();
String searchString = criteria.getSearchString();
List<String> queryStrings = new ArrayList<>();
addQueryStringToListOnlyIfAvailable(queryStrings, searchString, COLUMN_NAME_STREAMLINE_EVENT_KEYVALUES);
addQueryStringToListOnlyIfAvailable(queryStrings, searchString, COLUMN_NAME_STREAMLINE_EVENT_HEADERS);
addQueryStringToListOnlyIfAvailable(queryStrings, searchString, COLUMN_NAME_STREAMLINE_EVENT_AUX_KEYVALUES);
// this is to get rid of non-streamline events
String queryString = buildColumnAndValue(COLUMN_NAME_STREAMLINE_EVENT_ID, buildValue(null));
if (!queryStrings.isEmpty()) {
queryString += " AND (" + String.join(" OR ", queryStrings) + ")";
}
query.setQuery(queryString);
query.addFilterQuery(buildColumnAndValue(COLUMN_NAME_TYPE, COLUMN_VALUE_TYPE_EVENT));
query.addFilterQuery(buildColumnAndValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID, buildValue(criteria.getAppId())));
query.addFilterQuery(buildColumnAndValue(COLUMN_NAME_LOG_TIME, buildDateRangeValue(criteria.getFrom(), criteria.getTo())));
List<String> componentNames = criteria.getComponentNames();
if (componentNames != null && !componentNames.isEmpty()) {
query.addFilterQuery(buildColumnAndValue(COLUMN_NAME_STREAMLINE_COMPONENT_NAME, buildORValues(componentNames)));
}
String searchEventId = criteria.getSearchEventId();
if (searchEventId != null) {
// eventId OR rootId OR parentId
String queryToEventId = buildColumnAndValue(COLUMN_NAME_STREAMLINE_EVENT_ID, buildValue(searchEventId));
String queryToRootIds = buildColumnAndValue(COLUMN_NAME_STREAMLINE_EVENT_ROOT_ID_SET, buildValue("*" + searchEventId + "*"));
String queryToParentIds = buildColumnAndValue(COLUMN_NAME_STREAMLINE_EVENT_PARENT_ID_SET, buildValue("*" + searchEventId + "*"));
query.addFilterQuery(queryToEventId + " OR " + queryToRootIds + " OR " + queryToParentIds);
}
if (criteria.getAscending() == null || criteria.getAscending()) {
query.addSort(COLUMN_NAME_LOG_TIME, SolrQuery.ORDER.asc);
} else {
query.addSort(COLUMN_NAME_LOG_TIME, SolrQuery.ORDER.desc);
}
if (criteria.getStart() != null) {
query.setStart(criteria.getStart());
}
if (criteria.getLimit() != null) {
query.setRows(criteria.getLimit());
}
LOG.debug("Querying to Solr: query => {}", query);
long numFound;
List<EventSearchResult.Event> results = new ArrayList<>();
try {
QueryResponse response = solr.query(query);
SolrDocumentList docList = response.getResults();
numFound = docList.getNumFound();
for (SolrDocument document : docList) {
String appId = (String) document.getFieldValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID);
String componentName = (String) document.getFieldValue(COLUMN_NAME_STREAMLINE_COMPONENT_NAME);
String eventId = (String) document.getFieldValue(COLUMN_NAME_STREAMLINE_EVENT_ID);
String rootIds = (String) document.getFieldValue(COLUMN_NAME_STREAMLINE_EVENT_ROOT_ID_SET);
String parentIds = (String) document.getFieldValue(COLUMN_NAME_STREAMLINE_EVENT_PARENT_ID_SET);
String keyValues = (String) document.getFieldValue(COLUMN_NAME_STREAMLINE_EVENT_KEYVALUES);
String headers = (String) document.getFieldValue(COLUMN_NAME_STREAMLINE_EVENT_HEADERS);
String auxKeyValues = (String) document.getFieldValue(COLUMN_NAME_STREAMLINE_EVENT_AUX_KEYVALUES);
Date logDate = (Date) document.getFieldValue(COLUMN_NAME_LOG_TIME);
long timestamp = logDate.toInstant().toEpochMilli();
EventSearchResult.Event event = new EventSearchResult.Event(appId, componentName, eventId, rootIds, parentIds, keyValues, headers, auxKeyValues, timestamp);
results.add(event);
}
} catch (SolrServerException | IOException e) {
// TODO: any fine-grained control needed?
throw new RuntimeException(e);
}
return new EventSearchResult(numFound, results);
}
Aggregations