Search in sources :

Example 1 with Processor

use of org.apache.metron.integration.Processor in project metron by apache.

the class ElasticsearchIndexingIntegrationTest method getProcessor.

@Override
public Processor<List<Map<String, Object>>> getProcessor(final List<byte[]> inputMessages) {
    return new Processor<List<Map<String, Object>>>() {

        List<Map<String, Object>> docs = null;

        List<byte[]> errors = null;

        final AtomicInteger missCount = new AtomicInteger(0);

        @Override
        public ReadinessState process(ComponentRunner runner) {
            ElasticSearchComponent elasticSearchComponent = runner.getComponent("search", ElasticSearchComponent.class);
            KafkaComponent kafkaComponent = runner.getComponent("kafka", KafkaComponent.class);
            if (elasticSearchComponent.hasIndex(index)) {
                try {
                    docs = elasticSearchComponent.getAllIndexedDocs(index, testSensorType + "_doc");
                } catch (IOException e) {
                    throw new IllegalStateException("Unable to retrieve indexed documents.", e);
                }
                if (docs.size() < inputMessages.size()) {
                    errors = kafkaComponent.readMessages(ERROR_TOPIC);
                    if (errors.size() > 0 && errors.size() + docs.size() == inputMessages.size()) {
                        return ReadinessState.READY;
                    }
                    return ReadinessState.NOT_READY;
                } else {
                    return ReadinessState.READY;
                }
            } else {
                return ReadinessState.NOT_READY;
            }
        }

        @Override
        public ProcessorResult<List<Map<String, Object>>> getResult() {
            ProcessorResult.Builder<List<Map<String, Object>>> builder = new ProcessorResult.Builder();
            return builder.withResult(docs).withProcessErrors(errors).build();
        }
    };
}
Also used : Processor(org.apache.metron.integration.Processor) KafkaComponent(org.apache.metron.integration.components.KafkaComponent) ProcessorResult(org.apache.metron.integration.ProcessorResult) ElasticSearchComponent(org.apache.metron.elasticsearch.integration.components.ElasticSearchComponent) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) ComponentRunner(org.apache.metron.integration.ComponentRunner) Map(java.util.Map)

Example 2 with Processor

use of org.apache.metron.integration.Processor in project metron by apache.

the class SolrIndexingIntegrationTest method getProcessor.

@Override
public Processor<List<Map<String, Object>>> getProcessor(final List<byte[]> inputMessages) {
    return new Processor<List<Map<String, Object>>>() {

        List<Map<String, Object>> docs = null;

        List<byte[]> errors = null;

        @Override
        public ReadinessState process(ComponentRunner runner) {
            SolrComponent solrComponent = runner.getComponent("search", SolrComponent.class);
            KafkaComponent kafkaComponent = runner.getComponent("kafka", KafkaComponent.class);
            if (solrComponent.hasCollection(collection)) {
                docs = solrComponent.getAllIndexedDocs(collection);
                if (docs.size() < inputMessages.size()) {
                    errors = kafkaComponent.readMessages(ERROR_TOPIC);
                    if (errors.size() > 0 && errors.size() + docs.size() == inputMessages.size()) {
                        return ReadinessState.READY;
                    }
                    return ReadinessState.NOT_READY;
                } else {
                    return ReadinessState.READY;
                }
            } else {
                return ReadinessState.NOT_READY;
            }
        }

        @Override
        public ProcessorResult<List<Map<String, Object>>> getResult() {
            ProcessorResult.Builder<List<Map<String, Object>>> builder = new ProcessorResult.Builder();
            return builder.withResult(docs).withProcessErrors(errors).build();
        }
    };
}
Also used : Processor(org.apache.metron.integration.Processor) KafkaComponent(org.apache.metron.integration.components.KafkaComponent) ProcessorResult(org.apache.metron.integration.ProcessorResult) SolrComponent(org.apache.metron.solr.integration.components.SolrComponent) List(java.util.List) ComponentRunner(org.apache.metron.integration.ComponentRunner) Map(java.util.Map)

Aggregations

List (java.util.List)2 Map (java.util.Map)2 ComponentRunner (org.apache.metron.integration.ComponentRunner)2 Processor (org.apache.metron.integration.Processor)2 ProcessorResult (org.apache.metron.integration.ProcessorResult)2 KafkaComponent (org.apache.metron.integration.components.KafkaComponent)2 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ElasticSearchComponent (org.apache.metron.elasticsearch.integration.components.ElasticSearchComponent)1 SolrComponent (org.apache.metron.solr.integration.components.SolrComponent)1