From 9b340d9f6c7759b7892bea4b9172dd31f0c92546 Mon Sep 17 00:00:00 2001 From: Dhruv Parthasarathy Date: Thu, 1 Aug 2013 14:06:22 -0700 Subject: [PATCH] simplified console code. Added Builder. Fixed urls --- .../com/metamx/druid/http/InfoResource.java | 20 ++++-- .../com/metamx/druid/master/DruidMaster.java | 7 +- .../master/DruidMasterRuntimeParams.java | 2 +- .../metamx/druid/master/DynamicConfigs.java | 70 +++++++++++++++---- .../main/resources/static/dynamicConfigs.html | 41 ++++------- .../static/js/createDynamicParamsGrid.js | 33 --------- .../resources/static/js/dynamicConfigs.js | 25 +++++++ .../druid/master/DruidMasterBalancerTest.java | 31 ++++---- .../master/DruidMasterRuleRunnerTest.java | 64 ++--------------- .../master/DruidMasterSegmentMergerTest.java | 13 +--- 10 files changed, 133 insertions(+), 173 deletions(-) delete mode 100644 server/src/main/resources/static/js/createDynamicParamsGrid.js create mode 100644 server/src/main/resources/static/js/dynamicConfigs.js diff --git a/server/src/main/java/com/metamx/druid/http/InfoResource.java b/server/src/main/java/com/metamx/druid/http/InfoResource.java index 0e56ad54874..02de4c15c2f 100644 --- a/server/src/main/java/com/metamx/druid/http/InfoResource.java +++ b/server/src/main/java/com/metamx/druid/http/InfoResource.java @@ -121,7 +121,7 @@ public class InfoResource this.serverInventoryView = serverInventoryView; this.databaseSegmentManager = databaseSegmentManager; this.databaseRuleManager = databaseRuleManager; - this.configManager=configManager; + this.configManager = configManager; this.indexingServiceClient = indexingServiceClient; } @@ -136,11 +136,17 @@ public class InfoResource } @GET - @Path("/master/dynamicConfigs") + @Path("/master/config") @Produces("application/json") public Response getDynamicConfigs() { - Response.ResponseBuilder builder = Response.status(Response.Status.OK).entity(configManager.watch(DynamicConfigs.CONFIG_KEY,DynamicConfigs.class).get()); + Response.ResponseBuilder builder = Response.status(Response.Status.OK) + .entity( + configManager.watch( + DynamicConfigs.CONFIG_KEY, + DynamicConfigs.class + ).get() + ); return builder.build(); } @@ -389,13 +395,13 @@ public class InfoResource } @POST - @Path("master/dynamicConfigs") + @Path("master/config") @Consumes("application/json") public Response setDynamicConfigs( - final DynamicConfigs dynamicConfigs) + final DynamicConfigs dynamicConfigs + ) { - if (!configManager.set(DynamicConfigs.CONFIG_KEY, dynamicConfigs)) - { + if (!configManager.set(DynamicConfigs.CONFIG_KEY, dynamicConfigs)) { return Response.status(Response.Status.BAD_REQUEST).build(); } return Response.status(Response.Status.OK).build(); diff --git a/server/src/main/java/com/metamx/druid/master/DruidMaster.java b/server/src/main/java/com/metamx/druid/master/DruidMaster.java index 409abe9c5cd..7ae6bb4a7f9 100644 --- a/server/src/main/java/com/metamx/druid/master/DruidMaster.java +++ b/server/src/main/java/com/metamx/druid/master/DruidMaster.java @@ -80,7 +80,6 @@ public class DruidMaster private volatile boolean started = false; private volatile boolean master = false; - private volatile boolean defaultConfigsSet=false; private final DruidMasterConfig config; private final ZkPathsConfig zkPaths; @@ -466,12 +465,8 @@ public class DruidMaster serverInventoryView.start(); final List> masterRunnables = Lists.newArrayList(); - if (!defaultConfigsSet) - { configManager.watch(DynamicConfigs.CONFIG_KEY, DynamicConfigs.class); - configManager.set(DynamicConfigs.CONFIG_KEY, new DynamicConfigs(null,null,null,null)); - defaultConfigsSet=true; - } + configManager.set(DynamicConfigs.CONFIG_KEY, (new DynamicConfigs.Builder()).build()); masterRunnables.add(Pair.of(new MasterComputeManagerRunnable(), config.getMasterPeriod())); if (indexingServiceClient != null) { diff --git a/server/src/main/java/com/metamx/druid/master/DruidMasterRuntimeParams.java b/server/src/main/java/com/metamx/druid/master/DruidMasterRuntimeParams.java index f0610fd3dac..efa2632e13f 100644 --- a/server/src/main/java/com/metamx/druid/master/DruidMasterRuntimeParams.java +++ b/server/src/main/java/com/metamx/druid/master/DruidMasterRuntimeParams.java @@ -214,7 +214,7 @@ public class DruidMasterRuntimeParams this.replicationManager = null; this.emitter = null; this.stats = new MasterStats(); - this.dynamicConfigs = new DynamicConfigs(null,null,null,null); + this.dynamicConfigs = new DynamicConfigs.Builder().build(); this.balancerReferenceTimestamp = null; } diff --git a/server/src/main/java/com/metamx/druid/master/DynamicConfigs.java b/server/src/main/java/com/metamx/druid/master/DynamicConfigs.java index b6fa793824b..1e934b2d1a4 100644 --- a/server/src/main/java/com/metamx/druid/master/DynamicConfigs.java +++ b/server/src/main/java/com/metamx/druid/master/DynamicConfigs.java @@ -30,31 +30,18 @@ public class DynamicConfigs private int maxSegmentsToMove = 5; @JsonCreator - public DynamicConfigs(@JsonProperty("millisToWaitBeforeDeleting") Integer millisToWaitBeforeDeleting, + public DynamicConfigs(@JsonProperty("millisToWaitBeforeDeleting") Long millisToWaitBeforeDeleting, @JsonProperty("mergeBytesLimit") Long mergeBytesLimit, @JsonProperty("mergeSegmentsLimit") Integer mergeSegmentsLimit, @JsonProperty("maxSegmentsToMove") Integer maxSegmentsToMove ) { - if (maxSegmentsToMove!=null) - { this.maxSegmentsToMove=maxSegmentsToMove; - } - if (millisToWaitBeforeDeleting!=null) - { this.millisToWaitBeforeDeleting=millisToWaitBeforeDeleting; - } - if (mergeSegmentsLimit!=null) - { this.mergeSegmentsLimit=mergeSegmentsLimit; - } - if (mergeBytesLimit!=null) - { this.mergeBytesLimit=mergeBytesLimit; - } } - public static String getConfigKey() { return CONFIG_KEY; @@ -83,4 +70,59 @@ public class DynamicConfigs { return maxSegmentsToMove; } + + + public static class Builder + { + public static final String CONFIG_KEY = "master.dynamicConfigs"; + private long millisToWaitBeforeDeleting; + private long mergeBytesLimit; + private int mergeSegmentsLimit; + private int maxSegmentsToMove; + + public Builder() + { + this.millisToWaitBeforeDeleting=15 * 60 * 1000L; + this.mergeBytesLimit= 100000000L; + this.mergeSegmentsLimit= Integer.MAX_VALUE; + this.maxSegmentsToMove = 5; + } + + public Builder(long millisToWaitBeforeDeleting, long mergeBytesLimit, int mergeSegmentsLimit, int maxSegmentsToMove) + { + this.millisToWaitBeforeDeleting = millisToWaitBeforeDeleting; + this.mergeBytesLimit = mergeBytesLimit; + this.mergeSegmentsLimit = mergeSegmentsLimit; + this.maxSegmentsToMove = maxSegmentsToMove; + } + + public Builder withMillisToWaitBeforeDeleting(long millisToWaitBeforeDeleting) + { + this.millisToWaitBeforeDeleting=millisToWaitBeforeDeleting; + return this; + } + + public Builder withMergeBytesLimit(long mergeBytesLimit) + { + this.mergeBytesLimit=mergeBytesLimit; + return this; + } + + public Builder withMergeSegmentsLimit(int mergeSegmentsLimit) + { + this.mergeSegmentsLimit=mergeSegmentsLimit; + return this; + } + + public Builder withMaxSegmentsToMove(int maxSegmentsToMove) + { + this.maxSegmentsToMove=maxSegmentsToMove; + return this; + } + + public DynamicConfigs build() + { + return new DynamicConfigs(millisToWaitBeforeDeleting,mergeBytesLimit,mergeSegmentsLimit,maxSegmentsToMove); + } + } } diff --git a/server/src/main/resources/static/dynamicConfigs.html b/server/src/main/resources/static/dynamicConfigs.html index 30e3c90e8b8..63751c3413f 100644 --- a/server/src/main/resources/static/dynamicConfigs.html +++ b/server/src/main/resources/static/dynamicConfigs.html @@ -2,33 +2,22 @@ Configure Dynamic Master Parameters - - - - - - - -
-
-
- - - - - - - - - - - - - - - - +
+ millisToWaitBeforeDeleting: +
+ mergeBytesLimit: +
+ mergeSegmentsLimit: +
+ maxSegmentsToMove: +
+ +
+ + + + \ No newline at end of file diff --git a/server/src/main/resources/static/js/createDynamicParamsGrid.js b/server/src/main/resources/static/js/createDynamicParamsGrid.js deleted file mode 100644 index 23cfa4914d3..00000000000 --- a/server/src/main/resources/static/js/createDynamicParamsGrid.js +++ /dev/null @@ -1,33 +0,0 @@ - var grid; - var columns = [ - {id: "millisToWaitBeforeDeleting", name: "millisToWaitBeforeDeleting", field: "millisToWaitBeforeDeleting",editor: Slick.Editors.LongText}, - {id: "mergeBytesLimit", name: "mergeBytesLimit", field: "mergeBytesLimit",editor: Slick.Editors.LongText}, - {id: "mergeSegmentsLimit", name: "mergeSegmentsLimit", field: "mergeSegmentsLimit",editor: Slick.Editors.LongText}, - {id: "maxSegmentsToMove", name: "maxSegmentsToMove", field: "maxSegmentsToMove",editor: Slick.Editors.LongText} - ]; - - var options = { - enableCellNavigation: true, - enableColumnReorder: false, - editable: true, - autoEdit: false, - fullWidthRows: true - }; - - $(function () { - $.get('../info/master/dynamicConfigs', function (data) { - var rowData = []; - rowData[0]=data; - grid = new Slick.Grid("#myGrid", rowData, columns, options); - grid.onCellChange.subscribe(function (e) { - var paramJson = JSON.stringify(grid.getData()[0]); - $.ajax({ - url:'../info/master/dynamicConfigs', - type:"POST", - data:paramJson, - contentType:"application/json; charset=utf-8", - dataType:"json" - }); - }); - }); - }); \ No newline at end of file diff --git a/server/src/main/resources/static/js/dynamicConfigs.js b/server/src/main/resources/static/js/dynamicConfigs.js new file mode 100644 index 00000000000..c7774451dee --- /dev/null +++ b/server/src/main/resources/static/js/dynamicConfigs.js @@ -0,0 +1,25 @@ +$(function () { + $.get('../info/master/config', function (data) { + document.getElementById("millis").value=data["millisToWaitBeforeDeleting"]; + document.getElementById("mergeBytes").value = data["mergeBytesLimit"]; + document.getElementById("mergeSegments").value = data["mergeSegmentsLimit"]; + document.getElementById("maxSegments").value = data["maxSegmentsToMove"]; + }); + + $("#submit").click( function () + { + values = {}; + list = $('form').serializeArray(); + for (var i=0;i< list.length;i++) + { + values[list[i]["name"]]=list[i]["value"]; + } + $.ajax({ + url:'../info/master/config', + type:"POST", + data: JSON.stringify(values), + contentType:"application/json; charset=utf-8", + dataType:"json" + }); + }); +}); diff --git a/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTest.java b/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTest.java index 7e5f0059807..93b1f4b5050 100644 --- a/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTest.java +++ b/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTest.java @@ -193,14 +193,7 @@ public class DruidMasterBalancerTest ) .withAvailableSegments(segments.values()) .withDynamicConfigs( - new DynamicConfigs(null,null,null,null) - { - @Override - public int getMaxSegmentsToMove() - { - return MAX_SEGMENTS_TO_MOVE; - } - } + new DynamicConfigs.Builder().withMaxSegmentsToMove(MAX_SEGMENTS_TO_MOVE).build() ) .withBalancerReferenceTimestamp(new DateTime("2013-01-01")) .build(); @@ -277,16 +270,20 @@ public class DruidMasterBalancerTest ) ) ) - .withLoadManagementPeons(ImmutableMap.of("1", peon1, "2", peon2, "3", peon3, "4", peon4)) + .withLoadManagementPeons( + ImmutableMap.of( + "1", + peon1, + "2", + peon2, + "3", + peon3, + "4", + peon4 + ) + ) .withAvailableSegments(segments.values()) - .withDynamicConfigs(new DynamicConfigs(null,null,null,null) - { - @Override - public int getMaxSegmentsToMove() - { - return MAX_SEGMENTS_TO_MOVE; - } - }) + .withDynamicConfigs(new DynamicConfigs.Builder().withMaxSegmentsToMove(MAX_SEGMENTS_TO_MOVE).build()) .withBalancerReferenceTimestamp(new DateTime("2013-01-01")) .build(); diff --git a/server/src/test/java/com/metamx/druid/master/DruidMasterRuleRunnerTest.java b/server/src/test/java/com/metamx/druid/master/DruidMasterRuleRunnerTest.java index 89fdb3f26db..7e32b5a6fda 100644 --- a/server/src/test/java/com/metamx/druid/master/DruidMasterRuleRunnerTest.java +++ b/server/src/test/java/com/metamx/druid/master/DruidMasterRuleRunnerTest.java @@ -177,15 +177,7 @@ public class DruidMasterRuleRunnerTest .withAvailableSegments(availableSegments) .withDatabaseRuleManager(databaseRuleManager) .withSegmentReplicantLookup(SegmentReplicantLookup.make(new DruidCluster())) - .withDynamicConfigs(new DynamicConfigs(null,null,null,null) - { - @Override - public int getMaxSegmentsToMove() - { - return 5; - } - }) - .withBalancerReferenceTimestamp(new DateTime("2013-01-01")) + .withDynamicConfigs(new DynamicConfigs.Builder().withMaxSegmentsToMove(5).build()) .build(); DruidMasterRuntimeParams afterParams = ruleRunner.run(params); @@ -530,14 +522,7 @@ public class DruidMasterRuleRunnerTest DruidMasterRuntimeParams params = new DruidMasterRuntimeParams.Builder() .withDruidCluster(druidCluster) - .withDynamicConfigs( new DynamicConfigs(null,null,null,null) - { - @Override - public long getMillisToWaitBeforeDeleting() - { - return 0L; - } - }) + .withDynamicConfigs(new DynamicConfigs.Builder().withMillisToWaitBeforeDeleting(0L).build()) .withAvailableSegments(availableSegments) .withDatabaseRuleManager(databaseRuleManager) .withSegmentReplicantLookup(segmentReplicantLookup) @@ -611,14 +596,7 @@ public class DruidMasterRuleRunnerTest DruidMasterRuntimeParams params = new DruidMasterRuntimeParams.Builder() .withDruidCluster(druidCluster) - .withDynamicConfigs( new DynamicConfigs(null,null,null,null) - { - @Override - public long getMillisToWaitBeforeDeleting() - { - return 0L; - } - }) + .withDynamicConfigs(new DynamicConfigs.Builder().withMillisToWaitBeforeDeleting(0L).build()) .withAvailableSegments(availableSegments) .withDatabaseRuleManager(databaseRuleManager) .withSegmentReplicantLookup(segmentReplicantLookup) @@ -699,14 +677,7 @@ public class DruidMasterRuleRunnerTest DruidMasterRuntimeParams params = new DruidMasterRuntimeParams.Builder() .withDruidCluster(druidCluster) - .withDynamicConfigs( new DynamicConfigs(null,null,null,null) - { - @Override - public long getMillisToWaitBeforeDeleting() - { - return 0L; - } - }) + .withDynamicConfigs(new DynamicConfigs.Builder().withMillisToWaitBeforeDeleting(0L).build()) .withAvailableSegments(availableSegments) .withDatabaseRuleManager(databaseRuleManager) .withSegmentReplicantLookup(segmentReplicantLookup) @@ -783,14 +754,7 @@ public class DruidMasterRuleRunnerTest DruidMasterRuntimeParams params = new DruidMasterRuntimeParams.Builder() .withDruidCluster(druidCluster) - .withDynamicConfigs( new DynamicConfigs(null,null,null,null) - { - @Override - public long getMillisToWaitBeforeDeleting() - { - return 0L; - } - }) + .withDynamicConfigs(new DynamicConfigs.Builder().withMillisToWaitBeforeDeleting(0L).build()) .withAvailableSegments(availableSegments) .withDatabaseRuleManager(databaseRuleManager) .withSegmentReplicantLookup(segmentReplicantLookup) @@ -879,14 +843,7 @@ public class DruidMasterRuleRunnerTest DruidMasterRuntimeParams params = new DruidMasterRuntimeParams.Builder() .withDruidCluster(druidCluster) - .withDynamicConfigs( new DynamicConfigs(null,null,null,null) - { - @Override - public long getMillisToWaitBeforeDeleting() - { - return 0L; - } - }) + .withDynamicConfigs(new DynamicConfigs.Builder().withMillisToWaitBeforeDeleting(0L).build()) .withAvailableSegments(availableSegments) .withDatabaseRuleManager(databaseRuleManager) .withSegmentReplicantLookup(segmentReplicantLookup) @@ -1072,14 +1029,7 @@ public class DruidMasterRuleRunnerTest DruidMasterRuntimeParams params = new DruidMasterRuntimeParams.Builder() .withDruidCluster(druidCluster) - .withDynamicConfigs( new DynamicConfigs(null,null,null,null) - { - @Override - public long getMillisToWaitBeforeDeleting() - { - return 0L; - } - }) + .withDynamicConfigs(new DynamicConfigs.Builder().withMillisToWaitBeforeDeleting(0L).build()) .withAvailableSegments(longerAvailableSegments) .withDatabaseRuleManager(databaseRuleManager) .withSegmentReplicantLookup(segmentReplicantLookup) diff --git a/server/src/test/java/com/metamx/druid/master/DruidMasterSegmentMergerTest.java b/server/src/test/java/com/metamx/druid/master/DruidMasterSegmentMergerTest.java index 39b357734b2..6550b03091b 100644 --- a/server/src/test/java/com/metamx/druid/master/DruidMasterSegmentMergerTest.java +++ b/server/src/test/java/com/metamx/druid/master/DruidMasterSegmentMergerTest.java @@ -422,19 +422,8 @@ public class DruidMasterSegmentMergerTest final DruidMasterRuntimeParams params = DruidMasterRuntimeParams.newBuilder() .withAvailableSegments(ImmutableSet.copyOf(segments)) .withDynamicConfigs( - new DynamicConfigs(null,null,null,null) - { - @Override - public long getMergeBytesLimit(){ - return mergeBytesLimit; - } - @Override - public int getMergeSegmentsLimit(){ - return mergeSegmentsLimit; - } - }) + new DynamicConfigs.Builder().withMergeBytesLimit(mergeBytesLimit).withMergeSegmentsLimit(mergeSegmentsLimit).build()) .build(); - merger.run(params); return retVal; }