List of usage examples for org.apache.solr.client.solrj.request CollectionAdminRequest reloadCollection
public static Reload reloadCollection(String collection)
From source file:io.redlink.solrlib.cloud.SolrCloudConnector.java
License:Apache License
@Override
@SuppressWarnings({ "squid:S1141", "squid:S3776" })
protected void init(ExecutorService executorService) throws IOException, SolrServerException {
final Path sharedLibs = Files.createTempDirectory("solrSharedLibs");
try (CloudSolrClient client = createSolrClient()) {
/* NOTE: do not use as this breaks compatibility with lower Solr Versions
* <code>final List<String> existingCollections = CollectionAdminRequest.listCollections(client);</code>
*//* w ww .j a v a2 s. c o m*/
@SuppressWarnings("unchecked")
final List<String> existingCollections = (List<String>) new CollectionAdminRequest.List()
.process(client).getResponse().get("collections");
for (SolrCoreDescriptor coreDescriptor : coreDescriptors) {
final String coreName = coreDescriptor.getCoreName();
final String remoteName = createRemoteName(coreName);
if (availableCores.containsKey(coreName)) {
log.warn("CoreName-Clash: {} already initialized. Skipping {}", coreName,
coreDescriptor.getClass());
continue;
} else {
log.info("Initializing Core {} (remote: {})", coreName, remoteName);
}
if (config.isDeployCores()) {
final Path tmp = Files.createTempDirectory(coreName);
try {
coreDescriptor.initCoreDirectory(tmp, sharedLibs);
uploadConfig(remoteName, tmp);
if (!existingCollections.contains(remoteName)) {
// TODO: Check and log the response
final NamedList<Object> response = client.request(CollectionAdminRequest
.createCollection(remoteName, remoteName,
Math.max(1, coreDescriptor.getNumShards()),
Math.max(2, coreDescriptor.getReplicationFactor()))
.setMaxShardsPerNode(config.getMaxShardsPerNode()));
log.debug("Created Collection {}, CoreAdminResponse: {}", coreName, response);
scheduleCoreInit(executorService, coreDescriptor, true);
} else {
log.debug("Collection {} already exists in SolrCloud '{}' as {}", coreName,
config.getZkConnection(), remoteName);
// TODO: Check and log the response
final NamedList<Object> response = client
.request(CollectionAdminRequest.reloadCollection(remoteName));
log.debug("Reloaded Collection {}, CoreAdminResponse: {}", coreName, response);
scheduleCoreInit(executorService, coreDescriptor, false);
}
availableCores.put(coreName, coreDescriptor);
} catch (SolrServerException e) {
log.debug("Initializing core {} ({}) failed: {}", coreName, remoteName, e.getMessage());
throw new IOException(
String.format("Initializing collection %s (%s) failed", coreName, remoteName), e);
} finally {
PathUtils.deleteRecursive(tmp);
}
} else {
if (existingCollections.contains(remoteName)) {
log.debug("Collection {} exists in SolrCloud '{}' as {}", coreName,
config.getZkConnection(), remoteName);
scheduleCoreInit(executorService, coreDescriptor, false);
availableCores.put(coreName, coreDescriptor);
} else {
log.warn(
"Collection {} (remote: {}) not available in SolrCloud '{}' "
+ "but deployCores is set to false",
coreName, remoteName, config.getZkConnection());
}
}
}
log.info("Initialized {} collections in Solr-Cloud {}: {}", availableCores.size(),
config.getZkConnection(), availableCores);
} catch (IOException e) {
throw e;
} catch (SolrServerException e) {
log.error("Could not list existing collections: {}", e.getMessage(), e);
throw new IOException("Could not list existing collections", e);
} catch (final Exception t) {
log.error("Unexpected {} during init(): {}", t.getClass().getSimpleName(), t.getMessage(), t);
throw t;
} finally {
PathUtils.deleteRecursive(sharedLibs);
}
}