Find out how large a potential download from the given URI is.
| 306 | |
| 307 | // Find out how large a potential download from the given URI is. |
| 308 | static Try<Bytes> fetchSize( |
| 309 | const string& uri, |
| 310 | const Option<string>& frameworksHome) |
| 311 | { |
| 312 | VLOG(1) << "Fetching size for URI: " << uri; |
| 313 | |
| 314 | Result<string> path = Fetcher::uriToLocalPath(uri, frameworksHome); |
| 315 | if (path.isError()) { |
| 316 | return Error(path.error()); |
| 317 | } |
| 318 | if (path.isSome()) { |
| 319 | Try<Bytes> size = os::stat::size( |
| 320 | path.get(), os::stat::FollowSymlink::FOLLOW_SYMLINK); |
| 321 | if (size.isError()) { |
| 322 | return Error("Could not determine file size for: '" + path.get() + |
| 323 | "', error: " + size.error()); |
| 324 | } |
| 325 | return size.get(); |
| 326 | } |
| 327 | |
| 328 | if (Fetcher::isNetUri(uri)) { |
| 329 | Try<Bytes> size = net::contentLength(uri); |
| 330 | if (size.isError()) { |
| 331 | return Error(size.error()); |
| 332 | } |
| 333 | if (size.get() == 0) { |
| 334 | return Error("URI reported content-length 0: " + uri); |
| 335 | } |
| 336 | |
| 337 | return size.get(); |
| 338 | } |
| 339 | |
| 340 | // TODO(hausdorff): (MESOS-5460) Explore adding support for fetching from |
| 341 | // HDFS. |
| 342 | #ifndef __WINDOWS__ |
| 343 | Try<Owned<HDFS>> hdfs = HDFS::create(); |
| 344 | if (hdfs.isError()) { |
| 345 | return Error("Failed to create HDFS client: " + hdfs.error()); |
| 346 | } |
| 347 | |
| 348 | Future<Bytes> size = hdfs.get()->du(uri); |
| 349 | size.await(); |
| 350 | |
| 351 | if (!size.isReady()) { |
| 352 | return Error("Hadoop client could not determine size: " + |
| 353 | (size.isFailed() ? size.failure() : "discarded")); |
| 354 | } |
| 355 | |
| 356 | return size.get(); |
| 357 | #else |
| 358 | return Error("Windows currently does not support fetching files from HDFS"); |
| 359 | #endif // __WINDOWS__ |
| 360 | } |
| 361 | |
| 362 | |
| 363 | Future<Nothing> FetcherProcess::fetch( |
no test coverage detected