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");
public String getWarning() { return (String) getResponse().get( "warning" ); }
@SuppressWarnings("unchecked") public NamedList<NamedList<Object>> getCollectionStatus() { return (NamedList<NamedList<Object>>) getResponse().get( "success" ); }
@SuppressWarnings("unchecked") public NamedList<String> getErrorMessages() { return (NamedList<String>) getResponse().get( "failure" ); }
public boolean isSuccess() { return getResponse().get( "success" ) != null; }
@SuppressWarnings("unchecked") public NamedList<NamedList<Object>> getCollectionStatus() { return (NamedList<NamedList<Object>>) getResponse().get( "success" ); }
@SuppressWarnings("unchecked") public NamedList<String> getErrorMessages() { return (NamedList<String>) getResponse().get( "failure" ); }
public boolean isSuccess() { return getResponse().get( "success" ) != null; }
@SuppressWarnings("unchecked") public Map<String, String> getAliases() { NamedList<Object> response = getResponse(); if (response.get("aliases") != null) { return ((Map<String, String>)response.get("aliases")); } return Collections.emptyMap(); }
/** * 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"); }
@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"); }
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 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); } }
protected void createCollectionRetry(String testCollectionName, String configSetName, int numShards, int replicationFactor, int maxShardsPerNode) throws SolrServerException, IOException { CollectionAdminResponse resp = createCollection(testCollectionName, configSetName, numShards, replicationFactor, maxShardsPerNode); if (resp.getResponse().get("failure") != null) { CollectionAdminRequest.Delete req = CollectionAdminRequest.deleteCollection(testCollectionName); req.process(cloudClient); resp = createCollection(testCollectionName, configSetName, numShards, replicationFactor, maxShardsPerNode); if (resp.getResponse().get("failure") != null) { fail("Could not create " + testCollectionName); } } }
/** * @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; }
@SuppressWarnings("unchecked") public ClusterStatus getClusterStatus() throws SolrFlintException { CollectionAdminResponse response = null; try { CollectionAdminRequest.ClusterStatus req = CollectionAdminRequest.getClusterStatus(); 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 null; return ClusterStatus.fromNamedList((NamedList<Object>) response.getResponse().get("cluster")); }
static RequestStatusState getRequestState(String requestId, SolrClient client) throws IOException, SolrServerException { CollectionAdminResponse response = getStatusResponse(requestId, client); NamedList innerResponse = (NamedList) response.getResponse().get("status"); return RequestStatusState.fromKey((String) innerResponse.get("state")); }
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); }