use of eu.europeana.indexing.exception.IndexingException in project Europeana-Cloud by europeana.
the class IndexingBolt method execute.
@Override
public void execute(Tuple anchorTuple, StormTaskTuple stormTaskTuple) {
// Get variables.
final var useAltEnv = stormTaskTuple.getParameter(PluginParameterKeys.METIS_USE_ALT_INDEXING_ENV);
final var datasetId = stormTaskTuple.getParameter(PluginParameterKeys.METIS_DATASET_ID);
final var database = stormTaskTuple.getParameter(PluginParameterKeys.METIS_TARGET_INDEXING_DATABASE);
final var preserveTimestampsString = Boolean.parseBoolean(stormTaskTuple.getParameter(PluginParameterKeys.METIS_PRESERVE_TIMESTAMPS));
final var datasetIdsToRedirectFrom = stormTaskTuple.getParameter(PluginParameterKeys.DATASET_IDS_TO_REDIRECT_FROM);
final var datasetIdsToRedirectFromList = datasetIdsToRedirectFrom == null ? null : Arrays.asList(datasetIdsToRedirectFrom.trim().split("\\s*,\\s*"));
final var performRedirects = Boolean.parseBoolean(stormTaskTuple.getParameter(PluginParameterKeys.PERFORM_REDIRECTS));
DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US);
final Date recordDate;
try {
recordDate = dateFormat.parse(stormTaskTuple.getParameter(PluginParameterKeys.METIS_RECORD_DATE));
final var properties = new IndexingProperties(recordDate, preserveTimestampsString, datasetIdsToRedirectFromList, performRedirects, true);
String metisDatasetId = stormTaskTuple.getParameter(PluginParameterKeys.METIS_DATASET_ID);
String europeanaId = europeanaIdFinder.findForFileUrl(metisDatasetId, stormTaskTuple.getFileUrl());
if (!stormTaskTuple.isMarkedAsDeleted()) {
indexRecord(stormTaskTuple, useAltEnv, database, properties);
} else {
removeIndexedRecord(stormTaskTuple, useAltEnv, database, europeanaId);
}
updateHarvestedRecord(stormTaskTuple, europeanaId);
prepareTuple(stormTaskTuple, useAltEnv, datasetId, database, recordDate);
outputCollector.emit(anchorTuple, stormTaskTuple.toStormTuple());
LOGGER.info("Indexing bolt executed for: {} (alternative environment: {}, record date: {}, preserve timestamps: {}).", database, useAltEnv, recordDate, preserveTimestampsString);
} catch (RuntimeException | MalformedURLException | CloudException e) {
logAndEmitError(anchorTuple, e, e.getMessage(), stormTaskTuple);
} catch (ParseException e) {
logAndEmitError(anchorTuple, e, PARSE_RECORD_DATE_ERROR_MESSAGE, stormTaskTuple);
} catch (IndexingException e) {
logAndEmitError(anchorTuple, e, INDEXING_FILE_ERROR_MESSAGE, stormTaskTuple);
}
outputCollector.ack(anchorTuple);
}
use of eu.europeana.indexing.exception.IndexingException in project metis-sandbox by europeana.
the class IndexingServiceImpl method remove.
@Override
public void remove(String datasetId) {
requireNonNull(datasetId, "Dataset id must not be null");
try {
previewIndexer.removeAll(datasetId, null);
publishIndexer.removeAll(datasetId, null);
} catch (IndexingException e) {
throw new DatasetIndexRemoveException(datasetId, e);
}
}
use of eu.europeana.indexing.exception.IndexingException in project metis-sandbox by europeana.
the class IndexingServiceImpl method index.
@Override
public RecordInfo index(Record record, IndexEnvironment indexEnvironment) {
requireNonNull(record, "Record must not be null");
requireNonNull(indexEnvironment, "Index must not be null");
Indexer indexer = IndexEnvironment.PREVIEW == indexEnvironment ? previewIndexer : publishIndexer;
try {
indexer.index(record.getContentInputStream(), new IndexingProperties(new Date(), false, null, false, true));
} catch (IndexingException ex) {
throw new RecordProcessingException(record.getRecordId(), ex);
}
return new RecordInfo(record);
}
use of eu.europeana.indexing.exception.IndexingException in project metis-framework by europeana.
the class IndexerPool method indexRecord.
private void indexRecord(IndexTask indexTask) throws IndexingException {
// Obtain indexer from the pool.
final Indexer indexer;
try {
indexer = pool.borrowObject();
} catch (IndexingException e) {
throw e;
} catch (Exception e) {
throw new IndexerRelatedIndexingException("Error while obtaining indexer from the pool.", e);
}
// Perform indexing and release indexer.
try {
indexTask.performTask(indexer);
} catch (IndexerRelatedIndexingException e) {
invalidateAndSwallowException(indexer);
throw e;
} catch (IndexingException e) {
// If any other indexing exception occurs we want to return the indexer to the pool
pool.returnObject(indexer);
throw e;
}
// Return indexer to the pool if it has not been invalidated.
pool.returnObject(indexer);
}
use of eu.europeana.indexing.exception.IndexingException in project metis-framework by europeana.
the class FullBeanPublisher method publish.
/**
* Publishes an RDF.
*
* @param rdf RDF to publish.
* @param recordDate The date that would represent the created/updated date of a record
* @param datasetIdsToRedirectFrom The dataset ids that their records need to be redirected
* @param performRedirects flag that indicates if redirect should be performed
* @throws IndexingException which can be one of:
* <ul>
* <li>{@link IndexerRelatedIndexingException} In case an error occurred during publication.</li>
* <li>{@link SetupRelatedIndexingException} in case an error occurred during indexing setup</li>
* <li>{@link RecordRelatedIndexingException} in case an error occurred related to record
* contents</li>
* </ul>
*/
private void publish(RdfWrapper rdf, Date recordDate, List<String> datasetIdsToRedirectFrom, boolean performRedirects) throws IndexingException {
// Convert RDF to Full Bean.
final RdfToFullBeanConverter fullBeanConverter = fullBeanConverterSupplier.get();
final FullBeanImpl fullBean = fullBeanConverter.convertRdfToFullBean(rdf);
// Provide the preprocessor: this will set the created and updated timestamps as needed.
final TriConsumer<FullBeanImpl, FullBeanImpl, Pair<Date, Date>> fullBeanPreprocessor = preserveUpdateAndCreateTimesFromRdf ? EMPTY_PREPROCESSOR : (FullBeanPublisher::setUpdateAndCreateTime);
// Perform redirection
final List<Pair<String, Date>> recordsForRedirection;
try {
recordsForRedirection = RecordRedirectsUtil.checkAndApplyRedirects(recordRedirectDao, rdf, recordDate, datasetIdsToRedirectFrom, performRedirects, this::getSolrDocuments);
} catch (RuntimeException e) {
throw new RecordRelatedIndexingException(REDIRECT_PUBLISH_ERROR, e);
}
// Publish to Mongo
final FullBeanImpl savedFullBean;
try {
savedFullBean = new FullBeanUpdater(fullBeanPreprocessor).update(fullBean, recordDate, recordsForRedirection.stream().map(Pair::getValue).min(Comparator.naturalOrder()).orElse(null), edmMongoClient);
} catch (MongoIncompatibleDriverException | MongoConfigurationException | MongoSecurityException e) {
throw new SetupRelatedIndexingException(MONGO_SERVER_PUBLISH_ERROR, e);
} catch (MongoSocketException | MongoClientException | MongoInternalException | MongoInterruptedException e) {
throw new IndexerRelatedIndexingException(MONGO_SERVER_PUBLISH_ERROR, e);
} catch (RuntimeException e) {
throw new RecordRelatedIndexingException(MONGO_SERVER_PUBLISH_ERROR, e);
}
// Publish to Solr
try {
retryableExternalRequestForNetworkExceptions(() -> {
try {
publishToSolr(rdf, savedFullBean);
} catch (IndexingException e) {
throw new RuntimeException(e);
}
return null;
});
} catch (Exception e) {
throw new RecordRelatedIndexingException(SOLR_SERVER_PUBLISH_ERROR, e);
}
}
Aggregations