Search in sources :

Example 1 with CollectionAdminResponse

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

the class SolrSnapshotsTool method listCollectionSnapshots.

private Collection<CollectionSnapshotMetaData> listCollectionSnapshots(String collectionName) throws SolrServerException, IOException {
    CollectionAdminRequest.ListSnapshots listSnapshots = new CollectionAdminRequest.ListSnapshots(collectionName);
    CollectionAdminResponse resp = listSnapshots.process(solrClient);
    Preconditions.checkState(resp.getStatus() == 0);
    NamedList apiResult = (NamedList) resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO);
    Collection<CollectionSnapshotMetaData> result = new ArrayList<>();
    for (int i = 0; i < apiResult.size(); i++) {
        result.add(new CollectionSnapshotMetaData((NamedList<Object>) apiResult.getVal(i)));
    }
    return result;
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest)

Example 2 with CollectionAdminResponse

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

the class SolrSnapshotsTool method createSnapshot.

public void createSnapshot(String collectionName, String snapshotName) {
    CollectionAdminRequest.CreateSnapshot createSnap = new CollectionAdminRequest.CreateSnapshot(collectionName, snapshotName);
    CollectionAdminResponse resp;
    try {
        resp = createSnap.process(solrClient);
        Preconditions.checkState(resp.getStatus() == 0, "The CREATESNAPSHOT request failed. The status code is " + resp.getStatus());
        System.out.println("Successfully created snapshot with name " + snapshotName + " for collection " + collectionName);
    } catch (Exception e) {
        log.error("Failed to create a snapshot with name " + snapshotName + " for collection " + collectionName, e);
        System.out.println("Failed to create a snapshot with name " + snapshotName + " for collection " + collectionName + " due to following error : " + e.getLocalizedMessage());
    }
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) URISyntaxException(java.net.URISyntaxException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 3 with CollectionAdminResponse

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

the class TestLTROnSolrCloud method createCollection.

private void createCollection(String name, String config, int numShards, int numReplicas, int maxShardsPerNode) throws Exception {
    CollectionAdminResponse response;
    CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(name, config, numShards, numReplicas);
    create.setMaxShardsPerNode(maxShardsPerNode);
    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 4 with CollectionAdminResponse

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

the class TestLTROnSolrCloud method reloadCollection.

private void reloadCollection(String collection) throws Exception {
    CollectionAdminRequest.Reload reloadRequest = CollectionAdminRequest.reloadCollection(collection);
    CollectionAdminResponse response = reloadRequest.process(solrCluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest)

Example 5 with CollectionAdminResponse

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

the class BasicDistributedZkTest method createCollection.

protected CollectionAdminResponse createCollection(Map<String, List<Integer>> collectionInfos, String collectionName, int numShards, int numReplicas, int maxShardsPerNode, SolrClient client, String createNodeSetStr) throws SolrServerException, IOException {
    // TODO: Use CollectionAdminRequest for this test
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionAction.CREATE.toString());
    params.set(OverseerCollectionMessageHandler.NUM_SLICES, numShards);
    params.set(ZkStateReader.REPLICATION_FACTOR, numReplicas);
    params.set(ZkStateReader.MAX_SHARDS_PER_NODE, maxShardsPerNode);
    if (createNodeSetStr != null)
        params.set(OverseerCollectionMessageHandler.CREATE_NODE_SET, createNodeSetStr);
    int clientIndex = clients.size() > 1 ? random().nextInt(2) : 0;
    List<Integer> list = new ArrayList<>();
    list.add(numShards);
    list.add(numReplicas);
    if (collectionInfos != null) {
        collectionInfos.put(collectionName, list);
    }
    params.set("name", collectionName);
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    CollectionAdminResponse res = new CollectionAdminResponse();
    if (client == null) {
        final String baseUrl = ((HttpSolrClient) clients.get(clientIndex)).getBaseURL().substring(0, ((HttpSolrClient) clients.get(clientIndex)).getBaseURL().length() - DEFAULT_COLLECTION.length() - 1);
        try (SolrClient aClient = createNewSolrClient("", baseUrl)) {
            res.setResponse(aClient.request(request));
        }
    } else {
        res.setResponse(client.request(request));
    }
    return res;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ArrayList(java.util.ArrayList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

CollectionAdminResponse (org.apache.solr.client.solrj.response.CollectionAdminResponse)71 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)40 Test (org.junit.Test)21 SolrServerException (org.apache.solr.client.solrj.SolrServerException)13 NamedList (org.apache.solr.common.util.NamedList)13 SolrClient (org.apache.solr.client.solrj.SolrClient)9 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)9 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)9 ArrayList (java.util.ArrayList)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 IOException (java.io.IOException)7 Replica (org.apache.solr.common.cloud.Replica)7 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)6 Map (java.util.Map)5 SolrRequest (org.apache.solr.client.solrj.SolrRequest)5 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)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