/** * Method to initialize a Solr collection using the provided default configs. * * @deprecated since 1.2.0 use {@link SolrCollectionInitializer} instead. * @param zkHost host and optional port of one of a zookeeper instance (localhost:2181) * @param collectionName name of the collection to be created * @throws IOException if something goes wrong with the upload * @throws SolrServerException if something goes wrong with the upload */ @Deprecated public static void initSolr(String zkHost, String collectionName) throws IOException, SolrServerException { try (SolrClient solr = new CloudSolrClient.Builder().withZkHost(zkHost).build()) { List<String> existingCollectionNames = CollectionAdminRequest.listCollections(solr); if (!existingCollectionNames.contains(collectionName)) { solr.request(CollectionAdminRequest.createCollection(collectionName, 1, 1)); } } } }
replicas = this.defaultReplicas; CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(name, shards <= 0 ? this.defaultShards : shards, replicas <= 0 ? this.defaultReplicas : replicas);
protected void doAccept(String collection, MiniSolrCloudCluster cluster) { try { CollectionAdminRequest .createCollection(collection, "conf", numShards, numReplicas) .setMaxShardsPerNode(maxShardsPerNode) .processAndWait(cluster.getSolrClient(), SolrCloudTestCase.DEFAULT_TIMEOUT); AbstractDistribZkTestBase.waitForRecoveriesToFinish(collection, cluster.getSolrClient().getZkStateReader(), false, true, SolrCloudTestCase.DEFAULT_TIMEOUT); } catch (Exception e) { throw new RuntimeException(e); } }
.createCollection("control_collection", 1, 1) .setCreateNodeSet(controlJetty.getNodeName()) .process(controlClient).isSuccess());
/** * Creates a SolrCloud collection if it doesn't already exist with the given config set. * * @deprecated since 1.2.0 use {@link SolrCollectionInitializer} instead. * @param zkHost host and optional port of one of a zookeeper instance (localhost:2181) * @param collectionName name of the collection to be created * @param configSetName name of the config set to use * @param configSetPath location of the config set (folder containing solr configs such as * solrconfig.xml) * @throws IOException if something goes wrong with the upload * @throws SolrServerException if something goes wrong with the upload */ @Deprecated public static void initSolr( String zkHost, String collectionName, String configSetName, Path configSetPath) throws IOException, SolrServerException { try (ZkClientClusterStateProvider provider = new ZkClientClusterStateProvider(zkHost)) { provider.uploadConfig(configSetPath, configSetName); } try (SolrClient solr = new CloudSolrClient.Builder().withZkHost(zkHost).build()) { List<String> existingCollectionNames = CollectionAdminRequest.listCollections(solr); if (!existingCollectionNames.contains(collectionName)) { solr.request(CollectionAdminRequest.createCollection(collectionName, configSetName, 1, 1)); } } }
private static void createCollection(CloudSolrClient cloudSolrClient, String collection, Path configPath) { try { LOGGER.info("Creating SOLR collection {}", collection); int numShards = getEnvInt("SOLR_NUM_SHARDS", 1); int numReplicas = getEnvInt("SOLR_REPLICATION_FACTOR", 1); cloudSolrClient.getZkStateReader().getZkClient().upConfig(configPath, collection); Create createCollection = CollectionAdminRequest.createCollection(collection, collection, numShards, numReplicas); createCollection.setMaxShardsPerNode(getEnvInt("SOLR_MAX_SHARDS_PER_NODE", 1)); createCollection.setAutoAddReplicas(getEnvBoolean("SOLR_AUTO_ADD_REPLICAS", false)); CollectionAdminResponse response = createCollection.process(cloudSolrClient); if (!response.isSuccess()) { LOGGER.error("Could not create collection {}: {}", collection, response.getErrorMessages()); } } catch (SolrServerException | SolrException | IOException e) { LOGGER.error("Error creating collection {}", collection, e); } }
} else { solrClient.request( CollectionAdminRequest.createCollection( collectionName, configsetName, shardCount, replicaCount));
/** * 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); }
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); }
.createCollection(DEFAULT_COLLECTION, "conf1", sliceCount, 1) .setStateFormat(Integer.parseInt(getStateFormat())) .setCreateNodeSet("")
@BeforeClass public static void setupCluster() throws Exception { configureCluster(2) .addConfig("conf", SOLR_CONF_DIR.toPath()) .configure(); CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 1) .processAndWait(cluster.getSolrClient(), TIMEOUT); AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTION, cluster.getSolrClient().getZkStateReader(), false, true, TIMEOUT); }
try (SolrClient client = createCloudClient("control_collection")) { assertEquals(0, CollectionAdminRequest .createCollection("control_collection", "conf1", 1, 1) .setCreateNodeSet(controlJetty.getNodeName()) .process(client).getStatus());