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); }
protected void createCollectionIfNotExist(CloudSolrClient client, String collectionName) { Set<String> collectionNames = client.getZkStateReader().getClusterState().getCollections(); if (!collectionNames.contains(collectionName)) { try { new CollectionAdminRequest.Create().setCollectionName(collectionName).setNumShards(getSolrCloudNumShards()) .setMaxShardsPerNode(getSolrCloudNumShards()).setConfigName(getSolrCloudConfigName()).process(client); } catch (SolrServerException e) { throw ExceptionHelper.refineException(e); } catch (IOException e) { throw ExceptionHelper.refineException(e); } } }
String m = atts.remove(MAX_SHARDS_PER_NODE); try { create.setMaxShardsPerNode(Integer.parseInt(m)); } catch (NumberFormatException ex) { LOGGER.error("Ignoring invalid max shards per node {} for collection {}", m, name);
/** * 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); }
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); CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create(); createRequest.setConfigName(collection); 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); }
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); CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create(); createRequest.setConfigName(collection); 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); }
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); } }
static void createCollection( String collection, int numShards, int replicationFactor, AuthorizedSolrClient client) throws Exception { CollectionAdminRequest.Create create = new CollectionAdminRequest.Create() .setCollectionName(collection) .setNumShards(numShards) .setReplicationFactor(replicationFactor) .setMaxShardsPerNode(2); client.process(create); }
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); } }