| 214 | |
| 215 | |
| 216 | static Try<string> download( |
| 217 | const string& _sourceUri, |
| 218 | const string& destinationPath, |
| 219 | const Option<string>& frameworksHome, |
| 220 | const Option<Duration>& stallTimeout) |
| 221 | { |
| 222 | // Trim leading whitespace for 'sourceUri'. |
| 223 | const string sourceUri = strings::trim(_sourceUri, strings::PREFIX); |
| 224 | |
| 225 | Try<Nothing> validation = Fetcher::validateUri(sourceUri); |
| 226 | if (validation.isError()) { |
| 227 | return Error(validation.error()); |
| 228 | } |
| 229 | |
| 230 | // 1. Try to fetch using a local copy. |
| 231 | // We regard as local: "file://" or the absence of any URI scheme. |
| 232 | Result<string> sourcePath = |
| 233 | Fetcher::uriToLocalPath(sourceUri, frameworksHome); |
| 234 | |
| 235 | if (sourcePath.isError()) { |
| 236 | return Error(sourcePath.error()); |
| 237 | } else if (sourcePath.isSome()) { |
| 238 | return copyFile(sourcePath.get(), destinationPath); |
| 239 | } |
| 240 | |
| 241 | // 2. Try to fetch URI using os::net / libcurl implementation. |
| 242 | // We consider http, https, ftp, ftps compatible with libcurl. |
| 243 | if (Fetcher::isNetUri(sourceUri)) { |
| 244 | return downloadWithNet(sourceUri, destinationPath, stallTimeout); |
| 245 | } |
| 246 | |
| 247 | // 3. Try to fetch the URI using hadoop client. |
| 248 | // We use the hadoop client to fetch any URIs that are not |
| 249 | // handled by other fetchers(local / os::net). These URIs may be |
| 250 | // `hdfs://` URIs or any other URI that has been configured (and |
| 251 | // hence handled) in the hadoop client. This allows mesos to |
| 252 | // externalize the handling of previously unknown resource |
| 253 | // endpoints without the need to support them natively. |
| 254 | // Note: Hadoop Client is not a hard dependency for running mesos. |
| 255 | // This allows users to get mesos up and running without a |
| 256 | // hadoop_home or the hadoop client setup but in case we reach |
| 257 | // this part and don't have one configured, the fetch would fail |
| 258 | // and log an appropriate error. |
| 259 | return downloadWithHadoopClient(sourceUri, destinationPath); |
| 260 | } |
| 261 | |
| 262 | |
| 263 | // TODO(bernd-mesos): Refactor this into stout so that we can more easily |
no test coverage detected