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 698ba974552..7d25d909ef2 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 @@ -144,11 +144,15 @@ public class AutoScalingHandler extends RequestHandlerBase implements Permission if (path != null) { List parts = StrUtils.splitSmart(path, '/'); if (parts.get(0).isEmpty()) parts.remove(0); - if (parts.size() == 3 && SUGGESTIONS.equals(parts.get(2))) { + if(parts.size() == 3) { Map map = (Map) Utils.fromJSON(req.getContentStreams().iterator().next().getStream()); - AutoScalingConfig config = new AutoScalingConfig(map); - handleSuggestions(rsp, config); - return; + if (SUGGESTIONS.equals(parts.get(2))) { + handleSuggestions(rsp, new AutoScalingConfig(map)); + return; + } else if (DIAGNOSTICS.equals(parts.get(2))) { + handleDiagnostics(rsp, new AutoScalingConfig(map)); + return; + } } } 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 29159985865..d950c3c6191 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 @@ -127,6 +127,26 @@ public class AutoScalingHandlerTest extends SolrCloudTestCase { CollectionAdminRequest.deleteCollection(COLLNAME) .process(cluster.getSolrClient()); } + public void testDiagnosticsWithPayload() throws Exception { + CloudSolrClient solrClient = cluster.getSolrClient(); + String COLLNAME = "testDiagnosticsWithPayload.COLL"; + CollectionAdminResponse adminResponse = CollectionAdminRequest.createCollection(COLLNAME, CONFIGSET_NAME, 1, 2) + .setMaxShardsPerNode(4) + .process(solrClient); + cluster.waitForActiveCollection(COLLNAME, 1, 2); + DocCollection collection = solrClient.getClusterStateProvider().getCollection(COLLNAME); + Replica aReplica = collection.getReplicas().get(0); + + String configPayload = "{\n" + + " 'cluster-policy': [{'replica': 0, 'node': '_NODE'}]\n" + + "}"; + configPayload = configPayload.replaceAll("_NODE", aReplica.getNodeName()); + SolrRequest req = AutoScalingRequest.create(SolrRequest.METHOD.POST, "/diagnostics", configPayload); + NamedList response = solrClient.request(req); + assertEquals(response._getStr("diagnostics/violations[0]/node",null),response._getStr("diagnostics/violations[0]/node",null)); + CollectionAdminRequest.deleteCollection(COLLNAME) + .process(cluster.getSolrClient()); + } @Test public void testSuspendTrigger() throws Exception {