String defaultName = "hadoopFs";
Class<?> defaultType = FileSystem.class;
if (ctx.containsBean(defaultName)) {
FileSystem fs = (FileSystem) ctx.getBean(defaultName, defaultType);
return (fs instanceof SimplerFileSystem ? fs : new SimplerFileSystem(fs));
}
String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ctx, defaultType);
if (names != null && names.length == 1) {
return ctx.getBean(names[0], defaultType);
}
// sanity check
if (detectedCfg == null) {
log.warn(String.format(
"No Hadoop Configuration or FileSystem detected; not binding variable '%s' to script",
variableName));
return null;
}
try {
FileSystem fs = FileSystem.get(detectedCfg);
return (fs instanceof SimplerFileSystem ? fs : new SimplerFileSystem(fs));
} catch (IOException ex) {
log.warn(String.format("Cannot create HDFS file system'; not binding variable '%s' to script",
defaultName, defaultType, variableName), ex);
}