Search in sources :

Example 51 with CollectionAdminResponse

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

the class CollectionsAPISolrJTest method testAddAndDeleteReplicaProp.

@Test
public void testAddAndDeleteReplicaProp() throws InterruptedException, IOException, SolrServerException {
    final String collection = "replicaProperties";
    CollectionAdminRequest.createCollection(collection, "conf", 2, 2).process(cluster.getSolrClient());
    final Replica replica = getCollectionState(collection).getLeader("shard1");
    CollectionAdminResponse response = CollectionAdminRequest.addReplicaProperty(collection, "shard1", replica.getName(), "preferredleader", "true").process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    waitForState("Expecting property 'preferredleader' to appear on replica " + replica.getName(), collection, (n, c) -> "true".equals(c.getReplica(replica.getName()).getStr("property.preferredleader")));
    response = CollectionAdminRequest.deleteReplicaProperty(collection, "shard1", replica.getName(), "property.preferredleader").process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    waitForState("Expecting property 'preferredleader' to be removed from replica " + replica.getName(), collection, (n, c) -> c.getReplica(replica.getName()).getStr("property.preferredleader") == null);
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) Replica(org.apache.solr.common.cloud.Replica) Test(org.junit.Test)

Example 52 with CollectionAdminResponse

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

the class CollectionsAPIDistributedZkTest method testCreateShouldFailOnExistingCore.

@Test
public void testCreateShouldFailOnExistingCore() throws Exception {
    // first we make a core with the core name the collections api
    // will try and use - this will cause our mock fail
    Create createCmd = new Create();
    createCmd.setCoreName(Assign.buildCoreName("halfcollection", "shard1", Replica.Type.NRT, 1));
    createCmd.setCollection("halfcollectionblocker");
    String dataDir = createTempDir().toFile().getAbsolutePath();
    createCmd.setDataDir(dataDir);
    createCmd.setNumShards(1);
    createCmd.setCollectionConfigName("conf");
    try (SolrClient client = cluster.getJettySolrRunner(0).newClient()) {
        client.request(createCmd);
    }
    createCmd = new Create();
    createCmd.setCoreName(Assign.buildCoreName("halfcollection", "shard1", Replica.Type.NRT, 1));
    createCmd.setCollection("halfcollectionblocker2");
    dataDir = createTempDir().toFile().getAbsolutePath();
    createCmd.setDataDir(dataDir);
    createCmd.setNumShards(1);
    createCmd.setCollectionConfigName("conf");
    try (SolrClient client = cluster.getJettySolrRunner(1).newClient()) {
        client.request(createCmd);
    }
    String nn1 = cluster.getJettySolrRunner(0).getNodeName();
    String nn2 = cluster.getJettySolrRunner(1).getNodeName();
    CollectionAdminResponse resp = CollectionAdminRequest.createCollection("halfcollection", "conf", 2, 1).setCreateNodeSet(nn1 + "," + nn2).process(cluster.getSolrClient());
    SimpleOrderedMap success = (SimpleOrderedMap) resp.getResponse().get("success");
    SimpleOrderedMap failure = (SimpleOrderedMap) resp.getResponse().get("failure");
    assertNotNull(resp.toString(), success);
    assertNotNull(resp.toString(), failure);
    String val1 = success.getVal(0).toString();
    String val2 = failure.getVal(0).toString();
    assertTrue(val1.contains("SolrException") || val2.contains("SolrException"));
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Test(org.junit.Test)

Example 53 with CollectionAdminResponse

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

the class CollectionsAPISolrJTest method testSplitShard.

@Test
public void testSplitShard() throws Exception {
    final String collectionName = "solrj_test_splitshard";
    CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1).process(cluster.getSolrClient());
    CollectionAdminResponse response = CollectionAdminRequest.splitShard(collectionName).setShardName("shard1").process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
    assertEquals(0, (int) coresStatus.get(Assign.buildCoreName(collectionName, "shard1_0", Replica.Type.NRT, 1)).get("status"));
    assertEquals(0, (int) coresStatus.get(Assign.buildCoreName(collectionName, "shard1_1", Replica.Type.NRT, 1)).get("status"));
    waitForState("Expected all shards to be active and parent shard to be removed", collectionName, (n, c) -> {
        if (c.getSlice("shard1").getState() == Slice.State.ACTIVE)
            return false;
        for (Replica r : c.getReplicas()) {
            if (r.isActive(n) == false)
                return false;
        }
        return true;
    });
    // Test splitting using split.key
    response = CollectionAdminRequest.splitShard(collectionName).setSplitKey("b!").process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    waitForState("Expected 5 slices to be active", collectionName, (n, c) -> c.getActiveSlices().size() == 5);
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) NamedList(org.apache.solr.common.util.NamedList) Replica(org.apache.solr.common.cloud.Replica) Test(org.junit.Test)

Example 54 with CollectionAdminResponse

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

the class CollectionsAPISolrJTest method testList.

@Test
public void testList() throws IOException, SolrServerException {
    CollectionAdminResponse response = new CollectionAdminRequest.List().process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertNotNull("collection list should not be null", response.getResponse().get("collections"));
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) Test(org.junit.Test)

Example 55 with CollectionAdminResponse

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

the class CollectionsAPISolrJTest method testCloudInfoInCoreStatus.

@Test
public void testCloudInfoInCoreStatus() throws IOException, SolrServerException {
    String collectionName = "corestatus_test";
    CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).setStateFormat(1).process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    String nodeName = ((NamedList) response.getResponse().get("success")).getName(0);
    String corename = (String) ((NamedList) ((NamedList) response.getResponse().get("success")).getVal(0)).get("core");
    try (HttpSolrClient coreclient = getHttpSolrClient(cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeName))) {
        CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreclient);
        Map m = status.getResponse().asMap(5);
        assertEquals(collectionName, Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "collection")));
        assertNotNull(Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "shard")));
        assertNotNull(Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "replica")));
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) NamedList(org.apache.solr.common.util.NamedList) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) Map(java.util.Map) 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