Search in sources :

Example 46 with CollectionAdminResponse

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

the class BaseCdcrDistributedZkTest method deleteCollection.

/**
   * Delete a collection through the Collection API.
   */
protected CollectionAdminResponse deleteCollection(String collectionName) throws Exception {
    SolrClient client = createCloudClient(null);
    CollectionAdminResponse res;
    try {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.DELETE.toString());
        params.set("name", collectionName);
        QueryRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        res = new CollectionAdminResponse();
        res.setResponse(client.request(request));
    } catch (Exception e) {
        log.warn("Error while deleting the collection " + collectionName, e);
        return new CollectionAdminResponse();
    } finally {
        client.close();
    }
    return res;
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 47 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse 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)

Example 48 with CollectionAdminResponse

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

the class CollectionsAPISolrJTest method testClusterProp.

@Test
public void testClusterProp() throws InterruptedException, IOException, SolrServerException {
    // sanity check our expected default
    final ClusterProperties props = new ClusterProperties(zkClient());
    assertEquals("Expecting prop to default to unset, test needs upated", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, null), null);
    CollectionAdminResponse response = CollectionAdminRequest.setClusterProperty(ZkStateReader.LEGACY_CLOUD, "false").process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertEquals("Cluster property was not set", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, null), "false");
    // Unset ClusterProp that we set.
    CollectionAdminRequest.setClusterProperty(ZkStateReader.LEGACY_CLOUD, null).process(cluster.getSolrClient());
    assertEquals("Cluster property was not unset", props.getClusterProperty(ZkStateReader.LEGACY_CLOUD, null), null);
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) ClusterProperties(org.apache.solr.common.cloud.ClusterProperties) Test(org.junit.Test)

Example 49 with CollectionAdminResponse

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

the class CollectionsAPISolrJTest method testCreateCollectionWithPropertyParam.

@Test
public void testCreateCollectionWithPropertyParam() throws Exception {
    String collectionName = "solrj_test_core_props";
    Path tmpDir = createTempDir("testPropertyParamsForCreate");
    Path dataDir = tmpDir.resolve("dataDir-" + TestUtil.randomSimpleString(random(), 1, 5));
    Path ulogDir = tmpDir.resolve("ulogDir-" + TestUtil.randomSimpleString(random(), 1, 5));
    CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1).withProperty(CoreAdminParams.DATA_DIR, dataDir.toString()).withProperty(CoreAdminParams.ULOG_DIR, ulogDir.toString()).process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
    assertEquals(1, coresStatus.size());
    DocCollection testCollection = getCollectionState(collectionName);
    Replica replica1 = testCollection.getReplica("core_node1");
    CoreStatus coreStatus = getCoreStatus(replica1);
    assertEquals(Paths.get(coreStatus.getDataDirectory()).toString(), dataDir.toString());
}
Also used : Path(java.nio.file.Path) CoreStatus(org.apache.solr.client.solrj.request.CoreStatus) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) NamedList(org.apache.solr.common.util.NamedList) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) Test(org.junit.Test)

Example 50 with CollectionAdminResponse

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

the class CollectionsAPISolrJTest method testAddAndDeleteReplica.

@Test
public void testAddAndDeleteReplica() throws Exception {
    final String collectionName = "solrj_replicatests";
    CollectionAdminRequest.createCollection(collectionName, "conf", 1, 2).process(cluster.getSolrClient());
    String newReplicaName = Assign.assignNode(getCollectionState(collectionName));
    ArrayList<String> nodeList = new ArrayList<>(cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes());
    Collections.shuffle(nodeList, random());
    final String node = nodeList.get(0);
    CollectionAdminResponse response = CollectionAdminRequest.addReplicaToShard(collectionName, "shard1").setNode(node).process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    waitForState("Expected to see replica " + newReplicaName + " on node " + node, collectionName, (n, c) -> {
        Replica r = c.getSlice("shard1").getReplica(newReplicaName);
        return r != null && r.getNodeName().equals(node);
    });
    // Test DELETEREPLICA
    response = CollectionAdminRequest.deleteReplica(collectionName, "shard1", newReplicaName).process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    waitForState("Expected replica " + newReplicaName + " to vanish from cluster state", collectionName, (n, c) -> c.getSlice("shard1").getReplica(newReplicaName) == null);
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica) 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