Search in sources :

Example 1 with IndexingException

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);
}
Also used : IndexingException(eu.europeana.indexing.exception.IndexingException) MalformedURLException(java.net.MalformedURLException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CloudException(eu.europeana.cloud.client.uis.rest.CloudException) ParseException(java.text.ParseException) IndexingProperties(eu.europeana.indexing.IndexingProperties) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with IndexingException

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);
    }
}
Also used : IndexingException(eu.europeana.indexing.exception.IndexingException) DatasetIndexRemoveException(eu.europeana.metis.sandbox.common.exception.DatasetIndexRemoveException)

Example 3 with IndexingException

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);
}
Also used : IndexingException(eu.europeana.indexing.exception.IndexingException) RecordProcessingException(eu.europeana.metis.sandbox.common.exception.RecordProcessingException) Indexer(eu.europeana.indexing.Indexer) RecordInfo(eu.europeana.metis.sandbox.domain.RecordInfo) IndexingProperties(eu.europeana.indexing.IndexingProperties) Date(java.util.Date)

Example 4 with IndexingException

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);
}
Also used : IndexingException(eu.europeana.indexing.exception.IndexingException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) IndexingException(eu.europeana.indexing.exception.IndexingException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException)

Example 5 with IndexingException

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);
    }
}
Also used : MongoConfigurationException(com.mongodb.MongoConfigurationException) MongoClientException(com.mongodb.MongoClientException) MongoInterruptedException(com.mongodb.MongoInterruptedException) MongoIncompatibleDriverException(com.mongodb.MongoIncompatibleDriverException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) MongoInternalException(com.mongodb.MongoInternalException) MongoClientException(com.mongodb.MongoClientException) MongoConfigurationException(com.mongodb.MongoConfigurationException) MongoSocketException(com.mongodb.MongoSocketException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IndexingException(eu.europeana.indexing.exception.IndexingException) MongoInterruptedException(com.mongodb.MongoInterruptedException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) IOException(java.io.IOException) MongoSecurityException(com.mongodb.MongoSecurityException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) MongoIncompatibleDriverException(com.mongodb.MongoIncompatibleDriverException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) IndexingException(eu.europeana.indexing.exception.IndexingException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) FullBeanImpl(eu.europeana.corelib.solr.bean.impl.FullBeanImpl) MongoSecurityException(com.mongodb.MongoSecurityException) RdfToFullBeanConverter(eu.europeana.indexing.fullbean.RdfToFullBeanConverter) FullBeanUpdater(eu.europeana.indexing.mongo.FullBeanUpdater) MongoSocketException(com.mongodb.MongoSocketException) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) IndexerRelatedIndexingException(eu.europeana.indexing.exception.IndexerRelatedIndexingException) Pair(org.apache.commons.lang3.tuple.Pair) MongoInternalException(com.mongodb.MongoInternalException)

Aggregations

IndexingException (eu.europeana.indexing.exception.IndexingException)6 IndexingProperties (eu.europeana.indexing.IndexingProperties)2 IndexerRelatedIndexingException (eu.europeana.indexing.exception.IndexerRelatedIndexingException)2 SetupRelatedIndexingException (eu.europeana.indexing.exception.SetupRelatedIndexingException)2 Date (java.util.Date)2 Pair (org.apache.commons.lang3.tuple.Pair)2 MongoClientException (com.mongodb.MongoClientException)1 MongoConfigurationException (com.mongodb.MongoConfigurationException)1 MongoIncompatibleDriverException (com.mongodb.MongoIncompatibleDriverException)1 MongoInternalException (com.mongodb.MongoInternalException)1 MongoInterruptedException (com.mongodb.MongoInterruptedException)1 MongoSecurityException (com.mongodb.MongoSecurityException)1 MongoSocketException (com.mongodb.MongoSocketException)1 CloudException (eu.europeana.cloud.client.uis.rest.CloudException)1 FullBeanImpl (eu.europeana.corelib.solr.bean.impl.FullBeanImpl)1 Indexer (eu.europeana.indexing.Indexer)1 RecordRelatedIndexingException (eu.europeana.indexing.exception.RecordRelatedIndexingException)1 RdfToFullBeanConverter (eu.europeana.indexing.fullbean.RdfToFullBeanConverter)1 FullBeanUpdater (eu.europeana.indexing.mongo.FullBeanUpdater)1 EdmLabel (eu.europeana.indexing.solr.EdmLabel)1