Search in sources :

Example 66 with CollectionAdminResponse

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

the class BackupCommandTest method createDefaultCollection.

private static void createDefaultCollection() throws Exception {
    CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(DEFAULT_CORE_NAME, DEFAULT_CONFIGSET, 1, 1);
    CollectionAdminResponse response = create.process(miniSolrCloud.getSolrClient());
    if (response.getStatus() != 0 || response.getErrorMessages() != null) {
        fail("Could not create collection. Response: " + response.toString());
    }
    List<String> collections = CollectionAdminRequest.listCollections(miniSolrCloud.getSolrClient());
    assertThat(collections.size(), is(1));
    miniSolrCloud.getSolrClient().setDefaultCollection(DEFAULT_CORE_NAME);
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 67 with CollectionAdminResponse

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

the class RemoteSolrServerProvider method createCollectionIfNeeded.

private void createCollectionIfNeeded(CloudSolrClient cloudSolrServer) throws SolrServerException {
    String solrCollection = remoteSolrServerConfiguration.getSolrCollection();
    ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader();
    SolrZkClient zkClient = zkStateReader.getZkClient();
    log.debug("creating {} collection if needed", solrCollection);
    try {
        if (zkClient.isConnected() && !zkClient.exists("/configs/" + solrCollection, true)) {
            String solrConfDir = remoteSolrServerConfiguration.getSolrConfDir();
            Path dir;
            if (solrConfDir != null && solrConfDir.length() > 0) {
                log.info("uploading config from {}", solrConfDir);
                dir = Paths.get(solrConfDir);
            } else {
                Path tempDirectory = Files.createTempDirectory("oak-solr-conf");
                copy("schema", tempDirectory);
                copy("solrconfig", tempDirectory);
                log.info("uploading config from {}", tempDirectory);
                dir = tempDirectory;
            }
            log.debug("uploading config from {}", dir);
            cloudSolrServer.uploadConfig(dir, solrCollection);
            log.debug("creating collection {}", solrCollection);
            CollectionAdminRequest.Create req = new CollectionAdminRequest.Create();
            CollectionAdminResponse response = req.setCollectionName(solrCollection).setReplicationFactor(remoteSolrServerConfiguration.getSolrReplicationFactor()).setConfigName(solrCollection).setNumShards(remoteSolrServerConfiguration.getSolrShardsNo()).process(cloudSolrServer);
            log.info("collection creation response {}", response);
            cloudSolrServer.request(req);
        }
    } catch (Exception e) {
        log.warn("could not create collection {}", solrCollection);
        throw new SolrServerException(e);
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) Path(java.nio.file.Path) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException)

Example 68 with CollectionAdminResponse

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

the class SolrCollectionBootstrapper method createCollection.

private boolean createCollection() {
    try {
        List<String> allCollectionList = getCollections();
        if (allCollectionList != null) {
            if (!allCollectionList.contains(solr_collection_name)) {
                int shardsCalculation = solrCloudClient != null ? solrCloudClient.getClusterStateProvider().getLiveNodes().size() : DEFAULT_VALUE;
                int no_of_shards = EmbeddedServerUtil.getIntConfig(SOLR_NO_SHARDS, shardsCalculation);
                logger.info("No. of shards provided is : " + no_of_shards);
                CollectionAdminRequest.Create createCollection = CollectionAdminRequest.createCollection(solr_collection_name, solr_config_name, no_of_shards, no_of_replicas);
                createCollection.setMaxShardsPerNode(max_node_per_shards);
                CollectionAdminResponse createResponse = createCollection.process(solrClient);
                if (createResponse.getStatus() != 0) {
                    logger.severe("Error creating collection. collectionName=" + solr_collection_name + " , solr config name = " + solr_config_name + " , replicas = " + no_of_replicas + ", shards=" + no_of_shards + " , max node per shards = " + max_node_per_shards + ", response=" + createResponse);
                    return false;
                } else {
                    allCollectionList = getCollections();
                    if (allCollectionList != null) {
                        if (allCollectionList.contains(solr_collection_name)) {
                            logger.info("Created collection " + solr_collection_name + " with config name " + solr_config_name + " replicas =  " + no_of_replicas + " Shards = " + no_of_shards + " max node per shards  = " + max_node_per_shards);
                            return true;
                        } else {
                            logger.severe("Collection does not exist. collectionName=" + solr_collection_name + " , solr config name = " + solr_config_name + " , replicas = " + no_of_replicas + ", shards=" + no_of_shards + " , max node per shards = " + max_node_per_shards + ", response=" + createResponse);
                            return false;
                        }
                    } else {
                        logger.severe("Error while getting collection list after creating collection");
                        return false;
                    }
                }
            } else {
                logger.info("Collection already exists with name " + solr_collection_name);
                return true;
            }
        } else {
            logger.severe("Error while connecting to solr ");
            return false;
        }
    } catch (Exception ex) {
        logger.severe("Error while creating collection in solr : " + ex);
        return false;
    }
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) ParseException(com.google.protobuf.TextFormat.ParseException) FileNotFoundException(java.io.FileNotFoundException)

Example 69 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project janusgraph by JanusGraph.

the class SolrIndex method createCollectionIfNotExists.

private static void createCollectionIfNotExists(CloudSolrClient client, Configuration config, String collection) throws IOException, SolrServerException, KeeperException, InterruptedException {
    if (!checkIfCollectionExists(client, collection)) {
        final Integer numShards = config.get(NUM_SHARDS);
        final Integer maxShardsPerNode = config.get(MAX_SHARDS_PER_NODE);
        final 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
        final String genericConfigSet = config.has(SOLR_DEFAULT_CONFIG) ? config.get(SOLR_DEFAULT_CONFIG) : collection;
        final CollectionAdminRequest.Create createRequest = CollectionAdminRequest.createCollection(collection, genericConfigSet, numShards, replicationFactor);
        createRequest.setMaxShardsPerNode(maxShardsPerNode);
        final 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) SolrServerException(org.apache.solr.client.solrj.SolrServerException) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest)

Example 70 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project beijingThirdPeriod by weidongcao.

the class SolrCollectionTest method createCollection.

/**
 * @param collectionName Solr 集合名
 * @param confName  Zookeeper上的Solr配置文件所在目录
 * @param numShards 分片数
 * @param numReplicas 副本数
 * @throws IOException
 * @throws SolrServerException
 */
public static void createCollection(String collectionName, String confName, int numShards, int numReplicas) throws IOException, SolrServerException {
    SolrClient client = new CloudSolrClient.Builder().withZkHost(zkhost).build();
    CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, confName, numShards, numReplicas);
    create.setMaxShardsPerNode(2);
    CollectionAdminResponse response = create.process(client);
    System.out.println(response);
    client.close();
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest)

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