Search in sources :

Example 6 with CollectionAdminResponse

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

the class TestConfigSetsAPI method testUploadWithRunExecutableListener.

@Test
public void testUploadWithRunExecutableListener() throws Exception {
    String suffix = "-untrusted";
    uploadConfigSet("with-run-executable-listener", suffix, null, null);
    // try to create a collection with the uploaded configset
    CollectionAdminResponse resp = createCollection("newcollection3", "with-run-executable-listener" + suffix, 1, 1, solrCluster.getSolrClient());
    log.info("Client saw errors: " + resp.getErrorMessages());
    assertTrue(resp.getErrorMessages() != null && resp.getErrorMessages().size() > 0);
    assertTrue(resp.getErrorMessages().getVal(0).contains("The configset for this collection was uploaded without any authentication"));
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) BasicAuthIntegrationTest(org.apache.solr.security.BasicAuthIntegrationTest) Test(org.junit.Test)

Example 7 with CollectionAdminResponse

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

the class TestConfigSetsAPI method createCollection.

protected CollectionAdminResponse createCollection(String collectionName, String confSetName, int numShards, int replicationFactor, SolrClient client) throws SolrServerException, IOException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionAction.CREATE.toString());
    params.set("collection.configName", confSetName);
    params.set("name", collectionName);
    params.set("numShards", numShards);
    params.set("replicationFactor", replicationFactor);
    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) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 8 with CollectionAdminResponse

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

the class TestPullReplica method testCreateDelete.

// 2 times to make sure cleanup is complete and we can create the same collection
@Repeat(iterations = 2)
public void testCreateDelete() throws Exception {
    try {
        switch(random().nextInt(3)) {
            case 0:
                // Sometimes use SolrJ
                CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1, 0, 3).setMaxShardsPerNode(100).process(cluster.getSolrClient());
                break;
            case 1:
                // Sometimes use v1 API
                String url = String.format(Locale.ROOT, "%s/admin/collections?action=CREATE&name=%s&numShards=%s&pullReplicas=%s&maxShardsPerNode=%s", cluster.getRandomJetty(random()).getBaseUrl(), collectionName, // numShards
                2, // pullReplicas
                3, // maxShardsPerNode
                100);
                // These options should all mean the same
                url = url + pickRandom("", "&nrtReplicas=1", "&replicationFactor=1");
                HttpGet createCollectionGet = new HttpGet(url);
                cluster.getSolrClient().getHttpClient().execute(createCollectionGet);
                break;
            case 2:
                // Sometimes use V2 API
                url = cluster.getRandomJetty(random()).getBaseUrl().toString() + "/____v2/c";
                String requestBody = String.format(Locale.ROOT, "{create:{name:%s, numShards:%s, pullReplicas:%s, maxShardsPerNode:%s %s}}", collectionName, // numShards
                2, // pullReplicas
                3, // maxShardsPerNode
                100, // These options should all mean the same
                pickRandom("", ", nrtReplicas:1", ", replicationFactor:1"));
                HttpPost createCollectionPost = new HttpPost(url);
                createCollectionPost.setHeader("Content-type", "application/json");
                createCollectionPost.setEntity(new StringEntity(requestBody));
                HttpResponse httpResponse = cluster.getSolrClient().getHttpClient().execute(createCollectionPost);
                assertEquals(200, httpResponse.getStatusLine().getStatusCode());
                break;
        }
        boolean reloaded = false;
        while (true) {
            DocCollection docCollection = getCollectionState(collectionName);
            assertNotNull(docCollection);
            assertEquals("Expecting 4 relpicas per shard", 8, docCollection.getReplicas().size());
            assertEquals("Expecting 6 pull replicas, 3 per shard", 6, docCollection.getReplicas(EnumSet.of(Replica.Type.PULL)).size());
            assertEquals("Expecting 2 writer replicas, one per shard", 2, docCollection.getReplicas(EnumSet.of(Replica.Type.NRT)).size());
            for (Slice s : docCollection.getSlices()) {
                // read-only replicas can never become leaders
                assertFalse(s.getLeader().getType() == Replica.Type.PULL);
                List<String> shardElectionNodes = cluster.getZkClient().getChildren(ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), null, true);
                assertEquals("Unexpected election nodes for Shard: " + s.getName() + ": " + Arrays.toString(shardElectionNodes.toArray()), 1, shardElectionNodes.size());
            }
            assertUlogPresence(docCollection);
            if (reloaded) {
                break;
            } else {
                // reload
                CollectionAdminResponse response = CollectionAdminRequest.reloadCollection(collectionName).process(cluster.getSolrClient());
                assertEquals(0, response.getStatus());
                reloaded = true;
            }
        }
    } finally {
        zkClient().printLayoutToStdOut();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) Slice(org.apache.solr.common.cloud.Slice) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DocCollection(org.apache.solr.common.cloud.DocCollection) Repeat(com.carrotsearch.randomizedtesting.annotations.Repeat)

Example 9 with CollectionAdminResponse

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

the class TestDistribIDF method createCollection.

private void createCollection(String name, String config, String router) throws Exception {
    CollectionAdminResponse response;
    if (router.equals(ImplicitDocRouter.NAME)) {
        CollectionAdminRequest.Create create = CollectionAdminRequest.createCollectionWithImplicitRouter(name, config, "a,b,c", 1);
        create.setMaxShardsPerNode(1);
        response = create.process(solrCluster.getSolrClient());
    } else {
        CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(name, config, 2, 1);
        create.setMaxShardsPerNode(1);
        response = create.process(solrCluster.getSolrClient());
    }
    if (response.getStatus() != 0 || response.getErrorMessages() != null) {
        fail("Could not create collection. Response" + response.toString());
    }
    ZkStateReader zkStateReader = solrCluster.getSolrClient().getZkStateReader();
    AbstractDistribZkTestBase.waitForRecoveriesToFinish(name, zkStateReader, false, true, 100);
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest)

Example 10 with CollectionAdminResponse

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

the class ShardSplitTest method testSplitShardWithRule.

@Test
public void testSplitShardWithRule() throws Exception {
    waitForThingsToLevelOut(15);
    if (usually()) {
        log.info("Using legacyCloud=false for cluster");
        CollectionAdminRequest.setClusterProperty(ZkStateReader.LEGACY_CLOUD, "false").process(cloudClient);
    }
    log.info("Starting testSplitShardWithRule");
    String collectionName = "shardSplitWithRule";
    CollectionAdminRequest.Create createRequest = CollectionAdminRequest.createCollection(collectionName, 1, 2).setRule("shard:*,replica:<2,node:*");
    CollectionAdminResponse response = createRequest.process(cloudClient);
    assertEquals(0, response.getStatus());
    CollectionAdminRequest.SplitShard splitShardRequest = CollectionAdminRequest.splitShard(collectionName).setShardName("shard1");
    response = splitShardRequest.process(cloudClient);
    assertEquals(String.valueOf(response.getErrorMessages()), 0, response.getStatus());
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) Test(org.junit.Test)

Aggregations

CollectionAdminResponse (org.apache.solr.client.solrj.response.CollectionAdminResponse)58 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)29 Test (org.junit.Test)21 NamedList (org.apache.solr.common.util.NamedList)11 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)9 SolrClient (org.apache.solr.client.solrj.SolrClient)8 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 ArrayList (java.util.ArrayList)7 SolrServerException (org.apache.solr.client.solrj.SolrServerException)7 Replica (org.apache.solr.common.cloud.Replica)7 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)6 IOException (java.io.IOException)5 Map (java.util.Map)5 SolrRequest (org.apache.solr.client.solrj.SolrRequest)5 HttpResponse (org.apache.http.HttpResponse)4 HttpGet (org.apache.http.client.methods.HttpGet)4 HttpPost (org.apache.http.client.methods.HttpPost)4 StringEntity (org.apache.http.entity.StringEntity)4 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)4