nicoloboschi commented on code in PR #20116: URL: https://github.com/apache/pulsar/pull/20116#discussion_r1177963377
########## pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java: ########## @@ -870,6 +872,56 @@ private void setupInput(ContextImpl contextImpl) throws Exception { Thread.currentThread().setContextClassLoader(this.instanceClassLoader); } } + private Map<String, Object> parseComponentConfig(String connectorConfigs) throws IOException { + return parseComponentConfig(connectorConfigs, instanceConfig, componentClassLoader, componentType); + } + + static Map<String, Object> parseComponentConfig(String connectorConfigs, + InstanceConfig instanceConfig, + ClassLoader componentClassLoader, + org.apache.pulsar.functions.proto.Function + .FunctionDetails.ComponentType componentType) + throws IOException { + final Map<String, Object> config = ObjectMapperFactory + .getMapper() + .reader() + .forType(new TypeReference<Map<String, Object>>() {}) + .readValue(connectorConfigs); + if (instanceConfig.isIgnoreUnknownConfigFields() && componentClassLoader instanceof NarClassLoader) { + final String configClass; + if (componentType == org.apache.pulsar.functions.proto.Function.FunctionDetails.ComponentType.SOURCE) { + configClass = ConnectorUtils + .getConnectorDefinition((NarClassLoader) componentClassLoader).getSourceConfigClass(); + } else if (componentType == org.apache.pulsar.functions.proto.Function.FunctionDetails.ComponentType.SINK) { + configClass = ConnectorUtils + .getConnectorDefinition((NarClassLoader) componentClassLoader).getSinkConfigClass(); + } else { + return config; + } + if (configClass != null) { + final Object configInstance = Reflections.createInstance(configClass, + Thread.currentThread().getContextClassLoader()); + final List<String> allFields = + Reflections + .getAllFields(configInstance.getClass()) + .stream() + .map(Field::getName) + .collect(Collectors.toList()); + + for (String s : config.keySet()) { + if (!allFields.contains(s)) { + log.warn("Field '{}' not defined in the {} configuration {}, the field will be ignored", 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: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org