Apache Mesos
store.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 __PROVISIONER_STORE_HPP__
18 #define __PROVISIONER_STORE_HPP__
19 
20 #include <string>
21 #include <vector>
22 
23 #include <mesos/mesos.hpp>
24 
25 #include <mesos/appc/spec.hpp>
26 
27 #include <mesos/docker/v1.hpp>
28 
30 
31 #include <process/future.hpp>
32 #include <process/owned.hpp>
33 
34 #include <stout/hashset.hpp>
35 #include <stout/try.hpp>
36 
37 #include "slave/flags.hpp"
38 
39 namespace mesos {
40 namespace internal {
41 namespace slave {
42 
43 // Includes a vector of rootfs layers in topological order corresponding
44 // to a specific image, and its runtime configuration.
45 struct ImageInfo
46 {
47  std::vector<std::string> layers;
48 
49  // Docker v1 image manifest.
51 
52  // Appc image manifest.
54 
55  // Path of docker manifest v2 schema2 config.
57 };
58 
59 
60 // An image store abstraction that "stores" images. It serves as a
61 // read-through cache (cache misses are fetched remotely and
62 // transparently) for images.
63 class Store
64 {
65 public:
67  const Flags& flags,
68  SecretResolver* secretResolver = nullptr);
69 
70  virtual ~Store() {}
71 
72  virtual process::Future<Nothing> recover() = 0;
73 
74  // Get the specified image (and all its recursive dependencies) as a
75  // list of rootfs layers in the topological order (dependencies go
76  // before dependents in the list). The images required to build this
77  // list are either retrieved from the local cache or fetched
78  // remotely.
79  //
80  // NOTE: The returned list should not have duplicates. e.g., in the
81  // following scenario the result should be [C, B, D, A] (B before D
82  // in this example is decided by the order in which A specifies its
83  // dependencies).
84  //
85  // A --> B --> C
86  // | ^
87  // |---> D ----|
88  //
89  // The returned future fails if the requested image or any of its
90  // dependencies cannot be found or failed to be fetched.
91  virtual process::Future<ImageInfo> get(
92  const Image& image,
93  const std::string& backend) = 0;
94 
95  // Prune unused images from the given store. This is called within
96  // an exclusive lock from `provisioner`, which means any other
97  // image provision or prune are blocked until the future is satsified,
98  // so an implementation should minimize the blocking time.
99  //
100  // Any image specified in `excludedImages` should not be pruned if
101  // it is already cached previously.
102  //
103  // On top of this, all layer paths used to provisioner all active
104  // containers are also passed in `activeLayerPaths`, and these layers
105  // should also be retained. Because in certain store (e.g, docker store)
106  // the cache is not source of truth, and we need to not only keep the
107  // excluded images, but also maintain the cache.
108  virtual process::Future<Nothing> prune(
109  const std::vector<Image>& excludedImages,
110  const hashset<std::string>& activeLayerPaths);
111 };
112 
113 } // namespace slave {
114 } // namespace internal {
115 } // namespace mesos {
116 
117 #endif // __PROVISIONER_STORE_HPP__
Protocol< RecoverRequest, RecoverResponse > recover
Definition: check.hpp:33
virtual ~Store()
Definition: store.hpp:70
Definition: store.hpp:63
Definition: flags.hpp:39
Definition: store.hpp:45
Option<::appc::spec::ImageManifest > appcManifest
Definition: store.hpp:53
Option< std::string > config
Definition: store.hpp:56
Definition: agent.hpp:25
Option<::docker::spec::v1::ImageManifest > dockerManifest
Definition: store.hpp:50
URI image(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:30
Definition: attributes.hpp:24
std::vector< std::string > layers
Definition: store.hpp:47
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
Definition: resolver.hpp:34
Definition: parse.hpp:33