Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.commons.io.file.PathUtils;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.response.CoreAdminResponse;
import org.apache.solr.embedded.JettyConfig;
Expand Down Expand Up @@ -78,7 +79,8 @@ public void bootstrapJettyServer() throws Exception {

solrRunner = new JettySolrRunner(tmpSolrHome.toString(), buildJettyConfig());
solrRunner.start(false);
try (SolrClient client = solrRunner.newClient()) {
try (SolrClient client =
new HttpJettySolrClient.Builder(solrRunner.getBaseUrl().toString()).build()) {
for (int i = 0; i < NUM_CORES; i++) {
createCore(client, "core-prefix-" + i);
}
Expand Down
3 changes: 2 additions & 1 deletion solr/core/src/test/org/apache/solr/TestCpuTimeSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.request.UpdateRequest;
Expand Down Expand Up @@ -100,7 +101,7 @@ public void testWithoutDistrib() throws SolrServerException, IOException {
coll.getSlices().stream()
.flatMap(s -> s.getReplicas().stream())
.toArray(Replica[]::new));
try (SolrClient client = getHttpSolrClient(randomReplica.getCoreUrl())) {
try (SolrClient client = new HttpJettySolrClient.Builder(randomReplica.getCoreUrl()).build()) {
response = client.query(query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.cloud.MiniSolrCloudCluster;
Expand Down Expand Up @@ -376,7 +377,9 @@ protected void testExample(String exampleName) throws Exception {

if ("techproducts".equals(exampleName)) {
try (SolrClient solrClient =
getHttpSolrClient("http://localhost:" + bindPort + "/solr", exampleName)) {
new HttpJettySolrClient.Builder("http://localhost:" + bindPort + "/solr")
.withDefaultCollection(exampleName)
.build()) {
SolrQuery query = new SolrQuery("*:*");
QueryResponse qr = solrClient.query(query);
long numFound = qr.getResults().getNumFound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.ClusterStateProvider;
import org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.request.UpdateRequest;
Expand Down Expand Up @@ -959,11 +960,15 @@ private void searchSeveralWays(
// HttpSolrClient
JettySolrRunner jetty = cluster.getRandomJetty(random());
if (random().nextBoolean()) {
try (SolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString(), collectionList)) {
try (SolrClient client =
new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString())
.withDefaultCollection(collectionList)
.build()) {
responseConsumer.accept(client.query(null, solrQuery));
}
} else {
try (SolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) {
try (SolrClient client =
new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build()) {
responseConsumer.accept(client.query(collectionList, solrQuery));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.SolrQuery;
Expand Down Expand Up @@ -221,7 +222,10 @@ private void addAndQueryDocs(final String baseUrl, int docs) throws Exception {

SolrQuery query = new SolrQuery("*:*");

try (SolrClient client = getHttpSolrClient(baseUrl, "onenodecollection")) {
try (SolrClient client =
new HttpJettySolrClient.Builder(baseUrl)
.withDefaultCollection("onenodecollection")
.build()) {
// add a doc
client.add(sdoc("id", docs));
client.commit();
Expand Down Expand Up @@ -442,7 +446,9 @@ private void bringDownShardIndexSomeDocsAndRecover() throws Exception {

// try a backup command
try (final SolrClient client =
getHttpSolrClient((String) shardToJetty.get(SHARD2).get(0).info.get("base_url"))) {
new HttpJettySolrClient.Builder(
(String) shardToJetty.get(SHARD2).get(0).info.get("base_url"))
.build()) {
final String backupName = "the_backup";
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command", "backup");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Create;
Expand Down Expand Up @@ -913,7 +914,10 @@ private long checkSlicesSameCounts(DocCollection dColl) throws SolrServerExcepti
for (Slice slice : dColl.getActiveSlices()) {
long sliceDocCount = -1;
for (Replica rep : slice.getReplicas()) {
try (SolrClient one = getHttpSolrClient(rep)) {
try (SolrClient one =
new HttpJettySolrClient.Builder(rep.getBaseUrl())
.withDefaultCollection(rep.getCoreName())
.build()) {
SolrQuery query = new SolrQuery("*:*");
query.setDistrib(false);
QueryResponse resp = one.query(query);
Expand Down Expand Up @@ -1503,7 +1507,7 @@ private void createSolrCore(
final String shardId) {
Callable<Object> call =
() -> {
try (SolrClient client = getHttpSolrClient(baseUrl)) {
try (SolrClient client = new HttpJettySolrClient.Builder(baseUrl).build()) {
// client.setConnectionTimeout(15000);
Create createCmd = new Create();
createCmd.setCoreName(collection + num);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.TimeUnit;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
Expand Down Expand Up @@ -81,7 +82,9 @@ public static void setupCluster() throws Exception {
clusterBuilder.configure();

// pick an arbitrary node to use for our requests
client = cluster.getRandomJetty(random()).newClient();
client =
new HttpJettySolrClient.Builder(cluster.getRandomJetty(random()).getBaseUrl().toString())
.build();

CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 1)
.processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CollectionPropertiesApi;
import org.apache.solr.client.solrj.request.CollectionsApi;
Expand Down Expand Up @@ -300,7 +301,8 @@ public void testCloudInfoInCoreStatus() throws IOException, SolrServerException
String corename = response._getStr(asList("success", nodeName, "core"), null);

try (SolrClient coreClient =
getHttpSolrClient(cluster.getZkStateReader().getBaseUrlForNodeName(nodeName))) {
new HttpJettySolrClient.Builder(cluster.getZkStateReader().getBaseUrlForNodeName(nodeName))
.build()) {
CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreClient);
assertEquals(
collectionName, status._get(asList("status", corename, "cloud", "collection"), null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.common.util.IOUtils;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void testConcurrentCreateRoutedAliasMinimal() {
for (; num < threads.length + numStart; num++) {
final String aliasName = "testAlias" + num;
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build();

int i = num - numStart;
threads[i] =
Expand All @@ -120,7 +121,7 @@ public void testConcurrentCreateRoutedAliasComplex() {
for (; num < threads.length + numStart; num++) {
final String aliasName = "testAliasCplx" + num;
final String baseUrl = solrCluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
final SolrClient solrClient = new HttpJettySolrClient.Builder(baseUrl).build();

int i = num - numStart;
threads[i] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.file.Files;
import java.util.concurrent.TimeUnit;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.common.cloud.DocCollection;
Expand Down Expand Up @@ -108,7 +109,8 @@ public void deleteInactiveReplicaTest() throws Exception {
&& !FileUtils.fileExists(replicaCd.getDataDir()));

// Check that we can't create a core with no coreNodeName
try (SolrClient queryClient = getHttpSolrClient(jetty.getBaseUrl().toString())) {
try (SolrClient queryClient =
new HttpJettySolrClient.Builder(jetty.getBaseUrl().toString()).build()) {
Exception e =
expectThrows(
Exception.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
Expand Down Expand Up @@ -288,7 +289,10 @@ private Map<String, ReplicaData> getTestDataForAllReplicas()
for (Replica replica : collectionState.getReplicas()) {

String coreName = replica.getCoreName();
try (SolrClient client = getHttpSolrClient(replica)) {
try (SolrClient client =
new HttpJettySolrClient.Builder(replica.getBaseUrl())
.withDefaultCollection(replica.getCoreName())
.build()) {

ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command", "indexversion");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
Expand Down Expand Up @@ -107,7 +108,10 @@ public void testReplicaVersionHandling() throws Exception {
maxOnReplica);

// send the same doc but with a lower version than the max in the index
try (SolrClient client = getHttpSolrClient(replica)) {
try (SolrClient client =
new HttpJettySolrClient.Builder(replica.getBaseUrl())
.withDefaultCollection(replica.getCoreName())
.build()) {
String docId = String.valueOf(1);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", docId);
Expand Down Expand Up @@ -298,7 +302,10 @@ protected long getVersionFromIndex(Replica replica, String docId)
query.addSort(new SolrQuery.SortClause("_version_", SolrQuery.ORDER.desc));
query.setParam("distrib", false);

try (SolrClient client = getHttpSolrClient(replica)) {
try (SolrClient client =
new HttpJettySolrClient.Builder(replica.getBaseUrl())
.withDefaultCollection(replica.getCoreName())
.build()) {
QueryResponse qr = client.query(query);
SolrDocumentList hits = qr.getResults();
if (hits.isEmpty()) fail("No results returned from query: " + query);
Expand All @@ -320,9 +327,16 @@ protected void assertDocsExistInAllReplicas(
int lastDocId,
Set<Integer> deletedDocs)
throws Exception {
SolrClient leaderSolr = getHttpSolrClient(leader);
SolrClient leaderSolr =
new HttpJettySolrClient.Builder(leader.getBaseUrl())
.withDefaultCollection(leader.getCoreName())
.build();
List<SolrClient> replicas = new ArrayList<SolrClient>(notLeaders.size());
for (Replica r : notLeaders) replicas.add(getHttpSolrClient(r));
for (Replica r : notLeaders)
replicas.add(
new HttpJettySolrClient.Builder(r.getBaseUrl())
.withDefaultCollection(r.getCoreName())
.build());

try {
for (int d = firstDocId; d <= lastDocId; d++) {
Expand Down Expand Up @@ -376,7 +390,7 @@ protected Long assertDocExists(SolrClient solr, String docId, Long expVers) thro
protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception {
String coreName = replica.getCoreName();
boolean reloadedOk = false;
try (SolrClient client = getHttpSolrClient(replica.getBaseUrl())) {
try (SolrClient client = new HttpJettySolrClient.Builder(replica.getBaseUrl()).build()) {
CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client);
long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.jetty.ConcurrentUpdateJettySolrClient;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.request.UpdateRequest;
Expand Down Expand Up @@ -170,8 +171,16 @@ public void testDeleteByIdImplicitRouter() throws Exception {
(n, c1) -> SolrCloudTestCase.replicasForCollectionAreFullyActive(n, c1, 2, 2));

final DocCollection docCol = cloudClient.getClusterState().getCollection(testCollectionName);
try (SolrClient shard1 = getHttpSolrClient(docCol.getSlice("shard1").getLeader());
SolrClient shard2 = getHttpSolrClient(docCol.getSlice("shard2").getLeader())) {
Replica shard1Leader = docCol.getSlice("shard1").getLeader();
Replica shard2Leader = docCol.getSlice("shard2").getLeader();
try (SolrClient shard1 =
new HttpJettySolrClient.Builder(shard1Leader.getBaseUrl())
.withDefaultCollection(shard1Leader.getCoreName())
.build();
SolrClient shard2 =
new HttpJettySolrClient.Builder(shard2Leader.getBaseUrl())
.withDefaultCollection(shard2Leader.getCoreName())
.build()) {

// Add three documents to shard1
shard1.add(sdoc("id", "1", "title", "s1 one"));
Expand Down Expand Up @@ -325,8 +334,16 @@ public void testDeleteByIdCompositeRouterWithRouterField() throws Exception {
(n, c1) -> SolrCloudTestCase.replicasForCollectionAreFullyActive(n, c1, 2, 2));

final DocCollection docCol = cloudClient.getClusterState().getCollection(testCollectionName);
try (SolrClient shard1 = getHttpSolrClient(docCol.getSlice("shard1").getLeader());
SolrClient shard2 = getHttpSolrClient(docCol.getSlice("shard2").getLeader())) {
Replica shard1Leader = docCol.getSlice("shard1").getLeader();
Replica shard2Leader = docCol.getSlice("shard2").getLeader();
try (SolrClient shard1 =
new HttpJettySolrClient.Builder(shard1Leader.getBaseUrl())
.withDefaultCollection(shard1Leader.getCoreName())
.build();
SolrClient shard2 =
new HttpJettySolrClient.Builder(shard2Leader.getBaseUrl())
.withDefaultCollection(shard2Leader.getCoreName())
.build()) {

// Add six documents w/diff routes (all sent to shard1 leader's core)
shard1.add(sdoc("id", "1", "routefield_s", "europe"));
Expand Down Expand Up @@ -488,7 +505,10 @@ public void testThatCantForwardToLeaderFails() throws Exception {
}

// create client to send our updates to...
try (SolrClient indexClient = getHttpSolrClient(indexingBaseUrl, collectionName)) {
try (SolrClient indexClient =
new HttpJettySolrClient.Builder(indexingBaseUrl)
.withDefaultCollection(collectionName)
.build()) {

// Sanity check: we should be able to send a bunch of updates that work right now...
for (int i = 0; i < 100; i++) {
Expand Down Expand Up @@ -862,11 +882,17 @@ private void checkShardConsistency(String collectionName, final SolrParams param
final Slice slice = entry.getValue();
log.info("Checking: {} -> {}", shardName, slice);
final Replica leader = entry.getValue().getLeader();
try (SolrClient leaderClient = getHttpSolrClient(leader)) {
try (SolrClient leaderClient =
new HttpJettySolrClient.Builder(leader.getBaseUrl())
.withDefaultCollection(leader.getCoreName())
.build()) {
final SolrDocumentList leaderResults = leaderClient.query(perReplicaParams).getResults();
log.debug("Shard {}: Leader results: {}", shardName, leaderResults);
for (Replica replica : slice) {
try (SolrClient replicaClient = getHttpSolrClient(replica)) {
try (SolrClient replicaClient =
new HttpJettySolrClient.Builder(replica.getBaseUrl())
.withDefaultCollection(replica.getCoreName())
.build()) {
final SolrDocumentList replicaResults =
replicaClient.query(perReplicaParams).getResults();
if (log.isDebugEnabled()) {
Expand Down
Loading