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

The following examples show how to use org.apache.solr.client.solrj.request.CollectionAdminRequest#Delete . 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: DistribJoinFromCollectionTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void shutdown() {
  log.info("DistribJoinFromCollectionTest logic complete ... deleting the {} and {} collections", toColl, fromColl);

  // try to clean up
  for (String c : new String[]{ toColl, fromColl }) {
    try {
      CollectionAdminRequest.Delete req =  CollectionAdminRequest.deleteCollection(c);
      req.process(cluster.getSolrClient());
    } catch (Exception e) {
      // don't fail the test
      log.warn("Could not delete collection {} after test completed due to:", c, e);
    }
  }

  log.info("DistribJoinFromCollectionTest succeeded ... shutting down now!");
}
 
Example 2
Source File: CollectionManagementService.java    From vind with Apache License 2.0 5 votes vote down vote up
protected void removeCollection(String collectionName) throws IOException {
    final CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collectionName);

    try (CloudSolrClient client = createCloudSolrClient()) {
        delete.process(client);
    } catch (SolrServerException |IOException e) {
        throw new IOException("Error during solr request: Cannot delete collection " + collectionName, e);
    }
}
 
Example 3
Source File: AbstractFullDistribZkTestBase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void createCollectionRetry(String testCollectionName, String configSetName, int numShards, int replicationFactor, int maxShardsPerNode)
    throws SolrServerException, IOException, InterruptedException, TimeoutException {
  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);
    }
  }
}
 
Example 4
Source File: TestSolrCloudWithHadoopAuthPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void testCollectionCreateSearchDelete() throws Exception {
  CloudSolrClient solrClient = cluster.getSolrClient();
  String collectionName = "testkerberoscollection";

  // create collection
  CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, "conf1",
      NUM_SHARDS, REPLICATION_FACTOR);
  create.process(solrClient);
  // The metrics counter for wrong credentials here really just means  
  assertAuthMetricsMinimums(6, 3, 0, 3, 0, 0);

  SolrInputDocument doc = new SolrInputDocument();
  doc.setField("id", "1");
  solrClient.add(collectionName, doc);
  solrClient.commit(collectionName);
  assertAuthMetricsMinimums(10, 5, 0, 5, 0, 0);

  SolrQuery query = new SolrQuery();
  query.setQuery("*:*");
  QueryResponse rsp = solrClient.query(collectionName, query);
  assertEquals(1, rsp.getResults().getNumFound());

  CollectionAdminRequest.Delete deleteReq = CollectionAdminRequest.deleteCollection(collectionName);
  deleteReq.process(solrClient);
  AbstractDistribZkTestBase.waitForCollectionToDisappear(collectionName,
      solrClient.getZkStateReader(), true, 330);
  assertAuthMetricsMinimums(14, 8, 0, 6, 0, 0);
}
 
Example 5
Source File: ConcurrentDeleteAndCreateCollectionTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void deleteCollection() {
  try {
    final CollectionAdminRequest.Delete deleteCollectionRequest
      = CollectionAdminRequest.deleteCollection(collectionName);
    final CollectionAdminResponse response = deleteCollectionRequest.process(solrClient);
    if (response.getStatus() != 0) {
      addFailure(new RuntimeException("failed to delete collection " + collectionName));
    }
  } catch (Exception e) {
    addFailure(e);
  }
}
 
Example 6
Source File: TestSimLargeCluster.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLargeSimCollections() throws Exception {
  SolrClient solrClient = cluster.simGetSolrClient();

  final int numCollections = atLeast(5);
  for (int i = 0; i < numCollections; i++) {
    // wide and shallow, or deep and narrow...
    final int numShards = TestUtil.nextInt(random(), 5, 20);
    final int nReps = TestUtil.nextInt(random(), 2, 25 - numShards);
    final int tReps = TestUtil.nextInt(random(), 2, 25 - numShards);
    final int pReps = TestUtil.nextInt(random(), 2, 25 - numShards);
    final int repsPerShard = (nReps + tReps + pReps);
    final int totalCores = repsPerShard * numShards;
    final int maxShardsPerNode = atLeast(2) + (totalCores / NUM_NODES);
    final String name = "large_sim_collection" + i;
    
    final CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection
      (name, "conf", numShards, nReps, tReps, pReps);
    create.setMaxShardsPerNode(maxShardsPerNode);
    create.setAutoAddReplicas(false);
    
    log.info("CREATE: {}", create);
    create.process(solrClient);

    // Since our current goal is to try and find situations where cores are just flat out missing
    // no matter how long we wait, let's be excessive and generous in our timeout.
    // (REMINDER: this uses the cluster's timesource, and ADDREPLICA has a hardcoded delay of 500ms)
    CloudUtil.waitForState(cluster, name, 2 * totalCores, TimeUnit.SECONDS,
        CloudUtil.clusterShape(numShards, repsPerShard, false, true));
    
    final CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(name);
    log.info("DELETE: {}", delete);
    delete.process(solrClient);
  }
}
 
Example 7
Source File: QuerySolrIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void teardown() {
    try {
        CloudSolrClient solrClient = createSolrClient();
        CollectionAdminRequest.Delete deleteCollection = CollectionAdminRequest.deleteCollection(SOLR_COLLECTION);
        deleteCollection.process(solrClient);
        solrClient.close();
    } catch (Exception e) {
    }
}
 
Example 8
Source File: CollectionAdminRequestRequiredParamsTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void testDeleteCollection() {
  final CollectionAdminRequest.Delete request = CollectionAdminRequest.deleteCollection("collection");
  assertContainsParams(request.getParams(), ACTION, NAME);
}
 
Example 9
Source File: AliasIntegrationTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteOneOfTwoCollectionsAliased() throws Exception {
  CollectionAdminRequest.createCollection("collection_one", "conf", 2, 1).process(cluster.getSolrClient());
  CollectionAdminRequest.createCollection("collection_two", "conf", 1, 1).process(cluster.getSolrClient());

  cluster.waitForActiveCollection("collection_one", 2, 2);
  cluster.waitForActiveCollection("collection_two", 1, 1);

  waitForState("Expected collection_one to be created with 2 shards and 1 replica", "collection_one", clusterShape(2, 2));
  waitForState("Expected collection_two to be created with 1 shard and 1 replica", "collection_two", clusterShape(1, 1));

  new UpdateRequest()
      .add("id", "1", "a_t", "humpty dumpy sat on a wall")
      .commit(cluster.getSolrClient(), "collection_one");


  new UpdateRequest()
      .add("id", "10", "a_t", "humpty dumpy sat on a high wall")
      .add("id", "11", "a_t", "humpty dumpy sat on a low wall")
      .commit(cluster.getSolrClient(), "collection_two");

  ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader();
  int lastVersion = zkStateReader.aliasesManager.getAliases().getZNodeVersion();

  // Create an alias pointing to both
  CollectionAdminRequest.createAlias("collection_alias_pair", "collection_one,collection_two").process(cluster.getSolrClient());
  lastVersion = waitForAliasesUpdate(lastVersion, zkStateReader);

  QueryResponse res = cluster.getSolrClient().query("collection_alias_pair", new SolrQuery("*:*"));
  assertEquals(3, res.getResults().getNumFound());

  // Now delete one of the collections, should fail since an alias points to it.
  RequestStatusState delResp = CollectionAdminRequest.deleteCollection("collection_one").processAndWait(cluster.getSolrClient(), 60);
  // failed because the collection is a part of a compound alias
  assertEquals("Should have failed to delete collection: ", delResp, RequestStatusState.FAILED);

  CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection("collection_alias_pair");
  delResp = delete.processAndWait(cluster.getSolrClient(), 60);
  // failed because we tried to delete an alias with followAliases=false
  assertEquals("Should have failed to delete alias: ", delResp, RequestStatusState.FAILED);

  delete.setFollowAliases(true);
  delResp = delete.processAndWait(cluster.getSolrClient(), 60);
  // failed because we tried to delete compound alias
  assertEquals("Should have failed to delete collection: ", delResp, RequestStatusState.FAILED);

  CollectionAdminRequest.createAlias("collection_alias_one", "collection_one").process(cluster.getSolrClient());
  lastVersion = waitForAliasesUpdate(lastVersion, zkStateReader);

  delete = CollectionAdminRequest.deleteCollection("collection_one");
  delResp = delete.processAndWait(cluster.getSolrClient(), 60);
  // failed because we tried to delete collection referenced by multiple aliases
  assertEquals("Should have failed to delete collection: ", delResp, RequestStatusState.FAILED);

  delete = CollectionAdminRequest.deleteCollection("collection_alias_one");
  delete.setFollowAliases(true);
  delResp = delete.processAndWait(cluster.getSolrClient(), 60);
  // failed because we tried to delete collection referenced by multiple aliases
  assertEquals("Should have failed to delete collection: ", delResp, RequestStatusState.FAILED);

  CollectionAdminRequest.deleteAlias("collection_alias_one").process(cluster.getSolrClient());
  lastVersion = waitForAliasesUpdate(lastVersion, zkStateReader);

  // Now redefine the alias to only point to collection two
  CollectionAdminRequest.createAlias("collection_alias_pair", "collection_two").process(cluster.getSolrClient());
  lastVersion = waitForAliasesUpdate(lastVersion, zkStateReader);

  //Delete collection_one.
  delResp = CollectionAdminRequest.deleteCollection("collection_one").processAndWait(cluster.getSolrClient(), 60);

  assertEquals("Should not have failed to delete collection, it was removed from the alias: ", delResp, RequestStatusState.COMPLETED);

  // Should only see two docs now in second collection
  res = cluster.getSolrClient().query("collection_alias_pair", new SolrQuery("*:*"));
  assertEquals(2, res.getResults().getNumFound());

  // We shouldn't be able to ping the deleted collection directly as
  // was deleted (and, assuming that it only points to collection_old).
  try {
    cluster.getSolrClient().query("collection_one", new SolrQuery("*:*"));
    fail("should have failed");
  } catch (SolrServerException | SolrException se) {

  }

  // Clean up
  CollectionAdminRequest.deleteAlias("collection_alias_pair").processAndWait(cluster.getSolrClient(), 60);
  CollectionAdminRequest.deleteCollection("collection_two").processAndWait(cluster.getSolrClient(), 60);
  // collection_one already deleted
  lastVersion = waitForAliasesUpdate(lastVersion, zkStateReader);

  assertNull("collection_alias_pair should be gone",
      cluster.getSolrClient().getZkStateReader().getAliases().getCollectionAliasMap().get("collection_alias_pair"));

  assertFalse("collection_one should be gone",
      cluster.getSolrClient().getZkStateReader().getClusterState().hasCollection("collection_one"));

  assertFalse("collection_two should be gone",
      cluster.getSolrClient().getZkStateReader().getClusterState().hasCollection("collection_two"));

}