/** * Returns a SolrRequest to add a replica of type {@link org.apache.solr.common.cloud.Replica.Type#NRT} to a shard in a collection * */ public static AddReplica addReplicaToShard(String collection, String shard) { return addReplicaToShard(collection, shard, Replica.Type.NRT); }
/** * Logs a WARN if collection can't be deleted, but does not fail or throw an exception * @return true if success, else false */ protected static boolean attemptCollectionDelete(CloudSolrClient client, String collectionName) { // try to clean up try { CollectionAdminRequest.deleteCollection(collectionName).process(client); return true; } catch (Exception e) { // don't fail the test log.warn("Could not delete collection {} - ignoring", collectionName); } return false; }
@Override public SolrParams getParams() { ModifiableSolrParams params = (ModifiableSolrParams) super.getParams(); params.set(CoreAdminParams.REQUESTID, requestId); return params; }
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); } }
/** * 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)); } } } }
new CloudSolrClient.Builder(zkHosts, Optional.ofNullable(chroot)).build(); List<String> existingCollectionNames = CollectionAdminRequest.listCollections(solrClient); solrClient.request(CollectionAdminRequest.reloadCollection(collectionName)); } else { solrClient.request( CollectionAdminRequest.createCollection( collectionName, configsetName, shardCount, replicaCount));
replicas = this.defaultReplicas; CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(name, shards <= 0 ? this.defaultShards : shards, replicas <= 0 ? this.defaultReplicas : replicas); LOGGER.info("Solr collection {} already exists - reloading it", name); try { response = CollectionAdminRequest.reloadCollection(name).process(this._solr); } catch (RemoteSolrException | SolrServerException | IOException ex) { if (ex.getCause() != null && ex.getCause() instanceof ConnectException) throw new SolrFlintException(true);
.createCollection(DEFAULT_COLLECTION, "conf1", sliceCount, 1) .setStateFormat(Integer.parseInt(getStateFormat())) .setCreateNodeSet("") + cnt) : null, null, "solrconfig.xml", null, Replica.Type.TLOG); response = CollectionAdminRequest .addReplicaToShard(DEFAULT_COLLECTION, "shard"+((i%sliceCount)+1)) .setNode(j.getNodeName()) .setType(Replica.Type.TLOG) + cnt) : null, null, "solrconfig.xml", null, null); response = CollectionAdminRequest .addReplicaToShard(DEFAULT_COLLECTION, "shard"+((i%sliceCount)+1)) .setNode(j.getNodeName()) .setType(Replica.Type.NRT) + cnt) : null, null, "solrconfig.xml", null, Replica.Type.PULL); response = CollectionAdminRequest .addReplicaToShard(DEFAULT_COLLECTION, "shard"+((i%sliceCount)+1)) .setNode(j.getNodeName()) .setType(Replica.Type.PULL)
@Override public void writeMap(EntryWriter ew) throws IOException { ew.put("class", this.getClass().getName()); ew.put("method", getMethod().toString()); SolrParams params = getParams(); if (params != null) { for (Iterator<String> it = params.getParameterNamesIterator(); it.hasNext(); ) { final String name = it.next(); final String [] values = params.getParams(name); for (String value : values) { ew.put("params." + name, value); } } } }
public static void waitForAsyncRequest(String requestId, SolrClient client, long timeout) throws SolrServerException, InterruptedException, IOException { requestStatus(requestId).waitFor(client, timeout); }
private List<String> fetchCloudCores() { SolrClient client = getQueryingSolrClient(); CollectionAdminRequest request = new CollectionAdminRequest.List(); List<String> collections = null; try { CollectionAdminResponse response = (CollectionAdminResponse) request.process(client); if (response != null) { collections = (List) response.getResponse().get("collections"); if (LOG.isDebugEnabled()) { for (String collection : collections) { LOG.debug("Fetched Collection '{}' of Solr Cloud", collection); } } } } catch (SolrServerException e) { LOG.error("Error fetching Cloud Cores.", e); } catch (IOException e) { LOG.error("Error fetching Cloud Cores.", e); } return collections; }
private String getCollections(List<String> indices) throws IOException, SolrServerException { List<String> existingCollections = CollectionAdminRequest.listCollections(client); return indices.stream().filter(existingCollections::contains).collect(Collectors.joining(",")); }
.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)); } } }
static CollectionAdminResponse getStatusResponse(String requestId, SolrClient client) throws SolrServerException, IOException { return CollectionAdminRequest.requestStatus(requestId).process(client); }
@Override public StatusResult getBackendStatus() { int statusCode = -1; try { if(SearchConfiguration.get(SearchConfiguration.SERVER_SOLR_CLOUD, false)) { CollectionAdminRequest request = new CollectionAdminRequest.ClusterStatus(); SolrResponse response = request.process(this.solrClient); statusCode = Integer.valueOf(((NamedList)response.getResponse().get("responseHeader")).get("status").toString()); } else { CoreAdminRequest request = new CoreAdminRequest(); request.setAction(CoreAdminParams.CoreAdminAction.STATUS); CoreAdminResponse response = request.process(this.solrClient); statusCode = response.getStatus(); } if(statusCode != 0) { return StatusResult.down().setDetail("status", statusCode); } else { return StatusResult.up().setDetail("status", statusCode); } } catch (SolrServerException | IOException e) { log.error("Cannot ping server"); throw new SearchServerException("Cannot ping server", e); } }
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); } }
@Override public SolrParams getParams() { ModifiableSolrParams params = (ModifiableSolrParams) super.getParams(); params.set(CoreAdminParams.REQUESTID, requestId); return params; }
/** * @param name the name of core * @return the status whether it exists * @throws SolrFlintException */ public boolean deleteCollection(String name) throws SolrFlintException { CollectionAdminResponse response = null; try { response = CollectionAdminRequest.deleteCollection(name).process(this._solr); } catch (RemoteSolrException | SolrServerException | IOException ex) { if (ex.getCause() != null && ex.getCause() instanceof ConnectException) throw new SolrFlintException(true); throw new SolrFlintException("Failed to delete collection " + name, ex); } return response.getResponse().get("success") != null; }
this.session = bestNode.session; return CollectionAdminRequest .addReplicaToShard(shard.first(), shard.second()) .setType(type) .setNode(bestNode.node);