Search in sources :

Example 36 with SolrRequest

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

the class MultiThreadedOCPTest method testLongAndShortRunningParallelApiCalls.

private void testLongAndShortRunningParallelApiCalls() throws InterruptedException, IOException, SolrServerException {
    Thread indexThread = new Thread() {

        @Override
        public void run() {
            Random random = random();
            int max = atLeast(random, 200);
            for (int id = 101; id < max; id++) {
                try {
                    doAddDoc(String.valueOf(id));
                } catch (Exception e) {
                    log.error("Exception while adding docs", e);
                }
            }
        }
    };
    indexThread.start();
    try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
        SplitShard splitShardRequest = CollectionAdminRequest.splitShard("collection1").setShardName(SHARD1);
        splitShardRequest.processAsync("2000", client);
        RequestStatusState state = getRequestState("2000", client);
        while (state == RequestStatusState.SUBMITTED) {
            state = getRequestState("2000", client);
            Thread.sleep(10);
        }
        assertSame("SplitShard task [2000] was supposed to be in [running] but isn't. It is [" + state + "]", RequestStatusState.RUNNING, state);
        // CLUSTERSTATE is always mutually exclusive, it should return with a response before the split completes
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", "collection1");
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        client.request(request);
        state = getRequestState("2000", client);
        assertSame("After invoking OVERSEERSTATUS, SplitShard task [2000] was still supposed to be in [running] but " + "isn't. It is [" + state + "]", RequestStatusState.RUNNING, state);
    } finally {
        try {
            indexThread.join();
        } catch (InterruptedException e) {
            log.warn("Indexing thread interrupted.");
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Random(java.util.Random) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SplitShard(org.apache.solr.client.solrj.request.CollectionAdminRequest.SplitShard) RequestStatusState(org.apache.solr.client.solrj.response.RequestStatusState) SolrRequest(org.apache.solr.client.solrj.SolrRequest) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 37 with SolrRequest

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

the class TestRequestStatusCollectionAPI method sendRequest.

protected NamedList sendRequest(ModifiableSolrParams params) throws SolrServerException, IOException {
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    String baseUrl = ((HttpSolrClient) shardToJetty.get(SHARD1).get(0).client.solrClient).getBaseURL();
    baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
    try (HttpSolrClient baseServer = getHttpSolrClient(baseUrl)) {
        baseServer.setConnectionTimeout(15000);
        return baseServer.request(request);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest)

Example 38 with SolrRequest

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

the class TestSolrCloudWithDelegationTokens method getStatusCode.

private int getStatusCode(String token, final String user, final String op, HttpSolrClient client) throws Exception {
    SolrClient delegationTokenClient;
    if (random().nextBoolean())
        delegationTokenClient = new HttpSolrClient.Builder(client.getBaseURL().toString()).withKerberosDelegationToken(token).withResponseParser(client.getParser()).build();
    else
        delegationTokenClient = new CloudSolrClient.Builder().withZkHost((miniCluster.getZkServer().getZkAddress())).withLBHttpSolrClientBuilder(new LBHttpSolrClient.Builder().withResponseParser(client.getParser()).withHttpSolrClientBuilder(new HttpSolrClient.Builder().withKerberosDelegationToken(token))).build();
    try {
        ModifiableSolrParams p = new ModifiableSolrParams();
        if (user != null)
            p.set(USER_PARAM, user);
        if (op != null)
            p.set("op", op);
        SolrRequest req = getAdminRequest(p);
        if (user != null || op != null) {
            Set<String> queryParams = new HashSet<>();
            if (user != null)
                queryParams.add(USER_PARAM);
            if (op != null)
                queryParams.add("op");
            req.setQueryParams(queryParams);
        }
        try {
            delegationTokenClient.request(req, null);
            return HttpStatus.SC_OK;
        } catch (HttpSolrClient.RemoteSolrException re) {
            return re.code();
        }
    } finally {
        delegationTokenClient.close();
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) LBHttpSolrClient(org.apache.solr.client.solrj.impl.LBHttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) LBHttpSolrClient(org.apache.solr.client.solrj.impl.LBHttpSolrClient) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) HashSet(java.util.HashSet)

Example 39 with SolrRequest

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

the class TestSolrCloudWithDelegationTokens method testDelegationTokenSolrClient.

/**
   * Test HttpSolrServer's delegation token support
   */
@Test
public void testDelegationTokenSolrClient() throws Exception {
    // Get token
    String token = getDelegationToken(null, "bar", solrClientPrimary);
    assertNotNull(token);
    SolrRequest request = getAdminRequest(new ModifiableSolrParams());
    // test without token
    HttpSolrClient ss = new HttpSolrClient.Builder(solrClientPrimary.getBaseURL().toString()).withResponseParser(solrClientPrimary.getParser()).build();
    try {
        doSolrRequest(ss, request, ErrorCode.UNAUTHORIZED.code);
    } finally {
        ss.close();
    }
    ss = new HttpSolrClient.Builder(solrClientPrimary.getBaseURL().toString()).withKerberosDelegationToken(token).withResponseParser(solrClientPrimary.getParser()).build();
    try {
        // test with token via property
        doSolrRequest(ss, request, HttpStatus.SC_OK);
        // test with param -- should throw an exception
        ModifiableSolrParams tokenParam = new ModifiableSolrParams();
        tokenParam.set("delegation", "invalidToken");
        try {
            doSolrRequest(ss, getAdminRequest(tokenParam), ErrorCode.FORBIDDEN.code);
            Assert.fail("Expected exception");
        } catch (IllegalArgumentException ex) {
        }
    } finally {
        ss.close();
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) LBHttpSolrClient(org.apache.solr.client.solrj.impl.LBHttpSolrClient) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 40 with SolrRequest

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

the class TestRebalanceLeaders method rebalanceLeaderUsingDirectCall.

private void rebalanceLeaderUsingDirectCall() throws IOException, SolrServerException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionParams.CollectionAction.REBALANCELEADERS.toString());
    // Insure we get error returns when omitting required parameters
    params.set("collection", COLLECTION_NAME);
    params.set("maxAtOnce", "10");
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    cloudClient.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

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