}
Set<String> sourceSet =
new HashSet<String>(Arrays.asList(sources.split("\\s+")));
Map<String, Context> newContextMap = new HashMap<String, Context>();
Iterator<String> iter = sourceSet.iterator();
SourceConfiguration srcConf = null;
/*
* The logic for the following code:
*
* Is it a known component?
* -Yes: Get the SourceType and set the string name of that to
* config and set configSpecified to true.
* -No.Look for config type for the given component:
* -Config Found:
* Set config to the type mentioned, set configSpecified to true
* -No Config found:
* Set config to OTHER, configSpecified to false,
* do basic validation. Leave the context in the
* contextMap to process later. Setting it to other returns
* a vanilla configuration(Source/Sink/Channel Configuration),
* which does basic syntactic validation. This object is not
* put into the map, so the context is retained which can be
* picked up - this is meant for older classes which don't
* implement ConfigurableComponent.
*/
while (iter.hasNext()) {
String sourceName = iter.next();
Context srcContext = sourceContextMap.get(sourceName);
String config = null;
boolean configSpecified = false;
if (srcContext != null) {
SourceType srcType = getKnownSource(srcContext.getString(
BasicConfigurationConstants.CONFIG_TYPE));
if (srcType == null) {
config = srcContext.getString(
BasicConfigurationConstants.CONFIG_CONFIG);
if (config == null || config.isEmpty()) {
config = "OTHER";
} else {
configSpecified = true;
}
} else {
config = srcType.toString().toUpperCase(Locale.ENGLISH);
configSpecified = true;
}
try {
// Possible reason the configuration can fail here:
// Old component is configured directly using Context
srcConf =
(SourceConfiguration) ComponentConfigurationFactory.create(
sourceName, config, ComponentType.SOURCE);
if (srcConf != null) {
srcConf.configure(srcContext);
Set<String> channels = new HashSet<String>();
if (srcConf.getChannels() != null) {
channels.addAll(srcConf.getChannels());
}
channels.retainAll(channelSet);
if(channels.isEmpty()){
throw new ConfigurationException(
"No Channels configured for " + sourceName);
}
srcContext.put(BasicConfigurationConstants.CONFIG_CHANNELS,
this.getSpaceDelimitedList(channels));
}
if ((configSpecified && srcConf.isNotFoundConfigClass()) ||
!configSpecified) {
newContextMap.put(sourceName, srcContext);
} else if (configSpecified){
sourceConfigMap.put(sourceName, srcConf);
}
if (srcConf != null) errorList.addAll(srcConf.getErrors());
} catch (ConfigurationException e) {
if (srcConf != null) errorList.addAll(srcConf.getErrors());
iter.remove();
logger.warn("Could not configure source " + sourceName
+ " due to: " + e.getMessage(), e);
}
} else {