This is an automated email from the ASF dual-hosted git repository.
suneet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 5fcf4205e4b Handle empty values for task and datasource conditions in
pod template selector (#17400)
5fcf4205e4b is described below
commit 5fcf4205e4b1f17edccc4a37cf338ed5e3047ae1
Author: Kiran Gadhave <[email protected]>
AuthorDate: Wed Oct 30 21:18:20 2024 -0600
Handle empty values for task and datasource conditions in pod template
selector (#17400)
* handling empty sets for dataSourceCondition and taskTypeCondition
* using new HashSet<>() to fix forbidden api error in testCheck
* fixing style issues
---
.../druid/k8s/overlord/execution/Selector.java | 8 +--
.../druid/k8s/overlord/execution/SelectorTest.java | 57 ++++++++++++++++++++++
2 files changed, 62 insertions(+), 3 deletions(-)
diff --git
a/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/Selector.java
b/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/Selector.java
index a314a69b381..29e31218ad0 100644
---
a/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/Selector.java
+++
b/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/execution/Selector.java
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.druid.indexing.common.task.Task;
import org.apache.druid.query.DruidMetrics;
+import org.apache.druid.utils.CollectionUtils;
import java.util.Map;
import java.util.Objects;
@@ -70,6 +71,7 @@ public class Selector
public boolean evaluate(Task task)
{
boolean isMatch = true;
+
if (cxtTagsConditions != null) {
isMatch = cxtTagsConditions.entrySet().stream().allMatch(entry -> {
String tagKey = entry.getKey();
@@ -80,15 +82,15 @@ public class Selector
}
Object tagValue = tags.get(tagKey);
- return tagValue == null ? false : tagValues.contains((String)
tagValue);
+ return tagValue != null && tagValues.contains((String) tagValue);
});
}
- if (isMatch && taskTypeCondition != null) {
+ if (isMatch && !CollectionUtils.isNullOrEmpty(taskTypeCondition)) {
isMatch = taskTypeCondition.contains(task.getType());
}
- if (isMatch && dataSourceCondition != null) {
+ if (isMatch && !CollectionUtils.isNullOrEmpty(dataSourceCondition)) {
isMatch = dataSourceCondition.contains(task.getDataSource());
}
diff --git
a/extensions-contrib/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/execution/SelectorTest.java
b/extensions-contrib/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/execution/SelectorTest.java
index 0ecff67408e..14e2ffb2143 100644
---
a/extensions-contrib/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/execution/SelectorTest.java
+++
b/extensions-contrib/kubernetes-overlord-extensions/src/test/java/org/apache/druid/k8s/overlord/execution/SelectorTest.java
@@ -30,11 +30,68 @@ import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class SelectorTest
{
+ @Test
+ public void shouldReturnTrueWhenMatchTasksTagsAndEmptyDataSource()
+ {
+ Map<String, Set<String>> cxtTagsConditions = new HashMap<>();
+ cxtTagsConditions.put("tag1", Sets.newHashSet("tag1Value"));
+
+ Task task = NoopTask.create();
+ task.addToContext(DruidMetrics.TAGS, ImmutableMap.of("tag1", "tag1Value"));
+
+ Selector selector = new Selector(
+ "TestSelector",
+ cxtTagsConditions,
+ Sets.newHashSet(NoopTask.TYPE),
+ new HashSet<>()
+ );
+
+ Assert.assertTrue(selector.evaluate(task));
+ }
+
+ @Test
+ public void shouldReturnTrueWhenMatchDataSourceTagsAndEmptyTasks()
+ {
+ String datasource = "table";
+ Map<String, Set<String>> cxtTagsConditions = new HashMap<>();
+ cxtTagsConditions.put("tag1", Sets.newHashSet("tag1Value"));
+
+ Task task = NoopTask.forDatasource(datasource);
+ task.addToContext(DruidMetrics.TAGS, ImmutableMap.of("tag1", "tag1Value"));
+
+ Selector selector = new Selector(
+ "TestSelector",
+ cxtTagsConditions,
+ new HashSet<>(),
+ Sets.newHashSet(datasource)
+ );
+
+ Assert.assertTrue(selector.evaluate(task));
+ }
+
+ @Test
+ public void shouldReturnTrueWhenMatchDataSourceTasksAndEmptyTags()
+ {
+ String datasource = "table";
+ Map<String, Set<String>> cxtTagsConditions = new HashMap<>();
+
+ Task task = NoopTask.forDatasource(datasource);
+
+ Selector selector = new Selector(
+ "TestSelector",
+ cxtTagsConditions,
+ Sets.newHashSet(NoopTask.TYPE),
+ Sets.newHashSet(datasource)
+ );
+
+ Assert.assertTrue(selector.evaluate(task));
+ }
@Test
public void shouldReturnTrueWhenAllTagsAndTasksMatch()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]