Search in sources :

Example 36 with PreparationDTO

use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.

the class PipelineTransformer method buildExecutable.

@Override
public ExecutableTransformer buildExecutable(DataSet input, Configuration configuration) {
    final RowMetadata rowMetadata = input.getMetadata().getRowMetadata();
    final TransformerWriter writer = writerRegistrationService.getWriter(configuration.formatId(), configuration.output(), configuration.getArguments());
    final ConfiguredCacheWriter metadataWriter = new ConfiguredCacheWriter(contentCache, DEFAULT);
    final TransformationMetadataCacheKey metadataKey = cacheKeyGenerator.generateMetadataKey(configuration.getPreparationId(), configuration.stepId(), configuration.getSourceType());
    final PreparationDTO preparation = configuration.getPreparation();
    // function that from a step gives the rowMetadata associated to the previous/parent step
    final Function<String, RowMetadata> stepRowMetadataSupplier = s -> Optional.ofNullable(// 
    s).map(// 
    id -> stepMetadataRepository.get(id)).orElse(null);
    final Pipeline pipeline = Pipeline.Builder.builder().withAnalyzerService(// 
    analyzerService).withActionRegistry(// 
    actionRegistry).withPreparation(// 
    preparation).withActions(// 
    actionParser.parse(configuration.getActions())).withInitialMetadata(rowMetadata, // 
    configuration.volume() == SMALL).withMonitor(// 
    configuration.getMonitor()).withFilter(// 
    configuration.getFilter()).withLimit(// 
    configuration.getLimit()).withFilterOut(// 
    configuration.getOutFilter()).withOutput(// 
    () -> new WriterNode(writer, metadataWriter, metadataKey)).withStatisticsAdapter(// 
    adapter).withStepMetadataSupplier(// 
    stepRowMetadataSupplier).withGlobalStatistics(// 
    configuration.isGlobalStatistics()).allowMetadataChange(// 
    configuration.isAllowMetadataChange()).build();
    // wrap this transformer into an executable transformer
    return new ExecutableTransformer() {

        @Override
        public void execute() {
            final Optional<Span> span = tracer.map(t -> {
                final Span pipelineSpan = t.createSpan("transformer-pipeline");
                pipelineSpan.tag("preparation id", configuration.getPreparationId());
                pipelineSpan.tag("arguments", configuration.getArguments().toString());
                return pipelineSpan;
            });
            try {
                LOGGER.debug("Before execution: {}", pipeline);
                pipeline.execute(input);
                if (preparation != null && JsonFormat.JSON.equals(configuration.formatId())) {
                    final UpdatedStepVisitor visitor = new UpdatedStepVisitor(stepMetadataRepository);
                    pipeline.accept(visitor);
                }
            } finally {
                LOGGER.debug("After execution: {}", pipeline);
                span.ifPresent(s -> {
                    s.tag("execution", pipeline.toString());
                    tracer.ifPresent(t -> t.close(s));
                });
            }
        }

        @Override
        public void signal(Signal signal) {
            pipeline.signal(signal);
        }
    };
}
Also used : WriterNode(org.talend.dataprep.transformation.pipeline.model.WriterNode) JsonFormat(org.talend.dataprep.transformation.format.JsonFormat) SMALL(org.talend.dataprep.transformation.api.transformer.configuration.Configuration.Volume.SMALL) WriterRegistrationService(org.talend.dataprep.transformation.format.WriterRegistrationService) StepMetadataRepository(org.talend.dataprep.transformation.service.StepMetadataRepository) TransformerWriter(org.talend.dataprep.transformation.api.transformer.TransformerWriter) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) DEFAULT(org.talend.dataprep.cache.ContentCache.TimeToLive.DEFAULT) Configuration(org.talend.dataprep.transformation.api.transformer.configuration.Configuration) Signal(org.talend.dataprep.transformation.pipeline.Signal) Function(java.util.function.Function) AnalyzerService(org.talend.dataprep.quality.AnalyzerService) ActionParser(org.talend.dataprep.transformation.api.action.ActionParser) CacheKeyGenerator(org.talend.dataprep.cache.CacheKeyGenerator) TransformationMetadataCacheKey(org.talend.dataprep.cache.TransformationMetadataCacheKey) Span(org.springframework.cloud.sleuth.Span) Tracer(org.springframework.cloud.sleuth.Tracer) DataSet(org.talend.dataprep.api.dataset.DataSet) Logger(org.slf4j.Logger) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) ConfiguredCacheWriter(org.talend.dataprep.transformation.api.transformer.ConfiguredCacheWriter) ContentCache(org.talend.dataprep.cache.ContentCache) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) ExecutableTransformer(org.talend.dataprep.transformation.api.transformer.ExecutableTransformer) Component(org.springframework.stereotype.Component) StatisticsAdapter(org.talend.dataprep.dataset.StatisticsAdapter) Optional(java.util.Optional) Pipeline(org.talend.dataprep.transformation.pipeline.Pipeline) Transformer(org.talend.dataprep.transformation.api.transformer.Transformer) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) TransformationMetadataCacheKey(org.talend.dataprep.cache.TransformationMetadataCacheKey) Span(org.springframework.cloud.sleuth.Span) Pipeline(org.talend.dataprep.transformation.pipeline.Pipeline) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) Signal(org.talend.dataprep.transformation.pipeline.Signal) WriterNode(org.talend.dataprep.transformation.pipeline.model.WriterNode) ExecutableTransformer(org.talend.dataprep.transformation.api.transformer.ExecutableTransformer) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) TransformerWriter(org.talend.dataprep.transformation.api.transformer.TransformerWriter) ConfiguredCacheWriter(org.talend.dataprep.transformation.api.transformer.ConfiguredCacheWriter)

Example 37 with PreparationDTO

use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.

the class PreparationExportStrategyTest method shouldUsedVersionedPreparation.

@Test
public void shouldUsedVersionedPreparation() throws IOException {
    // Given
    final ExportParameters parameters = new ExportParameters();
    parameters.setExportType("JSON");
    parameters.setPreparationId("prep-1234");
    parameters.setStepId("step-1234");
    final PreparationDTO preparation = new PreparationDTO();
    preparation.setId("prep-1234");
    preparation.setHeadId("step-1234");
    configurePreparation(preparation, "prep-1234", "step-1234");
    // When
    final StreamingResponseBody body = strategy.execute(parameters);
    body.writeTo(new NullOutputStream());
    // Then
    final ArgumentCaptor<Configuration> captor = ArgumentCaptor.forClass(Configuration.class);
    verify(transformer).buildExecutable(any(), captor.capture());
    assertEquals("prep-1234", captor.getValue().getPreparationId());
    assertEquals("step-1234", captor.getValue().getPreparation().getHeadId());
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) Configuration(org.talend.dataprep.transformation.api.transformer.configuration.Configuration) ExportParameters(org.talend.dataprep.api.export.ExportParameters) NullOutputStream(org.apache.commons.io.output.NullOutputStream) Test(org.junit.Test)

Example 38 with PreparationDTO

use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.

the class PreparationExportStrategyTest method shouldUsedHeadPreparation.

@Test
public void shouldUsedHeadPreparation() throws IOException {
    // Given
    final ExportParameters parameters = new ExportParameters();
    parameters.setExportType("JSON");
    parameters.setPreparationId("prep-1234");
    parameters.setStepId("head");
    final PreparationDTO preparation = new PreparationDTO();
    preparation.getSteps().add(Step.ROOT_STEP.id());
    preparation.setId("prep-1234");
    preparation.setHeadId("head");
    configurePreparation(preparation, "prep-1234", "head");
    // When
    final StreamingResponseBody body = strategy.execute(parameters);
    body.writeTo(new NullOutputStream());
    // Then
    final ArgumentCaptor<Configuration> captor = ArgumentCaptor.forClass(Configuration.class);
    verify(transformer).buildExecutable(any(), captor.capture());
    assertEquals("prep-1234", captor.getValue().getPreparationId());
    assertEquals("head", captor.getValue().getPreparation().getHeadId());
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) Configuration(org.talend.dataprep.transformation.api.transformer.configuration.Configuration) ExportParameters(org.talend.dataprep.api.export.ExportParameters) NullOutputStream(org.apache.commons.io.output.NullOutputStream) Test(org.junit.Test)

Example 39 with PreparationDTO

use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.

the class PrepHasStepCondition method apply.

@Override
public boolean apply(Object... args) {
    // check pre-condition
    Validate.notNull(args);
    Validate.isTrue(args.length == 2);
    Validate.isInstanceOf(String.class, args[0]);
    Validate.isInstanceOf(String.class, args[1]);
    String preparationId = (String) args[0];
    String headId = (String) args[1];
    PreparationDTO prep = exportParametersUtil.getPreparation(preparationId, headId);
    return prep.getSteps().size() > 1;
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO)

Example 40 with PreparationDTO

use of org.talend.dataprep.api.preparation.PreparationDTO in project data-prep by Talend.

the class PreparationAPI method previewUpdate.

// @formatter:off
@RequestMapping(value = "/api/preparations/preview/update", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get a preview diff between the same step of the same preparation but with one step update.")
public StreamingResponseBody previewUpdate(@RequestBody final PreviewUpdateParameters input) {
    // @formatter:on
    // get preparation details
    final PreparationDTO preparation = internalGetPreparation(input.getPreparationId());
    final List<Action> actions = internalGetActions(preparation.getId());
    final HystrixCommand<InputStream> transformation = getCommand(PreviewUpdate.class, input, preparation, actions);
    return executePreviewCommand(transformation);
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) PreparationDeleteAction(org.talend.dataprep.api.service.command.preparation.PreparationDeleteAction) Action(org.talend.dataprep.api.preparation.Action) PreparationAddAction(org.talend.dataprep.api.PreparationAddAction) PreparationUpdateAction(org.talend.dataprep.api.service.command.preparation.PreparationUpdateAction) InputStream(java.io.InputStream) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)45 Test (org.junit.Test)22 ExportParameters (org.talend.dataprep.api.export.ExportParameters)9 ApiOperation (io.swagger.annotations.ApiOperation)7 InputStream (java.io.InputStream)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ArrayList (java.util.ArrayList)6 Action (org.talend.dataprep.api.preparation.Action)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)5 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)5 Preparation (org.talend.dataprep.api.preparation.Preparation)5 PreparationDetailsDTO (org.talend.dataprep.api.preparation.PreparationDetailsDTO)5 TransformationCacheKey (org.talend.dataprep.cache.TransformationCacheKey)5 TDPException (org.talend.dataprep.exception.TDPException)5 OutputStream (java.io.OutputStream)4 StringUtils (org.apache.commons.lang3.StringUtils)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Component (org.springframework.stereotype.Component)4