Search in sources :

Example 1 with SolrComponent

use of org.apache.metron.solr.integration.components.SolrComponent in project metron by apache.

the class SolrIndexingIntegrationTest method getSearchComponent.

@Override
public InMemoryComponent getSearchComponent(final Properties topologyProperties) throws Exception {
    SolrComponent solrComponent = new SolrComponent.Builder().addCollection(collection, "../metron-solr/src/test/resources/solr/conf").withPostStartCallback(new Function<SolrComponent, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable SolrComponent solrComponent) {
            topologyProperties.setProperty("solr.zk", solrComponent.getZookeeperUrl());
            try {
                String testZookeeperUrl = topologyProperties.getProperty(ZKServerComponent.ZOOKEEPER_PROPERTY);
                Configurations configurations = SampleUtil.getSampleConfigs();
                Map<String, Object> globalConfig = configurations.getGlobalConfig();
                globalConfig.put("solr.zookeeper", solrComponent.getZookeeperUrl());
                ConfigurationsUtils.writeGlobalConfigToZookeeper(JSONUtils.INSTANCE.toJSONPretty(globalConfig), testZookeeperUrl);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    }).build();
    return solrComponent;
}
Also used : Function(com.google.common.base.Function) SolrComponent(org.apache.metron.solr.integration.components.SolrComponent) Configurations(org.apache.metron.common.configuration.Configurations) Nullable(javax.annotation.Nullable) IOException(java.io.IOException)

Example 2 with SolrComponent

use of org.apache.metron.solr.integration.components.SolrComponent 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

SolrComponent (org.apache.metron.solr.integration.components.SolrComponent)2 Function (com.google.common.base.Function)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 Configurations (org.apache.metron.common.configuration.Configurations)1 ComponentRunner (org.apache.metron.integration.ComponentRunner)1 Processor (org.apache.metron.integration.Processor)1 ProcessorResult (org.apache.metron.integration.ProcessorResult)1 KafkaComponent (org.apache.metron.integration.components.KafkaComponent)1