| 35 | namespace fetcher { |
| 36 | |
| 37 | Try<Owned<Fetcher>> create(const Option<Flags>& _flags) |
| 38 | { |
| 39 | // Use the default flags if not specified. |
| 40 | Flags flags; |
| 41 | if (_flags.isSome()) { |
| 42 | flags = _flags.get(); |
| 43 | } |
| 44 | |
| 45 | // Load built-in plugins. |
| 46 | typedef lambda::function<Try<Owned<Fetcher::Plugin>>()> Creator; |
| 47 | |
| 48 | hashmap<string, Creator> creators = { |
| 49 | {CurlFetcherPlugin::NAME, |
| 50 | [flags]() { return CurlFetcherPlugin::create(flags); }}, |
| 51 | {CopyFetcherPlugin::NAME, |
| 52 | [flags]() { return CopyFetcherPlugin::create(flags); }}, |
| 53 | {HadoopFetcherPlugin::NAME, |
| 54 | [flags]() { return HadoopFetcherPlugin::create(flags); }}, |
| 55 | #ifndef __WINDOWS__ |
| 56 | {DockerFetcherPlugin::NAME, |
| 57 | [flags]() { return DockerFetcherPlugin::create(flags); }}, |
| 58 | #endif // __WINDOWS__ |
| 59 | }; |
| 60 | |
| 61 | vector<Owned<Fetcher::Plugin>> plugins; |
| 62 | |
| 63 | foreachpair (const string& name, const Creator& creator, creators) { |
| 64 | Try<Owned<Fetcher::Plugin>> plugin = creator(); |
| 65 | if (plugin.isError()) { |
| 66 | // NOTE: We skip the plugin if it cannot be created, instead of |
| 67 | // returning an Error so that we can still use other plugins. |
| 68 | LOG(INFO) << "Skipping URI fetcher plugin " << "'" << name << "' " |
| 69 | << "as it could not be created: " << plugin.error(); |
| 70 | continue; |
| 71 | } |
| 72 | |
| 73 | plugins.push_back(plugin.get()); |
| 74 | } |
| 75 | |
| 76 | return Owned<Fetcher>(new Fetcher(plugins)); |
| 77 | } |
| 78 | |
| 79 | } // namespace fetcher { |
| 80 | |