Search in sources :

Example 31 with SolrRequest

use of org.apache.solr.client.solrj.SolrRequest in project lucene-solr by apache.

the class TestCollectionAPI method testAliasCreationNameValidation.

private void testAliasCreationNameValidation() throws Exception {
    try (CloudSolrClient client = createCloudClient(null)) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CREATEALIAS.toString());
        params.set("name", "invalid@name#with$weird%characters");
        params.set("collections", COLLECTION_NAME);
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        try {
            client.request(request);
            fail();
        } catch (RemoteSolrException e) {
            final String errorMessage = e.getMessage();
            assertTrue(errorMessage.contains("Invalid alias"));
            assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
            assertTrue(errorMessage.contains("alias names must consist entirely of"));
        }
    }
}
Also used : RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 32 with SolrRequest

use of org.apache.solr.client.solrj.SolrRequest in project lucene-solr by apache.

the class TestCollectionAPI method clusterStatusAliasTest.

private void clusterStatusAliasTest() throws Exception {
    try (CloudSolrClient client = createCloudClient(null)) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CREATEALIAS.toString());
        params.set("name", "myalias");
        params.set("collections", DEFAULT_COLLECTION + "," + COLLECTION_NAME);
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        client.request(request);
        params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", DEFAULT_COLLECTION);
        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);
        Map<String, String> aliases = (Map<String, String>) cluster.get("aliases");
        assertNotNull("Aliases should not be null", aliases);
        assertEquals("Alias: myalias not found in cluster status", DEFAULT_COLLECTION + "," + COLLECTION_NAME, aliases.get("myalias"));
        NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
        assertNotNull("Collections should not be null in cluster state", collections);
        assertNotNull(collections.get(DEFAULT_COLLECTION));
        Map<String, Object> collection = (Map<String, Object>) collections.get(DEFAULT_COLLECTION);
        assertEquals("conf1", collection.get("configName"));
        List<String> collAlias = (List<String>) collection.get("aliases");
        assertEquals("Aliases not found", Lists.newArrayList("myalias"), collAlias);
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with SolrRequest

use of org.apache.solr.client.solrj.SolrRequest in project lucene-solr by apache.

the class TestCollectionAPI method clusterStatusRolesTest.

private void clusterStatusRolesTest() throws Exception {
    try (CloudSolrClient client = createCloudClient(null)) {
        client.connect();
        Replica replica = client.getZkStateReader().getLeaderRetry(DEFAULT_COLLECTION, SHARD1);
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.ADDROLE.toString());
        params.set("node", replica.getNodeName());
        params.set("role", "overseer");
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        client.request(request);
        params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", DEFAULT_COLLECTION);
        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);
        Map<String, Object> roles = (Map<String, Object>) cluster.get("roles");
        assertNotNull("Role information should not be null", roles);
        List<String> overseer = (List<String>) roles.get("overseer");
        assertNotNull(overseer);
        assertEquals(1, overseer.size());
        assertTrue(overseer.contains(replica.getNodeName()));
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest) Replica(org.apache.solr.common.cloud.Replica) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with SolrRequest

use of org.apache.solr.client.solrj.SolrRequest in project lucene-solr by apache.

the class BaseCdcrDistributedZkTest method invokeCdcrAction.

/**
   * Invokes a CDCR action on a given node.
   */
protected NamedList invokeCdcrAction(CloudJettyRunner jetty, CdcrParams.CdcrAction action) throws Exception {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CommonParams.ACTION, action.toString());
    SolrRequest request = new QueryRequest(params);
    request.setPath(CDCR_PATH);
    return jetty.client.request(request);
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 35 with SolrRequest

use of org.apache.solr.client.solrj.SolrRequest in project lucene-solr by apache.

the class BaseCdcrDistributedZkTest method createCollection.

private CollectionAdminResponse createCollection(Map<String, List<Integer>> collectionInfos, String collectionName, Map<String, Object> collectionProps, SolrClient client, String confSetName) throws SolrServerException, IOException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionParams.CollectionAction.CREATE.toString());
    for (Map.Entry<String, Object> entry : collectionProps.entrySet()) {
        if (entry.getValue() != null)
            params.set(entry.getKey(), String.valueOf(entry.getValue()));
    }
    Integer numShards = (Integer) collectionProps.get(NUM_SLICES);
    if (numShards == null) {
        String shardNames = (String) collectionProps.get(SHARDS_PROP);
        numShards = StrUtils.splitSmart(shardNames, ',').size();
    }
    Integer replicationFactor = (Integer) collectionProps.get(REPLICATION_FACTOR);
    if (replicationFactor == null) {
        replicationFactor = (Integer) OverseerCollectionMessageHandler.COLL_PROPS.get(REPLICATION_FACTOR);
    }
    if (confSetName != null) {
        params.set("collection.configName", confSetName);
    }
    List<Integer> list = new ArrayList<>();
    list.add(numShards);
    list.add(replicationFactor);
    if (collectionInfos != null) {
        collectionInfos.put(collectionName, list);
    }
    params.set("name", collectionName);
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    CollectionAdminResponse res = new CollectionAdminResponse();
    res.setResponse(client.request(request));
    return res;
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

SolrRequest (org.apache.solr.client.solrj.SolrRequest)42 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)36 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)35 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)18 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)11 NamedList (org.apache.solr.common.util.NamedList)11 HashMap (java.util.HashMap)10 RemoteSolrException (org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)7 Test (org.junit.Test)7 List (java.util.List)6 SolrClient (org.apache.solr.client.solrj.SolrClient)5 CollectionAdminResponse (org.apache.solr.client.solrj.response.CollectionAdminResponse)5 LBHttpSolrClient (org.apache.solr.client.solrj.impl.LBHttpSolrClient)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 SolrException (org.apache.solr.common.SolrException)3 Utils.makeMap (org.apache.solr.common.util.Utils.makeMap)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2