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;
}
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());
}
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());
}
}
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;
}
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);
}
}
Aggregations