Search in sources :

Example 31 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project ddf by codice.

the class BackupCommand method backup.

private boolean backup(SolrClient client, String collection, String backupLocation, String backupName) throws IOException, SolrServerException {
    CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(collection, backupName).setLocation(backupLocation);
    CollectionAdminResponse response = backup.process(client, collection);
    LOGGER.debug("Backup status: {}", response.getStatus());
    if (response.getStatus() != 0) {
        printErrorMessage("Backup failed. ");
        printResponseErrorMessages(response);
    }
    return response.isSuccess();
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest)

Example 32 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project ddf by codice.

the class SolrCloudClientFactory method createCollection.

private static void createCollection(String collection, CloudSolrClient client) throws SolrFactoryException {
    try {
        CollectionAdminResponse response = new CollectionAdminRequest.List().process(client);
        if (response == null || response.getResponse() == null || response.getResponse().get("collections") == null) {
            throw new SolrFactoryException("Failed to get a list of existing collections");
        }
        List<String> collections = (List<String>) response.getResponse().get("collections");
        if (!collections.contains(collection)) {
            response = new CollectionAdminRequest.Create().setNumShards(SHARD_COUNT).setMaxShardsPerNode(MAXIMUM_SHARDS_PER_NODE).setReplicationFactor(REPLICATION_FACTOR).setCollectionName(collection).process(client);
            if (!response.isSuccess()) {
                throw new SolrFactoryException("Failed to create collection [" + collection + "]: " + response.getErrorMessages());
            }
            if (!isCollectionReady(client, collection)) {
                throw new SolrFactoryException("Solr collection [" + collection + "] was not ready in time.");
            }
        } else {
            LOGGER.debug("Collection already exists: " + collection);
        }
    } catch (SolrServerException | IOException e) {
        throw new SolrFactoryException("Failed to create collection: " + collection, e);
    }
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) List(java.util.List) IOException(java.io.IOException)

Example 33 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project titan by thinkaurelius.

the class SolrIndex method createCollectionIfNotExists.

private static void createCollectionIfNotExists(CloudSolrClient client, Configuration config, String collection) throws IOException, SolrServerException, KeeperException, InterruptedException {
    if (!checkIfCollectionExists(client, collection)) {
        Integer numShards = config.get(NUM_SHARDS);
        Integer maxShardsPerNode = config.get(MAX_SHARDS_PER_NODE);
        Integer replicationFactor = config.get(REPLICATION_FACTOR);
        // Ideally this property used so a new configset is not uploaded for every single
        // index (collection) created in solr.
        // if a generic configSet is not set, make the configset name the same as the collection.
        // This was the default behavior before a default configSet could be specified 
        String genericConfigSet = config.has(SOLR_DEFAULT_CONFIG) ? config.get(SOLR_DEFAULT_CONFIG) : collection;
        CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create();
        createRequest.setConfigName(genericConfigSet);
        createRequest.setCollectionName(collection);
        createRequest.setNumShards(numShards);
        createRequest.setMaxShardsPerNode(maxShardsPerNode);
        createRequest.setReplicationFactor(replicationFactor);
        CollectionAdminResponse createResponse = createRequest.process(client);
        if (createResponse.isSuccess()) {
            logger.trace("Collection {} successfully created.", collection);
        } else {
            throw new SolrServerException(Joiner.on("\n").join(createResponse.getErrorMessages()));
        }
    }
    waitForRecoveriesToFinish(client, collection);
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest)

Example 34 with CollectionAdminResponse

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

the class AbstractFullDistribZkTestBase method createCollection.

// TODO: Use CollectionAdminRequest#createCollection() instead of a raw request
protected 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", 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 numNrtReplicas = (Integer) collectionProps.get(ZkStateReader.NRT_REPLICAS);
    if (numNrtReplicas == null) {
        numNrtReplicas = (Integer) collectionProps.get(ZkStateReader.REPLICATION_FACTOR);
    }
    if (numNrtReplicas == null) {
        numNrtReplicas = (Integer) OverseerCollectionMessageHandler.COLL_PROPS.get(ZkStateReader.REPLICATION_FACTOR);
    }
    if (numNrtReplicas == null) {
        numNrtReplicas = Integer.valueOf(0);
    }
    Integer numTlogReplicas = (Integer) collectionProps.get(ZkStateReader.TLOG_REPLICAS);
    if (numTlogReplicas == null) {
        numTlogReplicas = Integer.valueOf(0);
    }
    Integer numPullReplicas = (Integer) collectionProps.get(ZkStateReader.PULL_REPLICAS);
    if (numPullReplicas == null) {
        numPullReplicas = Integer.valueOf(0);
    }
    if (confSetName != null) {
        params.set("collection.configName", confSetName);
    }
    int clientIndex = random().nextInt(2);
    List<Integer> list = new ArrayList<>();
    list.add(numShards);
    list.add(numNrtReplicas + numTlogReplicas + numPullReplicas);
    if (collectionInfos != null) {
        collectionInfos.put(collectionName, list);
    }
    params.set("name", collectionName);
    if ("1".equals(getStateFormat())) {
        log.info("Creating collection with stateFormat=1: " + collectionName);
        params.set(DocCollection.STATE_FORMAT, "1");
    }
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    CollectionAdminResponse res = new CollectionAdminResponse();
    if (client == null) {
        final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(clientIndex));
        try (SolrClient adminClient = createNewSolrClient("", baseUrl)) {
            res.setResponse(adminClient.request(request));
        }
    } else {
        res.setResponse(client.request(request));
    }
    return res;
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ArrayList(java.util.ArrayList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) Map(java.util.Map) Utils.makeMap(org.apache.solr.common.util.Utils.makeMap) HashMap(java.util.HashMap)

Example 35 with CollectionAdminResponse

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

the class AbstractFullDistribZkTestBase method createCollectionRetry.

protected void createCollectionRetry(String testCollectionName, int numShards, int replicationFactor, int maxShardsPerNode) throws SolrServerException, IOException {
    CollectionAdminResponse resp = createCollection(testCollectionName, numShards, replicationFactor, maxShardsPerNode);
    if (resp.getResponse().get("failure") != null) {
        CollectionAdminRequest.Delete req = CollectionAdminRequest.deleteCollection(testCollectionName);
        req.process(cloudClient);
        resp = createCollection(testCollectionName, numShards, replicationFactor, maxShardsPerNode);
        if (resp.getResponse().get("failure") != null) {
            fail("Could not create " + testCollectionName);
        }
    }
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest)

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