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.");
}
}
}
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);
}
}
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();
}
}
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();
}
}
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);
}
Aggregations