Search in sources :

Example 1 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.

the class SolrExampleStreamingBinaryTest method createNewSolrClient.

@Override
public SolrClient createNewSolrClient() {
    ConcurrentUpdateSolrClient client = (ConcurrentUpdateSolrClient) super.createNewSolrClient();
    client.setParser(new BinaryResponseParser());
    client.setRequestWriter(new BinaryRequestWriter());
    return client;
}
Also used : BinaryResponseParser(org.apache.solr.client.solrj.impl.BinaryResponseParser) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient)

Example 2 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.

the class SolrExampleBinaryTest method createNewSolrClient.

@Override
public SolrClient createNewSolrClient() {
    try {
        // setup the server...
        String url = jetty.getBaseUrl().toString() + "/collection1";
        HttpSolrClient client = getHttpSolrClient(url);
        client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
        client.setUseMultiPartPost(random().nextBoolean());
        // where the magic happens
        client.setParser(new BinaryResponseParser());
        client.setRequestWriter(new BinaryRequestWriter());
        return client;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) BinaryResponseParser(org.apache.solr.client.solrj.impl.BinaryResponseParser) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter)

Example 3 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.

the class TestBatchUpdate method testWithBinaryBean.

@Test
public void testWithBinaryBean() throws Exception {
    HttpSolrClient client = (HttpSolrClient) getSolrClient();
    client.setRequestWriter(new BinaryRequestWriter());
    // delete everything!
    client.deleteByQuery("*:*");
    final int[] counter = new int[1];
    counter[0] = 0;
    client.addBeans(new Iterator<Bean>() {

        @Override
        public boolean hasNext() {
            return counter[0] < numdocs;
        }

        @Override
        public Bean next() {
            Bean bean = new Bean();
            bean.id = "" + (++counter[0]);
            bean.cat = "foocat";
            return bean;
        }

        @Override
        public void remove() {
        //do nothing
        }
    });
    client.commit();
    SolrQuery query = new SolrQuery("*:*");
    QueryResponse response = client.query(query);
    assertEquals(0, response.getStatus());
    assertEquals(numdocs, response.getResults().getNumFound());
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) Test(org.junit.Test)

Example 4 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.

the class TestBatchUpdate method testWithBinary.

@Test
public void testWithBinary() throws Exception {
    HttpSolrClient client = (HttpSolrClient) getSolrClient();
    client.setRequestWriter(new BinaryRequestWriter());
    // delete everything!
    client.deleteByQuery("*:*");
    doIt(client);
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) Test(org.junit.Test)

Example 5 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project ranger by apache.

the class DbToSolrMigrationUtil method createSolrClient.

private SolrClient createSolrClient() throws Exception {
    SolrClient solrClient = null;
    registerSolrClientJAAS();
    String zkHosts = PropertiesUtil.getProperty(SOLR_ZK_HOSTS);
    if (zkHosts == null) {
        zkHosts = PropertiesUtil.getProperty("ranger.audit.solr.zookeeper");
    }
    if (zkHosts == null) {
        zkHosts = PropertiesUtil.getProperty("ranger.solr.zookeeper");
    }
    String solrURL = PropertiesUtil.getProperty(SOLR_URLS_PROP);
    if (solrURL == null) {
        // Try with url
        solrURL = PropertiesUtil.getProperty("ranger.audit.solr.url");
    }
    if (solrURL == null) {
        // Let's try older property name
        solrURL = PropertiesUtil.getProperty("ranger.solr.url");
    }
    if (zkHosts != null && !"".equals(zkHosts.trim()) && !"none".equalsIgnoreCase(zkHosts.trim())) {
        zkHosts = zkHosts.trim();
        String collectionName = PropertiesUtil.getProperty(SOLR_COLLECTION_NAME);
        if (collectionName == null || "none".equalsIgnoreCase(collectionName)) {
            collectionName = DEFAULT_COLLECTION_NAME;
        }
        logger.info("Solr zkHosts=" + zkHosts + ", collectionName=" + collectionName);
        try {
            // Instantiate
            Krb5HttpClientBuilder krbBuild = new Krb5HttpClientBuilder();
            SolrHttpClientBuilder kb = krbBuild.getBuilder();
            HttpClientUtil.setHttpClientBuilder(kb);
            final List<String> zkhosts = new ArrayList<String>(Arrays.asList(zkHosts.split(",")));
            CloudSolrClient solrCloudClient = new CloudSolrClient.Builder(zkhosts, null).build();
            solrCloudClient.setDefaultCollection(collectionName);
            return solrCloudClient;
        } catch (Exception e) {
            logger.error("Can't connect to Solr server. ZooKeepers=" + zkHosts + ", collection=" + collectionName, e);
            throw e;
        }
    } else {
        if (solrURL == null || solrURL.isEmpty() || "none".equalsIgnoreCase(solrURL)) {
            logger.error("Solr ZKHosts and URL for Audit are empty. Please set property " + SOLR_ZK_HOSTS + " or " + SOLR_URLS_PROP);
        } else {
            try {
                Krb5HttpClientBuilder krbBuild = new Krb5HttpClientBuilder();
                SolrHttpClientBuilder kb = krbBuild.getBuilder();
                HttpClientUtil.setHttpClientBuilder(kb);
                HttpSolrClient.Builder builder = new HttpSolrClient.Builder();
                builder.withBaseSolrUrl(solrURL);
                builder.allowCompression(true);
                builder.withConnectionTimeout(1000);
                HttpSolrClient httpSolrClient = builder.build();
                httpSolrClient.setRequestWriter(new BinaryRequestWriter());
                solrClient = httpSolrClient;
            } catch (Exception e) {
                logger.error("Can't connect to Solr server. URL=" + solrURL, e);
                throw e;
            }
        }
    }
    return solrClient;
}
Also used : Krb5HttpClientBuilder(org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder) SolrHttpClientBuilder(org.apache.solr.client.solrj.impl.SolrHttpClientBuilder) ArrayList(java.util.ArrayList) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) IOException(java.io.IOException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrHttpClientBuilder(org.apache.solr.client.solrj.impl.SolrHttpClientBuilder) Krb5HttpClientBuilder(org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder)

Aggregations

BinaryRequestWriter (org.apache.solr.client.solrj.impl.BinaryRequestWriter)14 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)7 Test (org.junit.Test)5 BinaryResponseParser (org.apache.solr.client.solrj.impl.BinaryResponseParser)4 ArrayList (java.util.ArrayList)2 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 CommonsHttpSolrServer (org.apache.solr.client.solrj.impl.CommonsHttpSolrServer)2 ConcurrentUpdateSolrClient (org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient)2 Krb5HttpClientBuilder (org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder)2 SolrHttpClientBuilder (org.apache.solr.client.solrj.impl.SolrHttpClientBuilder)2 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 NamedList (org.apache.solr.common.util.NamedList)2 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1