lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject lucene-solr:feature/autoscaling: SOLR-11157: remove-policy must fail if a policy to be deleted is used by a collection
Date Thu, 03 Aug 2017 01:50:32 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/feature/autoscaling 82a426c6e -> b89015a2d


SOLR-11157: remove-policy must fail if a policy to be deleted is used by a collection


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b89015a2
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b89015a2
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b89015a2

Branch: refs/heads/feature/autoscaling
Commit: b89015a2d45b368d07a49ca3361172600b441c62
Parents: 82a426c
Author: Noble Paul <noble@apache.org>
Authored: Thu Aug 3 11:20:16 2017 +0930
Committer: Noble Paul <noble@apache.org>
Committed: Thu Aug 3 11:20:16 2017 +0930

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 ++
 .../cloud/autoscaling/AutoScalingHandler.java   |  5 +++++
 .../autoscaling/AutoScalingHandlerTest.java     | 22 ++++++++++++++++++++
 3 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b89015a2/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index cae7754..cc759a9 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -133,6 +133,8 @@ Other Changes
 * SOLR-10397: Port 'autoAddReplicas' feature to the autoscaling framework and make it work
with non-shared filesystems
   (Cao Manh Dat, shalin)
 
+* SOLR-11157: remove-policy must fail if a policy to be deleted is used by a collection (noble)
+
 ==================  7.0.0 ==================
 
 Versions of Major Components

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b89015a2/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
b/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
index 837f7fd..0e075e8 100644
--- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
+++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/AutoScalingHandler.java
@@ -273,6 +273,11 @@ public class AutoScalingHandler extends RequestHandlerBase implements
Permission
     if (policies == null || !policies.containsKey(policyName)) {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No policy exists with
name: " + policyName);
     }
+    container.getZkController().getZkStateReader().getClusterState().forEachCollection(coll
-> {
+      if (policyName.equals(coll.getPolicyName())) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
+          StrUtils.formatString("policy : {0} is being used by collection {1}", policyName,
coll.getName()));
+    });
+
     policies = new HashMap<>(policies);
     policies.remove(policyName);
     Policy p = currentConfig.getPolicy().withPolicies(policies);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b89015a2/solr/core/src/test/org/apache/solr/cloud/autoscaling/AutoScalingHandlerTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/AutoScalingHandlerTest.java
b/solr/core/src/test/org/apache/solr/cloud/autoscaling/AutoScalingHandlerTest.java
index 0d97909..7ce59a3 100644
--- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/AutoScalingHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/AutoScalingHandlerTest.java
@@ -737,6 +737,28 @@ public class AutoScalingHandlerTest extends SolrCloudTestCase {
     return count;
   }
 
+  @Test
+  public void testDeleteUsedPolicy() throws Exception {
+    CloudSolrClient solrClient = cluster.getSolrClient();
+    // add multiple policies
+    String setPolicyCommand = "{'set-policy': {" +
+        "    'nodelete':[" +
+        "      {'nodeRole':'overseer', 'replica':0}]}}";
+    solrClient.request(createAutoScalingRequest(SolrRequest.METHOD.POST, setPolicyCommand));
+    CollectionAdminRequest.createCollection("COLL1", "conf", 1, 1)
+        .setPolicy("nodelete")
+        .process(cluster.getSolrClient());
+    String removePolicyCommand = "{remove-policy : nodelete}";
+    createAutoScalingRequest(SolrRequest.METHOD.POST, removePolicyCommand);
+    try {
+      solrClient.request(createAutoScalingRequest(SolrRequest.METHOD.POST, removePolicyCommand));
+      fail("should have failed");
+    } catch (Exception e) {
+      assertTrue(e.getMessage().contains("is being used by collection"));
+    }
+    solrClient.request(CollectionAdminRequest.deleteCollection("COLL1"));
+  }
+
   public static SolrRequest createAutoScalingRequest(SolrRequest.METHOD m, String message)
{
     return createAutoScalingRequest(m, null, message);
   }


Mime
View raw message