NamedList<Object> listResponse = new CollectionAdminRequest.List().process(primary).getResponse(); List<String> collectionNames = listResponse.get("collections") == null ? collectionNames = new ArrayList<>() : (List<String>) listResponse.get("collections"); listResponse = new CollectionAdminRequest.List().process(primary).getResponse(); collectionNames = listResponse.get("collections") == null ? collectionNames = new ArrayList<>() : (List<String>) listResponse.get("collections");
private static void bootstrap(CloudSolrClient cloudSolrClient, Path solrHome) { CollectionAdminRequest.List req = new CollectionAdminRequest.List(); try { CollectionAdminResponse response = req.process(cloudSolrClient); List<String> existingCollections = (List<String>) response.getResponse().get("collections"); if (existingCollections == null) { existingCollections = new ArrayList<>(); } Path commonConf = solrHome.resolve(SolrUtils.COMMON).resolve(SolrUtils.CONF); copyFilesFromClasspath(RodaConstants.CORE_CONFIG_FOLDER + "/" + RodaConstants.CORE_INDEX_FOLDER + "/" + SolrUtils.COMMON + "/" + SolrUtils.CONF + "/", commonConf, true); for (String collection : SolrCollectionRegistry.registryIndexNames()) { if (!existingCollections.contains(collection)) { createCollection(cloudSolrClient, collection, commonConf); } } } catch (SolrServerException | IOException e) { LOGGER.error("Solr bootstrap failed", e); } }
@SuppressWarnings("unchecked") public Collection<String> listCollections() throws SolrFlintException { CollectionAdminResponse response = null; try { CollectionAdminRequest.List req = new CollectionAdminRequest.List(); response = req.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 list Solr collections", ex); } if (response == null) return Collections.emptyList(); return (ArrayList<String>) response.getResponse().get("collections"); }
protected boolean existsCloudCollection(String name) throws IOException, SolrServerException { CollectionAdminRequest.List listRequest = new CollectionAdminRequest.List(); CollectionAdminResponse response = listRequest.process(getClient(), name); if (response.getErrorMessages() != null) { throw new DatastoreClientServiceException("Unable to fetch collection list"); } return ((ArrayList) response.getResponse().get("collections")).contains(name); }
/** * Returns a SolrRequest to get a list of collections in the cluster */ public static java.util.List<String> listCollections(SolrClient client) throws IOException, SolrServerException { CollectionAdminResponse resp = new List().process(client); return (java.util.List<String>) resp.getResponse().get("collections"); }