Search in sources :

Example 76 with HttpSolrClient

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();
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 77 with HttpSolrClient

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);
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IOException(java.io.IOException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 78 with HttpSolrClient

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);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 79 with HttpSolrClient

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);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 80 with HttpSolrClient

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());
        }
    }
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica) URI(java.net.URI) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) Entry(java.util.Map.Entry) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) Slice(org.apache.solr.common.cloud.Slice) SolrDocumentList(org.apache.solr.common.SolrDocumentList) List(java.util.List) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) DocCollection(org.apache.solr.common.cloud.DocCollection)

Aggregations

HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)187 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)48 SolrClient (org.apache.solr.client.solrj.SolrClient)46 Test (org.junit.Test)46 SolrQuery (org.apache.solr.client.solrj.SolrQuery)38 ArrayList (java.util.ArrayList)35 Replica (org.apache.solr.common.cloud.Replica)34 SolrInputDocument (org.apache.solr.common.SolrInputDocument)31 IOException (java.io.IOException)26 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)25 Slice (org.apache.solr.common.cloud.Slice)25 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)24 SolrException (org.apache.solr.common.SolrException)23 SolrServerException (org.apache.solr.client.solrj.SolrServerException)21 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)20 NamedList (org.apache.solr.common.util.NamedList)19 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)18 DocCollection (org.apache.solr.common.cloud.DocCollection)18 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)15 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)15