Java Code Examples for org.apache.solr.client.solrj.request.CollectionAdminRequest#List

The following examples show how to use org.apache.solr.client.solrj.request.CollectionAdminRequest#List . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListCollectionHandler.java    From ambari-logsearch with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public List<String> handle(CloudSolrClient solrClient, SolrPropsConfig solrPropsConfig) throws Exception {
  try {
    CollectionAdminRequest.List colListReq = new CollectionAdminRequest.List();
    CollectionAdminResponse response = colListReq.process(solrClient);
    if (response.getStatus() != 0) {
      logger.error("Error getting collection list from solr.  response=" + response);
      return null;
    }
    return (List<String>) response.getResponse().get("collections");
  } catch (SolrException e) {
    logger.error("getCollections() operation failed", e);
    return new ArrayList<>();
  }
}
 
Example 2
Source File: TestCloudSolrClientConnections.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testCloudClientCanConnectAfterClusterComesUp() throws Exception {

  // Start by creating a cluster with no jetties
  MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(0, createTempDir(), buildJettyConfig("/solr"));
  try {

    CloudSolrClient client = cluster.getSolrClient();
    CollectionAdminRequest.List listReq = new CollectionAdminRequest.List();

    SolrException e = expectThrows(SolrException.class, () -> client.request(listReq));
    assertTrue("Unexpected message: " + e.getMessage(), e.getMessage().contains("cluster not found/not ready"));

    cluster.startJettySolrRunner();
    cluster.waitForAllNodes(30);
    client.connect(20, TimeUnit.SECONDS);

    // should work now!
    client.request(listReq);

  }
  finally {
    cluster.shutdown();
  }

}
 
Example 3
Source File: ServiceSolrClient.java    From ranger with Apache License 2.0 6 votes vote down vote up
public List<String> getCollectionList(List<String> ignoreCollectionList)
		throws Exception {
	if (!isSolrCloud) {
		return getCoresList(ignoreCollectionList);
	}

	CollectionAdminRequest<?> request = new CollectionAdminRequest.List();
	String decPassword = getDecryptedPassword();
       if (username != null && decPassword != null) {
	    request.setBasicAuthCredentials(username, decPassword);
	}
	SolrResponse response = request.process(solrClient);

	List<String> list = new ArrayList<String>();
	List<String> responseCollectionList = (ArrayList<String>)response.getResponse().get("collections");
	if(CollectionUtils.isEmpty(responseCollectionList)) {
		return list;
	}
	for (String responseCollection : responseCollectionList) {
		if (ignoreCollectionList == null
				|| !ignoreCollectionList.contains(responseCollection)) {
			list.add(responseCollection);
		}
	}
	return list;
}
 
Example 4
Source File: TestDelegationWithHadoopAuth.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
private SolrRequest getAdminRequest(final SolrParams params) {
  return new CollectionAdminRequest.List() {
    @Override
    public SolrParams getParams() {
      ModifiableSolrParams p = new ModifiableSolrParams(super.getParams());
      p.add(params);
      return p;
    }
  };
}
 
Example 5
Source File: ImpersonationUtil.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
static SolrRequest getProxyRequest(String user, String doAs) {
  return new CollectionAdminRequest.List() {
    @Override
    public SolrParams getParams() {
      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
      params.set(PseudoAuthenticator.USER_NAME, user);
      params.set(KerberosPlugin.IMPERSONATOR_DO_AS_HTTP_PARAM, doAs);
      return params;
    }
  };
}
 
Example 6
Source File: TestSolrCloudWithSecureImpersonation.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
private SolrRequest getProxyRequest(String user, String doAs, String remoteHost, String remoteAddress) {
  return new CollectionAdminRequest.List() {
    @Override
    public SolrParams getParams() {
      ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
      params.set(USER_PARAM, user);
      params.set(KerberosPlugin.IMPERSONATOR_DO_AS_HTTP_PARAM, doAs);
      if (remoteHost != null) params.set(REMOTE_HOST_PARAM, remoteHost);
      if (remoteAddress != null) params.set(REMOTE_ADDRESS_PARAM, remoteAddress);
      return params;
    }
  };
}
 
Example 7
Source File: TestSolrCloudWithDelegationTokens.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
private SolrRequest getAdminRequest(final SolrParams params) {
  return new CollectionAdminRequest.List() {
    @Override
    public SolrParams getParams() {
      ModifiableSolrParams p = new ModifiableSolrParams(super.getParams());
      p.add(params);
      return p;
    }
  };
}
 
Example 8
Source File: CollectionAdminRequestRequiredParamsTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void testListCollections() {
  final CollectionAdminRequest.List request = new CollectionAdminRequest.List();
  assertContainsParams(request.getParams(), ACTION);
}