Search in sources :

Example 11 with SolrRequest

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

the class TestCollectionAPI method clusterStatusWithRouteKey.

private void clusterStatusWithRouteKey() throws IOException, SolrServerException {
    try (CloudSolrClient client = createCloudClient(DEFAULT_COLLECTION)) {
        SolrInputDocument doc = new SolrInputDocument();
        // goes to shard2. see ShardRoutingTest for details
        doc.addField("id", "a!123");
        client.add(doc);
        client.commit();
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", DEFAULT_COLLECTION);
        params.set(ShardParams._ROUTE_, "a!");
        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(DEFAULT_COLLECTION));
        assertEquals(1, collections.size());
        Map<String, Object> collection = (Map<String, Object>) collections.get(DEFAULT_COLLECTION);
        assertEquals("conf1", collection.get("configName"));
        Map<String, Object> shardStatus = (Map<String, Object>) collection.get("shards");
        assertEquals(1, shardStatus.size());
        Map<String, Object> selectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD2);
        assertNotNull(selectedShardStatus);
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest) HashMap(java.util.HashMap) Map(java.util.Map) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 12 with SolrRequest

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

the class TestCollectionAPI method clusterStatusBadCollectionTest.

private void clusterStatusBadCollectionTest() throws Exception {
    try (CloudSolrClient client = createCloudClient(null)) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", "bad_collection_name");
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        try {
            client.request(request);
            fail("Collection does not exist. An exception should be thrown");
        } catch (SolrException e) {
            //expected
            assertTrue(e.getMessage().contains("Collection: bad_collection_name not found"));
        }
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 13 with SolrRequest

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

the class TestCollectionAPI method testShardCreationNameValidation.

private void testShardCreationNameValidation() throws Exception {
    try (CloudSolrClient client = createCloudClient(null)) {
        client.connect();
        // Create a collection w/ implicit router
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CREATE.toString());
        params.set("name", "valid_collection_name");
        params.set("shards", "a");
        params.set("router.name", "implicit");
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        client.request(request);
        params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CREATESHARD.toString());
        params.set("collection", "valid_collection_name");
        params.set("shard", "invalid@name#with$weird%characters");
        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 14 with SolrRequest

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

the class TestCollectionAPI method clusterStatusWithCollectionAndShard.

private void clusterStatusWithCollectionAndShard() throws IOException, SolrServerException {
    try (CloudSolrClient client = createCloudClient(null)) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", COLLECTION_NAME);
        params.set("shard", SHARD1);
        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_NAME));
        assertEquals(1, collections.size());
        Map<String, Object> collection = (Map<String, Object>) collections.get(COLLECTION_NAME);
        Map<String, Object> shardStatus = (Map<String, Object>) collection.get("shards");
        assertEquals(1, shardStatus.size());
        Map<String, Object> selectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD1);
        assertNotNull(selectedShardStatus);
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest) HashMap(java.util.HashMap) Map(java.util.Map) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 15 with SolrRequest

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

the class TestConfigSetsAPI method createCollection.

protected CollectionAdminResponse createCollection(String collectionName, String confSetName, int numShards, int replicationFactor, SolrClient client) throws SolrServerException, IOException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionAction.CREATE.toString());
    params.set("collection.configName", confSetName);
    params.set("name", collectionName);
    params.set("numShards", numShards);
    params.set("replicationFactor", replicationFactor);
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    CollectionAdminResponse res = new CollectionAdminResponse();
    res.setResponse(client.request(request));
    return res;
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

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