Apache Mesos
volume.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 __NVIDIA_VOLUME_HPP__
18 #define __NVIDIA_VOLUME_HPP__
19 
20 #include <string>
21 
22 #include <mesos/mesos.hpp>
23 
24 #include <mesos/docker/spec.hpp>
25 
26 #include <stout/try.hpp>
27 
28 namespace mesos {
29 namespace internal {
30 namespace slave {
31 
32 // Provides a consolidated volume of binaries and libraries
33 // from the user-space portion of the Nvidia GPU drivers.
34 // We follow the approach taken by Nvidia's docker plugin:
35 // https://github.com/NVIDIA/nvidia-docker/
37 {
38 public:
39  // Returns the Nvidia volume. Once we create the volume it is
40  // never deleted until reboot. This means that if an agent
41  // crashes and tries to recreate the volume it will only ever
42  // *add* new libraries to it (nothing will be deleted from it).
43  // This prevents already-running containers from having
44  // whatever libraries they depend on ripped out from under them.
45  static Try<NvidiaVolume> create();
46 
47  const std::string& HOST_PATH() const;
48  const std::string& CONTAINER_PATH() const;
49  Environment ENV(const ::docker::spec::v1::ImageManifest& manifest) const;
50 
51  // Returns whether the container based on a docker image should have the
52  // volume injected.
53  bool shouldInject(const ::docker::spec::v1::ImageManifest& manifest) const;
54 
55 private:
56  NvidiaVolume() = delete;
57 
58  NvidiaVolume(const std::string& _hostPath,
59  const std::string& _containerPath)
60  : hostPath(_hostPath),
61  containerPath(_containerPath) {}
62 
63  std::string hostPath;
64  std::string containerPath;
65 };
66 
67 } // namespace slave {
68 } // namespace internal {
69 } // namespace mesos {
70 
71 #endif // __NVIDIA_GPU_VOLUME_HPP__
Definition: check.hpp:33
URI manifest(const std::string &repository, const std::string &reference, const std::string &registry, const Option< std::string > &scheme=None(), const Option< int > &port=None())
Definition: docker.hpp:47
static Try< NvidiaVolume > create()
bool shouldInject(const ::docker::spec::v1::ImageManifest &manifest) const
const std::string & HOST_PATH() const
Definition: agent.hpp:25
const std::string & CONTAINER_PATH() const
Definition: attributes.hpp:24
Environment ENV(const ::docker::spec::v1::ImageManifest &manifest) const
Definition: volume.hpp:36