Search in sources :

Example 6 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class TestJavabinTupleStreamParser method convert2OrderedMap.

public SimpleOrderedMap convert2OrderedMap(Map m) {
    SimpleOrderedMap result = new SimpleOrderedMap<>();
    m.forEach((k, v) -> {
        if (v instanceof List)
            v = ((List) v).iterator();
        if (v instanceof Map)
            v = convert2OrderedMap((Map) v);
        result.add((String) k, v);
    });
    return result;
}
Also used : SmileWriterTest.constructSolrDocList(org.apache.solr.response.SmileWriterTest.constructSolrDocList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ArrayList(java.util.ArrayList) List(java.util.List) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map)

Example 7 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class TestSolrQueryResponse method testResponseHeader.

@Test
public void testResponseHeader() throws Exception {
    final SolrQueryResponse response = new SolrQueryResponse();
    assertEquals("responseHeader initially present", null, response.getResponseHeader());
    final NamedList<Object> newValue = new SimpleOrderedMap<>();
    newValue.add("key1", "value1");
    response.add("key2", "value2");
    response.addResponseHeader(newValue);
    assertEquals("responseHeader new value", newValue, response.getResponseHeader());
    response.removeResponseHeader();
    assertEquals("responseHeader removed value", null, response.getResponseHeader());
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Test(org.junit.Test)

Example 8 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class TestSolrQueryResponse method testValues.

@Test
public void testValues() throws Exception {
    final SolrQueryResponse response = new SolrQueryResponse();
    assertEquals("values initially not empty", 0, response.getValues().size());
    // initially empty, then add something
    final NamedList<Object> newValue = new SimpleOrderedMap<>();
    newValue.add("key1", "value1");
    response.setAllValues(newValue);
    assertEquals("values new value", newValue, response.getValues());
    response.add("key2", "value2");
    {
        final Iterator<Map.Entry<String, Object>> it = response.getValues().iterator();
        assertTrue(it.hasNext());
        final Map.Entry<String, Object> entry1 = it.next();
        assertEquals("key1", entry1.getKey());
        assertEquals("value1", entry1.getValue());
        assertTrue(it.hasNext());
        final Map.Entry<String, Object> entry2 = it.next();
        assertEquals("key2", entry2.getKey());
        assertEquals("value2", entry2.getValue());
        assertFalse(it.hasNext());
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) Test(org.junit.Test)

Example 9 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class HttpClusterStateProvider method fetchClusterState.

@SuppressWarnings({ "rawtypes", "unchecked" })
private ClusterState fetchClusterState(SolrClient client, String collection) throws SolrServerException, IOException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("collection", collection);
    params.set("action", "CLUSTERSTATUS");
    QueryRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    NamedList cluster = (SimpleOrderedMap) client.request(request).get("cluster");
    Map<String, Object> collectionsMap = Collections.singletonMap(collection, ((NamedList) cluster.get("collections")).get(collection));
    int znodeVersion = (int) ((Map<String, Object>) (collectionsMap).get(collection)).get("znodeVersion");
    Set<String> liveNodes = new HashSet((List<String>) (cluster.get("live_nodes")));
    this.liveNodes = liveNodes;
    liveNodesTimestamp = System.nanoTime();
    ClusterState cs = ClusterState.load(znodeVersion, collectionsMap, liveNodes, ZkStateReader.CLUSTER_STATE);
    return cs;
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) HashSet(java.util.HashSet)

Example 10 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class CloudSolrClientTest method queryWithPreferLocalShards.

private void queryWithPreferLocalShards(CloudSolrClient cloudClient, boolean preferLocalShards, String collectionName) throws Exception {
    SolrQuery qRequest = new SolrQuery("*:*");
    ModifiableSolrParams qParams = new ModifiableSolrParams();
    qParams.add(CommonParams.PREFER_LOCAL_SHARDS, Boolean.toString(preferLocalShards));
    qParams.add(ShardParams.SHARDS_INFO, "true");
    qRequest.add(qParams);
    // CloudSolrClient sends the request to some node.
    // And since all the nodes are hosting cores from all shards, the
    // distributed query formed by this node will select cores from the
    // local shards only
    QueryResponse qResponse = cloudClient.query(collectionName, qRequest);
    Object shardsInfo = qResponse.getResponse().get(ShardParams.SHARDS_INFO);
    assertNotNull("Unable to obtain " + ShardParams.SHARDS_INFO, shardsInfo);
    // Iterate over shards-info and check what cores responded
    SimpleOrderedMap<?> shardsInfoMap = (SimpleOrderedMap<?>) shardsInfo;
    Iterator<Map.Entry<String, ?>> itr = shardsInfoMap.asMap(100).entrySet().iterator();
    List<String> shardAddresses = new ArrayList<String>();
    while (itr.hasNext()) {
        Map.Entry<String, ?> e = itr.next();
        assertTrue("Did not find map-type value in " + ShardParams.SHARDS_INFO, e.getValue() instanceof Map);
        String shardAddress = (String) ((Map) e.getValue()).get("shardAddress");
        assertNotNull(ShardParams.SHARDS_INFO + " did not return 'shardAddress' parameter", shardAddress);
        shardAddresses.add(shardAddress);
    }
    log.info("Shards giving the response: " + Arrays.toString(shardAddresses.toArray()));
    // Make sure the distributed queries were directed to a single node only
    if (preferLocalShards) {
        Set<Integer> ports = new HashSet<Integer>();
        for (String shardAddr : shardAddresses) {
            URL url = new URL(shardAddr);
            ports.add(url.getPort());
        }
        // This assertion would hold true as long as every shard has a core on each node
        assertTrue("Response was not received from shards on a single node", shardAddresses.size() > 1 && ports.size() == 1);
    }
}
Also used : ArrayList(java.util.ArrayList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrQuery(org.apache.solr.client.solrj.SolrQuery) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) URL(java.net.URL) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)131 NamedList (org.apache.solr.common.util.NamedList)69 ArrayList (java.util.ArrayList)36 SolrException (org.apache.solr.common.SolrException)32 Map (java.util.Map)27 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 IOException (java.io.IOException)19 List (java.util.List)19 HashMap (java.util.HashMap)18 SolrParams (org.apache.solr.common.params.SolrParams)16 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)16 SchemaField (org.apache.solr.schema.SchemaField)16 FieldType (org.apache.solr.schema.FieldType)14 BytesRef (org.apache.lucene.util.BytesRef)13 Test (org.junit.Test)13 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)12 SolrDocumentList (org.apache.solr.common.SolrDocumentList)11 HashSet (java.util.HashSet)10 SolrCore (org.apache.solr.core.SolrCore)10 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)9