Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref #FLUME-3361 Added support for environment variable in ZooKeeper b… #326

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* ZooKeeper based configuration implementation provider.
*
Expand Down Expand Up @@ -70,6 +73,10 @@ public abstract class AbstractZooKeeperConfigurationProvider extends

protected final String zkConnString;

private static final String DEFAULT_PROPERTIES_IMPLEMENTATION = "java.util.Properties";
private static final Logger LOGGER = LoggerFactory.getLogger(
AbstractZooKeeperConfigurationProvider.class);

protected AbstractZooKeeperConfigurationProvider(String agentName,
String zkConnString, String basePath) {
super(agentName);
Expand All @@ -90,14 +97,24 @@ protected CuratorFramework createClient() {

protected FlumeConfiguration configFromBytes(byte[] configData)
throws IOException {
Map<String, String> configMap;
if (configData == null || configData.length == 0) {
configMap = Collections.emptyMap();
} else {
String fileContent = new String(configData, Charsets.UTF_8);
Properties properties = new Properties();
properties.load(new StringReader(fileContent));
configMap = toMap(properties);
Map<String, String> configMap = Collections.emptyMap();
if (configData != null && configData.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else case previously set configMap = Collections.emptyMap(). We should retain this behaviour.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking it up Tristan!
I have initialized configMap to emptyMap (Map<String, String> configMap = Collections.emptyMap();) so that an emptyMap (and not null) is returned even in case of a handled exception.
Tried to explain in detail below. Please let me know if I'm missing anything.

BEFORE:

Map m = null

if config does not exists
m = empty Map
return m
else
m = Map with config value //IO Exception is thrown

return m

NOW:

Map m = empty Map (so that I don't end up returning null in case of exceptions below)

if config exists
m = Map with config value
catch new possible exceptions other than IO

return m //so returning empty map like before (retaining the behavior)
//if Config does not exist or if an exception occurs that is handled

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tristan, please let me know if you are waiting for anything else from me.

try {
String fileContent = new String(configData, Charsets.UTF_8);
String resolverClassName = System.getProperty("propertiesImplementation",
DEFAULT_PROPERTIES_IMPLEMENTATION);
Class<? extends Properties> propsclass = Class.forName(resolverClassName)
.asSubclass(Properties.class);
Properties properties = propsclass.newInstance();
properties.load(new StringReader(fileContent));
configMap = toMap(properties);
} catch (ClassNotFoundException e) {
LOGGER.error("Configuartion resolver class not found", e);
} catch (InstantiationException e) {
LOGGER.error("Instantiation exception", e);
} catch (IllegalAccessException e) {
LOGGER.error("Illegal access exception", e);
}
}
return new FlumeConfiguration(configMap);
}
Expand Down