maytasm commented on a change in pull request #11601:
URL: https://github.com/apache/druid/pull/11601#discussion_r690363886
##########
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 = new
HashSet<>();
+ 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);
+ } else {
+ adjustedProps.put(typeProperty, dutyName);
+ }
+ coordinatorCustomDutyProvider.inject(adjustedProps, configurator);
+ Supplier<CoordinatorCustomDuty> coordinatorCustomDutySupplier =
coordinatorCustomDutyProvider.get();
+ if (coordinatorCustomDutySupplier == null) {
+ throw new ISE("Could not create CoordinatorCustomDuty with name:
%s for group: %s", dutyName, coordinatorCustomDutyGroupName);
+ }
+ CoordinatorCustomDuty coordinatorCustomDuty =
coordinatorCustomDutySupplier.get();
Review comment:
Done
--
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]