Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.rbmhtechnology.vind.solr.cmt;
import com.google.common.collect.Streams;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.InputStreamResponseParser;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.Create;
import org.apache.solr.client.solrj.request.ConfigSetAdminRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.client.solrj.response.ConfigSetAdminResponse;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.util.ClientUtils;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
;
/**
* @author Thomas Kurz ([email protected])
* @since 29.03.17.
*/
public class CollectionManagementService {
private static Logger logger = LoggerFactory.getLogger(CollectionManagementService.class);
private static final String RUNTIME_LIB_FILE_NAME = "runtimelibs.txt";
private static final int BLOB_STORE_SHARDS = 1;
private static final int BLOB_STORE_REPLICAS = 1;
private String zkHost;
private List repositories = new ArrayList<>();
public CollectionManagementService(String zkHost) throws IOException {
this(zkHost, new String[0]);
}
public CollectionManagementService(String zkHost, String ... repositories) throws IOException {
this(repositories);
this.zkHost = zkHost;
try (CloudSolrClient client = new CloudSolrClient(zkHost)) {
NamedList result = client.request(new CollectionAdminRequest.ClusterStatus());
if (((NamedList) ((NamedList) result.get("cluster")).get("collections")).get(".system") == null) {
logger.warn("Blob store '.system' for runtime libs is not yet created. Will create one");
try {
Create create = new CollectionAdminRequest.Create();
create.setCollectionName(".system");
create.setConfigName(null);
create.setNumShards(BLOB_STORE_SHARDS);
create.setReplicationFactor(BLOB_STORE_REPLICAS);
create.process(client);
logger.info("Blob store has been created successfully");
} catch (SolrServerException e1) {
throw new IOException("Blob store is not available and cannot be created");
}
}
} catch (SolrServerException | IOException e) {
logger.error("Error in collection management service: {}", e.getMessage(), e);
throw new IOException("Error in collection management service: " + e.getMessage(), e);
}
}
protected CollectionManagementService(String ... repositories) {
if(repositories != null && repositories.length > 0) {
this.repositories = Arrays.asList(repositories);
} else {
this.repositories = ConfigurationService.getInstance().getProperties().entrySet().stream().filter(e -> e.getKey().toString().startsWith("repository.")).map(e -> e.getValue().toString()).collect(Collectors.toList());
}
}
/**
* 1. Check if config set is already deployed on the solr server, if not: download from repo and upload to zK
* 2. Create collection
* 3. Check if dependencies (runtime-libs) are installed, if not download and install (and name it with group:artefact:version)
* 4. Add/Update collection runtime-libs
*
* @param collectionName {@link String} name of the collection to create.
* @param configName should be either the name of an already defined configuration in the solr cloud or the full
* name of an artifact accessible in one of the default repositories.
* @param numOfShards integer number of shards
* @param numOfReplicas integer number of replicas
* @throws {@link IOException} thrown if is not possible to create the collection.
*/
public void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas) throws IOException {
checkAndInstallConfiguration(configName);
try (CloudSolrClient client = new CloudSolrClient(zkHost)) {
Create create = new CollectionAdminRequest.Create();
create.setCollectionName(collectionName);
create.setConfigName(configName);
create.setNumShards(numOfShards);
create.setReplicationFactor(numOfReplicas);
create.process(client);
} catch (IOException | SolrServerException e) {
throw new IOException("Cannot create collection", e);
}
Map runtimeDependencies = checkAndInstallRuntimeDependencies(collectionName);
addOrUpdateRuntimeDependencies(runtimeDependencies, collectionName);
}
/**
* Checks whether a collection is already existing in the solr server.
* @param collectionName String name of the collection to check.
* @return true if the collection is already existing in the server false otherwise.
* @throws {@link IOException} is thrown when a problem with the solr request occurs.
*/
public boolean collectionExists(String collectionName) throws IOException {
try (CloudSolrClient client = new CloudSolrClient(zkHost)) {
final NamedList