Search in sources :

Example 11 with QueryRequest

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

the class TestCollectionAPI method missingParamsError.

private void missingParamsError(CloudSolrClient client, ModifiableSolrParams origParams) throws IOException, SolrServerException {
    SolrRequest request;
    try {
        request = new QueryRequest(origParams);
        request.setPath("/admin/collections");
        client.request(request);
        fail("Should have thrown a SolrException due to lack of a required parameter.");
    } catch (SolrException se) {
        assertTrue("Should have gotten a specific message back mentioning 'missing required parameter'. Got: " + se.getMessage(), se.getMessage().toLowerCase(Locale.ROOT).contains("missing required parameter:"));
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) SolrException(org.apache.solr.common.SolrException) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)

Example 12 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest 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 13 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest 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 14 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest 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 15 with QueryRequest

use of org.apache.solr.client.solrj.request.QueryRequest 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)

Aggregations

QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)110 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)75 SolrRequest (org.apache.solr.client.solrj.SolrRequest)35 NamedList (org.apache.solr.common.util.NamedList)35 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)29 Test (org.junit.Test)28 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)21 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)17 Map (java.util.Map)17 SolrQuery (org.apache.solr.client.solrj.SolrQuery)17 IOException (java.io.IOException)16 SolrException (org.apache.solr.common.SolrException)15 SolrInputDocument (org.apache.solr.common.SolrInputDocument)14 SolrClient (org.apache.solr.client.solrj.SolrClient)13 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)12 List (java.util.List)11 SolrServerException (org.apache.solr.client.solrj.SolrServerException)8 RemoteSolrException (org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)8 SolrDocumentList (org.apache.solr.common.SolrDocumentList)8