Java Code Examples for org.apache.solr.client.solrj.response.CollectionAdminResponse#getCollectionCoresStatus()

The following examples show how to use org.apache.solr.client.solrj.response.CollectionAdminResponse#getCollectionCoresStatus() . 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: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * When a config name is not specified during collection creation, the _default should
 * be used.
 */
@Test
public void testCreateWithDefaultConfigSet() throws Exception {
  String collectionName = "solrj_default_configset";
  CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, 2, 2)
      .process(cluster.getSolrClient());
  
  cluster.waitForActiveCollection(collectionName, 2, 4);

  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
  assertEquals(4, coresStatus.size());
  for (String coreName : coresStatus.keySet()) {
    NamedList<Integer> status = coresStatus.get(coreName);
    assertEquals(0, (int)status.get("status"));
    assertTrue(status.get("QTime") > 0);
  }
  // Use of _default configset should generate a warning for data-driven functionality in production use
  assertTrue(response.getWarning() != null && response.getWarning().contains("NOT RECOMMENDED for production use"));

  response = CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  Map<String,NamedList<Integer>> nodesStatus = response.getCollectionNodesStatus();
  assertEquals(4, nodesStatus.size());

  waitForState("Expected " + collectionName + " to disappear from cluster state", collectionName, (n, c) -> c == null);
}
 
Example 2
Source File: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateAndDeleteCollection() throws Exception {
  String collectionName = "solrj_test";
  CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2)
      .process(cluster.getSolrClient());

  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
  assertEquals(4, coresStatus.size());
  for (String coreName : coresStatus.keySet()) {
    NamedList<Integer> status = coresStatus.get(coreName);
    assertEquals(0, (int)status.get("status"));
    assertTrue(status.get("QTime") > 0);
  }

  response = CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());

  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  Map<String,NamedList<Integer>> nodesStatus = response.getCollectionNodesStatus();
  assertEquals(4, nodesStatus.size());

  waitForState("Expected " + collectionName + " to disappear from cluster state", collectionName, (n, c) -> c == null);

  // Test Creating a new collection.
  collectionName = "solrj_test2";

  response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2)
      .process(cluster.getSolrClient());
  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());

  waitForState("Expected " + collectionName + " to appear in cluster state", collectionName, (n, c) -> c != null);
}
 
Example 3
Source File: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-13021")
public void testCreateAndDeleteShard() throws Exception {
  // Create an implicit collection
  String collectionName = "solrj_implicit";
  CollectionAdminResponse response
      = CollectionAdminRequest.createCollectionWithImplicitRouter(collectionName, "conf", "shardA,shardB", 1, 1, 1)
      .setMaxShardsPerNode(3)
      .process(cluster.getSolrClient());

  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  
  cluster.waitForActiveCollection(collectionName, 2, 6);
  
  Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
  assertEquals(6, coresStatus.size());

  // Add a shard to the implicit collection
  response = CollectionAdminRequest.createShard(collectionName, "shardC").process(cluster.getSolrClient());

  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  
  cluster.getSolrClient().waitForState(collectionName, 30, TimeUnit.SECONDS, (l,c) -> c != null && c.getSlice("shardC") != null); 
  
  coresStatus = response.getCollectionCoresStatus();
  assertEquals(3, coresStatus.size());
  int replicaTlog = 0;
  int replicaNrt = 0;
  int replicaPull = 0;
  for (String coreName : coresStatus.keySet()) {
    assertEquals(0, (int) coresStatus.get(coreName).get("status"));
    if (coreName.contains("shardC_replica_t")) replicaTlog++;
    else if (coreName.contains("shardC_replica_n")) replicaNrt++;
    else replicaPull++;
  }
  assertEquals(1, replicaNrt);
  assertEquals(1, replicaTlog);
  assertEquals(1, replicaPull);

  response = CollectionAdminRequest.deleteShard(collectionName, "shardC").process(cluster.getSolrClient());

  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  Map<String, NamedList<Integer>> nodesStatus = response.getCollectionNodesStatus();
  assertEquals(1, nodesStatus.size());
}
 
Example 4
Source File: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testSplitShard() throws Exception {

  final String collectionName = "solrj_test_splitshard";
  CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1)
      .process(cluster.getSolrClient());

  cluster.waitForActiveCollection(collectionName, 2, 2);
  
  CollectionAdminResponse response = CollectionAdminRequest.splitShard(collectionName)
      .setShardName("shard1")
      .process(cluster.getSolrClient());

  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
  int shard10 = 0;
  int shard11 = 0;
  for (String coreName : coresStatus.keySet()) {
    assertEquals(0, (int) coresStatus.get(coreName).get("status"));
    if (coreName.contains("_shard1_0")) shard10++;
    else shard11++;
  }
  assertEquals(1, shard10);
  assertEquals(1, shard11);

  waitForState("Expected all shards to be active and parent shard to be removed", collectionName, (n, c) -> {
    if (c.getSlice("shard1").getState() == Slice.State.ACTIVE)
      return false;
    for (Replica r : c.getReplicas()) {
      if (r.isActive(n) == false)
        return false;
    }
    return true;
  });

  // Test splitting using split.key
  response = CollectionAdminRequest.splitShard(collectionName)
      .setSplitKey("b!")
      .process(cluster.getSolrClient());

  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());

  waitForState("Expected 5 slices to be active", collectionName, (n, c) -> c.getActiveSlices().size() == 5);

}
 
Example 5
Source File: CollectionsAPISolrJTest.java    From lucene-solr with Apache License 2.0 3 votes vote down vote up
@Test
public void testCreateCollectionWithPropertyParam() throws Exception {

  String collectionName = "solrj_test_core_props";

  Path tmpDir = createTempDir("testPropertyParamsForCreate");
  Path dataDir = tmpDir.resolve("dataDir-" + TestUtil.randomSimpleString(random(), 1, 5));
  Path ulogDir = tmpDir.resolve("ulogDir-" + TestUtil.randomSimpleString(random(), 1, 5));
  cluster.getJettySolrRunners().forEach(j -> j.getCoreContainer().getAllowPaths().add(tmpDir));

  CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1)
      .withProperty(CoreAdminParams.DATA_DIR, dataDir.toString())
      .withProperty(CoreAdminParams.ULOG_DIR, ulogDir.toString())
      .process(cluster.getSolrClient());

  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());
  
  cluster.waitForActiveCollection(collectionName, 1, 1);
  
  Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
  assertEquals(1, coresStatus.size());

  DocCollection testCollection = getCollectionState(collectionName);

  Replica replica1 = testCollection.getReplicas().iterator().next();
  CoreStatus coreStatus = getCoreStatus(replica1);

  assertEquals(Paths.get(coreStatus.getDataDirectory()).toString(), dataDir.toString());

}