Merge branch 'branch_6x' of https://git-wip-us.apache.org/repos/asf/lucene-solr into branch_6x

This commit is contained in:
Karl Wright 2016-04-08 20:35:29 -04:00
commit 1e695d835e
116 changed files with 1451 additions and 512 deletions

View File

@ -106,6 +106,9 @@ Other Changes
* SOLR-8892: Allow SolrInfoMBeans to return different statistics for /jmx vs web ui calls.
(Gregory Chanan, Mark Miller)
* SOLR-8097: Implement builder pattern design for constructing SolrJ clients and also deprecate direct construction
of client objects. (Jason Gerlowski, Shawn Heisey, Anshum Gupta)
================== 6.0.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

View File

@ -22,6 +22,7 @@ import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
@ -111,11 +112,16 @@ public class SolrEntityProcessor extends EntityProcessorBase {
// (wt="javabin|xml") default is javabin
if ("xml".equals(context.getResolvedEntityAttribute(CommonParams.WT))) {
// TODO: it doesn't matter for this impl when passing a client currently, but we should close this!
solrClient = new HttpSolrClient(url.toExternalForm(), client, new XMLResponseParser());
solrClient = new Builder(url.toExternalForm())
.withHttpClient(client)
.withResponseParser(new XMLResponseParser())
.build();
LOG.info("using XMLResponseParser");
} else {
// TODO: it doesn't matter for this impl when passing a client currently, but we should close this!
solrClient = new HttpSolrClient(url.toExternalForm(), client);
solrClient = new Builder(url.toExternalForm())
.withHttpClient(client)
.build();
LOG.info("using BinaryResponseParser");
}
} catch (MalformedURLException e) {

View File

@ -69,7 +69,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
params.set("command", "full-import");
params.set("clean", "false");
req.setParams(params);
try (HttpSolrClient solrClient = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
try (HttpSolrClient solrClient = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
solrClient.request(req);
ModifiableSolrParams qparams = new ModifiableSolrParams();
qparams.add("q", "*:*");
@ -89,7 +89,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
"clean", "false", UpdateParams.COMMIT, "false",
UpdateParams.COMMIT_WITHIN, "1000");
req.setParams(params);
try (HttpSolrClient solrServer = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
try (HttpSolrClient solrServer = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
solrServer.request(req);
Thread.sleep(100);
ModifiableSolrParams queryAll = params("q", "*");

View File

@ -282,7 +282,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
sidl.add(sd);
}
try (HttpSolrClient solrServer = new HttpSolrClient(getSourceUrl())) {
try (HttpSolrClient solrServer = getHttpSolrClient(getSourceUrl())) {
solrServer.setConnectionTimeout(15000);
solrServer.setSoTimeout(30000);
solrServer.add(sidl);

View File

@ -90,7 +90,7 @@ class GoLive {
Callable<Request> task = () -> {
Request req = new Request();
LOG.info("Live merge " + dir.getPath() + " into " + mergeUrl);
try (final HttpSolrClient client = new HttpSolrClient(mergeUrl)) {
try (final HttpSolrClient client = new HttpSolrClient.Builder(mergeUrl).build()) {
CoreAdminRequest.MergeIndexes mergeRequest = new CoreAdminRequest.MergeIndexes();
mergeRequest.setCoreName(name);
mergeRequest.setIndexDirs(Arrays.asList(dir.getPath().toString() + "/data/index"));
@ -138,7 +138,7 @@ class GoLive {
try {
LOG.info("Committing live merge...");
if (options.zkHost != null) {
try (CloudSolrClient server = new CloudSolrClient(options.zkHost)) {
try (CloudSolrClient server = new CloudSolrClient.Builder().withZkHost(options.zkHost).build()) {
server.setDefaultCollection(options.collection);
server.commit();
}
@ -146,7 +146,7 @@ class GoLive {
for (List<String> urls : options.shardUrls) {
for (String url : urls) {
// TODO: we should do these concurrently
try (HttpSolrClient server = new HttpSolrClient(url)) {
try (HttpSolrClient server = new HttpSolrClient.Builder(url).build()) {
server.commit();
}
}

View File

@ -380,7 +380,7 @@ public class MorphlineGoLiveMiniMRTest extends AbstractFullDistribZkTestBase {
String[] args = new String[]{};
List<String> argList = new ArrayList<>();
try (HttpSolrClient server = new HttpSolrClient(cloudJettys.get(0).url)) {
try (HttpSolrClient server = getHttpSolrClient(cloudJettys.get(0).url)) {
args = new String[]{
"--solr-home-dir=" + MINIMR_CONF_DIR.getAbsolutePath(),
@ -706,7 +706,7 @@ public class MorphlineGoLiveMiniMRTest extends AbstractFullDistribZkTestBase {
Collection<Replica> replicas = slice.getReplicas();
long found = -1;
for (Replica replica : replicas) {
try (HttpSolrClient client = new HttpSolrClient(new ZkCoreNodeProps(replica).getCoreUrl())) {
try (HttpSolrClient client = getHttpSolrClient(new ZkCoreNodeProps(replica).getCoreUrl())) {
SolrQuery query = new SolrQuery("*:*");
query.set("distrib", false);
QueryResponse replicaResults = client.query(query);

View File

@ -39,7 +39,7 @@ final class SafeConcurrentUpdateSolrClient extends ConcurrentUpdateSolrClient {
}
public SafeConcurrentUpdateSolrClient(String solrServerUrl, HttpClient client, int queueSize, int threadCount) {
super(solrServerUrl, client, queueSize, threadCount);
super(solrServerUrl, client, queueSize, threadCount, null, false);
}
@Override

View File

@ -30,6 +30,7 @@ import com.typesafe.config.ConfigRenderOptions;
import com.typesafe.config.ConfigUtil;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrResourceLoader;
@ -92,7 +93,9 @@ public class SolrLocator {
if (collectionName == null || collectionName.length() == 0) {
throw new MorphlineCompilationException("Parameter 'zkHost' requires that you also pass parameter 'collection'", config);
}
CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost);
CloudSolrClient cloudSolrClient = new Builder()
.withZkHost(zkHost)
.build();
cloudSolrClient.setDefaultCollection(collectionName);
cloudSolrClient.connect();
return new SolrClientDocumentLoader(cloudSolrClient, batchSize);

View File

@ -16,6 +16,22 @@
*/
package org.apache.solr.morphlines.solr;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicInteger;
import com.codahale.metrics.MetricRegistry;
import com.google.common.base.Joiner;
import com.google.common.io.Files;
@ -46,22 +62,6 @@ import org.kitesdk.morphline.stdlib.PipeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicInteger;
public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 {
private static Locale savedLocale;
protected Collector collector;
@ -123,7 +123,7 @@ public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 {
if (EXTERNAL_SOLR_SERVER_URL != null) {
//solrServer = new ConcurrentUpdateSolrServer(EXTERNAL_SOLR_SERVER_URL, 2, 2);
//solrServer = new SafeConcurrentUpdateSolrServer(EXTERNAL_SOLR_SERVER_URL, 2, 2);
solrClient = new HttpSolrClient(EXTERNAL_SOLR_SERVER_URL);
solrClient = getHttpSolrClient(EXTERNAL_SOLR_SERVER_URL);
((HttpSolrClient) solrClient).setParser(new XMLResponseParser());
} else {
if (TEST_WITH_EMBEDDED_SOLR_SERVER) {

View File

@ -201,7 +201,7 @@ public class LeaderInitiatedRecoveryThread extends Thread {
log.info("Asking core={} coreNodeName={} on " + recoveryUrl + " to recover", coreNeedingRecovery, replicaCoreNodeName);
}
try (HttpSolrClient client = new HttpSolrClient(recoveryUrl)) {
try (HttpSolrClient client = new HttpSolrClient.Builder(recoveryUrl).build()) {
client.setSoTimeout(60000);
client.setConnectionTimeout(15000);
try {

View File

@ -16,9 +16,22 @@
*/
package org.apache.solr.cloud;
import java.io.Closeable;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Create;
import org.apache.solr.common.SolrException;
@ -34,21 +47,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import java.io.Closeable;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
// TODO: how to tmp exclude nodes?
@ -434,7 +432,7 @@ public class OverseerAutoReplicaFailoverThread implements Runnable, Closeable {
final String createUrl, final String dataDir, final String ulogDir,
final String coreNodeName, final String coreName) {
try (HttpSolrClient client = new HttpSolrClient(createUrl)) {
try (HttpSolrClient client = new HttpSolrClient.Builder(createUrl).build()) {
log.debug("create url={}", createUrl);
client.setConnectionTimeout(30000);
client.setSoTimeout(60000);

View File

@ -1315,7 +1315,7 @@ public class OverseerCollectionMessageHandler implements OverseerMessageHandler
static UpdateResponse softCommit(String url) throws SolrServerException, IOException {
try (HttpSolrClient client = new HttpSolrClient(url)) {
try (HttpSolrClient client = new HttpSolrClient.Builder(url).build()) {
client.setConnectionTimeout(30000);
client.setSoTimeout(120000);
UpdateRequest ureq = new UpdateRequest();

View File

@ -17,7 +17,6 @@
package org.apache.solr.cloud;
import java.io.Closeable;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
@ -195,7 +194,7 @@ public class RecoveryStrategy extends Thread implements Closeable {
private void commitOnLeader(String leaderUrl) throws SolrServerException,
IOException {
try (HttpSolrClient client = new HttpSolrClient(leaderUrl)) {
try (HttpSolrClient client = new HttpSolrClient.Builder(leaderUrl).build()) {
client.setConnectionTimeout(30000);
UpdateRequest ureq = new UpdateRequest();
ureq.setParams(new ModifiableSolrParams());
@ -575,7 +574,7 @@ public class RecoveryStrategy extends Thread implements Closeable {
private void sendPrepRecoveryCmd(String leaderBaseUrl, String leaderCoreName, Slice slice)
throws SolrServerException, IOException, InterruptedException, ExecutionException {
try (HttpSolrClient client = new HttpSolrClient(leaderBaseUrl)) {
try (HttpSolrClient client = new HttpSolrClient.Builder(leaderBaseUrl).build()) {
client.setConnectionTimeout(30000);
WaitForState prepCmd = new WaitForState();
prepCmd.setCoreName(leaderCoreName);

View File

@ -292,7 +292,7 @@ public class SyncStrategy {
recoverRequestCmd.setAction(CoreAdminAction.REQUESTRECOVERY);
recoverRequestCmd.setCoreName(coreName);
try (HttpSolrClient client = new HttpSolrClient(baseUrl, SyncStrategy.this.client)) {
try (HttpSolrClient client = new HttpSolrClient.Builder(baseUrl).withHttpClient(SyncStrategy.this.client).build()) {
client.setConnectionTimeout(30000);
client.setSoTimeout(120000);
client.request(recoverRequestCmd);

View File

@ -35,6 +35,7 @@ import java.util.concurrent.TimeoutException;
import com.google.common.base.Strings;
import org.apache.commons.lang.StringUtils;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
import org.apache.solr.client.solrj.request.CoreAdminRequest.WaitForState;
import org.apache.solr.cloud.overseer.OverseerAction;
import org.apache.solr.cloud.overseer.SliceMutator;
@ -1574,7 +1575,7 @@ public final class ZkController {
log.info("Replica " + myCoreNodeName +
" NOT in leader-initiated recovery, need to wait for leader to see down state.");
try (HttpSolrClient client = new HttpSolrClient(leaderBaseUrl)) {
try (HttpSolrClient client = new Builder(leaderBaseUrl).build()) {
client.setConnectionTimeout(15000);
client.setSoTimeout(120000);
WaitForState prepCmd = new WaitForState();

View File

@ -105,7 +105,8 @@ public class SnitchContext implements RemoteCallback {
public SimpleSolrResponse invoke(UpdateShardHandler shardHandler, final String url, String path, SolrParams params)
throws IOException, SolrServerException {
GenericSolrRequest request = new GenericSolrRequest(SolrRequest.METHOD.GET, path, params);
try (HttpSolrClient client = new HttpSolrClient(url, shardHandler.getHttpClient(), new BinaryResponseParser())) {
try (HttpSolrClient client = new HttpSolrClient.Builder(url).withHttpClient(shardHandler.getHttpClient())
.withResponseParser(new BinaryResponseParser()).build()) {
NamedList<Object> rsp = client.request(request);
request.response.nl = rsp;
return request.response;

View File

@ -16,9 +16,16 @@
*/
package org.apache.solr.handler;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
@ -30,12 +37,6 @@ import org.apache.solr.update.CdcrUpdateLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
class CdcrReplicatorManager implements CdcrStateManager.CdcrStateObserver {
private List<CdcrReplicatorState> replicatorStates;
@ -64,7 +65,10 @@ class CdcrReplicatorManager implements CdcrStateManager.CdcrStateObserver {
String zkHost = params.get(CdcrParams.ZK_HOST_PARAM);
String targetCollection = params.get(CdcrParams.TARGET_COLLECTION_PARAM);
CloudSolrClient client = new CloudSolrClient(zkHost, true);
CloudSolrClient client = new Builder()
.withZkHost(zkHost)
.sendUpdatesOnlyToShardLeaders()
.build();
client.setDefaultCollection(targetCollection);
replicatorStates.add(new CdcrReplicatorState(targetCollection, zkHost, client));
}

View File

@ -595,7 +595,7 @@ public class CdcrRequestHandler extends RequestHandlerBase implements SolrCoreAw
@Override
public Long call() throws Exception {
try (HttpSolrClient server = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient server = new HttpSolrClient.Builder(baseUrl).build()) {
server.setConnectionTimeout(15000);
server.setSoTimeout(60000);

View File

@ -129,7 +129,7 @@ class CdcrUpdateLogSynchronizer implements CdcrStateManager.CdcrStateObserver {
return;
}
HttpSolrClient server = new HttpSolrClient(leaderUrl);
HttpSolrClient server = new HttpSolrClient.Builder(leaderUrl).build();
server.setConnectionTimeout(15000);
server.setSoTimeout(60000);

View File

@ -218,7 +218,7 @@ public class IndexFetcher {
QueryRequest req = new QueryRequest(params);
// TODO modify to use shardhandler
try (HttpSolrClient client = new HttpSolrClient(masterUrl, myHttpClient)) {
try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl).withHttpClient(myHttpClient).build()) {
client.setSoTimeout(60000);
client.setConnectionTimeout(15000);
@ -240,7 +240,7 @@ public class IndexFetcher {
QueryRequest req = new QueryRequest(params);
// TODO modify to use shardhandler
try (HttpSolrClient client = new HttpSolrClient(masterUrl, myHttpClient)) {
try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl).withHttpClient(myHttpClient).build()) {
client.setSoTimeout(60000);
client.setConnectionTimeout(15000);
NamedList response = client.request(req);
@ -1606,7 +1606,11 @@ public class IndexFetcher {
InputStream is = null;
// TODO use shardhandler
try (HttpSolrClient client = new HttpSolrClient(masterUrl, myHttpClient, null)) {
try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl)
.withHttpClient(myHttpClient)
.withResponseParser(null)
.build()
) {
client.setSoTimeout(60000);
client.setConnectionTimeout(15000);
QueryRequest req = new QueryRequest(params);
@ -1715,7 +1719,7 @@ public class IndexFetcher {
params.set(CommonParams.QT, "/replication");
// TODO use shardhandler
try (HttpSolrClient client = new HttpSolrClient(masterUrl, myHttpClient)) {
try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl).withHttpClient(myHttpClient).build()) {
client.setSoTimeout(60000);
client.setConnectionTimeout(15000);
QueryRequest request = new QueryRequest(params);

View File

@ -69,7 +69,6 @@ import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.SchemaManager;
import org.apache.solr.security.AuthorizationContext;
import org.apache.solr.security.PermissionNameProvider;
import org.apache.solr.security.PermissionNameProvider.Name;
import org.apache.solr.util.CommandOperation;
import org.apache.solr.util.DefaultSolrThreadFactory;
import org.apache.solr.util.RTimer;
@ -785,7 +784,7 @@ public class SolrConfigHandler extends RequestHandlerBase implements SolrCoreAwa
public Boolean call() throws Exception {
final RTimer timer = new RTimer();
int attempts = 0;
try (HttpSolrClient solr = new HttpSolrClient(coreUrl)) {
try (HttpSolrClient solr = new HttpSolrClient.Builder(coreUrl).build()) {
// eventually, this loop will get killed by the ExecutorService's timeout
while (true) {
try {

View File

@ -35,6 +35,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest.RequestSyncShard;
import org.apache.solr.client.solrj.response.RequestStatusState;
@ -427,7 +428,7 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission
ZkNodeProps leaderProps = clusterState.getLeader(collection, shard);
ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(leaderProps);
try (HttpSolrClient client = new HttpSolrClient(nodeProps.getBaseUrl())) {
try (HttpSolrClient client = new Builder(nodeProps.getBaseUrl()).build()) {
client.setConnectionTimeout(15000);
client.setSoTimeout(60000);
RequestSyncShard reqSyncShard = new CoreAdminRequest.RequestSyncShard();

View File

@ -35,7 +35,7 @@ import org.apache.http.client.HttpClient;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.util.ClientUtils;
@ -54,7 +54,6 @@ import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -192,7 +191,7 @@ public class HttpShardHandler extends ShardHandler {
if (urls.size() <= 1) {
String url = urls.get(0);
srsp.setShardAddress(url);
try (SolrClient client = new HttpSolrClient(url, httpClient)) {
try (SolrClient client = new Builder(url).withHttpClient(httpClient).build()) {
ssr.nl = client.request(req);
}
} else {

View File

@ -23,6 +23,7 @@ import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
import org.apache.solr.client.solrj.impl.LBHttpSolrClient.Builder;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.ExecutorUtil;
@ -202,7 +203,10 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory implements org.
}
protected LBHttpSolrClient createLoadbalancer(HttpClient httpClient){
return new LBHttpSolrClient(httpClient);
LBHttpSolrClient client = new Builder()
.withHttpClient(httpClient)
.build();
return client;
}
protected <T> T getParameter(NamedList initArgs, String configKey, T defaultValue, StringBuilder sb) {

View File

@ -29,6 +29,7 @@ import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
@ -84,7 +85,9 @@ public abstract class IterativeMergeStrategy implements MergeStrategy {
public CallBack(ShardResponse originalShardResponse, QueryRequest req) {
this.solrClient = new HttpSolrClient(originalShardResponse.getShardAddress(), getHttpClient());
this.solrClient = new Builder(originalShardResponse.getShardAddress())
.withHttpClient(getHttpClient())
.build();
this.req = req;
this.originalShardResponse = originalShardResponse;
req.setMethod(SolrRequest.METHOD.POST);
@ -132,4 +135,4 @@ public abstract class IterativeMergeStrategy implements MergeStrategy {
return httpClient;
}
}
}
}

View File

@ -326,7 +326,7 @@ public final class ManagedIndexSchema extends IndexSchema {
@Override
public Integer call() throws Exception {
int remoteVersion = -1;
try (HttpSolrClient solr = new HttpSolrClient(coreUrl)) {
try (HttpSolrClient solr = new HttpSolrClient.Builder(coreUrl).build()) {
// eventually, this loop will get killed by the ExecutorService's timeout
while (remoteVersion == -1 || remoteVersion < expectedZkVersion) {
try {

View File

@ -44,7 +44,6 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
@ -260,7 +259,7 @@ public class SolrCmdDistributor {
if (req.synchronous) {
blockAndDoRetries();
try (HttpSolrClient client = new HttpSolrClient(req.node.getUrl(), clients.getHttpClient())) {
try (HttpSolrClient client = new HttpSolrClient.Builder(req.node.getUrl()).withHttpClient(clients.getHttpClient()).build()) {
client.request(req.uReq);
} catch (Exception e) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Failed synchronous update on shard " + req.node + " update: " + req.uReq , e);

View File

@ -16,6 +16,16 @@
*/
package org.apache.solr.update;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.solr.client.solrj.SolrClient;
@ -29,16 +39,6 @@ import org.apache.solr.update.processor.DistributingUpdateProcessorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
public class StreamingSolrClients {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@ -72,24 +72,7 @@ public class StreamingSolrClients {
// NOTE: increasing to more than 1 threadCount for the client could cause updates to be reordered
// on a greater scale since the current behavior is to only increase the number of connections/Runners when
// the queue is more than half full.
client = new ConcurrentUpdateSolrClient(url, httpClient, 100, runnerCount, updateExecutor, true) {
@Override
public void handleError(Throwable ex) {
req.trackRequestResult(null, false);
log.error("error", ex);
Error error = new Error();
error.e = (Exception) ex;
if (ex instanceof SolrException) {
error.statusCode = ((SolrException) ex).code();
}
error.req = req;
errors.add(error);
}
@Override
public void onSuccess(HttpResponse resp) {
req.trackRequestResult(resp, true);
}
};
client = new ErrorReportingConcurrentUpdateSolrClient(url, httpClient, 100, runnerCount, updateExecutor, true, req);
client.setParser(new BinaryResponseParser());
client.setRequestWriter(new BinaryRequestWriter());
client.setPollQueueTime(req.pollQueueTime);
@ -132,4 +115,31 @@ public class StreamingSolrClients {
public ExecutorService getUpdateExecutor() {
return updateExecutor;
}
class ErrorReportingConcurrentUpdateSolrClient extends ConcurrentUpdateSolrClient {
private final SolrCmdDistributor.Req req;
public ErrorReportingConcurrentUpdateSolrClient(String solrServerUrl, HttpClient client, int queueSize,
int threadCount, ExecutorService es, boolean streamDeletes, SolrCmdDistributor.Req req) {
super(solrServerUrl, client, queueSize, threadCount, es, streamDeletes);
this.req = req;
}
@Override
public void handleError(Throwable ex) {
req.trackRequestResult(null, false);
log.error("error", ex);
Error error = new Error();
error.e = (Exception) ex;
if (ex instanceof SolrException) {
error.statusCode = ((SolrException) ex).code();
}
error.req = req;
errors.add(error);
}
@Override
public void onSuccess(HttpResponse resp) {
req.trackRequestResult(resp, true);
}
}
}

View File

@ -82,6 +82,7 @@ import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrException;
@ -210,7 +211,7 @@ public class SolrCLI {
String zkHost = cli.getOptionValue("zkHost", ZK_HOST);
log.debug("Connecting to Solr cluster: " + zkHost);
try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) {
try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) {
String collection = cli.getOptionValue("collection");
if (collection != null)
@ -1163,7 +1164,7 @@ public class SolrCLI {
q = new SolrQuery("*:*");
q.setRows(0);
q.set("distrib", "false");
try (HttpSolrClient solr = new HttpSolrClient(coreUrl)) {
try (HttpSolrClient solr = new HttpSolrClient.Builder(coreUrl).build()) {
String solrUrl = solr.getBaseURL();
@ -1286,7 +1287,7 @@ public class SolrCLI {
if (zkHost == null)
throw new IllegalStateException("Must provide either the '-solrUrl' or '-zkHost' parameters!");
try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) {
try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) {
cloudSolrClient.connect();
Set<String> liveNodes = cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes();
if (liveNodes.isEmpty())
@ -1399,7 +1400,7 @@ public class SolrCLI {
"create_collection can only be used when running in SolrCloud mode.\n");
}
try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) {
try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) {
echo("\nConnecting to ZooKeeper at " + zkHost+" ...");
cloudSolrClient.connect();
runCloudTool(cloudSolrClient, cli);
@ -1708,7 +1709,7 @@ public class SolrCLI {
" is running in standalone server mode, upconfig can only be used when running in SolrCloud mode.\n");
}
try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) {
try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) {
echo("\nConnecting to ZooKeeper at " + zkHost + " ...");
cloudSolrClient.connect();
upconfig(cloudSolrClient, cli, cli.getOptionValue("confname"), cli.getOptionValue("confdir"));
@ -1763,7 +1764,7 @@ public class SolrCLI {
}
try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) {
try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) {
echo("\nConnecting to ZooKeeper at " + zkHost + " ...");
cloudSolrClient.connect();
downconfig(cloudSolrClient, cli.getOptionValue("confname"), cli.getOptionValue("confdir"));
@ -1854,7 +1855,7 @@ public class SolrCLI {
protected void deleteCollection(CommandLine cli) throws Exception {
String zkHost = getZkHost(cli);
try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost)) {
try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zkHost).build()) {
echo("Connecting to ZooKeeper at " + zkHost);
cloudSolrClient.connect();
deleteCollection(cloudSolrClient, cli);
@ -2031,7 +2032,7 @@ public class SolrCLI {
echo("\nPOSTing request to Config API: " + solrUrl + updatePath);
echo(jsonBody);
try (SolrClient solrClient = new HttpSolrClient(solrUrl)) {
try (SolrClient solrClient = new Builder(solrUrl).build()) {
NamedList<Object> result = postJsonToSolr(solrClient, updatePath, jsonBody);
Integer statusCode = (Integer)((NamedList)result.get("responseHeader")).get("status");
if (statusCode == 0) {
@ -2426,7 +2427,9 @@ public class SolrCLI {
protected void waitToSeeLiveNodes(int maxWaitSecs, String zkHost, int numNodes) {
CloudSolrClient cloudClient = null;
try {
cloudClient = new CloudSolrClient(zkHost);
cloudClient = new CloudSolrClient.Builder()
.withZkHost(zkHost)
.build();
cloudClient.connect();
Set<String> liveNodes = cloudClient.getZkStateReader().getClusterState().getLiveNodes();
int numLiveNodes = (liveNodes != null) ? liveNodes.size() : 0;

View File

@ -59,8 +59,8 @@ public class TestTolerantSearch extends SolrJettyTestBase {
solrHome = createSolrHome();
createJetty(solrHome.getAbsolutePath());
String url = jetty.getBaseUrl().toString();
collection1 = new HttpSolrClient(url + "/collection1");
collection2 = new HttpSolrClient(url + "/collection2");
collection1 = getHttpSolrClient(url + "/collection1");
collection2 = getHttpSolrClient(url + "/collection2");
String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
@ -68,7 +68,7 @@ public class TestTolerantSearch extends SolrJettyTestBase {
shard2 = urlCollection2.replaceAll("https?://", "");
//create second core
try (HttpSolrClient nodeClient = new HttpSolrClient(url)) {
try (HttpSolrClient nodeClient = getHttpSolrClient(url)) {
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
req.setCoreName("collection2");
req.setConfigSet("collection1");

View File

@ -80,11 +80,11 @@ public class ConnectionReuseTest extends AbstractFullDistribZkTestBase {
HttpClient httpClient = HttpClientUtil.createClient(null);
int rndClient = random().nextInt(3);
if (rndClient == 0) {
client = new ConcurrentUpdateSolrClient(url.toString(), httpClient, 6, 1); // currently only testing with 1 thread
client = getConcurrentUpdateSolrClient(url.toString(), httpClient, 6, 1); // currently only testing with 1 thread
} else if (rndClient == 1) {
client = new HttpSolrClient(url.toString(), httpClient);
client = getHttpSolrClient(url.toString(), httpClient);
} else if (rndClient == 2) {
client = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean(), httpClient);
client = getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean(), httpClient);
((CloudSolrClient) client).setParallelUpdates(random().nextBoolean());
((CloudSolrClient) client).setDefaultCollection(DEFAULT_COLLECTION);
((CloudSolrClient) client).getLbClient().setConnectionTimeout(30000);

View File

@ -19,7 +19,6 @@ package org.apache.solr.client.solrj.embedded;
import com.google.common.base.Charsets;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.junit.Test;
@ -53,7 +52,7 @@ public class TestJettySolrRunner extends SolrTestCaseJ4 {
try {
runner.start();
SolrClient client = new HttpSolrClient(runner.getBaseUrl().toString());
SolrClient client = getHttpSolrClient(runner.getBaseUrl().toString());
CoreAdminRequest.Create createReq = new CoreAdminRequest.Create();
createReq.setCoreName("newcore");

View File

@ -16,6 +16,11 @@
*/
package org.apache.solr.cloud;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
@ -32,16 +37,9 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CollectionParams.CollectionAction;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.Test;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
/**
* Test sync phase that occurs when Leader goes down and a new Leader is
@ -119,7 +117,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
query.set("collection", "testalias");
JettySolrRunner jetty = jettys.get(random().nextInt(jettys.size()));
int port = jetty.getLocalPort();
try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
try (HttpSolrClient client = getHttpSolrClient(buildUrl(port) + "/testalias")) {
res = client.query(query);
assertEquals(3, res.getResults().getNumFound());
}
@ -128,7 +126,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
query = new SolrQuery("*:*");
jetty = jettys.get(random().nextInt(jettys.size()));
port = jetty.getLocalPort();
try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
try (HttpSolrClient client = getHttpSolrClient(buildUrl(port) + "/testalias")) {
res = client.query(query);
assertEquals(3, res.getResults().getNumFound());
}
@ -136,7 +134,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
createAlias("testalias", "collection2,collection1");
// search with new cloud client
try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean())) {
try (CloudSolrClient cloudSolrClient = getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean())) {
cloudSolrClient.setParallelUpdates(random().nextBoolean());
query = new SolrQuery("*:*");
query.set("collection", "testalias");
@ -155,7 +153,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
query.set("collection", "testalias");
jetty = jettys.get(random().nextInt(jettys.size()));
port = jetty.getLocalPort();
try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
try (HttpSolrClient client = getHttpSolrClient(buildUrl(port) + "/testalias")) {
res = client.query(query);
assertEquals(5, res.getResults().getNumFound());
}
@ -163,7 +161,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
query = new SolrQuery("*:*");
jetty = jettys.get(random().nextInt(jettys.size()));
port = jetty.getLocalPort();
try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
try (HttpSolrClient client = getHttpSolrClient(buildUrl(port) + "/testalias")) {
res = client.query(query);
assertEquals(5, res.getResults().getNumFound());
}
@ -190,7 +188,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
// try a std client
// search 1 and 2, but have no collections param
query = new SolrQuery("*:*");
try (HttpSolrClient client = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) {
try (HttpSolrClient client = getHttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) {
res = client.query(query);
assertEquals(5, res.getResults().getNumFound());
}
@ -200,7 +198,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
// a second alias
createAlias("testalias2", "collection2");
try (HttpSolrClient client = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) {
try (HttpSolrClient client = getHttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) {
SolrInputDocument doc8 = getDoc(id, 11, i1, -600, tlong, 600, t1,
"humpty dumpy4 sat on a walls");
client.add(doc8);

View File

@ -16,6 +16,8 @@
*/
package org.apache.solr.cloud;
import java.io.IOException;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
@ -27,8 +29,6 @@ import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.junit.Test;
import java.io.IOException;
public class AsyncMigrateRouteKeyTest extends MigrateRouteKeyTest {
public AsyncMigrateRouteKeyTest() {
@ -113,7 +113,7 @@ public class AsyncMigrateRouteKeyTest extends MigrateRouteKeyTest {
String baseUrl = ((HttpSolrClient) shardToJetty.get(SHARD1).get(0).client.solrClient).getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient baseServer = getHttpSolrClient(baseUrl)) {
baseServer.setConnectionTimeout(15000);
return baseServer.request(request);
}

View File

@ -49,7 +49,6 @@ import org.apache.solr.common.cloud.ZkCoreNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CollectionParams;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.StrUtils;
@ -172,7 +171,7 @@ public class BaseCdcrDistributedZkTest extends AbstractDistribZkTestBase {
}
protected CloudSolrClient createCloudClient(String defaultCollection) {
CloudSolrClient server = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean());
CloudSolrClient server = getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean());
server.setParallelUpdates(random().nextBoolean());
if (defaultCollection != null) server.setDefaultCollection(defaultCollection);
server.getLbClient().getHttpClient().getParams()
@ -745,7 +744,7 @@ public class BaseCdcrDistributedZkTest extends AbstractDistribZkTestBase {
protected static SolrClient createNewSolrServer(String baseUrl) {
try {
// setup the server...
HttpSolrClient s = new HttpSolrClient(baseUrl);
HttpSolrClient s = getHttpSolrClient(baseUrl);
s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
s.setDefaultMaxConnectionsPerHost(100);
s.setMaxTotalConnections(100);

View File

@ -147,7 +147,7 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase {
private void testNodeWithoutCollectionForwarding() throws Exception {
final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0));
try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient client = getHttpSolrClient(baseUrl)) {
client.setConnectionTimeout(30000);
Create createCmd = new Create();
createCmd.setRoles("none");
@ -180,7 +180,7 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase {
SolrQuery query = new SolrQuery("*:*");
try (HttpSolrClient qclient = new HttpSolrClient(baseUrl + "/onenodecollection" + "core")) {
try (HttpSolrClient qclient = getHttpSolrClient(baseUrl + "/onenodecollection" + "core")) {
// it might take a moment for the proxy node to see us in their cloud state
waitForNon403or404or503(qclient);
@ -196,7 +196,7 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase {
assertEquals(docs - 1, results.getResults().getNumFound());
}
try (HttpSolrClient qclient = new HttpSolrClient(baseUrl + "/onenodecollection")) {
try (HttpSolrClient qclient = getHttpSolrClient(baseUrl + "/onenodecollection")) {
QueryResponse results = qclient.query(query);
assertEquals(docs - 1, results.getResults().getNumFound());

View File

@ -404,7 +404,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
for (Slice slice : dColl.getActiveSlices()) {
long sliceDocCount = -1;
for (Replica rep : slice.getReplicas()) {
HttpSolrClient one = new HttpSolrClient(rep.getCoreUrl());
HttpSolrClient one = getHttpSolrClient(rep.getCoreUrl());
SolrQuery query = new SolrQuery("*:*");
query.setDistrib(false);
QueryResponse resp = one.query(query);
@ -528,7 +528,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
private void testStopAndStartCoresInOneInstance() throws Exception {
SolrClient client = clients.get(0);
String url3 = getBaseUrl(client);
try (final HttpSolrClient httpSolrClient = new HttpSolrClient(url3)) {
try (final HttpSolrClient httpSolrClient = getHttpSolrClient(url3)) {
httpSolrClient.setConnectionTimeout(15000);
httpSolrClient.setSoTimeout(60000);
ThreadPoolExecutor executor = null;
@ -749,7 +749,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
private Long getNumCommits(HttpSolrClient sourceClient) throws
SolrServerException, IOException {
try (HttpSolrClient client = new HttpSolrClient(sourceClient.getBaseURL())) {
try (HttpSolrClient client = getHttpSolrClient(sourceClient.getBaseURL())) {
client.setConnectionTimeout(15000);
client.setSoTimeout(60000);
ModifiableSolrParams params = new ModifiableSolrParams();
@ -840,7 +840,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
ZkCoreNodeProps props = new ZkCoreNodeProps(getCommonCloudSolrClient().getZkStateReader().getClusterState().getLeader(oneInstanceCollection2, "slice1"));
// now test that unloading a core gets us a new leader
try (HttpSolrClient unloadClient = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient unloadClient = getHttpSolrClient(baseUrl)) {
unloadClient.setConnectionTimeout(15000);
unloadClient.setSoTimeout(60000);
Unload unloadCmd = new Unload(true);
@ -960,7 +960,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
List<SolrClient> collectionClients, final String baseUrl, final int num,
final String shardId) {
Callable call = () -> {
try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient client = getHttpSolrClient(baseUrl)) {
client.setConnectionTimeout(15000);
Create createCmd = new Create();
createCmd.setRoles("none");
@ -1089,7 +1089,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
final int frozeUnique = unique;
Callable call = () -> {
try (HttpSolrClient client1 = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient client1 = getHttpSolrClient(baseUrl)) {
client1.setConnectionTimeout(15000);
client1.setSoTimeout(60000);
Create createCmd = new Create();
@ -1117,10 +1117,11 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
protected SolrClient createNewSolrClient(String collection, String baseUrl) {
try {
// setup the server...
HttpSolrClient client = new HttpSolrClient(baseUrl + "/" + collection);
HttpSolrClient client = getHttpSolrClient(baseUrl + "/" + collection);
client.setSoTimeout(120000);
client.setDefaultMaxConnectionsPerHost(100);
client.setMaxTotalConnections(100);
return client;
}
catch (Exception ex) {

View File

@ -16,7 +16,15 @@
*/
package org.apache.solr.cloud;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
import java.lang.invoke.MethodHandles;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4.SuppressObjectReleaseTracker;
@ -36,13 +44,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.invoke.MethodHandles;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
@Slow
@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
@ -295,14 +297,10 @@ public class ChaosMonkeyNothingIsSafeTest extends AbstractFullDistribZkTestBase
this.clients = clients;
HttpClientUtil.setConnectionTimeout(httpClient, clientConnectionTimeout);
HttpClientUtil.setSoTimeout(httpClient, clientSoTimeout);
cusc = new ConcurrentUpdateSolrClient(
((HttpSolrClient) clients.get(0)).getBaseURL(), httpClient, 8,
2) {
@Override
public void handleError(Throwable ex) {
log.warn("cusc error", ex);
}
};
cusc = new ErrorLoggingConcurrentUpdateSolrClient(((HttpSolrClient) clients.get(0)).getBaseURL(), httpClient, 8, 2);
cusc.setConnectionTimeout(10000);
cusc.setSoTimeout(clientSoTimeout);
}
@Override
@ -359,14 +357,8 @@ public class ChaosMonkeyNothingIsSafeTest extends AbstractFullDistribZkTestBase
clientIndex = 0;
}
cusc.shutdownNow();
cusc = new ConcurrentUpdateSolrClient(
((HttpSolrClient) clients.get(clientIndex)).getBaseURL(),
httpClient, 30, 3) {
@Override
public void handleError(Throwable ex) {
log.warn("cusc error", ex);
}
};
cusc = new ErrorLoggingConcurrentUpdateSolrClient(((HttpSolrClient) clients.get(clientIndex)).getBaseURL(),
httpClient, 30, 3);
}
}
@ -403,4 +395,13 @@ public class ChaosMonkeyNothingIsSafeTest extends AbstractFullDistribZkTestBase
indexDoc(doc);
}
class ErrorLoggingConcurrentUpdateSolrClient extends ConcurrentUpdateSolrClient {
public ErrorLoggingConcurrentUpdateSolrClient(String serverUrl, HttpClient httpClient, int queueSize, int threadCount) {
super(serverUrl, httpClient, queueSize, threadCount, null, false);
}
@Override
public void handleError(Throwable ex) {
log.warn("cusc error", ex);
}
}
}

View File

@ -131,7 +131,7 @@ public class CollectionReloadTest extends AbstractFullDistribZkTestBase {
ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica);
String coreName = coreProps.getCoreName();
boolean reloadedOk = false;
try (HttpSolrClient client = new HttpSolrClient(coreProps.getBaseUrl())) {
try (HttpSolrClient client = getHttpSolrClient(coreProps.getBaseUrl())) {
CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client);
long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime();

View File

@ -722,7 +722,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
String url = getUrlFromZk(collection);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
}
@ -742,7 +742,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
String url = getUrlFromZk(collection);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
}
@ -789,7 +789,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
String url = getUrlFromZk(collectionName);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
// lets try and use the solrj client to index a couple documents
SolrInputDocument doc1 = getDoc(id, 6, i1, -600, tlong, 600, t1,
@ -886,7 +886,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
url = getUrlFromZk(collectionName);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
}
@ -1061,7 +1061,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
Entry<String,Replica> shardEntry = shardIt.next();
ZkCoreNodeProps coreProps = new ZkCoreNodeProps(shardEntry.getValue());
CoreAdminResponse mcr;
try (HttpSolrClient server = new HttpSolrClient(coreProps.getBaseUrl())) {
try (HttpSolrClient server = getHttpSolrClient(coreProps.getBaseUrl())) {
mcr = CoreAdminRequest.getStatus(coreProps.getCoreName(), server);
}
long before = mcr.getStartTime(coreProps.getCoreName()).getTime();
@ -1196,7 +1196,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
null, client, props);
assertNotNull(newReplica);
HttpSolrClient coreclient = new HttpSolrClient(newReplica.getStr(ZkStateReader.BASE_URL_PROP));
HttpSolrClient coreclient = getHttpSolrClient(newReplica.getStr(ZkStateReader.BASE_URL_PROP));
CoreAdminResponse status = CoreAdminRequest.getStatus(newReplica.getStr("core"), coreclient);
NamedList<Object> coreStatus = status.getCoreStatus(newReplica.getStr("core"));
String instanceDirStr = (String) coreStatus.get("instanceDir");

View File

@ -257,7 +257,7 @@ public class CollectionsAPISolrJTest extends AbstractFullDistribZkTestBase {
Replica replica1 = testCollection.getReplica("core_node1");
try (HttpSolrClient client = new HttpSolrClient(replica1.getStr("base_url"))) {
try (HttpSolrClient client = getHttpSolrClient(replica1.getStr("base_url"))) {
CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), client);
NamedList<Object> coreStatus = status.getCoreStatus(replica1.getStr("core"));
String dataDirStr = (String) coreStatus.get("dataDir");

View File

@ -60,7 +60,8 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {
for (int i = 0; i < threads.length; i++) {
final String collectionName = "collection" + i;
uploadConfig(configDir, collectionName);
final SolrClient solrClient = new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
threads[i] = new CreateDeleteSearchCollectionThread("create-delete-search-" + i, collectionName, collectionName,
timeToRunSec, solrClient, failure);
}
@ -75,7 +76,8 @@ public class ConcurrentDeleteAndCreateCollectionTest extends SolrTestCaseJ4 {
final String configName = "testconfig";
final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile();
uploadConfig(configDir, configName); // upload config once, to be used by all collections
final SolrClient solrClient = new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
final AtomicReference<Exception> failure = new AtomicReference<>();
final int timeToRunSec = 30;
final Thread[] threads = new Thread[2];

View File

@ -167,7 +167,7 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collection);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
}
@ -195,7 +195,7 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
String shard_fld = "shard_s";
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
// lets try and use the solrj client to index a couple documents
@ -292,12 +292,12 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
}
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
}
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
// lets try and use the solrj client to index a couple documents
collectionClient.add(getDoc(id, 6, i1, -600, tlong, 600, t1,
@ -343,13 +343,13 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
// poll for a second - it can take a moment before we are ready to serve
waitForNon403or404or503(collectionClient);
}
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
// lets try and use the solrj client to index a couple documents
collectionClient.add(getDoc(id, 6, i1, -600, tlong, 600, t1,

View File

@ -128,7 +128,7 @@ public class DeleteInactiveReplicaTest extends AbstractFullDistribZkTestBase{
Map m = Utils.makeMap("qt", "/admin/cores", "action", "status");
try (SolrClient queryClient = new HttpSolrClient(replica1.getStr(ZkStateReader.BASE_URL_PROP))) {
try (SolrClient queryClient = getHttpSolrClient(replica1.getStr(ZkStateReader.BASE_URL_PROP))) {
NamedList<Object> resp = queryClient.request(new QueryRequest(new MapSolrParams(m)));
assertNull("The core is up and running again",
((NamedList) resp.get("status")).get(replica1.getStr("core")));

View File

@ -97,7 +97,7 @@ public class DeleteReplicaTest extends AbstractFullDistribZkTestBase {
if (replica1 == null) fail("no active replicas found");
String dataDir = null;
try (HttpSolrClient replica1Client = new HttpSolrClient(replica1.getStr("base_url"))) {
try (HttpSolrClient replica1Client = getHttpSolrClient(replica1.getStr("base_url"))) {
CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), replica1Client);
NamedList<Object> coreStatus = status.getCoreStatus(replica1.getStr("core"));
dataDir = (String) coreStatus.get("dataDir");
@ -186,7 +186,7 @@ public class DeleteReplicaTest extends AbstractFullDistribZkTestBase {
String instanceDir;
String dataDir;
try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient client = getHttpSolrClient(baseUrl)) {
CoreAdminResponse statusResp = CoreAdminRequest.getStatus(core, client);
NamedList r = statusResp.getCoreStatus().get(core);
instanceDir = (String) r.findRecursive("instanceDir");

View File

@ -121,7 +121,7 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase {
.getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient baseServer = getHttpSolrClient(baseUrl)) {
baseServer.setConnectionTimeout(15000);
baseServer.setSoTimeout(60000);
baseServer.request(request);
@ -173,7 +173,7 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase {
String instanceDir;
String dataDir;
try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient client = getHttpSolrClient(baseUrl)) {
CoreAdminResponse statusResp = CoreAdminRequest.getStatus(core, client);
NamedList r = statusResp.getCoreStatus().get(core);
instanceDir = (String) r.findRecursive("instanceDir");
@ -199,7 +199,7 @@ public class DeleteShardTest extends AbstractFullDistribZkTestBase {
baseUrl = (String) leader.get("base_url");
core = (String) leader.get("core");
try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient client = getHttpSolrClient(baseUrl)) {
CoreAdminResponse statusResp = CoreAdminRequest.getStatus(core, client);
NamedList r = statusResp.getCoreStatus().get(core);
instanceDir = (String) r.findRecursive("instanceDir");

View File

@ -105,7 +105,7 @@ public class DistributedVersionInfoTest extends AbstractFullDistribZkTestBase {
assertEquals("leader and replica should have same max version: " + maxOnLeader, maxOnLeader, maxOnReplica);
// send the same doc but with a lower version than the max in the index
try (SolrClient client = new HttpSolrClient(replica.getCoreUrl())) {
try (SolrClient client = getHttpSolrClient(replica.getCoreUrl())) {
String docId = String.valueOf(1);
SolrInputDocument doc = new SolrInputDocument();
doc.setField(id, docId);
@ -276,7 +276,7 @@ public class DistributedVersionInfoTest extends AbstractFullDistribZkTestBase {
query.addSort(new SolrQuery.SortClause("_version_", SolrQuery.ORDER.desc));
query.setParam("distrib", false);
try (SolrClient client = new HttpSolrClient(replica.getCoreUrl())) {
try (SolrClient client = getHttpSolrClient(replica.getCoreUrl())) {
QueryResponse qr = client.query(query);
SolrDocumentList hits = qr.getResults();
if (hits.isEmpty())
@ -343,7 +343,7 @@ public class DistributedVersionInfoTest extends AbstractFullDistribZkTestBase {
}
protected HttpSolrClient getHttpSolrClient(Replica replica) throws Exception {
return new HttpSolrClient(replica.getCoreUrl());
return getHttpSolrClient(replica.getCoreUrl());
}
protected void sendDoc(int docId) throws Exception {
@ -378,7 +378,7 @@ public class DistributedVersionInfoTest extends AbstractFullDistribZkTestBase {
ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica);
String coreName = coreProps.getCoreName();
boolean reloadedOk = false;
try (HttpSolrClient client = new HttpSolrClient(coreProps.getBaseUrl())) {
try (HttpSolrClient client = getHttpSolrClient(coreProps.getBaseUrl())) {
CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client);
long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime();

View File

@ -301,7 +301,7 @@ public class ForceLeaderTest extends HttpPartitionTest {
SolrRequest<SimpleSolrResponse> req = new GenericSolrRequest(METHOD.GET, "/admin/cores", params);
NamedList resp = null;
try (HttpSolrClient hsc = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient hsc = getHttpSolrClient(baseUrl)) {
resp = hsc.request(req);
}

View File

@ -698,7 +698,7 @@ public class FullSolrCloudDistribCmdsTest extends AbstractFullDistribZkTestBase
QueryResponse results = query(cloudClient);
long beforeCount = results.getResults().getNumFound();
int cnt = TEST_NIGHTLY ? 2933 : 313;
try (ConcurrentUpdateSolrClient concurrentClient = new ConcurrentUpdateSolrClient(
try (ConcurrentUpdateSolrClient concurrentClient = getConcurrentUpdateSolrClient(
((HttpSolrClient) clients.get(0)).getBaseURL(), 10, 2)) {
concurrentClient.setConnectionTimeout(120000);
for (int i = 0; i < cnt; i++) {

View File

@ -588,7 +588,7 @@ public class HttpPartitionTest extends AbstractFullDistribZkTestBase {
protected HttpSolrClient getHttpSolrClient(Replica replica, String coll) throws Exception {
ZkCoreNodeProps zkProps = new ZkCoreNodeProps(replica);
String url = zkProps.getBaseUrl() + "/" + coll;
return new HttpSolrClient(url);
return getHttpSolrClient(url);
}
protected int sendDoc(int docId) throws Exception {

View File

@ -163,7 +163,7 @@ public class LeaderInitiatedRecoveryOnCommitTest extends BasicDistributedZkTest
String replicaCoreUrl = replica.getCoreUrl();
log.info("Sending commit request to: "+replicaCoreUrl);
final RTimer timer = new RTimer();
try (HttpSolrClient client = new HttpSolrClient(replicaCoreUrl)) {
try (HttpSolrClient client = getHttpSolrClient(replicaCoreUrl)) {
try {
client.commit();

View File

@ -80,7 +80,7 @@ public class LeaderInitiatedRecoveryOnShardRestartTest extends AbstractFullDistr
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
String baseUrl = ((HttpSolrClient) clients.get(0)).getBaseURL();
HttpSolrClient delClient = new HttpSolrClient(baseUrl.substring(0, baseUrl.lastIndexOf("/")));
HttpSolrClient delClient = getHttpSolrClient(baseUrl.substring(0, baseUrl.lastIndexOf("/")));
delClient.request(request);
delClient.close();

View File

@ -106,7 +106,7 @@ public class MigrateRouteKeyTest extends BasicDistributedZkTest {
.getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
try (HttpSolrClient baseClient = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient baseClient = getHttpSolrClient(baseUrl)) {
baseClient.setConnectionTimeout(15000);
baseClient.setSoTimeout(60000 * 5);
baseClient.request(request);
@ -161,7 +161,7 @@ public class MigrateRouteKeyTest extends BasicDistributedZkTest {
String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), targetCollection);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
SolrQuery solrQuery = new SolrQuery("*:*");
assertEquals("DocCount on target collection does not match", 0, collectionClient.query(solrQuery).getResults().getNumFound());

View File

@ -179,7 +179,7 @@ public class ReplicationFactorTest extends AbstractFullDistribZkTestBase {
ZkCoreNodeProps zkProps = new ZkCoreNodeProps(replica);
String url = zkProps.getBaseUrl() + "/" + collection;
try (HttpSolrClient solrServer = new HttpSolrClient(url)) {
try (HttpSolrClient solrServer = getHttpSolrClient(url)) {
NamedList resp = solrServer.request(up);
NamedList hdr = (NamedList) resp.get("responseHeader");
Integer batchRf = (Integer)hdr.get(UpdateRequest.REPFACT);

View File

@ -130,7 +130,7 @@ public class SSLMigrationTest extends AbstractFullDistribZkTestBase {
urls.add(replica.getStr(ZkStateReader.BASE_URL_PROP));
}
//Create new SolrServer to configure new HttpClient w/ SSL config
new LBHttpSolrClient(urls.toArray(new String[]{})).request(request);
getLBHttpSolrClient(urls.toArray(new String[]{})).request(request);
}
}

View File

@ -16,6 +16,16 @@
*/
package org.apache.solr.cloud;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrClient;
@ -44,16 +54,6 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import static org.apache.solr.cloud.OverseerCollectionMessageHandler.NUM_SLICES;
import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
@ -274,7 +274,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
final DocRouter router = clusterState.getCollection(collectionName).getRouter();
@ -348,7 +348,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
String url = getUrlFromZk(getCommonCloudSolrClient().getZkStateReader().getClusterState(), collectionName);
try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
try (HttpSolrClient collectionClient = getHttpSolrClient(url)) {
String splitKey = "b!";
@ -445,7 +445,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
ZkCoreNodeProps shard1_0 = getLeaderUrlFromZk(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_0);
QueryResponse response;
try (HttpSolrClient shard1_0Client = new HttpSolrClient(shard1_0.getCoreUrl())) {
try (HttpSolrClient shard1_0Client = getHttpSolrClient(shard1_0.getCoreUrl())) {
response = shard1_0Client.query(query);
}
long shard10Count = response.getResults().getNumFound();
@ -453,7 +453,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
ZkCoreNodeProps shard1_1 = getLeaderUrlFromZk(
AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_1);
QueryResponse response2;
try (HttpSolrClient shard1_1Client = new HttpSolrClient(shard1_1.getCoreUrl())) {
try (HttpSolrClient shard1_1Client = getHttpSolrClient(shard1_1.getCoreUrl())) {
response2 = shard1_1Client.query(query);
}
long shard11Count = response2.getResults().getNumFound();
@ -475,7 +475,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
for (Replica replica : slice.getReplicas()) {
String coreUrl = new ZkCoreNodeProps(replica).getCoreUrl();
QueryResponse response;
try (HttpSolrClient client = new HttpSolrClient(coreUrl)) {
try (HttpSolrClient client = getHttpSolrClient(coreUrl)) {
response = client.query(query);
}
numFound[c++] = response.getResults().getNumFound();
@ -514,7 +514,7 @@ public class ShardSplitTest extends BasicDistributedZkTest {
.getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient baseServer = getHttpSolrClient(baseUrl)) {
baseServer.setConnectionTimeout(30000);
baseServer.setSoTimeout(60000 * 5);
baseServer.request(request);

View File

@ -110,7 +110,7 @@ public class SyncSliceTest extends AbstractFullDistribZkTestBase {
.getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
try (HttpSolrClient baseClient = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient baseClient = getHttpSolrClient(baseUrl)) {
// we only set the connect timeout, not so timeout
baseClient.setConnectionTimeout(30000);
baseClient.request(request);

View File

@ -145,17 +145,17 @@ public class TestCloudDeleteByQuery extends SolrCloudTestCase {
assertNotNull("could not find URL for " + shardName + " replica", passiveUrl);
if (shardName.equals("shard1")) {
S_ONE_LEADER_CLIENT = new HttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/");
S_ONE_NON_LEADER_CLIENT = new HttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/");
S_ONE_LEADER_CLIENT = getHttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/");
S_ONE_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/");
} else if (shardName.equals("shard2")) {
S_TWO_LEADER_CLIENT = new HttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/");
S_TWO_NON_LEADER_CLIENT = new HttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/");
S_TWO_LEADER_CLIENT = getHttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/");
S_TWO_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/");
} else {
fail("unexpected shard: " + shardName);
}
}
assertEquals("Should be exactly one server left (nost hosting either shard)", 1, urlMap.size());
NO_COLLECTION_CLIENT = new HttpSolrClient(urlMap.values().iterator().next() +
NO_COLLECTION_CLIENT = getHttpSolrClient(urlMap.values().iterator().next() +
"/" + COLLECTION_NAME + "/");
assertNotNull(S_ONE_LEADER_CLIENT);

View File

@ -79,8 +79,8 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 {
@Test
public void testCreateErrors() throws Exception {
final SolrClient solrClient =
new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile();
solrCluster.uploadConfigDir(configDir, "configSet");
@ -143,8 +143,8 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 {
private void verifyCreate(String baseConfigSetName, String configSetName,
Map<String, String> oldProps, Map<String, String> newProps) throws Exception {
final SolrClient solrClient =
new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
setupBaseConfigSet(baseConfigSetName, oldProps);
SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(),
@ -235,8 +235,8 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 {
@Test
public void testDeleteErrors() throws Exception {
final SolrClient solrClient =
new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile();
final File tmpConfigDir = createTempDir().toFile();
tmpConfigDir.deleteOnExit();
@ -274,8 +274,8 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 {
@Test
public void testDelete() throws Exception {
final SolrClient solrClient =
new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
final File configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf").toFile();
final String configSet = "configSet";
solrCluster.uploadConfigDir(configDir, configSet);
@ -300,8 +300,8 @@ public class TestConfigSetsAPI extends SolrTestCaseJ4 {
@Test
public void testList() throws Exception {
final SolrClient solrClient =
new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
SolrZkClient zkClient = new SolrZkClient(solrCluster.getZkServer().getZkAddress(),
AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null);

View File

@ -121,8 +121,8 @@ public class TestConfigSetsAPIExclusivity extends SolrTestCaseJ4 {
public abstract ConfigSetAdminRequest createRequest();
public void run() {
final SolrClient solrClient =
new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
ConfigSetAdminRequest request = createRequest();
for (int i = 0; i < trials; ++i) {

View File

@ -99,8 +99,8 @@ public class TestConfigSetsAPIZkFailure extends SolrTestCaseJ4 {
@Test
public void testCreateZkFailure() throws Exception {
final SolrClient solrClient =
new HttpSolrClient(solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString());
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
final Map<String, String> oldProps = ImmutableMap.of("immutable", "true");
setupBaseConfigSet(BASE_CONFIGSET_NAME, oldProps);

View File

@ -119,7 +119,7 @@ public class TestCryptoKeys extends AbstractFullDistribZkTestBase {
String baseURL = randomClient.getBaseURL();
baseURL = baseURL.substring(0, baseURL.lastIndexOf('/'));
TestBlobHandler.createSystemCollection(new HttpSolrClient(baseURL, randomClient.getHttpClient()));
TestBlobHandler.createSystemCollection(getHttpSolrClient(baseURL, randomClient.getHttpClient()));
waitForRecoveriesToFinish(".system", true);
ByteBuffer jar = TestDynamicLoading.getFileContent("runtimecode/runtimelibs.jar.bin");

View File

@ -74,7 +74,7 @@ public class TestMiniSolrCloudClusterSSL extends SolrTestCaseJ4 {
private void sendRequestToEachServer() throws Exception {
List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
for (JettySolrRunner jetty : jettys) {
try (HttpSolrClient client = new HttpSolrClient(jetty.getBaseUrl().toString())) {
try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) {
CoreAdminRequest req = new CoreAdminRequest();
req.setAction( CoreAdminAction.STATUS );
client.request(req);

View File

@ -96,7 +96,7 @@ public class TestRandomRequestDistribution extends AbstractFullDistribZkTestBase
assertEquals(1, replicas.size());
String baseUrl = replicas.iterator().next().getStr(ZkStateReader.BASE_URL_PROP);
if (!baseUrl.endsWith("/")) baseUrl += "/";
HttpSolrClient client = new HttpSolrClient(baseUrl + "a1x2");
HttpSolrClient client = getHttpSolrClient(baseUrl + "a1x2");
client.setSoTimeout(5000);
client.setConnectionTimeout(2000);
@ -173,7 +173,7 @@ public class TestRandomRequestDistribution extends AbstractFullDistribZkTestBase
if (!baseUrl.endsWith("/")) baseUrl += "/";
String path = baseUrl + "football";
log.info("Firing queries against path=" + path);
HttpSolrClient client = new HttpSolrClient(path);
HttpSolrClient client = getHttpSolrClient(path);
client.setSoTimeout(5000);
client.setConnectionTimeout(2000);

View File

@ -189,7 +189,7 @@ public class TestRequestStatusCollectionAPI extends BasicDistributedZkTest {
String baseUrl = ((HttpSolrClient) shardToJetty.get(SHARD1).get(0).client.solrClient).getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) {
try (HttpSolrClient baseServer = getHttpSolrClient(baseUrl)) {
baseServer.setConnectionTimeout(15000);
return baseServer.request(request);
}

View File

@ -162,17 +162,17 @@ public class TestTolerantUpdateProcessorCloud extends SolrCloudTestCase {
assertNotNull("could not find URL for " + shardName + " replica", passiveUrl);
if (shardName.equals("shard1")) {
S_ONE_LEADER_CLIENT = new HttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/");
S_ONE_NON_LEADER_CLIENT = new HttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/");
S_ONE_LEADER_CLIENT = getHttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/");
S_ONE_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/");
} else if (shardName.equals("shard2")) {
S_TWO_LEADER_CLIENT = new HttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/");
S_TWO_NON_LEADER_CLIENT = new HttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/");
S_TWO_LEADER_CLIENT = getHttpSolrClient(leaderUrl + "/" + COLLECTION_NAME + "/");
S_TWO_NON_LEADER_CLIENT = getHttpSolrClient(passiveUrl + "/" + COLLECTION_NAME + "/");
} else {
fail("unexpected shard: " + shardName);
}
}
assertEquals("Should be exactly one server left (nost hosting either shard)", 1, urlMap.size());
NO_COLLECTION_CLIENT = new HttpSolrClient(urlMap.values().iterator().next() +
NO_COLLECTION_CLIENT = getHttpSolrClient(urlMap.values().iterator().next() +
"/" + COLLECTION_NAME + "/");
assertNotNull(S_ONE_LEADER_CLIENT);

View File

@ -127,7 +127,7 @@ public class TestTolerantUpdateProcessorRandomCloud extends SolrCloudTestCase {
for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
URL jettyURL = jetty.getBaseUrl();
NODE_CLIENTS.add(new HttpSolrClient(jettyURL.toString() + "/" + COLLECTION_NAME + "/"));
NODE_CLIENTS.add(getHttpSolrClient(jettyURL.toString() + "/" + COLLECTION_NAME + "/"));
}
assertEquals(numServers, NODE_CLIENTS.size());

View File

@ -123,7 +123,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
SolrClient client = clients.get(0);
String url1 = getBaseUrl(client);
try (HttpSolrClient adminClient = new HttpSolrClient(url1)) {
try (HttpSolrClient adminClient = getHttpSolrClient(url1)) {
adminClient.setConnectionTimeout(15000);
adminClient.setSoTimeout(60000);
adminClient.request(createCmd);
@ -174,7 +174,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
// create a new collection collection
SolrClient client = clients.get(0);
String url1 = getBaseUrl(client);
try (HttpSolrClient adminClient = new HttpSolrClient(url1)) {
try (HttpSolrClient adminClient = getHttpSolrClient(url1)) {
adminClient.setConnectionTimeout(15000);
adminClient.setSoTimeout(60000);
@ -194,7 +194,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
client = clients.get(1);
String url2 = getBaseUrl(client);
try (HttpSolrClient adminClient = new HttpSolrClient(url2)) {
try (HttpSolrClient adminClient = getHttpSolrClient(url2)) {
Create createCmd = new Create();
createCmd.setCoreName("unloadcollection2");
@ -213,7 +213,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
Random random = random();
if (random.nextBoolean()) {
try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getCoreUrl())) {
try (HttpSolrClient collectionClient = getHttpSolrClient(leaderProps.getCoreUrl())) {
// lets try and use the solrj client to index and retrieve a couple
// documents
SolrInputDocument doc1 = getDoc(id, 6, i1, -600, tlong, 600, t1,
@ -232,7 +232,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
// create another replica for our collection
client = clients.get(2);
String url3 = getBaseUrl(client);
try (HttpSolrClient adminClient = new HttpSolrClient(url3)) {
try (HttpSolrClient adminClient = getHttpSolrClient(url3)) {
Create createCmd = new Create();
createCmd.setCoreName("unloadcollection3");
createCmd.setCollection("unloadcollection");
@ -246,7 +246,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
// so that we start with some versions when we reload...
DirectUpdateHandler2.commitOnClose = false;
try (HttpSolrClient addClient = new HttpSolrClient(url3 + "/unloadcollection3")) {
try (HttpSolrClient addClient = getHttpSolrClient(url3 + "/unloadcollection3")) {
addClient.setConnectionTimeout(30000);
// add a few docs
@ -260,7 +260,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
//collectionClient.commit();
// unload the leader
try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getBaseUrl())) {
try (HttpSolrClient collectionClient = getHttpSolrClient(leaderProps.getBaseUrl())) {
collectionClient.setConnectionTimeout(15000);
collectionClient.setSoTimeout(30000);
@ -284,7 +284,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
// ensure there is a leader
zkStateReader.getLeaderRetry("unloadcollection", "shard1", 15000);
try (HttpSolrClient addClient = new HttpSolrClient(url2 + "/unloadcollection2")) {
try (HttpSolrClient addClient = getHttpSolrClient(url2 + "/unloadcollection2")) {
addClient.setConnectionTimeout(30000);
addClient.setSoTimeout(90000);
@ -299,7 +299,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
// create another replica for our collection
client = clients.get(3);
String url4 = getBaseUrl(client);
try (HttpSolrClient adminClient = new HttpSolrClient(url4)) {
try (HttpSolrClient adminClient = getHttpSolrClient(url4)) {
adminClient.setConnectionTimeout(15000);
adminClient.setSoTimeout(30000);
@ -314,7 +314,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
// unload the leader again
leaderProps = getLeaderUrlFromZk("unloadcollection", "shard1");
try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getBaseUrl())) {
try (HttpSolrClient collectionClient = getHttpSolrClient(leaderProps.getBaseUrl())) {
collectionClient.setConnectionTimeout(15000);
collectionClient.setSoTimeout(30000);
@ -338,7 +338,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
DirectUpdateHandler2.commitOnClose = true;
// bring the downed leader back as replica
try (HttpSolrClient adminClient = new HttpSolrClient(leaderProps.getBaseUrl())) {
try (HttpSolrClient adminClient = getHttpSolrClient(leaderProps.getBaseUrl())) {
adminClient.setConnectionTimeout(15000);
adminClient.setSoTimeout(30000);
@ -352,7 +352,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
long found1, found3;
try (HttpSolrClient adminClient = new HttpSolrClient(url2 + "/unloadcollection")) {
try (HttpSolrClient adminClient = getHttpSolrClient(url2 + "/unloadcollection")) {
adminClient.setConnectionTimeout(15000);
adminClient.setSoTimeout(30000);
adminClient.commit();
@ -360,7 +360,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
q.set("distrib", false);
found1 = adminClient.query(q).getResults().getNumFound();
}
try (HttpSolrClient adminClient = new HttpSolrClient(url3 + "/unloadcollection")) {
try (HttpSolrClient adminClient = getHttpSolrClient(url3 + "/unloadcollection")) {
adminClient.setConnectionTimeout(15000);
adminClient.setSoTimeout(30000);
adminClient.commit();
@ -369,7 +369,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
found3 = adminClient.query(q).getResults().getNumFound();
}
try (HttpSolrClient adminClient = new HttpSolrClient(url4 + "/unloadcollection")) {
try (HttpSolrClient adminClient = getHttpSolrClient(url4 + "/unloadcollection")) {
adminClient.setConnectionTimeout(15000);
adminClient.setSoTimeout(30000);
adminClient.commit();
@ -387,7 +387,7 @@ public class UnloadDistributedZkTest extends BasicDistributedZkTest {
private void testUnloadLotsOfCores() throws Exception {
SolrClient client = clients.get(2);
String url3 = getBaseUrl(client);
try (final HttpSolrClient adminClient = new HttpSolrClient(url3)) {
try (final HttpSolrClient adminClient = getHttpSolrClient(url3)) {
adminClient.setConnectionTimeout(15000);
adminClient.setSoTimeout(60000);
int cnt = atLeast(3);

View File

@ -97,7 +97,7 @@ public class HdfsWriteToMultipleCollectionsTest extends BasicDistributedZkTest {
List<CloudSolrClient> cloudClients = new ArrayList<>();
List<StoppableIndexingThread> threads = new ArrayList<>();
for (int i = 0; i < cnt; i++) {
CloudSolrClient client = new CloudSolrClient(zkServer.getZkAddress());
CloudSolrClient client = getCloudSolrClient(zkServer.getZkAddress());
client.setDefaultCollection(ACOLLECTION + i);
cloudClients.add(client);
StoppableIndexingThread indexThread = new StoppableIndexingThread(null, client, "1", true, docCount, 1, true);

View File

@ -165,7 +165,7 @@ public class StressHdfsTest extends BasicDistributedZkTest {
int i = 0;
for (SolrClient client : clients) {
try (HttpSolrClient c = new HttpSolrClient(getBaseUrl(client) + "/" + DELETE_DATA_DIR_COLLECTION)) {
try (HttpSolrClient c = getHttpSolrClient(getBaseUrl(client) + "/" + DELETE_DATA_DIR_COLLECTION)) {
int docCnt = random().nextInt(1000) + 1;
for (int j = 0; j < docCnt; j++) {
c.add(getDoc("id", i++, "txt_t", "just some random text for a doc"));

View File

@ -148,14 +148,14 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
// Mostly to keep annoying logging messages from being sent out all the time.
for (int idx = 0; idx < indexingThreads; ++idx) {
HttpSolrClient client = new HttpSolrClient(url);
HttpSolrClient client = getHttpSolrClient(url);
client.setDefaultMaxConnectionsPerHost(25);
client.setConnectionTimeout(30000);
client.setSoTimeout(60000);
indexingClients.add(client);
}
for (int idx = 0; idx < queryThreads; ++idx) {
HttpSolrClient client = new HttpSolrClient(url);
HttpSolrClient client = getHttpSolrClient(url);
client.setDefaultMaxConnectionsPerHost(25);
client.setConnectionTimeout(30000);
client.setSoTimeout(30000);

View File

@ -112,7 +112,7 @@ public class TestDynamicLoading extends AbstractFullDistribZkTestBase {
assertEquals(TestBlobHandler.getAsString(map), ".system collection not available", map.get("msg"));
TestBlobHandler.createSystemCollection(new HttpSolrClient(baseURL, randomClient.getHttpClient()));
TestBlobHandler.createSystemCollection(getHttpSolrClient(baseURL, randomClient.getHttpClient()));
waitForRecoveriesToFinish(".system", true);
map = TestSolrConfigHandler.getRespMap("/test1?wt=json", client);

View File

@ -156,7 +156,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
private static SolrClient createNewSolrClient(int port) {
try {
// setup the client...
HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/" + DEFAULT_TEST_CORENAME);
final String baseUrl = buildUrl(port) + "/" + DEFAULT_TEST_CORENAME;
HttpSolrClient client = getHttpSolrClient(baseUrl);
client.setConnectionTimeout(15000);
client.setSoTimeout(60000);
client.setDefaultMaxConnectionsPerHost(100);
@ -277,7 +278,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
private HttpSolrClient adminClient(SolrClient client) {
String adminUrl = ((HttpSolrClient)client).getBaseURL().replace("/collection1", "");
return new HttpSolrClient(adminUrl);
return getHttpSolrClient(adminUrl);
}
@Test

View File

@ -79,7 +79,8 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
private static SolrClient createNewSolrClient(int port) {
try {
// setup the client...
HttpSolrClient client = new HttpSolrClient(buildUrl(port, context) + "/" + DEFAULT_TEST_CORENAME);
final String baseUrl = buildUrl(port, context) + "/" + DEFAULT_TEST_CORENAME;
HttpSolrClient client = getHttpSolrClient(baseUrl);
client.setConnectionTimeout(15000);
client.setSoTimeout(60000);
client.setDefaultMaxConnectionsPerHost(100);

View File

@ -72,7 +72,8 @@ public class TestRestoreCore extends SolrJettyTestBase {
private static SolrClient createNewSolrClient(int port) {
try {
// setup the client...
HttpSolrClient client = new HttpSolrClient(buildUrl(port, context) + "/" + DEFAULT_TEST_CORENAME);
final String baseUrl = buildUrl(port, context) + "/" + DEFAULT_TEST_CORENAME;
HttpSolrClient client = getHttpSolrClient(baseUrl);
client.setConnectionTimeout(15000);
client.setSoTimeout(60000);
client.setDefaultMaxConnectionsPerHost(100);

View File

@ -254,7 +254,7 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
JettySolrRunner runner = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), buildJettyConfig("/solr"));
runner.start();
try (HttpSolrClient client = new HttpSolrClient(runner.getBaseUrl() + "/corex")) {
try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex")) {
client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
SolrInputDocument doc = new SolrInputDocument();
@ -263,7 +263,7 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
client.commit();
}
try (HttpSolrClient client = new HttpSolrClient(runner.getBaseUrl().toString())) {
try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) {
client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
CoreAdminRequest.Unload req = new CoreAdminRequest.Unload(false);

View File

@ -67,8 +67,8 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
createJetty(solrHome.getAbsolutePath());
String url = jetty.getBaseUrl().toString();
collection1 = new HttpSolrClient(url + "/collection1");
collection2 = new HttpSolrClient(url + "/collection2");
collection1 = getHttpSolrClient(url + "/collection1");
collection2 = getHttpSolrClient(url + "/collection2");
String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
@ -76,7 +76,7 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
shard2 = urlCollection2.replaceAll("https?://", "");
//create second core
try (HttpSolrClient nodeClient = new HttpSolrClient(url)) {
try (HttpSolrClient nodeClient = getHttpSolrClient(url)) {
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
req.setCoreName("collection2");
req.setConfigSet("collection1");

View File

@ -109,7 +109,8 @@ public class DistributedQueryElevationComponentTest extends BaseDistributedSearc
assertEquals(true, document.getFieldValue("[elevated]"));
// Force javabin format
HttpSolrClient client = new HttpSolrClient(((HttpSolrClient)clients.get(0)).getBaseURL());
final String clientUrl = ((HttpSolrClient)clients.get(0)).getBaseURL();
HttpSolrClient client = getHttpSolrClient(clientUrl);
client.setParser(new BinaryResponseParser());
SolrQuery solrQuery = new SolrQuery("XXXX").setParam("qt", "/elevate").setParam("shards.qt", "/elevate").setRows(500).setFields("id,[elevated]")
.setParam("enableElevation", "true").setParam("forceElevation", "true").setParam("elevateIds", "6", "wt", "javabin")

View File

@ -59,7 +59,7 @@ public class TestSolrJ extends SolrTestCaseJ4 {
ConcurrentUpdateSolrClient concurrentClient = null;
// server = concurrentClient = new ConcurrentUpdateSolrServer(addr,32,8);
client = concurrentClient = new ConcurrentUpdateSolrClient(addr,64,nConnections);
client = concurrentClient = getConcurrentUpdateSolrClient(addr,64,nConnections);
client.deleteByQuery("*:*");
client.commit();
@ -164,7 +164,7 @@ public class TestSolrJ extends SolrTestCaseJ4 {
public void doCommitPerf() throws Exception {
try (HttpSolrClient client = new HttpSolrClient("http://127.0.0.1:8983/solr")) {
try (HttpSolrClient client = getHttpSolrClient("http://127.0.0.1:8983/solr")) {
final RTimer timer = new RTimer();

View File

@ -117,8 +117,8 @@ public class TestDistribIDF extends SolrTestCaseJ4 {
//Test against all nodes
for (JettySolrRunner jettySolrRunner : solrCluster.getJettySolrRunners()) {
SolrClient solrClient = new HttpSolrClient(jettySolrRunner.getBaseUrl().toString());
SolrClient solrClient_local = new HttpSolrClient(jettySolrRunner.getBaseUrl().toString());
SolrClient solrClient = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString());
SolrClient solrClient_local = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString());
SolrQuery query = new SolrQuery("cat:football");
query.setFields("*,score");
@ -161,8 +161,8 @@ public class TestDistribIDF extends SolrTestCaseJ4 {
//Test against all nodes
for (JettySolrRunner jettySolrRunner : solrCluster.getJettySolrRunners()) {
SolrClient solrClient = new HttpSolrClient(jettySolrRunner.getBaseUrl().toString());
SolrClient solrClient_local = new HttpSolrClient(jettySolrRunner.getBaseUrl().toString());
SolrClient solrClient = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString());
SolrClient solrClient_local = getHttpSolrClient(jettySolrRunner.getBaseUrl().toString());
SolrQuery query = new SolrQuery("cat:football");
query.setFields("*,score").add("collection", "collection1,collection2");

View File

@ -59,6 +59,7 @@ import org.slf4j.LoggerFactory;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Collections.singletonMap;
import static org.apache.solr.SolrTestCaseJ4.getHttpSolrClient;
import static org.apache.solr.common.cloud.ZkStateReader.BASE_URL_PROP;
@ -162,7 +163,7 @@ public class BasicAuthIntegrationTest extends TestMiniSolrCloudClusterBase {
CollectionAdminRequest.Reload reload = new CollectionAdminRequest.Reload();
reload.setCollectionName(defaultCollName);
HttpSolrClient solrClient = new HttpSolrClient(baseUrl);
HttpSolrClient solrClient = getHttpSolrClient(baseUrl);
try {
rsp = solrClient.request(reload);
fail("must have failed");

View File

@ -78,7 +78,8 @@ public class TestNamedUpdateProcessors extends AbstractFullDistribZkTestBase {
HttpSolrClient randomClient = (HttpSolrClient) clients.get(random().nextInt(clients.size()));
String baseURL = randomClient.getBaseURL();
TestBlobHandler.createSystemCollection(new HttpSolrClient(baseURL.substring(0, baseURL.lastIndexOf('/')), randomClient.getHttpClient()));
final String solrClientUrl = baseURL.substring(0, baseURL.lastIndexOf('/'));
TestBlobHandler.createSystemCollection(getHttpSolrClient(solrClientUrl, randomClient.getHttpClient()));
waitForRecoveriesToFinish(".system", true);
TestBlobHandler.postAndCheck(cloudClient, baseURL.substring(0, baseURL.lastIndexOf('/')), blobName, TestDynamicLoading.generateZip(RuntimeUrp.class), 1);

View File

@ -351,7 +351,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
exampleSolrHomeDir.isDirectory());
if ("techproducts".equals(exampleName)) {
HttpSolrClient solrClient = new HttpSolrClient("http://localhost:" + bindPort + "/solr/" + exampleName);
HttpSolrClient solrClient = getHttpSolrClient("http://localhost:" + bindPort + "/solr/" + exampleName);
SolrQuery query = new SolrQuery("*:*");
QueryResponse qr = solrClient.query(query);
long numFound = qr.getResults().getNumFound();
@ -439,7 +439,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
CloudSolrClient cloudClient = null;
try {
cloudClient = new CloudSolrClient(executor.solrCloudCluster.getZkServer().getZkAddress());
cloudClient = getCloudSolrClient(executor.solrCloudCluster.getZkServer().getZkAddress());
cloudClient.connect();
cloudClient.setDefaultCollection(collectionName);

View File

@ -32,7 +32,6 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@ -191,12 +190,17 @@ public class CloudSolrClient extends SolrClient {
* "host1:2181,host2:2181,host3:2181/mysolrchroot"
* <p>
* "zoo1.example.com:2181,zoo2.example.com:2181,zoo3.example.com:2181"
*
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public CloudSolrClient(String zkHost) {
this.zkHost = zkHost;
this.clientIsInternal = true;
this.myClient = HttpClientUtil.createClient(null);
this.lbClient = new LBHttpSolrClient(myClient);
this.lbClient = new LBHttpSolrClient.Builder()
.withHttpClient(myClient)
.build();
this.lbClient.setRequestWriter(new BinaryRequestWriter());
this.lbClient.setParser(new BinaryResponseParser());
this.updatesToLeaders = true;
@ -226,14 +230,15 @@ public class CloudSolrClient extends SolrClient {
* @param httpClient
* the {@link HttpClient} instance to be used for all requests. The
* provided httpClient should use a multi-threaded connection manager.
*
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public CloudSolrClient(String zkHost, HttpClient httpClient) {
this.zkHost = zkHost;
this.clientIsInternal = httpClient == null;
this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient;
this.lbClient = new LBHttpSolrClient(myClient);
this.lbClient.setRequestWriter(new BinaryRequestWriter());
this.lbClient.setParser(new BinaryResponseParser());
this.lbClient = createLBHttpSolrClient(myClient);
this.updatesToLeaders = true;
shutdownLBHttpSolrServer = true;
lbClient.addQueryParams(STATE_VERSION);
@ -256,7 +261,9 @@ public class CloudSolrClient extends SolrClient {
* @throws IllegalArgumentException
* if the chroot value does not start with a forward slash.
* @see #CloudSolrClient(String)
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public CloudSolrClient(Collection<String> zkHosts, String chroot) {
this(zkHosts, chroot, null);
}
@ -281,47 +288,64 @@ public class CloudSolrClient extends SolrClient {
* @throws IllegalArgumentException
* if the chroot value does not start with a forward slash.
* @see #CloudSolrClient(String)
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public CloudSolrClient(Collection<String> zkHosts, String chroot, HttpClient httpClient) {
StringBuilder zkBuilder = new StringBuilder();
int lastIndexValue = zkHosts.size() - 1;
int i = 0;
for (String zkHost : zkHosts) {
zkBuilder.append(zkHost);
if (i < lastIndexValue) {
zkBuilder.append(",");
}
i++;
}
if (chroot != null) {
if (chroot.startsWith("/")) {
zkBuilder.append(chroot);
} else {
throw new IllegalArgumentException(
"The chroot must start with a forward slash.");
}
}
/* Log the constructed connection string and then initialize. */
log.info("Final constructed zkHost string: " + zkBuilder.toString());
this.zkHost = zkBuilder.toString();
this.zkHost = buildZkHostString(zkHosts, chroot);
this.clientIsInternal = httpClient == null;
this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient;
this.lbClient = new LBHttpSolrClient(myClient);
this.lbClient.setRequestWriter(new BinaryRequestWriter());
this.lbClient.setParser(new BinaryResponseParser());
this.lbClient = createLBHttpSolrClient(myClient);
this.updatesToLeaders = true;
shutdownLBHttpSolrServer = true;
}
/**
* Create a new client object that connects to Zookeeper and is always aware
* of the SolrCloud state. If there is a fully redundant Zookeeper quorum and
* SolrCloud has enough replicas for every shard in a collection, there is no
* single point of failure. Updates will be sent to shard leaders by default.
*
* @param zkHosts
* A Java Collection (List, Set, etc) of HOST:PORT strings, one for
* each host in the zookeeper ensemble. Note that with certain
* Collection types like HashSet, the order of hosts in the final
* connect string may not be in the same order you added them.
* @param chroot
* A chroot value for zookeeper, starting with a forward slash. If no
* chroot is required, use null.
* @param httpClient
* the {@link HttpClient} instance to be used for all requests. The provided httpClient should use a
* multi-threaded connection manager. If null, a default HttpClient will be used.
* @param lbSolrClient
* LBHttpSolrServer instance for requests. If null, a default HttpClient will be used.
* @param updatesToLeaders
* If true, sends updates to shard leaders.
*
* @deprecated use {@link Builder} instead. This will soon be a protected method, and will only
* be available for use in implementing subclasses.
*/
@Deprecated
public CloudSolrClient(Collection<String> zkHosts, String chroot, HttpClient httpClient, LBHttpSolrClient lbSolrClient, boolean updatesToLeaders) {
this.zkHost = buildZkHostString(zkHosts, chroot);
this.updatesToLeaders = updatesToLeaders;
this.clientIsInternal = httpClient == null;
this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient;
this.shutdownLBHttpSolrServer = lbSolrClient == null;
this.lbClient = lbSolrClient == null ? createLBHttpSolrClient(myClient) : lbSolrClient;
}
/**
* @param zkHost
* A zookeeper client endpoint.
* @param updatesToLeaders
* If true, sends updates only to shard leaders.
* @see #CloudSolrClient(String) for full description and details on zkHost
* @deprecated use {@link CloudSolrClient.Builder} instead.
*/
@Deprecated
public CloudSolrClient(String zkHost, boolean updatesToLeaders) {
this(zkHost, updatesToLeaders, null);
}
@ -335,12 +359,16 @@ public class CloudSolrClient extends SolrClient {
* the {@link HttpClient} instance to be used for all requests. The provided httpClient should use a
* multi-threaded connection manager.
* @see #CloudSolrClient(String) for full description and details on zkHost
* @deprecated use {@link CloudSolrClient.Builder} instead.
*/
@Deprecated
public CloudSolrClient(String zkHost, boolean updatesToLeaders, HttpClient httpClient) {
this.zkHost = zkHost;
this.clientIsInternal = httpClient == null;
this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient;
this.lbClient = new LBHttpSolrClient(myClient);
this.lbClient = new LBHttpSolrClient.Builder()
.withHttpClient(myClient)
.build();
this.lbClient.setRequestWriter(new BinaryRequestWriter());
this.lbClient.setParser(new BinaryResponseParser());
this.updatesToLeaders = updatesToLeaders;
@ -362,7 +390,9 @@ public class CloudSolrClient extends SolrClient {
* @param lbClient
* LBHttpSolrServer instance for requests.
* @see #CloudSolrClient(String) for full description and details on zkHost
* @deprecated use {@link CloudSolrClient.Builder} instead.
*/
@Deprecated
public CloudSolrClient(String zkHost, LBHttpSolrClient lbClient) {
this(zkHost, lbClient, true);
}
@ -375,7 +405,9 @@ public class CloudSolrClient extends SolrClient {
* @param updatesToLeaders
* If true, sends updates only to shard leaders.
* @see #CloudSolrClient(String) for full description and details on zkHost
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public CloudSolrClient(String zkHost, LBHttpSolrClient lbClient, boolean updatesToLeaders) {
this.zkHost = zkHost;
this.lbClient = lbClient;
@ -1340,4 +1372,137 @@ public class CloudSolrClient extends SolrClient {
}
return results;
}
private static LBHttpSolrClient createLBHttpSolrClient(HttpClient httpClient) {
final LBHttpSolrClient lbClient = new LBHttpSolrClient.Builder()
.withHttpClient(httpClient)
.build();
lbClient.setRequestWriter(new BinaryRequestWriter());
lbClient.setParser(new BinaryResponseParser());
return lbClient;
}
private static String buildZkHostString(Collection<String> zkHosts, String chroot) {
if (zkHosts == null || zkHosts.isEmpty()) {
throw new IllegalArgumentException("Cannot create CloudSearchClient without valid ZooKeeper host; none specified!");
}
StringBuilder zkBuilder = new StringBuilder();
int lastIndexValue = zkHosts.size() - 1;
int i = 0;
for (String zkHost : zkHosts) {
zkBuilder.append(zkHost);
if (i < lastIndexValue) {
zkBuilder.append(",");
}
i++;
}
if (chroot != null) {
if (chroot.startsWith("/")) {
zkBuilder.append(chroot);
} else {
throw new IllegalArgumentException(
"The chroot must start with a forward slash.");
}
}
/* Log the constructed connection string and then initialize. */
final String zkHostString = zkBuilder.toString();
log.info("Final constructed zkHost string: " + zkHostString);
return zkHostString;
}
/**
* Constructs {@link CloudSolrClient} instances from provided configuration.
*/
public static class Builder {
private Collection<String> zkHosts;
private HttpClient httpClient;
private String zkChroot;
private LBHttpSolrClient loadBalancedSolrClient;
private boolean shardLeadersOnly;
public Builder() {
this.zkHosts = new ArrayList();
this.shardLeadersOnly = true;
}
/**
* Provide a ZooKeeper client endpoint to be used when configuring {@link CloudSolrClient} instances.
*
* Method may be called multiple times. All provided values will be used.
*
* @param zkHost
* The client endpoint of the ZooKeeper quorum containing the cloud
* state.
*/
public Builder withZkHost(String zkHost) {
this.zkHosts.add(zkHost);
return this;
}
/**
* Provides a {@link HttpClient} for the builder to use when creating clients.
*/
public Builder withHttpClient(HttpClient httpClient) {
this.httpClient = httpClient;
return this;
}
/**
* Provide a series of ZooKeeper client endpoints for the builder to use when creating clients.
*
* Method may be called multiple times. All provided values will be used.
*
* @param zkHosts
* A Java Collection (List, Set, etc) of HOST:PORT strings, one for
* each host in the ZooKeeper ensemble. Note that with certain
* Collection types like HashSet, the order of hosts in the final
* connect string may not be in the same order you added them.
*/
public Builder withZkHost(Collection<String> zkHosts) {
this.zkHosts.addAll(zkHosts);
return this;
}
/**
* Provides a ZooKeeper chroot for the builder to use when creating clients.
*/
public Builder withZkChroot(String zkChroot) {
this.zkChroot = zkChroot;
return this;
}
/**
* Provides a {@link LBHttpSolrClient} for the builder to use when creating clients.
*/
public Builder withLBHttpSolrClient(LBHttpSolrClient loadBalancedSolrClient) {
this.loadBalancedSolrClient = loadBalancedSolrClient;
return this;
}
/**
* Tells {@link Builder} that created clients should send updats only to shard leaders.
*/
public Builder sendUpdatesOnlyToShardLeaders() {
shardLeadersOnly = true;
return this;
}
/**
* Tells {@link Builder} that created clients should send updates to all replicas for a shard.
*/
public Builder sendUpdatesToAllReplicasInShard() {
shardLeadersOnly = false;
return this;
}
/**
* Create a {@link CloudSolrClient} based on the provided configuration.
*/
public CloudSolrClient build() {
return new CloudSolrClient(zkHosts, zkChroot, httpClient, loadBalancedSolrClient, shardLeadersOnly);
}
}
}

View File

@ -16,6 +16,21 @@
*/
package org.apache.solr.client.solrj.impl;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
@ -45,21 +60,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
/**
* ConcurrentUpdateSolrClient buffers all added documents and writes
* them into open HTTP connections. This class is thread safe.
@ -96,7 +96,10 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
* The buffer size before the documents are sent to the server
* @param threadCount
* The number of background threads used to empty the queue
*
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public ConcurrentUpdateSolrClient(String solrServerUrl, int queueSize,
int threadCount) {
this(solrServerUrl, null, queueSize, threadCount);
@ -104,6 +107,10 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
internalHttpClient = true;
}
/**
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public ConcurrentUpdateSolrClient(String solrServerUrl,
HttpClient client, int queueSize, int threadCount) {
this(solrServerUrl, client, queueSize, threadCount, ExecutorUtil.newMDCAwareCachedThreadPool(
@ -113,7 +120,10 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
/**
* Uses the supplied HttpClient to send documents to the Solr server.
*
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public ConcurrentUpdateSolrClient(String solrServerUrl,
HttpClient client, int queueSize, int threadCount, ExecutorService es) {
this(solrServerUrl, client, queueSize, threadCount, es, false);
@ -121,16 +131,30 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
/**
* Uses the supplied HttpClient to send documents to the Solr server.
*
* @deprecated use {@link Builder} instead. This will soon be a
* protected method, and will only be available for use in implementing subclasses.
*/
@Deprecated
public ConcurrentUpdateSolrClient(String solrServerUrl,
HttpClient client, int queueSize, int threadCount, ExecutorService es, boolean streamDeletes) {
this.client = new HttpSolrClient(solrServerUrl, client);
this.internalHttpClient = (client == null);
this.client = new HttpSolrClient.Builder(solrServerUrl)
.withHttpClient(client)
.build();
this.client.setFollowRedirects(false);
queue = new LinkedBlockingQueue<>(queueSize);
this.threadCount = threadCount;
runners = new LinkedList<>();
scheduler = es;
this.streamDeletes = streamDeletes;
if (es != null) {
scheduler = es;
shutdownExecutor = false;
} else {
scheduler = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrjNamedThreadFactory("concurrentUpdateScheduler"));
shutdownExecutor = true;
}
}
public Set<String> getQueryParams() {
@ -274,6 +298,7 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
method = new HttpPost(client.getBaseURL() + "/update"
+ requestParams.toQueryString());
method.setEntity(template);
method.addHeader("User-Agent", HttpSolrClient.AGENT);
method.addHeader("Content-Type", contentType);
@ -530,4 +555,91 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
public void setRequestWriter(RequestWriter requestWriter) {
client.setRequestWriter(requestWriter);
}
/**
* Constructs {@link ConcurrentUpdateSolrClient} instances from provided configuration.
*/
public static class Builder {
private String baseSolrUrl;
private HttpClient httpClient;
private int queueSize;
private int threadCount;
private ExecutorService executorService;
private boolean streamDeletes;
/**
* Create a Builder object, based on the provided Solr URL.
*
* @param baseSolrUrl the base URL of the Solr server that will be targeted by any created clients.
*/
public Builder(String baseSolrUrl) {
this.baseSolrUrl = baseSolrUrl;
}
/**
* Provides a {@link HttpClient} for the builder to use when creating clients.
*/
public Builder withHttpClient(HttpClient httpClient) {
this.httpClient = httpClient;
return this;
}
/**
* The number of documents to batch together before sending to Solr.
*/
public Builder withQueueSize(int queueSize) {
if (queueSize <= 0) {
throw new IllegalArgumentException("queueSize must be a positive integer.");
}
this.queueSize = queueSize;
return this;
}
/**
* The number of threads used to empty {@link ConcurrentUpdateSolrClient}s queue.
*/
public Builder withThreadCount(int threadCount) {
if (threadCount <= 0) {
throw new IllegalArgumentException("threadCount must be a positive integer.");
}
this.threadCount = threadCount;
return this;
}
/**
* Provides the {@link ExecutorService} for clients to use when servicing requests.
*/
public Builder withExecutorService(ExecutorService executorService) {
this.executorService = executorService;
return this;
}
/**
* Configures created clients to always stream delete requests.
*/
public Builder alwaysStreamDeletes() {
this.streamDeletes = true;
return this;
}
/**
* Configures created clients to not stream delete requests.
*/
public Builder neverStreamDeletes() {
this.streamDeletes = false;
return this;
}
/**
* Create a {@link ConcurrentUpdateSolrClient} based on the provided configuration options.
*/
public ConcurrentUpdateSolrClient build() {
if (baseSolrUrl == null) {
throw new IllegalArgumentException("Cannot create HttpSolrClient without a valid baseSolrUrl!");
}
return new ConcurrentUpdateSolrClient(baseSolrUrl, httpClient, queueSize, threadCount, executorService, streamDeletes);
}
}
}

View File

@ -16,6 +16,23 @@
*/
package org.apache.solr.client.solrj.impl;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.invoke.MethodHandles;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import org.apache.commons.io.IOUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
@ -61,24 +78,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.invoke.MethodHandles;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
/**
* A SolrClient implementation that talks directly to a Solr server via HTTP
*
@ -157,16 +156,35 @@ public class HttpSolrClient extends SolrClient {
* The URL of the Solr server. For example, "
* <code>http://localhost:8983/solr/</code>" if you are using the
* standard distribution Solr webapp on your local machine.
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public HttpSolrClient(String baseURL) {
this(baseURL, null, new BinaryResponseParser());
}
/**
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public HttpSolrClient(String baseURL, HttpClient client) {
this(baseURL, client, new BinaryResponseParser());
}
/**
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public HttpSolrClient(String baseURL, HttpClient client, ResponseParser parser) {
this(baseURL, client, parser, false);
}
/**
* @deprecated use {@link Builder} instead. This will soon be a 'protected'
* method, and will only be available for use in implementing subclasses.
*/
@Deprecated
public HttpSolrClient(String baseURL, HttpClient client, ResponseParser parser, boolean allowCompression) {
this.baseUrl = baseURL;
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
@ -468,7 +486,7 @@ public class HttpSolrClient extends SolrClient {
protected NamedList<Object> executeMethod(HttpRequestBase method, final ResponseParser processor) throws SolrServerException {
method.addHeader("User-Agent", AGENT);
HttpEntity entity = null;
InputStream respBody = null;
boolean shouldClose = true;
@ -752,4 +770,60 @@ public class HttpSolrClient extends SolrClient {
super(code, "Error from server at " + remoteHost + ": " + msg, th);
}
}
/**
* Constructs {@link HttpSolrClient} instances from provided configuration.
*/
public static class Builder {
private String baseSolrUrl;
private HttpClient httpClient;
private ResponseParser responseParser;
private boolean compression;
/**
* Create a Builder object, based on the provided Solr URL.
*
* By default, compression is not enabled in created HttpSolrClient objects.
*
* @param baseSolrUrl the base URL of the Solr server that will be targeted by any created clients.
*/
public Builder(String baseSolrUrl) {
this.baseSolrUrl = baseSolrUrl;
this.responseParser = new BinaryResponseParser();
}
/**
* Provides a {@link HttpClient} for the builder to use when creating clients.
*/
public Builder withHttpClient(HttpClient httpClient) {
this.httpClient = httpClient;
return this;
}
/**
* Provides a {@link ResponseParser} for created clients to use when handling requests.
*/
public Builder withResponseParser(ResponseParser responseParser) {
this.responseParser = responseParser;
return this;
}
/**
* Chooses whether created {@link HttpSolrClient}s use compression by default.
*/
public Builder allowCompression(boolean compression) {
this.compression = compression;
return this;
}
/**
* Create a {@link HttpSolrClient} based on provided configuration.
*/
public HttpSolrClient build() {
if (baseSolrUrl == null) {
throw new IllegalArgumentException("Cannot create HttpSolrClient without a valid baseSolrUrl!");
}
return new HttpSolrClient(baseSolrUrl, httpClient, responseParser, compression);
}
}
}

View File

@ -16,19 +16,6 @@
*/
package org.apache.solr.client.solrj.impl;
import org.apache.http.client.HttpClient;
import org.apache.solr.client.solrj.*;
import org.apache.solr.client.solrj.request.IsUpdateRequest;
import org.apache.solr.client.solrj.request.RequestWriter;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SolrjNamedThreadFactory;
import org.apache.solr.common.SolrException;
import org.slf4j.MDC;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.ConnectException;
@ -36,9 +23,36 @@ import java.net.MalformedURLException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.concurrent.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.*;
import org.apache.http.client.HttpClient;
import org.apache.solr.client.solrj.ResponseParser;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.IsUpdateRequest;
import org.apache.solr.client.solrj.request.RequestWriter;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SolrjNamedThreadFactory;
import org.slf4j.MDC;
/**
* LBHttpSolrClient or "LoadBalanced HttpSolrClient" is a load balancing wrapper around
@ -206,19 +220,31 @@ public class LBHttpSolrClient extends SolrClient {
}
}
/**
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public LBHttpSolrClient(String... solrServerUrls) throws MalformedURLException {
this(null, solrServerUrls);
}
/** The provided httpClient should use a multi-threaded connection manager */
/**
* The provided httpClient should use a multi-threaded connection manager
* @deprecated use {@link Builder} instead.
*/
@Deprecated
public LBHttpSolrClient(HttpClient httpClient, String... solrServerUrl) {
this(httpClient, new BinaryResponseParser(), solrServerUrl);
}
/** The provided httpClient should use a multi-threaded connection manager */
/**
* The provided httpClient should use a multi-threaded connection manager
* @deprecated use {@link Builder} instead. This will soon be a protected
* method and will only be available for use in implementing subclasses.
*/
@Deprecated
public LBHttpSolrClient(HttpClient httpClient, ResponseParser parser, String... solrServerUrl) {
clientIsInternal = (httpClient == null);
this.parser = parser;
if (httpClient == null) {
ModifiableSolrParams params = new ModifiableSolrParams();
if (solrServerUrl.length > 1) {
@ -231,6 +257,9 @@ public class LBHttpSolrClient extends SolrClient {
} else {
this.httpClient = httpClient;
}
this.parser = parser;
for (String s : solrServerUrl) {
ServerWrapper wrapper = new ServerWrapper(makeSolrClient(s));
aliveServers.put(wrapper.getKey(), wrapper);
@ -260,7 +289,10 @@ public class LBHttpSolrClient extends SolrClient {
}
protected HttpSolrClient makeSolrClient(String server) {
HttpSolrClient client = new HttpSolrClient(server, httpClient, parser);
HttpSolrClient client = new HttpSolrClient.Builder(server)
.withHttpClient(httpClient)
.withResponseParser(parser)
.build();
if (requestWriter != null) {
client.setRequestWriter(requestWriter);
}
@ -717,4 +749,64 @@ public class LBHttpSolrClient extends SolrClient {
private static final int CHECK_INTERVAL = 60 * 1000; //1 minute between checks
private static final int NONSTANDARD_PING_LIMIT = 5; // number of times we'll ping dead servers not in the server list
/**
* Constructs {@link LBHttpSolrClient} instances from provided configuration.
*/
public static class Builder {
private final List<String> baseSolrUrls;
private HttpClient httpClient;
private ResponseParser responseParser;
public Builder() {
this.baseSolrUrls = new ArrayList<String>();
this.responseParser = new BinaryResponseParser();
}
/**
* Provide a Solr endpoint to be used when configuring {@link LBHttpSolrClient} instances.
*
* Method may be called multiple times. All provided values will be used.
*/
public Builder withBaseSolrUrl(String baseSolrUrl) {
this.baseSolrUrls.add(baseSolrUrl);
return this;
}
/**
* Provide Solr endpoints to be used when configuring {@link LBHttpSolrClient} instances.
*
* Method may be called multiple times. All provided values will be used.
*/
public Builder withBaseSolrUrls(String... solrUrls) {
for (String baseSolrUrl : solrUrls) {
this.baseSolrUrls.add(baseSolrUrl);
}
return this;
}
/**
* Provides a {@link HttpClient} for the builder to use when creating clients.
*/
public Builder withHttpClient(HttpClient httpClient) {
this.httpClient = httpClient;
return this;
}
/**
* Provides a {@link ResponseParser} for created clients to use when handling requests.
*/
public Builder withResponseParser(ResponseParser responseParser) {
this.responseParser = responseParser;
return this;
}
/**
* Create a {@link HttpSolrClient} based on provided configuration.
*/
public LBHttpSolrClient build() {
final String[] baseUrlArray = new String[baseSolrUrls.size()];
return new LBHttpSolrClient(httpClient, responseParser, baseSolrUrls.toArray(baseUrlArray));
}
}
}

View File

@ -21,7 +21,7 @@ import java.io.Serializable;
import java.lang.invoke.MethodHandles;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
@ -44,7 +44,9 @@ public class SolrClientCache implements Serializable {
if (solrClients.containsKey(zkHost)) {
client = (CloudSolrClient) solrClients.get(zkHost);
} else {
client = new CloudSolrClient(zkHost);
client = new CloudSolrClient.Builder()
.withZkHost(zkHost)
.build();
client.connect();
solrClients.put(zkHost, client);
}
@ -57,7 +59,8 @@ public class SolrClientCache implements Serializable {
if (solrClients.containsKey(host)) {
client = (HttpSolrClient) solrClients.get(host);
} else {
client = new HttpSolrClient(host);
client = new HttpSolrClient.Builder(host)
.build();
solrClients.put(host, client);
}
return client;

View File

@ -29,7 +29,7 @@ import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.util.SimpleOrderedMap;
@ -119,7 +119,7 @@ class DatabaseMetaDataImpl implements DatabaseMetaData {
for (String node : liveNodes) {
try {
String nodeURL = cloudSolrClient.getZkStateReader().getBaseUrlForNodeName(node);
solrClient = new HttpSolrClient(nodeURL);
solrClient = new Builder(nodeURL).build();
QueryResponse rsp = solrClient.query(sysQuery);
return String.valueOf(((SimpleOrderedMap) rsp.getResponse().get("lucene")).get("solr-spec-version"));

View File

@ -34,6 +34,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.ComparatorOrder;
@ -236,7 +237,9 @@ public class CloudSolrStream extends TupleStream implements Expressible {
if(this.cache != null) {
this.cloudSolrClient = this.cache.getCloudSolrClient(zkHost);
} else {
this.cloudSolrClient = new CloudSolrClient(zkHost);
this.cloudSolrClient = new Builder()
.withZkHost(zkHost)
.build();
this.cloudSolrClient.connect();
}
constructStreams();
@ -476,4 +479,4 @@ public class CloudSolrStream extends TupleStream implements Expressible {
}
}
}
}
}

View File

@ -19,7 +19,6 @@ package org.apache.solr.client.solrj.io.stream;
import java.io.IOException;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -27,6 +26,7 @@ import java.util.Collections;
import java.util.Map.Entry;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.ComparatorOrder;
@ -281,7 +281,9 @@ public class FacetStream extends TupleStream implements Expressible {
if(cache != null) {
cloudSolrClient = cache.getCloudSolrClient(zkHost);
} else {
cloudSolrClient = new CloudSolrClient(zkHost);
cloudSolrClient = new Builder()
.withZkHost(zkHost)
.build();
}
FieldComparator[] adjustedSorts = adjustSorts(buckets, bucketSorts);
@ -479,4 +481,4 @@ public class FacetStream extends TupleStream implements Expressible {
return bucketSorts[0];
}
}
}
}

View File

@ -86,7 +86,7 @@ public class SolrStream extends TupleStream {
if(cache == null) {
client = new HttpSolrClient(baseUrl);
client = new HttpSolrClient.Builder(baseUrl).build();
} else {
client = cache.getHttpSolrClient(baseUrl);
}
@ -230,4 +230,4 @@ public class SolrStream extends TupleStream {
return fields;
}
}
}

View File

@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Map.Entry;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@ -162,7 +163,9 @@ public class StatsStream extends TupleStream implements Expressible {
if(cache != null) {
cloudSolrClient = cache.getCloudSolrClient(zkHost);
} else {
cloudSolrClient = new CloudSolrClient(zkHost);
cloudSolrClient = new Builder()
.withZkHost(zkHost)
.build();
}
ModifiableSolrParams params = getParams(this.props);
@ -290,4 +293,4 @@ public class StatsStream extends TupleStream implements Expressible {
map.put(stat+"("+field+")", val);
}
}
}
}

View File

@ -33,7 +33,7 @@ import java.util.TreeSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.ComparatorOrder;
@ -218,7 +218,9 @@ public class TopicStream extends CloudSolrStream implements Expressible {
if(cache != null) {
cloudSolrClient = cache.getCloudSolrClient(zkHost);
} else {
cloudSolrClient = new CloudSolrClient(zkHost);
cloudSolrClient = new Builder()
.withZkHost(zkHost)
.build();
this.cloudSolrClient.connect();
}
@ -474,4 +476,4 @@ public class TopicStream extends CloudSolrStream implements Expressible {
throw new IOException(e);
}
}
}
}

View File

@ -26,6 +26,7 @@ import java.util.Map;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient.Builder;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
import org.apache.solr.client.solrj.io.comp.StreamComparator;
@ -219,7 +220,9 @@ public class UpdateStream extends TupleStream implements Expressible {
if(this.cache != null) {
this.cloudSolrClient = this.cache.getCloudSolrClient(zkHost);
} else {
this.cloudSolrClient = new CloudSolrClient(zkHost);
this.cloudSolrClient = new Builder()
.withZkHost(zkHost)
.build();
this.cloudSolrClient.connect();
}
}

View File

@ -40,7 +40,7 @@ public class SolrExampleBinaryTest extends SolrExampleTests {
try {
// setup the server...
String url = jetty.getBaseUrl().toString() + "/collection1";
HttpSolrClient client = new HttpSolrClient( url );
HttpSolrClient client = getHttpSolrClient(url);
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
client.setDefaultMaxConnectionsPerHost(100);
client.setMaxTotalConnections(100);

View File

@ -220,7 +220,7 @@ abstract public class SolrExampleTests extends SolrExampleTestsBase
if (jetty != null) {
// check system wide system handler + "/admin/info/system"
String url = jetty.getBaseUrl().toString();
try (HttpSolrClient adminClient = new HttpSolrClient(url)) {
try (HttpSolrClient adminClient = getHttpSolrClient(url)) {
SolrQuery q = new SolrQuery();
q.set("qt", "/admin/info/system");
QueryResponse rsp = adminClient.query(q);

View File

@ -37,7 +37,7 @@ public class SolrExampleXMLTest extends SolrExampleTests {
public SolrClient createNewSolrClient() {
try {
String url = jetty.getBaseUrl().toString() + "/collection1";
HttpSolrClient client = new HttpSolrClient(url);
HttpSolrClient client = getHttpSolrClient(url);
client.setUseMultiPartPost(random().nextBoolean());
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
client.setDefaultMaxConnectionsPerHost(100);

View File

@ -16,6 +16,8 @@
*/
package org.apache.solr.client.solrj;
import static org.apache.solr.SolrTestCaseJ4.getHttpSolrClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
@ -39,7 +41,7 @@ public class SolrExceptionTest extends LuceneTestCase {
// set a 1ms timeout to let the connection fail faster.
httpClient = HttpClientUtil.createClient(null);
HttpClientUtil.setConnectionTimeout(httpClient, 1);
SolrClient client = new HttpSolrClient("http://[ff01::114]:11235/solr/", httpClient);
SolrClient client = getHttpSolrClient("http://[ff01::114]:11235/solr/", httpClient);
SolrQuery query = new SolrQuery("test123");
client.query(query);
httpClient.close();

View File

@ -131,7 +131,7 @@ public class SolrSchemalessExampleTest extends SolrExampleTestsBase {
try {
// setup the server...
String url = jetty.getBaseUrl().toString() + "/collection1";
HttpSolrClient client = new HttpSolrClient(url);
HttpSolrClient client = getHttpSolrClient(url);
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
client.setDefaultMaxConnectionsPerHost(100);
client.setMaxTotalConnections(100);

Some files were not shown because too many files have changed in this diff Show More