Search in sources :

Example 81 with QueryRequest

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

the class TestCollectionAPI method clusterStatusRolesTest.

private void clusterStatusRolesTest() throws Exception {
    try (CloudSolrClient client = createCloudClient(null)) {
        client.connect();
        Replica replica = client.getZkStateReader().getLeaderRetry(DEFAULT_COLLECTION, SHARD1);
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.ADDROLE.toString());
        params.set("node", replica.getNodeName());
        params.set("role", "overseer");
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        client.request(request);
        params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", DEFAULT_COLLECTION);
        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);
        Map<String, Object> roles = (Map<String, Object>) cluster.get("roles");
        assertNotNull("Role information should not be null", roles);
        List<String> overseer = (List<String>) roles.get("overseer");
        assertNotNull(overseer);
        assertEquals(1, overseer.size());
        assertTrue(overseer.contains(replica.getNodeName()));
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest) Replica(org.apache.solr.common.cloud.Replica) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 82 with QueryRequest

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

the class TestCloudJSONFacetJoinDomain method assertFacetCountsAreCorrect.

/**
   * Given a set of (potentially nested) term facets, and a base query string, asserts that 
   * the actual counts returned when executing that query with those facets match the expected results
   * of filtering on the equivilent facet terms+domain
   */
private void assertFacetCountsAreCorrect(Map<String, TermFacet> expected, final String query) throws SolrServerException, IOException {
    final SolrParams baseParams = params("q", query, "rows", "0");
    final SolrParams facetParams = params("json.facet", "" + TermFacet.toJSONFacetParamValue(expected));
    final SolrParams initParams = SolrParams.wrapAppended(facetParams, baseParams);
    log.info("Doing full run: {}", initParams);
    NamedList topResponse = null;
    try {
        topResponse = getRandClient(random()).request(new QueryRequest(initParams));
        assertNotNull(initParams + " is null response?", topResponse);
    } catch (Exception e) {
        throw new RuntimeException("init query failed: " + initParams + ": " + e.getMessage(), e);
    }
    try {
        final NamedList facetResponse = (NamedList) topResponse.get("facets");
        assertNotNull("null facet results?", facetResponse);
        assertFacetCountsAreCorrect(expected, baseParams, facetResponse);
    } catch (AssertionError e) {
        throw new AssertionError(initParams + " ===> " + topResponse + " --> " + e.getMessage(), e);
    } finally {
        log.info("Ending full run");
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException)

Example 83 with QueryRequest

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

the class TestCloudJSONFacetJoinDomain method testMalformedGivesError.

/** Sanity check that malformed requests produce errors */
public void testMalformedGivesError() throws Exception {
    ignoreException(".*'join' domain change.*");
    for (String join : Arrays.asList("bogus", "{ }", "{ from:null, to:foo_s }", "{ from:foo_s }", "{ from:foo_s, to:foo_s, bogus:'what what?' }", "{ to:foo_s, bogus:'what what?' }")) {
        SolrException e = expectThrows(SolrException.class, () -> {
            final SolrParams req = params("q", "*:*", "json.facet", "{ x : { type:terms, field:x_s, domain: { join:" + join + " } } }");
            final NamedList trash = getRandClient(random()).request(new QueryRequest(req));
        });
        assertEquals(join + " -> " + e, SolrException.ErrorCode.BAD_REQUEST.code, e.code());
        assertTrue(join + " -> " + e, e.getMessage().contains("'join' domain change"));
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException)

Example 84 with QueryRequest

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

the class BaseCdcrDistributedZkTest method deleteCollection.

/**
   * Delete a collection through the Collection API.
   */
protected CollectionAdminResponse deleteCollection(String collectionName) throws Exception {
    SolrClient client = createCloudClient(null);
    CollectionAdminResponse res;
    try {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.DELETE.toString());
        params.set("name", collectionName);
        QueryRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        res = new CollectionAdminResponse();
        res.setResponse(client.request(request));
    } catch (Exception e) {
        log.warn("Error while deleting the collection " + collectionName, e);
        return new CollectionAdminResponse();
    } finally {
        client.close();
    }
    return res;
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 85 with QueryRequest

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

the class BaseCdcrDistributedZkTest method invokeCdcrAction.

/**
   * Invokes a CDCR action on a given node.
   */
protected NamedList invokeCdcrAction(CloudJettyRunner jetty, CdcrParams.CdcrAction action) throws Exception {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CommonParams.ACTION, action.toString());
    SolrRequest request = new QueryRequest(params);
    request.setPath(CDCR_PATH);
    return jetty.client.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)

Aggregations

QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)112 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)77 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