Search in sources :

Example 1 with SolrRequest

use of org.apache.solr.client.solrj.SolrRequest in project storm by apache.

the class SolrUpdateBolt method process.

@Override
protected void process(Tuple tuple) {
    try {
        SolrRequest request = solrMapper.toSolrRequest(tuple);
        solrClient.request(request, solrMapper.getCollection());
        ack(tuple);
    } catch (Exception e) {
        fail(tuple, e);
    }
}
Also used : SolrRequest(org.apache.solr.client.solrj.SolrRequest) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException)

Example 2 with SolrRequest

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

the class CollectionsAPIDistributedZkTest method testZeroNumShards.

@Test
public void testZeroNumShards() {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionAction.CREATE.toString());
    params.set("name", "acollection");
    params.set(REPLICATION_FACTOR, 10);
    params.set("numShards", 0);
    params.set("collection.configName", "conf");
    final SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    expectThrows(Exception.class, () -> {
        cluster.getSolrClient().request(request);
    });
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 3 with SolrRequest

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

the class CollectionsAPIDistributedZkTest method testMissingNumShards.

@Test
public void testMissingNumShards() {
    // No numShards should fail
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionAction.CREATE.toString());
    params.set("name", "acollection");
    params.set(REPLICATION_FACTOR, 10);
    params.set("collection.configName", "conf");
    final SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    expectThrows(Exception.class, () -> {
        cluster.getSolrClient().request(request);
    });
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 4 with SolrRequest

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

the class TestCollectionAPI method testCollectionCreationShardNameValidation.

private void testCollectionCreationShardNameValidation() throws Exception {
    try (CloudSolrClient client = createCloudClient(null)) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CREATE.toString());
        params.set("name", "valid_collection_name");
        params.set("router.name", "implicit");
        params.set("numShards", "1");
        params.set("shards", "invalid@name#with$weird%characters");
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        try {
            client.request(request);
            fail();
        } catch (RemoteSolrException e) {
            final String errorMessage = e.getMessage();
            assertTrue(errorMessage.contains("Invalid shard"));
            assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
            assertTrue(errorMessage.contains("shard names must consist entirely of"));
        }
    }
}
Also used : RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 5 with SolrRequest

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

the class TestCollectionAPI method clusterStatusNoCollection.

private void clusterStatusNoCollection() throws Exception {
    try (CloudSolrClient client = createCloudClient(null)) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        NamedList<Object> rsp = client.request(request);
        NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
        assertNotNull("Cluster state should not be null", cluster);
        NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
        assertNotNull("Collections should not be null in cluster state", collections);
        assertNotNull(collections.get(COLLECTION_NAME1));
        assertEquals(4, collections.size());
        List<String> liveNodes = (List<String>) cluster.get("live_nodes");
        assertNotNull("Live nodes should not be null", liveNodes);
        assertFalse(liveNodes.isEmpty());
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Aggregations

SolrRequest (org.apache.solr.client.solrj.SolrRequest)42 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)36 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)35 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)18 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)11 NamedList (org.apache.solr.common.util.NamedList)11 HashMap (java.util.HashMap)10 RemoteSolrException (org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)7 Test (org.junit.Test)7 List (java.util.List)6 SolrClient (org.apache.solr.client.solrj.SolrClient)5 CollectionAdminResponse (org.apache.solr.client.solrj.response.CollectionAdminResponse)5 LBHttpSolrClient (org.apache.solr.client.solrj.impl.LBHttpSolrClient)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 SolrException (org.apache.solr.common.SolrException)3 Utils.makeMap (org.apache.solr.common.util.Utils.makeMap)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2