String dataDir) {
Properties props = new Properties();
if ((agents == null || agents.length == 0) && (properties == null || properties.length == 0)) {
LOGGER.error("No Flume configuration provided");
throw new ConfigurationException("No Flume configuration provided");
}
if ((agents != null && agents.length > 0 && properties != null && properties.length > 0)) {
LOGGER.error("Agents and Flume configuration cannot both be specified");
throw new ConfigurationException("Agents and Flume configuration cannot both be specified");
}
if (agents != null && agents.length > 0) {
props.put(name + ".sources", FlumeEmbeddedManager.SOURCE_NAME);
props.put(name + ".sources." + FlumeEmbeddedManager.SOURCE_NAME + ".type", sourceType);
props.put(name + ".channels", "file");
props.put(name + ".channels.file.type", "file");
if (dataDir != null && dataDir.length() > 0) {
if (!dataDir.endsWith(LINE_SEP)) {
dataDir = dataDir + LINE_SEP;
}
props.put(name + ".channels.file.checkpointDir", dataDir + "checkpoint");
props.put(name + ".channels.file.dataDirs", dataDir + "data");
}
StringBuilder sb = new StringBuilder();
String leading = "";
int priority = agents.length;
for (int i=0; i < agents.length; ++i) {
sb.append(leading).append("agent").append(i);
leading = " ";
String prefix = name + ".sinks.agent" + i;
props.put(prefix + ".channel", "file");
props.put(prefix + ".type", "avro");
props.put(prefix + ".hostname", agents[i].getHost());
props.put(prefix + ".port", Integer.toString(agents[i].getPort()));
props.put(prefix + ".batch-size", Integer.toString(batchSize));
props.put(name + ".sinkgroups.group1.processor.priority.agent" + i, Integer.toString(priority));
--priority;
}
props.put(name + ".sinks", sb.toString());
props.put(name + ".sinkgroups", "group1");
props.put(name + ".sinkgroups.group1.sinks", sb.toString());
props.put(name + ".sinkgroups.group1.processor.type", "failover");
String sourceChannels = "file";
props.put(name + ".channels", sourceChannels);
props.put(name + ".sources." + FlumeEmbeddedManager.SOURCE_NAME + ".channels", sourceChannels);
} else {
String channels = null;
String[] sinks = null;
props.put(name + ".sources", FlumeEmbeddedManager.SOURCE_NAME);
props.put(name + ".sources." + FlumeEmbeddedManager.SOURCE_NAME + ".type", sourceType);
for (Property property : properties) {
String key = property.getName();
if (key == null || key.length() == 0) {
String msg = "A property name must be provided";
LOGGER.error(msg);
throw new ConfigurationException(msg);
}
String upperKey = key.toUpperCase();
if (upperKey.startsWith(name.toUpperCase())) {
String msg = "Specification of the agent name is allowed in Flume Appender configuration: " + key;
LOGGER.error(msg);
throw new ConfigurationException(msg);
}
if (upperKey.startsWith("SOURCES.")) {
String msg = "Specification of Sources is not allowed in Flume Appender: " + key;
LOGGER.error(msg);
throw new ConfigurationException(msg);
}
String value = property.getValue();
if (value == null || value.length() == 0) {
String msg = "A value for property " + key + " must be provided";
LOGGER.error(msg);
throw new ConfigurationException(msg);
}
if (upperKey.equals("CHANNELS")) {
channels = value.trim();
} else if (upperKey.equals("SINKS")) {
sinks = value.trim().split(" ");
}
props.put(name + "." + key, value);
}
String sourceChannels = channels;
if (channels == null) {
sourceChannels = "file";
props.put(name + ".channels", sourceChannels);
}
props.put(name + ".sources." + FlumeEmbeddedManager.SOURCE_NAME + ".channels", sourceChannels);
if (sinks == null || sinks.length == 0) {
String msg = "At least one Sink must be specified";
LOGGER.error(msg);
throw new ConfigurationException(msg);
}
}
return props;
}