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);
}
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);
}
}
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;
}
}
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);
}
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();
}
Aggregations