ppkarwasz commented on code in PR #524: URL: https://github.com/apache/logging-flume/pull/524#discussion_r4494255021
########## flume-node/src/main/java/org/apache/flume/node/OptionalConfigurationSource.java: ########## @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.flume.node; + +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import org.apache.flume.conf.ConfigurationException; +import org.apache.flume.node.net.AuthorizationProvider; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class OptionalConfigurationSource implements ConfigurationSource { + private static final Logger LOGGER = LogManager.getLogger(OptionalConfigurationSource.class); + private static final String OPTIONAL = "optional:"; + private final ConfigurationSource source; + private final URI realUri; + + public OptionalConfigurationSource(URI uri, AuthorizationProvider authorizationProvider, boolean verifyHost) { + String path = uri.toString().substring(OPTIONAL.length()); + try { + realUri = new URI(path); + } catch (URISyntaxException use) { + throw new ConfigurationException("Invalid URI"); + } + source = ConfigurationSourceFactory.getConfigurationSource(realUri, authorizationProvider, verifyHost); + if (source == null) { + LOGGER.warn("Unknown source for {}", path); + } + } Review Comment: This will only work with `optional:classpath`. Using `optional:file` or `optional:http` will fail, because those configuration sources load the data in their constructor. Before we introduce `optional:`, we probably need to decide a coherent semantics for `ConfigurationSourceFactory.getConfigurationSource` and `ConfigurationSource.getInputStream`. I think that: 1. The former should only check if the URI is recognized by some handler and fail if it isn't (pretty much like `URL`). This allows to detect typos early, otherwise a configuration like `optional:fiel` might be totally ignored for a long time. 2. The latter should also always return the **real** data or throw an exception. Returning `InputStream.nullInputStream()` might be a correct `*.properties` file, but it isn't a valid JSON, XML or YAML file. I think that `isOptional` should be a property of `ConfigurationSource` instead of being a configuration source itself. The caller can ignore exception if `isOptional()` is `true` and rethrow them otherwise. -- 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]
