use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class TransformationService method execute.
@RequestMapping(value = "/apply", method = POST)
@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 = GetPrepContentAsyncCondition.class, //
resultUrlGenerator = PreparationGetContentUrlGenerator.class, //
executionIdGeneratorClass = ExportParametersExecutionIdGenerator.class)
public StreamingResponseBody execute(@ApiParam(value = "Preparation id to apply.") @RequestBody @Valid @AsyncParameter @AsyncExecutionId final ExportParameters parameters) throws IOException {
ExportParameters completeParameters = parameters;
if (StringUtils.isNotEmpty(completeParameters.getPreparationId())) {
// we deal with preparation transformation (not dataset)
completeParameters = exportParametersUtil.populateFromPreparationExportParameter(parameters);
ContentCacheKey cacheKey = cacheKeyGenerator.generateContentKey(completeParameters);
if (!contentCache.has(cacheKey)) {
preparationExportStrategy.performPreparation(completeParameters, new NullOutputStream());
}
}
return executeSampleExportStrategy(completeParameters);
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class TransformationService method evictCache.
private void evictCache(final String preparationId, final ExportParameters.SourceType sourceType) {
final ContentCacheKey metadataKey = cacheKeyGenerator.metadataBuilder().preparationId(preparationId).sourceType(sourceType).build();
final ContentCacheKey contentKey = cacheKeyGenerator.contentBuilder().preparationId(preparationId).sourceType(sourceType).build();
contentCache.evictMatch(metadataKey);
contentCache.evictMatch(contentKey);
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class DatasetUpdateListener method onUpdate.
@EventListener
public void onUpdate(DatasetUpdatedEvent event) {
// when we update a dataset we need to clean cache
final DataSetMetadata dataSetMetadata = event.getSource();
final ContentCacheKey sampleKey = () -> "dataset-sample_" + dataSetMetadata.getId();
LOGGER.debug("Evicting sample cache entry for #{}", dataSetMetadata.getId());
publisher.publishEvent(new CleanCacheEvent(sampleKey));
LOGGER.debug("Evicting sample cache entry for #{} done.", dataSetMetadata.getId());
LOGGER.debug("Evicting transformation cache entry for dataset #{}", dataSetMetadata.getId());
publisher.publishEvent(new CleanCacheEvent(new ContentCacheKey() {
@Override
public String getKey() {
return dataSetMetadata.getId();
}
@Override
public Predicate<String> getMatcher() {
String regex = ".*_" + getKey() + "_.*";
// Build regular expression matcher
final Pattern pattern = Pattern.compile(regex);
return str -> pattern.matcher(str).matches();
}
}, Boolean.TRUE));
LOGGER.debug("Evicting transformation cache entry for dataset #{} done.", dataSetMetadata.getId());
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class TransformationServiceTest method testEvictPreparationCache.
@Test
public void testEvictPreparationCache() throws Exception {
// given
final String preparationId = "prepId";
final ContentCacheKey metadataKey = cacheKeyGenerator.metadataBuilder().preparationId(preparationId).stepId("step1").sourceType(FILTER).build();
final ContentCacheKey contentKey = cacheKeyGenerator.contentBuilder().datasetId("datasetId").preparationId(preparationId).stepId("step1").format(JSON).parameters(emptyMap()).sourceType(FILTER).build();
try (final OutputStream entry = contentCache.put(metadataKey, PERMANENT)) {
entry.write("metadata".getBytes());
entry.flush();
}
try (final OutputStream entry = contentCache.put(contentKey, PERMANENT)) {
entry.write("content".getBytes());
entry.flush();
}
assertThat(contentCache.has(metadataKey), is(true));
assertThat(contentCache.has(contentKey), is(true));
// when
//
given().expect().statusCode(200).log().ifError().when().delete("/preparation/{preparationId}/cache", //
preparationId).asString();
// then
assertThat(contentCache.has(metadataKey), is(false));
assertThat(contentCache.has(contentKey), is(false));
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class CacheCondition method apply.
@Override
public boolean apply(Object... args) {
// check pre-condition
Validate.notNull(args);
Validate.isTrue(args.length == 1);
Validate.isInstanceOf(ContentCacheKey.class, args[0]);
ContentCacheKey cacheKey = (ContentCacheKey) args[0];
return contentCache.has(cacheKey);
}
Aggregations