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

The following examples show how to use org.apache.solr.client.solrj.request.CollectionAdminRequest#ClusterStatus . 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: UsingSolrJRefGuideExamplesTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void otherSolrApisExample() throws Exception {
  expectLine("Found "+NUM_LIVE_NODES+" live nodes");
  // tag::solrj-other-apis[]
  final SolrClient client = getSolrClient();

  @SuppressWarnings({"rawtypes"})
  final SolrRequest request = new CollectionAdminRequest.ClusterStatus();

  final NamedList<Object> response = client.request(request);
  @SuppressWarnings({"unchecked"})
  final NamedList<Object> cluster = (NamedList<Object>) response.get("cluster");
  @SuppressWarnings({"unchecked"})
  final List<String> liveNodes = (List<String>) cluster.get("live_nodes");

  print("Found " + liveNodes.size() + " live nodes");
  // end::solrj-other-apis[]
}
 
Example 2
Source File: CollectionAdminRequestRequiredParamsTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testClusterStatus() {
  final CollectionAdminRequest.ClusterStatus request = CollectionAdminRequest.getClusterStatus();
  assertContainsParams(request.getParams(), ACTION);

  request.setCollectionName("foo");
  assertContainsParams(request.getParams(), ACTION, COLLECTION);
  
  request.setShardName("foo");
  assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD);

  request.setRouteKey("foo");
  request.setShardName(null);
  assertContainsParams(request.getParams(), ACTION, COLLECTION, ShardParams._ROUTE_);
  
}
 
Example 3
Source File: SolrCLI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private static boolean runningSolrIsCloud(String url) throws Exception {
  try (final HttpSolrClient client = new HttpSolrClient.Builder(url).build()) {
    final SolrRequest<CollectionAdminResponse> request = new CollectionAdminRequest.ClusterStatus();
    final CollectionAdminResponse response = request.process(client);
    return response != null;
  } catch (Exception e) {
    if (exceptionIsAuthRelated(e)) {
      throw e;
    }
    return false;
  }
}
 
Example 4
Source File: TestCollectionAPI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void testNoConfigset() throws Exception {
  String configSet = "delete_config";

  final String collection = "deleted_collection";
  try (CloudSolrClient client = createCloudClient(null)) {
    copyConfigUp(TEST_PATH().resolve("configsets"), "cloud-minimal", configSet, client.getZkHost());

    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("action", CollectionParams.CollectionAction.CREATE.toString());
    params.set("name", collection);
    params.set("numShards", "1");
    params.set("replicationFactor", "1");
    params.set("collection.configName", configSet);
    @SuppressWarnings({"rawtypes"})
    SolrRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");

    client.request(request);

    waitForCollection(cloudClient.getZkStateReader(), collection, 1);
    waitForRecoveriesToFinish(collection, false);

    // Now try deleting the configset and doing a clusterstatus.
    String parent = ZkConfigManager.CONFIGS_ZKNODE + "/" + configSet;
    deleteThemAll(client.getZkStateReader().getZkClient(), parent);
    client.getZkStateReader().forciblyRefreshAllClusterStateSlow();

    final CollectionAdminRequest.ClusterStatus req = CollectionAdminRequest.getClusterStatus();
    NamedList<Object> rsp = client.request(req);
    @SuppressWarnings({"unchecked"})
    NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
    assertNotNull("Cluster state should not be null", cluster);
    @SuppressWarnings({"unchecked"})
    NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
    assertNotNull("Collections should not be null in cluster state", collections);
    assertNotNull("Testing to insure collections are returned", collections.get(COLLECTION_NAME1));
  }
}
 
Example 5
Source File: TestCollectionAPI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void clusterStatusWithCollectionAndMultipleShards() throws IOException, SolrServerException {
  try (CloudSolrClient client = createCloudClient(null)) {
    final CollectionAdminRequest.ClusterStatus request = new CollectionAdminRequest.ClusterStatus();
    request.setCollectionName(COLLECTION_NAME);
    request.setShardName(SHARD1 + "," + SHARD2);

    NamedList<Object> rsp = request.process(client).getResponse();
    @SuppressWarnings({"unchecked"})
    NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
    assertNotNull("Cluster state should not be null", cluster);
    @SuppressWarnings({"unchecked"})
    NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
    assertNotNull("Collections should not be null in cluster state", collections);
    assertNotNull(collections.get(COLLECTION_NAME));
    assertEquals(1, collections.size());
    @SuppressWarnings({"unchecked"})
    Map<String, Object> collection = (Map<String, Object>) collections.get(COLLECTION_NAME);
    @SuppressWarnings({"unchecked"})
    Map<String, Object> shardStatus = (Map<String, Object>) collection.get("shards");
    assertEquals(2, shardStatus.size());
    @SuppressWarnings({"unchecked"})
    Map<String, Object> firstSelectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD1);
    assertNotNull(firstSelectedShardStatus);
    @SuppressWarnings({"unchecked"})
    Map<String, Object> secondSelectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD2);
    assertNotNull(secondSelectedShardStatus);
  }
}