|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.opensearch.ingest; |
| 10 | + |
| 11 | +import java.util.Map; |
| 12 | + |
| 13 | +/** |
| 14 | + * Abstract base class for batch system generated processors. |
| 15 | + * |
| 16 | + * System processors should not be used in the regular ingest pipelines. |
| 17 | + * |
| 18 | + * @opensearch.internal |
| 19 | + */ |
| 20 | +public abstract class AbstractBatchingSystemProcessor extends AbstractBatchingProcessor { |
| 21 | + protected AbstractBatchingSystemProcessor(String tag, String description, int batchSize) { |
| 22 | + super(tag, description, batchSize); |
| 23 | + } |
| 24 | + |
| 25 | + @Override |
| 26 | + public boolean isSystemGenerated() { |
| 27 | + return true; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Factory class for creating {@link AbstractBatchingSystemProcessor} instances systematically. |
| 32 | + * |
| 33 | + * Since the processor config is generated based on the index config so the batch size info should also be defined |
| 34 | + * as part of it. And different processors can have their own logic to decide the batch size so let each |
| 35 | + * implementation of the newProcessor to handle it. |
| 36 | + * |
| 37 | + * @opensearch.internal |
| 38 | + */ |
| 39 | + public abstract static class Factory implements Processor.Factory { |
| 40 | + final String processorType; |
| 41 | + |
| 42 | + protected Factory(String processorType) { |
| 43 | + this.processorType = processorType; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public boolean isSystemGenerated() { |
| 48 | + return true; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Creates a new processor instance. It will be invoked systematically. |
| 53 | + * |
| 54 | + * @param processorFactories The processor factories. |
| 55 | + * @param tag The processor tag. |
| 56 | + * @param description The processor description. |
| 57 | + * @param config The processor configuration. |
| 58 | + * @return The new AbstractBatchProcessor instance. |
| 59 | + * @throws Exception If the processor could not be created. |
| 60 | + */ |
| 61 | + @Override |
| 62 | + public AbstractBatchingSystemProcessor create( |
| 63 | + Map<String, Processor.Factory> processorFactories, |
| 64 | + String tag, |
| 65 | + String description, |
| 66 | + Map<String, Object> config |
| 67 | + ) throws Exception { |
| 68 | + return newProcessor(tag, description, config); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Returns a new processor instance. It will be invoked systematically. |
| 73 | + * |
| 74 | + * @param tag tag of the processor |
| 75 | + * @param description description of the processor |
| 76 | + * @param config configuration of the processor |
| 77 | + * @return a new batch processor instance |
| 78 | + */ |
| 79 | + protected abstract AbstractBatchingSystemProcessor newProcessor(String tag, String description, Map<String, Object> config); |
| 80 | + } |
| 81 | +} |
0 commit comments