use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.
the class TestImpersonationWithHadoopAuth method testForwarding.
@Test
@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/HADOOP-9893")
public void testForwarding() throws Exception {
String collectionName = "forwardingCollection";
// create collection
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, "conf1", 1, 1);
try (SolrClient solrClient = newSolrClient()) {
create.process(solrClient);
}
// try a command to each node, one of them must be forwarded
for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
HttpSolrClient client = new HttpSolrClient.Builder(jetty.getBaseUrl().toString() + "/" + collectionName).build();
try {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "*:*");
params.set(USER_PARAM, "user");
client.query(params);
} finally {
client.close();
}
}
}
use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.
the class StatsStream method open.
public void open() throws IOException {
ModifiableSolrParams paramsLoc = new ModifiableSolrParams(this.params);
addStats(paramsLoc, metrics);
paramsLoc.set("stats", "true");
paramsLoc.set("rows", "0");
Map<String, List<String>> shardsMap = (Map<String, List<String>>) streamContext.get("shards");
if (shardsMap == null) {
QueryRequest request = new QueryRequest(paramsLoc);
CloudSolrClient cloudSolrClient = cache.getCloudSolrClient(zkHost);
try {
NamedList response = cloudSolrClient.request(request, collection);
this.tuple = getTuple(response);
} catch (Exception e) {
throw new IOException(e);
}
} else {
List<String> shards = shardsMap.get(collection);
HttpSolrClient client = cache.getHttpSolrClient(shards.get(0));
if (shards.size() > 1) {
String shardsParam = getShardString(shards);
paramsLoc.add("shards", shardsParam);
paramsLoc.add("distrib", "true");
}
QueryRequest request = new QueryRequest(paramsLoc);
try {
NamedList response = client.request(request);
this.tuple = getTuple(response);
} catch (Exception e) {
throw new IOException(e);
}
}
}
use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method createNewSolrClient.
@Override
protected SolrClient createNewSolrClient(int port) {
try {
// setup the server...
String baseUrl = buildUrl(port);
String url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + DEFAULT_COLLECTION;
HttpSolrClient client = getHttpSolrClient(url);
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
client.setSoTimeout(60000);
return client;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method createNewSolrClient.
protected SolrClient createNewSolrClient(String collection, String baseUrl) {
try {
// setup the server...
HttpSolrClient client = getHttpSolrClient(baseUrl + "/" + collection);
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
return client;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method updateMappingsFromZk.
protected void updateMappingsFromZk(List<JettySolrRunner> jettys, List<SolrClient> clients, boolean allowOverSharding) throws Exception {
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
zkStateReader.forceUpdateCollection(DEFAULT_COLLECTION);
cloudJettys.clear();
shardToJetty.clear();
ClusterState clusterState = zkStateReader.getClusterState();
DocCollection coll = clusterState.getCollection(DEFAULT_COLLECTION);
List<CloudSolrServerClient> theClients = new ArrayList<>();
for (SolrClient client : clients) {
// find info for this client in zk
nextClient: // we find out state by simply matching ports...
for (Slice slice : coll.getSlices()) {
for (Replica replica : slice.getReplicas()) {
int port = new URI(((HttpSolrClient) client).getBaseURL()).getPort();
if (replica.getStr(ZkStateReader.BASE_URL_PROP).contains(":" + port)) {
CloudSolrServerClient csc = new CloudSolrServerClient();
csc.solrClient = client;
csc.port = port;
csc.shardName = replica.getStr(ZkStateReader.NODE_NAME_PROP);
csc.info = replica;
theClients.add(csc);
break nextClient;
}
}
}
}
for (JettySolrRunner jetty : jettys) {
int port = jetty.getLocalPort();
if (port == -1) {
throw new RuntimeException("Cannot find the port for jetty");
}
nextJetty: for (Slice slice : coll.getSlices()) {
Set<Entry<String, Replica>> entries = slice.getReplicasMap().entrySet();
for (Entry<String, Replica> entry : entries) {
Replica replica = entry.getValue();
if (replica.getStr(ZkStateReader.BASE_URL_PROP).contains(":" + port)) {
List<CloudJettyRunner> list = shardToJetty.get(slice.getName());
if (list == null) {
list = new ArrayList<>();
shardToJetty.put(slice.getName(), list);
}
boolean isLeader = slice.getLeader() == replica;
CloudJettyRunner cjr = new CloudJettyRunner();
cjr.jetty = jetty;
cjr.info = replica;
cjr.nodeName = replica.getStr(ZkStateReader.NODE_NAME_PROP);
cjr.coreNodeName = entry.getKey();
cjr.url = replica.getStr(ZkStateReader.BASE_URL_PROP) + "/" + replica.getStr(ZkStateReader.CORE_NAME_PROP);
cjr.client = findClientByPort(port, theClients);
list.add(cjr);
if (isLeader) {
shardToLeaderJetty.put(slice.getName(), cjr);
}
cloudJettys.add(cjr);
break nextJetty;
}
}
}
}
// running jetty though
for (Slice slice : coll.getSlices()) {
// check that things look right
List<CloudJettyRunner> jetties = shardToJetty.get(slice.getName());
if (!allowOverSharding) {
assertNotNull("Test setup problem: We found no jetties for shard: " + slice.getName() + " just:" + shardToJetty.keySet(), jetties);
assertEquals("slice:" + slice.getName(), slice.getReplicas().size(), jetties.size());
}
}
}
Aggregations