Apache Mesos
fetcher.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __SLAVE_CONTAINERIZER_FETCHER_HPP__
18 #define __SLAVE_CONTAINERIZER_FETCHER_HPP__
19 
20 #include <list>
21 #include <string>
22 
23 #include <mesos/mesos.hpp>
24 
26 
27 #include <process/future.hpp>
28 
29 #include "slave/flags.hpp"
30 
31 namespace mesos {
32 namespace internal {
33 namespace slave {
34 
35 // Forward declaration.
36 class FetcherProcess;
37 
38 // Argument passing to and invocation of the external fetcher program.
39 // Bookkeeping of executor files that are cached after downloading from
40 // a URI by the fetcher program. Cache eviction. There has to be exactly
41 // one fetcher with a distinct cache directory per active slave. This
42 // means that the cache directory can only be fixed after the slave ID
43 // has been determined by registration or recovery. Downloads to cache
44 // files are separated on a per-user basis. The cache must only be used
45 // for URIs for which the expected download size can be determined and
46 // trusted before downloading. If there is any problem using the cache
47 // for any given URI, the fetch procedure automatically reverts to
48 // fetching directly into the sandbox directory.
49 class Fetcher
50 {
51 public:
52  // Extracts the basename from a URI. For example, "d.txt" from
53  // "htpp://1.2.3.4:5050/a/b/c/d.txt". The current implementation
54  // only works for fairly regular-shaped URIs with a "/" and a proper
55  // file name at the end.
56  static Try<std::string> basename(const std::string& uri);
57 
58  // Some checks to make sure using the URI value in shell commands
59  // is safe.
60  // TODO(benh): These should be pushed into the scheduler driver and
61  // reported to the user.
62  static Try<Nothing> validateUri(const std::string& uri);
63 
64  // Checks to make sure the URI 'output_file' is valid.
65  static Try<Nothing> validateOutputFile(const std::string& path);
66 
67  // Determines if the given URI refers to a local file system path
68  // and prepends frameworksHome if it is a relative path. Fails if
69  // frameworksHome is empty and a local path is indicated.
71  const std::string& uri,
72  const Option<std::string>& frameworksHome);
73 
74  static bool isNetUri(const std::string& uri);
75 
76  Fetcher(const Flags& flags);
77 
78  // This is only public for tests.
80 
81  virtual ~Fetcher();
82 
83  // Download the URIs specified in the command info and place the
84  // resulting files into the given sandbox directory. Chmod said files
85  // to the user if given. Send stdout and stderr output to files
86  // "stdout" and "stderr" in the given directory. Extract archives and/or
87  // use the cache if so instructed by the given CommandInfo::URI items.
89  const ContainerID& containerId,
90  const CommandInfo& commandInfo,
91  const std::string& sandboxDirectory,
92  const Option<std::string>& user);
93 
94  // Best effort to kill the fetcher subprocess associated with the
95  // indicated container. Do nothing if no such subprocess exists.
96  void kill(const ContainerID& containerId);
97 
98 private:
100 };
101 
102 
103 } // namespace slave {
104 } // namespace internal {
105 } // namespace mesos {
106 
107 #endif // __SLAVE_CONTAINERIZER_FETCHER_HPP__
Definition: path.hpp:26
static Try< std::string > basename(const std::string &uri)
Definition: fetcher.hpp:49
Definition: check.hpp:33
Result< std::string > user(Option< uid_t > uid=None())
Definition: su.hpp:277
Definition: flags.hpp:39
Definition: check.hpp:30
Fetcher(const Flags &flags)
static Try< Nothing > validateUri(const std::string &uri)
static Result< std::string > uriToLocalPath(const std::string &uri, const Option< std::string > &frameworksHome)
process::Future< Nothing > fetch(const ContainerID &containerId, const CommandInfo &commandInfo, const std::string &sandboxDirectory, const Option< std::string > &user)
Definition: spec.hpp:30
static bool isNetUri(const std::string &uri)
void kill(const ContainerID &containerId)
Definition: attributes.hpp:24
Definition: executor.hpp:48
Definition: uri.hpp:21
Definition: owned.hpp:36
static Try< Nothing > validateOutputFile(const std::string &path)
Definition: parse.hpp:33