Search in sources :

Example 11 with NamedList

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

the class TestCollectionAPI method clusterStatusWithCollection.

private void clusterStatusWithCollection() throws IOException, SolrServerException {
    try (CloudSolrClient client = createCloudClient(null)) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", COLLECTION_NAME);
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        NamedList<Object> rsp = client.request(request);
        NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
        assertNotNull("Cluster state should not be null", cluster);
        NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
        assertNotNull("Collections should not be null in cluster state", collections);
        assertEquals(1, collections.size());
        Map<String, Object> collection = (Map<String, Object>) collections.get(COLLECTION_NAME);
        assertNotNull(collection);
        assertEquals("conf1", collection.get("configName"));
    //      assertEquals("1", collection.get("nrtReplicas"));
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest) HashMap(java.util.HashMap) Map(java.util.Map) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 12 with NamedList

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

the class TestCollectionAPI method listCollection.

private void listCollection() throws IOException, SolrServerException {
    try (CloudSolrClient client = createCloudClient(null)) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.LIST.toString());
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        NamedList<Object> rsp = client.request(request);
        List<String> collections = (List<String>) rsp.get("collections");
        assertTrue("control_collection was not found in list", collections.contains("control_collection"));
        assertTrue(DEFAULT_COLLECTION + " was not found in list", collections.contains(DEFAULT_COLLECTION));
        assertTrue(COLLECTION_NAME + " was not found in list", collections.contains(COLLECTION_NAME));
        assertTrue(COLLECTION_NAME1 + " was not found in list", collections.contains(COLLECTION_NAME1));
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 13 with NamedList

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

the class TestCollectionAPI method clusterStatusWithRouteKey.

private void clusterStatusWithRouteKey() throws IOException, SolrServerException {
    try (CloudSolrClient client = createCloudClient(DEFAULT_COLLECTION)) {
        SolrInputDocument doc = new SolrInputDocument();
        // goes to shard2. see ShardRoutingTest for details
        doc.addField("id", "a!123");
        client.add(doc);
        client.commit();
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", DEFAULT_COLLECTION);
        params.set(ShardParams._ROUTE_, "a!");
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        NamedList<Object> rsp = client.request(request);
        NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
        assertNotNull("Cluster state should not be null", cluster);
        NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
        assertNotNull("Collections should not be null in cluster state", collections);
        assertNotNull(collections.get(DEFAULT_COLLECTION));
        assertEquals(1, collections.size());
        Map<String, Object> collection = (Map<String, Object>) collections.get(DEFAULT_COLLECTION);
        assertEquals("conf1", collection.get("configName"));
        Map<String, Object> shardStatus = (Map<String, Object>) collection.get("shards");
        assertEquals(1, shardStatus.size());
        Map<String, Object> selectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD2);
        assertNotNull(selectedShardStatus);
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest) HashMap(java.util.HashMap) Map(java.util.Map) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 14 with NamedList

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

the class TestCollectionAPI method clusterStatusWithCollectionAndShard.

private void clusterStatusWithCollectionAndShard() throws IOException, SolrServerException {
    try (CloudSolrClient client = createCloudClient(null)) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", COLLECTION_NAME);
        params.set("shard", SHARD1);
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        NamedList<Object> rsp = client.request(request);
        NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
        assertNotNull("Cluster state should not be null", cluster);
        NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
        assertNotNull("Collections should not be null in cluster state", collections);
        assertNotNull(collections.get(COLLECTION_NAME));
        assertEquals(1, collections.size());
        Map<String, Object> collection = (Map<String, Object>) collections.get(COLLECTION_NAME);
        Map<String, Object> shardStatus = (Map<String, Object>) collection.get("shards");
        assertEquals(1, shardStatus.size());
        Map<String, Object> selectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD1);
        assertNotNull(selectedShardStatus);
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest) HashMap(java.util.HashMap) Map(java.util.Map) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 15 with NamedList

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

the class TestConfigSetsAPI method verifyProperties.

private void verifyProperties(String configSetName, Map<String, String> oldProps, Map<String, String> newProps, SolrZkClient zkClient) throws Exception {
    NamedList properties = getConfigSetPropertiesFromZk(zkClient, ZkConfigManager.CONFIGS_ZKNODE + "/" + configSetName + "/" + DEFAULT_FILENAME);
    // (since we'd probably repeat any bug in the MessageHandler here)
    if (oldProps == null && newProps == null) {
        assertNull(properties);
        return;
    }
    assertNotNull(properties);
    // check all oldProps are in props
    if (oldProps != null) {
        for (Map.Entry<String, String> entry : oldProps.entrySet()) {
            assertNotNull(properties.get(entry.getKey()));
        }
    }
    // check all newProps are in props
    if (newProps != null) {
        for (Map.Entry<String, String> entry : newProps.entrySet()) {
            assertNotNull(properties.get(entry.getKey()));
        }
    }
    // check the value in properties are correct
    Iterator<Map.Entry<String, Object>> it = properties.iterator();
    while (it.hasNext()) {
        Map.Entry<String, Object> entry = it.next();
        String newValue = newProps != null ? newProps.get(entry.getKey()) : null;
        String oldValue = oldProps != null ? oldProps.get(entry.getKey()) : null;
        if (newValue != null) {
            assertTrue(newValue.equals(entry.getValue()));
        } else if (oldValue != null) {
            assertTrue(oldValue.equals(entry.getValue()));
        } else {
            // not in either
            assert (false);
        }
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) NamedList(org.apache.solr.common.util.NamedList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

NamedList (org.apache.solr.common.util.NamedList)438 Test (org.junit.Test)125 ArrayList (java.util.ArrayList)110 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)83 Map (java.util.Map)82 SolrException (org.apache.solr.common.SolrException)80 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)78 List (java.util.List)75 HashMap (java.util.HashMap)64 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)55 IOException (java.io.IOException)53 SolrDocumentList (org.apache.solr.common.SolrDocumentList)45 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)35 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)35 SolrParams (org.apache.solr.common.params.SolrParams)31 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)31 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)30 SolrCore (org.apache.solr.core.SolrCore)30 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)27 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)27