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