mirror of https://github.com/apache/druid.git
killDataSourceWhitelist in CoordinatorDynamicConfig accepts comma separated list of strings in addition to json array of strings so that coordinator console can do the updates correctly (#3095)
This commit is contained in:
parent
c5dbf364e3
commit
ab4209c82a
|
@ -20,7 +20,10 @@ package io.druid.server.coordinator;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class CoordinatorDynamicConfig
|
||||
|
@ -47,7 +50,11 @@ public class CoordinatorDynamicConfig
|
|||
@JsonProperty("replicationThrottleLimit") int replicationThrottleLimit,
|
||||
@JsonProperty("balancerComputeThreads") int balancerComputeThreads,
|
||||
@JsonProperty("emitBalancingStats") boolean emitBalancingStats,
|
||||
@JsonProperty("killDataSourceWhitelist") Set<String> killDataSourceWhitelist
|
||||
|
||||
// Type is Object here so that we can support both string and list as
|
||||
// coordinator console can not send array of strings in the update request.
|
||||
// See https://github.com/druid-io/druid/issues/3055
|
||||
@JsonProperty("killDataSourceWhitelist") Object killDataSourceWhitelist
|
||||
)
|
||||
{
|
||||
this.maxSegmentsToMove = maxSegmentsToMove;
|
||||
|
@ -58,7 +65,21 @@ public class CoordinatorDynamicConfig
|
|||
this.replicationThrottleLimit = replicationThrottleLimit;
|
||||
this.emitBalancingStats = emitBalancingStats;
|
||||
this.balancerComputeThreads = Math.max(balancerComputeThreads, 1);
|
||||
this.killDataSourceWhitelist = killDataSourceWhitelist;
|
||||
|
||||
if (killDataSourceWhitelist instanceof String) {
|
||||
String[] tmp = ((String) killDataSourceWhitelist).split(",");
|
||||
this.killDataSourceWhitelist = new HashSet<>();
|
||||
for (int i = 0; i < tmp.length; i++) {
|
||||
String trimmed = tmp[i].trim();
|
||||
if (!trimmed.isEmpty()) {
|
||||
this.killDataSourceWhitelist.add(trimmed);
|
||||
}
|
||||
}
|
||||
} else if (killDataSourceWhitelist instanceof Collection){
|
||||
this.killDataSourceWhitelist = ImmutableSet.copyOf(((Collection) killDataSourceWhitelist));
|
||||
} else {
|
||||
this.killDataSourceWhitelist = ImmutableSet.of();
|
||||
}
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
|
|
|
@ -42,7 +42,7 @@ public class CoordinatorDynamicConfigTest
|
|||
+ " \"replicationThrottleLimit\": 1,\n"
|
||||
+ " \"balancerComputeThreads\": 2, \n"
|
||||
+ " \"emitBalancingStats\": true,\n"
|
||||
+ " \"killDataSourceWhitelist\": [\"test\"]\n"
|
||||
+ " \"killDataSourceWhitelist\": [\"test1\",\"test2\"]\n"
|
||||
+ "}\n";
|
||||
|
||||
ObjectMapper mapper = TestHelper.getObjectMapper();
|
||||
|
@ -57,7 +57,39 @@ public class CoordinatorDynamicConfigTest
|
|||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
new CoordinatorDynamicConfig(1, 1, 1, 1, 1, 1, 2, true, ImmutableSet.of("test")),
|
||||
new CoordinatorDynamicConfig(1, 1, 1, 1, 1, 1, 2, true, ImmutableSet.of("test1", "test2")),
|
||||
actual
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerdeWithStringinKillDataSourceWhitelist() throws Exception
|
||||
{
|
||||
String jsonStr = "{\n"
|
||||
+ " \"millisToWaitBeforeDeleting\": 1,\n"
|
||||
+ " \"mergeBytesLimit\": 1,\n"
|
||||
+ " \"mergeSegmentsLimit\" : 1,\n"
|
||||
+ " \"maxSegmentsToMove\": 1,\n"
|
||||
+ " \"replicantLifetime\": 1,\n"
|
||||
+ " \"replicationThrottleLimit\": 1,\n"
|
||||
+ " \"balancerComputeThreads\": 2, \n"
|
||||
+ " \"emitBalancingStats\": true,\n"
|
||||
+ " \"killDataSourceWhitelist\": \" test1 ,test2 \"\n"
|
||||
+ "}\n";
|
||||
|
||||
ObjectMapper mapper = TestHelper.getObjectMapper();
|
||||
CoordinatorDynamicConfig actual = mapper.readValue(
|
||||
mapper.writeValueAsString(
|
||||
mapper.readValue(
|
||||
jsonStr,
|
||||
CoordinatorDynamicConfig.class
|
||||
)
|
||||
),
|
||||
CoordinatorDynamicConfig.class
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
new CoordinatorDynamicConfig(1, 1, 1, 1, 1, 1, 2, true, ImmutableSet.of("test1", "test2")),
|
||||
actual
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue