Search in sources :

Example 1 with AsyncOperation

use of org.talend.dataprep.async.AsyncOperation in project data-prep by Talend.

the class TransformationService method executeMetadata.

@RequestMapping(value = "/apply/preparation/{preparationId}/{stepId}/metadata", method = GET)
@ApiOperation(value = "Run the transformation given the provided export parameters", notes = "This operation transforms the dataset or preparation using parameters in export parameters.")
@VolumeMetered
@// 
AsyncOperation(// 
conditionalClass = GetPrepMetadataAsyncCondition.class, // 
resultUrlGenerator = PrepMetadataGetContentUrlGenerator.class, executionIdGeneratorClass = PrepMetadataExecutionIdGenerator.class)
public DataSetMetadata executeMetadata(@PathVariable("preparationId") @AsyncParameter String preparationId, @PathVariable("stepId") @AsyncParameter String stepId) {
    LOG.debug("getting preparation metadata for #{}, step {}", preparationId, stepId);
    final PreparationDTO preparation = getPreparation(preparationId);
    if (preparation.getSteps().size() > 1) {
        String headId = "head".equalsIgnoreCase(stepId) ? preparation.getHeadId() : stepId;
        final TransformationMetadataCacheKey cacheKey = cacheKeyGenerator.generateMetadataKey(preparationId, headId, HEAD);
        // No metadata in cache, recompute it
        if (!contentCache.has(cacheKey)) {
            try {
                LOG.debug("Metadata not available for preparation '{}' at step '{}'", preparationId, headId);
                ExportParameters parameters = new ExportParameters();
                parameters.setPreparationId(preparationId);
                parameters.setExportType("JSON");
                parameters.setStepId(headId);
                parameters.setFrom(HEAD);
                // we regenerate cache
                parameters = exportParametersUtil.populateFromPreparationExportParameter(parameters);
                preparationExportStrategy.performPreparation(parameters, new NullOutputStream());
            } catch (Exception e) {
                throw new TDPException(TransformationErrorCodes.METADATA_NOT_FOUND, e);
            }
        }
        if (contentCache.has(cacheKey)) {
            try (InputStream stream = contentCache.get(cacheKey)) {
                return mapper.readerFor(DataSetMetadata.class).readValue(stream);
            } catch (IOException e) {
                throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
            }
        }
    } else {
        LOG.debug("No step in preparation '{}', falls back to get dataset metadata (id: {})", preparationId, preparation.getDataSetId());
        return datasetClient.getDataSetMetadata(preparation.getDataSetId());
    }
    return null;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) ExportParameters(org.talend.dataprep.api.export.ExportParameters) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) TransformationMetadataCacheKey(org.talend.dataprep.cache.TransformationMetadataCacheKey) IOException(java.io.IOException) IOException(java.io.IOException) TDPException(org.talend.dataprep.exception.TDPException) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) NullOutputStream(org.apache.commons.io.output.NullOutputStream) AsyncOperation(org.talend.dataprep.async.AsyncOperation) VolumeMetered(org.talend.dataprep.metrics.VolumeMetered) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 NullOutputStream (org.apache.commons.io.output.NullOutputStream)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 ExportParameters (org.talend.dataprep.api.export.ExportParameters)1 PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)1 AsyncOperation (org.talend.dataprep.async.AsyncOperation)1 TransformationMetadataCacheKey (org.talend.dataprep.cache.TransformationMetadataCacheKey)1 TDPException (org.talend.dataprep.exception.TDPException)1 VolumeMetered (org.talend.dataprep.metrics.VolumeMetered)1