MCPcopy Create free account
hub / github.com/apache/mesos / fetchSize

Function fetchSize

src/slave/containerizer/fetcher.cpp:308–360  ·  view source on GitHub ↗

Find out how large a potential download from the given URI is.

Source from the content-addressed store, hash-verified

306
307// Find out how large a potential download from the given URI is.
308static 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
363Future<Nothing> FetcherProcess::fetch(

Callers 1

foreachFunction · 0.85

Calls 13

contentLengthFunction · 0.85
duMethod · 0.80
isReadyMethod · 0.80
isFailedMethod · 0.80
failureMethod · 0.80
errorMethod · 0.65
ErrorFunction · 0.50
sizeFunction · 0.50
createFunction · 0.50
isErrorMethod · 0.45
isSomeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected