/** * Creates a new core, associated with a collection, in Solr. */ public void createCore(String coreName, String collectionName, String configName, int numShards) throws IOException { createCore(coreName, collectionName, configName, numShards, null); }
public void start() throws Exception { // Make the Solr home directory this.tmpDir = Files.createTempDir(); this.solrHomeDir = new File(tmpDir, "home"); if (!this.solrHomeDir.mkdir()) { throw new RuntimeException("Failed to create directory " + this.solrHomeDir.getAbsolutePath()); } writeSolrXml(); // Set required system properties System.setProperty("solr.solr.home", solrHomeDir.getAbsolutePath()); System.setProperty("zkHost", zkConnectString); System.setProperty("solr.port", Integer.toString(solrPort)); for (Entry<String, String> entry : configProperties.entrySet()) { System.setProperty(entry.getKey().toString(), entry.getValue()); } jettySolrRunner = createServer(); jettySolrRunner.start(); }
/** * Create a Solr collection with a given number of shards. * * @param collectionName name of the collection to be created * @param configName name of the config for the collection * @param numShards number of shards in the collection */ public void createCollection(String collectionName, String configName, int numShards) throws IOException { int TIMEOUT = 30; // seconds CloudSolrClient solrClient = new CloudSolrClient.Builder().withZkHost(getZkConnectString()).build(); solrClient.setDefaultCollection(collectionName); CollectionAdminRequest.Create request = CollectionAdminRequest.createCollection( collectionName, configName, numShards, 1); request.setMaxShardsPerNode(numShards); RequestStatusState state; try { state = request.processAndWait(solrClient, TIMEOUT); } catch (SolrServerException | InterruptedException e) { throw new RuntimeException(e); } if (state != RequestStatusState.COMPLETED && state != RequestStatusState.RUNNING) { throw new IllegalStateException("Unexpected state: " + state); } waitForRecoveriesToFinish( collectionName, solrClient.getZkStateReader(), true, true, TIMEOUT); }
/** * Utility method to upload a Solr config into ZooKeeper. This method only allows to supply schema and * solrconf, if you want to upload a full directory use {@link #uploadConfig(String, File)}. */ public void uploadConfig(String confName, byte[] schema, byte[] solrconf) throws IOException { // Write schema & solrconf to temporary dir, upload dir, delete tmp dir File tmpConfDir = Files.createTempDir(); Files.copy(ByteStreams.newInputStreamSupplier(schema), new File(tmpConfDir, "schema.xml")); Files.copy(ByteStreams.newInputStreamSupplier(solrconf), new File(tmpConfDir, "solrconfig.xml")); uploadConfig(confName, tmpConfDir); FileUtils.deleteDirectory(tmpConfDir); }
public void start() throws Exception { // Make the Solr home directory this.tmpDir = Files.createTempDir(); this.solrHomeDir = new File(tmpDir, "home"); if (!this.solrHomeDir.mkdir()) { throw new RuntimeException("Failed to create directory " + this.solrHomeDir.getAbsolutePath()); } writeSolrXml(); // Set required system properties System.setProperty("solr.solr.home", solrHomeDir.getAbsolutePath()); System.setProperty("zkHost", zkConnectString); System.setProperty("solr.port", Integer.toString(solrPort)); for (Entry<String, String> entry : configProperties.entrySet()) { System.setProperty(entry.getKey().toString(), entry.getValue()); } jettySolrRunner = createServer(); jettySolrRunner.start(); }
/** * Utility method to upload a Solr config into ZooKeeper. This method only allows to supply schema and * solrconf, if you want to upload a full directory use {@link #uploadConfig(String, File)}. */ public void uploadConfig(String confName, byte[] schema, byte[] solrconf) throws IOException { // Write schema & solrconf to temporary dir, upload dir, delete tmp dir File tmpConfDir = Files.createTempDir(); Files.copy(ByteStreams.newInputStreamSupplier(schema), new File(tmpConfDir, "managed-schema")); Files.copy(ByteStreams.newInputStreamSupplier(solrconf), new File(tmpConfDir, "solrconfig.xml")); uploadConfig(confName, tmpConfDir); FileUtils.deleteDirectory(tmpConfDir); }
/** * Create a Solr collection with a given number of shards. * * @param collectionName name of the collection to be created * @param configName name of the config for the collection * @param numShards number of shards in the collection */ public void createCollection(String collectionName, String configName, int numShards) throws IOException { for (int shardIndex = 0; shardIndex < numShards; shardIndex++) { String coreName = String.format("%s_shard%d", collectionName, shardIndex + 1); createCore(coreName, collectionName, configName, numShards, coreName + "_data"); } }