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();
}
};
}
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();
}
};
}
Aggregations