Search in sources :

Example 21 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)

Example 22 with CollectionAdminResponse

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

the class TestTlogReplica method setupCluster.

@BeforeClass
public static void setupCluster() throws Exception {
    // We'll be explicit about this in this test
    TestInjection.waitForReplicasInSync = null;
    // 2 + random().nextInt(3) 
    configureCluster(2).addConfig("conf", configset("cloud-minimal-inplace-updates")).configure();
    Boolean useLegacyCloud = rarely();
    LOG.info("Using legacyCloud?: {}", useLegacyCloud);
    CollectionAdminRequest.ClusterProp clusterPropRequest = CollectionAdminRequest.setClusterProperty(ZkStateReader.LEGACY_CLOUD, String.valueOf(useLegacyCloud));
    CollectionAdminResponse response = clusterPropRequest.process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) BeforeClass(org.junit.BeforeClass)

Example 23 with CollectionAdminResponse

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

the class TestTlogReplica method addReplicaToShard.

private void addReplicaToShard(String shardName, Replica.Type type) throws ClientProtocolException, IOException, SolrServerException {
    switch(random().nextInt(3)) {
        case // Add replica with SolrJ
        0:
            CollectionAdminResponse response = CollectionAdminRequest.addReplicaToShard(collectionName, shardName, type).process(cluster.getSolrClient());
            assertEquals("Unexpected response status: " + response.getStatus(), 0, response.getStatus());
            break;
        case // Add replica with V1 API
        1:
            String url = String.format(Locale.ROOT, "%s/admin/collections?action=ADDREPLICA&collection=%s&shard=%s&type=%s", cluster.getRandomJetty(random()).getBaseUrl(), collectionName, shardName, type);
            HttpGet addReplicaGet = new HttpGet(url);
            HttpResponse httpResponse = cluster.getSolrClient().getHttpClient().execute(addReplicaGet);
            assertEquals(200, httpResponse.getStatusLine().getStatusCode());
            break;
        case // Add replica with V2 API
        2:
            url = String.format(Locale.ROOT, "%s/____v2/c/%s/shards", cluster.getRandomJetty(random()).getBaseUrl(), collectionName);
            String requestBody = String.format(Locale.ROOT, "{add-replica:{shard:%s, type:%s}}", shardName, type);
            HttpPost addReplicaPost = new HttpPost(url);
            addReplicaPost.setHeader("Content-type", "application/json");
            addReplicaPost.setEntity(new StringEntity(requestBody));
            httpResponse = cluster.getSolrClient().getHttpClient().execute(addReplicaPost);
            assertEquals(200, httpResponse.getStatusLine().getStatusCode());
            break;
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse)

Example 24 with CollectionAdminResponse

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

the class TestTlogReplica 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:
                CollectionAdminRequest.createCollection(collectionName, "conf", 2, 0, 4, 0).setMaxShardsPerNode(100).process(cluster.getSolrClient());
                break;
            case 1:
                // Sometimes don't use SolrJ
                String url = String.format(Locale.ROOT, "%s/admin/collections?action=CREATE&name=%s&numShards=%s&tlogReplicas=%s&maxShardsPerNode=%s", cluster.getRandomJetty(random()).getBaseUrl(), collectionName, // numShards
                2, // tlogReplicas
                4, // maxShardsPerNode
                100);
                HttpGet createCollectionGet = new HttpGet(url);
                HttpResponse httpResponse = cluster.getSolrClient().getHttpClient().execute(createCollectionGet);
                assertEquals(200, httpResponse.getStatusLine().getStatusCode());
                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, tlogReplicas:%s, maxShardsPerNode:%s}}", collectionName, // numShards
                2, // tlogReplicas
                4, // maxShardsPerNode
                100);
                HttpPost createCollectionPost = new HttpPost(url);
                createCollectionPost.setHeader("Content-type", "application/json");
                createCollectionPost.setEntity(new StringEntity(requestBody));
                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 2 shards", 2, docCollection.getSlices().size());
            assertEquals("Expecting 4 relpicas per shard", 8, docCollection.getReplicas().size());
            assertEquals("Expecting 8 tlog replicas, 4 per shard", 8, docCollection.getReplicas(EnumSet.of(Replica.Type.TLOG)).size());
            assertEquals("Expecting no nrt replicas", 0, docCollection.getReplicas(EnumSet.of(Replica.Type.NRT)).size());
            assertEquals("Expecting no pull replicas", 0, docCollection.getReplicas(EnumSet.of(Replica.Type.PULL)).size());
            for (Slice s : docCollection.getSlices()) {
                assertTrue(s.getLeader().getType() == Replica.Type.TLOG);
                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()), 4, 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 25 with CollectionAdminResponse

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

the class TestSolrCloudWithSecureImpersonation method create1ShardCollection.

private void create1ShardCollection(String name, String config, MiniSolrCloudCluster solrCluster) throws Exception {
    CollectionAdminResponse response;
    CollectionAdminRequest.Create create = new CollectionAdminRequest.Create(name, config, 1, 1, 0, 0) {

        @Override
        public SolrParams getParams() {
            ModifiableSolrParams msp = new ModifiableSolrParams(super.getParams());
            msp.set(USER_PARAM, "user");
            return msp;
        }
    };
    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) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

CollectionAdminResponse (org.apache.solr.client.solrj.response.CollectionAdminResponse)59 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)30 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 SolrServerException (org.apache.solr.client.solrj.SolrServerException)8 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 ArrayList (java.util.ArrayList)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