Search in sources :

Example 1 with SynchronousDataSetAnalyzer

use of org.talend.dataprep.dataset.service.analysis.synchronous.SynchronousDataSetAnalyzer in project data-prep by Talend.

the class DataSetAnalyzersTest method testSynchronousOrder.

@Test
public void testSynchronousOrder() throws Exception {
    synchronousAnalyzers.sort((analyzer1, analyzer2) -> analyzer1.order() - analyzer2.order());
    int previousOrder = -1;
    for (SynchronousDataSetAnalyzer synchronousAnalyzer : synchronousAnalyzers) {
        assertThat(synchronousAnalyzer.order(), greaterThan(previousOrder));
    }
}
Also used : SynchronousDataSetAnalyzer(org.talend.dataprep.dataset.service.analysis.synchronous.SynchronousDataSetAnalyzer) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) Test(org.junit.Test)

Example 2 with SynchronousDataSetAnalyzer

use of org.talend.dataprep.dataset.service.analysis.synchronous.SynchronousDataSetAnalyzer in project data-prep by Talend.

the class BaseDataSetService method analyzeDataSet.

/**
 * Performs the analysis on the given dataset id.
 *
 * @param id the dataset id.
 * @param performAsyncBackgroundAnalysis true if the asynchronous background analysis should be performed.
 * @param analysersToSkip the list of analysers to skip.
 */
protected final void analyzeDataSet(String id, boolean performAsyncBackgroundAnalysis, List<Class<? extends DataSetAnalyzer>> analysersToSkip) {
    // Calls all synchronous analysis first
    try {
        for (SynchronousDataSetAnalyzer synchronousDataSetAnalyzer : synchronousAnalyzers) {
            if (analysersToSkip.contains(synchronousDataSetAnalyzer.getClass())) {
                continue;
            }
            LOG.info("Running {}", synchronousDataSetAnalyzer.getClass());
            synchronousDataSetAnalyzer.analyze(id);
            LOG.info("Done running {}", synchronousDataSetAnalyzer.getClass());
        }
    } catch (Exception e) {
        // Clean up content & metadata (don't keep invalid information)
        try {
            final DataSetMetadata metadata = metadataBuilder.metadata().id(id).build();
            contentStore.delete(metadata);
            dataSetMetadataRepository.remove(id);
        } catch (Exception unableToCleanResources) {
            LOG.error("Unable to clean temporary resources for '{}'.", id, unableToCleanResources);
        }
        throw e;
    }
    // important log here (TDP-4137)
    final DataSetMetadata metadata = dataSetMetadataRepository.get(id);
    LOG.info("New DataSet #{}, name: {}, type: {}, from: {}", metadata.getId(), metadata.getName(), metadata.getContent().getMediaType(), metadata.getLocation().getStoreName());
    // perform async analysis
    if (performAsyncBackgroundAnalysis) {
        LOG.debug("starting async background analysis");
        publisher.publishEvent(new DatasetImportedEvent(id));
    } else {
        LOG.info("skipping asynchronous background analysis");
    }
}
Also used : SynchronousDataSetAnalyzer(org.talend.dataprep.dataset.service.analysis.synchronous.SynchronousDataSetAnalyzer) TDPException(org.talend.dataprep.exception.TDPException) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DatasetImportedEvent(org.talend.dataprep.dataset.event.DatasetImportedEvent)

Aggregations

SynchronousDataSetAnalyzer (org.talend.dataprep.dataset.service.analysis.synchronous.SynchronousDataSetAnalyzer)2 Test (org.junit.Test)1 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 DataSetBaseTest (org.talend.dataprep.dataset.DataSetBaseTest)1 DatasetImportedEvent (org.talend.dataprep.dataset.event.DatasetImportedEvent)1 TDPException (org.talend.dataprep.exception.TDPException)1