Search in sources :

Example 86 with QueryRequest

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

the class BaseCdcrDistributedZkTest method createCollection.

private CollectionAdminResponse createCollection(Map<String, List<Integer>> collectionInfos, String collectionName, Map<String, Object> collectionProps, SolrClient client, String confSetName) throws SolrServerException, IOException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionParams.CollectionAction.CREATE.toString());
    for (Map.Entry<String, Object> entry : collectionProps.entrySet()) {
        if (entry.getValue() != null)
            params.set(entry.getKey(), String.valueOf(entry.getValue()));
    }
    Integer numShards = (Integer) collectionProps.get(NUM_SLICES);
    if (numShards == null) {
        String shardNames = (String) collectionProps.get(SHARDS_PROP);
        numShards = StrUtils.splitSmart(shardNames, ',').size();
    }
    Integer replicationFactor = (Integer) collectionProps.get(REPLICATION_FACTOR);
    if (replicationFactor == null) {
        replicationFactor = (Integer) OverseerCollectionMessageHandler.COLL_PROPS.get(REPLICATION_FACTOR);
    }
    if (confSetName != null) {
        params.set("collection.configName", confSetName);
    }
    List<Integer> list = new ArrayList<>();
    list.add(numShards);
    list.add(replicationFactor);
    if (collectionInfos != null) {
        collectionInfos.put(collectionName, list);
    }
    params.set("name", collectionName);
    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) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 87 with QueryRequest

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

the class BasicDistributedZkTest method doOptimisticLockingAndUpdating.

// cloud level test mainly needed just to make sure that versions and errors are propagated correctly
private void doOptimisticLockingAndUpdating() throws Exception {
    log.info("### STARTING doOptimisticLockingAndUpdating");
    printLayout();
    SolrInputDocument sd = sdoc("id", 1000, "_version_", -1);
    indexDoc(sd);
    ignoreException("version conflict");
    for (SolrClient client : clients) {
        try {
            client.add(sd);
            fail();
        } catch (SolrException e) {
            assertEquals(409, e.code());
        }
    }
    unIgnoreException("version conflict");
    // TODO: test deletes.  SolrJ needs a good way to pass version for delete...
    sd = sdoc("id", 1000, "foo_i", 5);
    clients.get(0).add(sd);
    List<Integer> expected = new ArrayList<>();
    int val = 0;
    for (SolrClient client : clients) {
        val += 10;
        client.add(sdoc("id", 1000, "val_i", map("add", val), "foo_i", val));
        expected.add(val);
    }
    QueryRequest qr = new QueryRequest(params("qt", "/get", "id", "1000"));
    for (SolrClient client : clients) {
        val += 10;
        NamedList rsp = client.request(qr);
        String match = JSONTestUtil.matchObj("/val_i", rsp.get("doc"), expected);
        if (match != null)
            throw new RuntimeException(match);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SolrInputDocument(org.apache.solr.common.SolrInputDocument) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) SolrException(org.apache.solr.common.SolrException)

Example 88 with QueryRequest

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

the class BasicDistributedZkTest method getNumCommits.

private Long getNumCommits(HttpSolrClient sourceClient) throws SolrServerException, IOException {
    // construct the /admin/metrics URL
    URL url = new URL(sourceClient.getBaseURL());
    String path = url.getPath().substring(1);
    String[] elements = path.split("/");
    String collection = elements[elements.length - 1];
    String urlString = url.toString();
    urlString = urlString.substring(0, urlString.length() - collection.length() - 1);
    try (HttpSolrClient client = getHttpSolrClient(urlString)) {
        client.setConnectionTimeout(15000);
        client.setSoTimeout(60000);
        ModifiableSolrParams params = new ModifiableSolrParams();
        //params.set("qt", "/admin/metrics?prefix=UPDATE.updateHandler&registry=solr.core." + collection);
        params.set("qt", "/admin/metrics");
        params.set("prefix", "UPDATE.updateHandler");
        params.set("registry", "solr.core." + collection);
        // use generic request to avoid extra processing of queries
        QueryRequest req = new QueryRequest(params);
        NamedList<Object> resp = client.request(req);
        NamedList metrics = (NamedList) resp.get("metrics");
        NamedList uhandlerCat = (NamedList) metrics.getVal(0);
        Map<String, Object> commits = (Map<String, Object>) uhandlerCat.get("UPDATE.updateHandler.commits");
        return (Long) commits.get("count");
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) Map(java.util.Map) HashMap(java.util.HashMap) URL(java.net.URL) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 89 with QueryRequest

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

the class ShowFileRequestHandlerTest method testDirList.

public void testDirList() throws SolrServerException, IOException {
    SolrClient client = getSolrClient();
    //assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4
    QueryRequest request = new QueryRequest();
    request.setPath("/admin/file");
    QueryResponse resp = request.process(client);
    assertEquals(0, resp.getStatus());
    //some files
    assertTrue(((NamedList) resp.getResponse().get("files")).size() > 0);
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrClient(org.apache.solr.client.solrj.SolrClient) NamedList(org.apache.solr.common.util.NamedList) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse)

Example 90 with QueryRequest

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

the class ShowFileRequestHandlerTest method test404ViaHttp.

public void test404ViaHttp() throws SolrServerException, IOException {
    SolrClient client = getSolrClient();
    QueryRequest request = new QueryRequest(params("file", "does-not-exist-404.txt"));
    request.setPath("/admin/file");
    try {
        QueryResponse resp = request.process(client);
        fail("didn't get 404 exception");
    } catch (SolrException e) {
        assertEquals(404, e.code());
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrClient(org.apache.solr.client.solrj.SolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrException(org.apache.solr.common.SolrException)

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