jon-wei commented on a change in pull request #11601:
URL: https://github.com/apache/druid/pull/11601#discussion_r689984638



##########
File path: docs/development/modules.md
##########
@@ -324,6 +324,25 @@ public class MyTransformModule implements DruidModule {
 }
 ```
 
+### Adding your own custom pluggable Coordinator Duty

Review comment:
       Suggest mentioning `KillSupervisorsCustomDuty` and how it's used in 
`common-custom-coordinator-duties` as an example in docs

##########
File path: services/src/main/java/org/apache/druid/cli/CliCoordinator.java
##########
@@ -353,4 +370,76 @@ public static boolean isOverlord(Properties properties)
   {
     return Boolean.parseBoolean(properties.getProperty(AS_OVERLORD_PROPERTY));
   }
+
+  private static class CoordinatorCustomDutyGroupsProvider implements 
Provider<CoordinatorCustomDutyGroups>
+  {
+    private Properties props;
+    private JsonConfigurator configurator;
+    private ObjectMapper jsonMapper;
+
+    @Inject
+    public void inject(Properties props, JsonConfigurator configurator, 
ObjectMapper jsonMapper)
+    {
+      this.props = props;
+      this.configurator = configurator;
+      this.jsonMapper = jsonMapper;
+    }
+
+    @Override
+    public CoordinatorCustomDutyGroups get()
+    {
+      try {
+        Set<CoordinatorCustomDutyGroup> coordinatorCustomDutyGroups = 
Sets.newHashSet();
+        if 
(Strings.isNullOrEmpty(props.getProperty("druid.coordinator.dutyGroups"))) {
+          return new CoordinatorCustomDutyGroups(coordinatorCustomDutyGroups);
+        }
+        List<String> coordinatorCustomDutyGroupNames = 
jsonMapper.readValue(props.getProperty(
+            "druid.coordinator.dutyGroups"), new TypeReference<List<String>>() 
{});
+        for (String coordinatorCustomDutyGroupName : 
coordinatorCustomDutyGroupNames) {
+          String dutyListProperty = 
StringUtils.format("druid.coordinator.%s.duties", 
coordinatorCustomDutyGroupName);
+          if (Strings.isNullOrEmpty(props.getProperty(dutyListProperty))) {
+            throw new IAE("Coordinator custom duty group given without any 
duty for group %s", coordinatorCustomDutyGroupName);
+          }
+          List<String> dutyForGroup = 
jsonMapper.readValue(props.getProperty(dutyListProperty), new 
TypeReference<List<String>>() {});
+          List<CoordinatorCustomDuty> coordinatorCustomDuties = new 
ArrayList<>();
+          for (String dutyName : dutyForGroup) {
+            final String dutyPropertyBase = StringUtils.format(
+                "druid.coordinator.%s.duty.%s",
+                coordinatorCustomDutyGroupName,
+                dutyName
+            );
+            final JsonConfigProvider<CoordinatorCustomDuty> 
coordinatorCustomDutyProvider = JsonConfigProvider.of(
+                dutyPropertyBase,
+                CoordinatorCustomDuty.class
+            );
+
+            String typeProperty = StringUtils.format("%s.type", 
dutyPropertyBase);
+            Properties adjustedProps = new Properties(props);
+            if (adjustedProps.containsKey(typeProperty)) {
+              throw new IAE("Type property [%s] is reserved.", typeProperty);

Review comment:
       ```suggestion
                 throw new IAE("'type' property [%s] is reserved.", 
typeProperty);
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to