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 
56 
57 // An image store abstraction that "stores" images. It serves as a
58 // read-through cache (cache misses are fetched remotely and
59 // transparently) for images.
60 class Store
61 {
62 public:
64  const Flags& flags,
65  SecretResolver* secretResolver = nullptr);
66 
67  virtual ~Store() {}
68 
69  virtual process::Future<Nothing> recover() = 0;
70 
71  // Get the specified image (and all its recursive dependencies) as a
72  // list of rootfs layers in the topological order (dependencies go
73  // before dependents in the list). The images required to build this
74  // list are either retrieved from the local cache or fetched
75  // remotely.
76  //
77  // NOTE: The returned list should not have duplicates. e.g., in the
78  // following scenario the result should be [C, B, D, A] (B before D
79  // in this example is decided by the order in which A specifies its
80  // dependencies).
81  //
82  // A --> B --> C
83  // | ^
84  // |---> D ----|
85  //
86  // The returned future fails if the requested image or any of its
87  // dependencies cannot be found or failed to be fetched.
88  virtual process::Future<ImageInfo> get(
89  const Image& image,
90  const std::string& backend) = 0;
91 
92  // Prune unused images from the given store. This is called within
93  // an exclusive lock from `provisioner`, which means any other
94  // image provision or prune are blocked until the future is satsified,
95  // so an implementation should minimize the blocking time.
96  //
97  // Any image specified in `excludedImages` should not be pruned if
98  // it is already cached previously.
99  //
100  // On top of this, all layer paths used to provisioner all active
101  // containers are also passed in `activeLayerPaths`, and these layers
102  // should also be retained. Because in certain store (e.g, docker store)
103  // the cache is not source of truth, and we need to not only keep the
104  // excluded images, but also maintain the cache.
106  const std::vector<Image>& excludedImages,
107  const hashset<std::string>& activeLayerPaths);
108 };
109 
110 } // namespace slave {
111 } // namespace internal {
112 } // namespace mesos {
113 
114 #endif // __PROVISIONER_STORE_HPP__
Definition: try.hpp:34
virtual ~Store()
Definition: store.hpp:67
Definition: store.hpp:60
Definition: flags.hpp:39
Definition: store.hpp:45
Option<::appc::spec::ImageManifest > appcManifest
Definition: store.hpp:53
Option<::docker::spec::v1::ImageManifest > dockerManifest
Definition: store.hpp:50
virtual process::Future< Nothing > recover()=0
#define flags
Definition: decoder.hpp:18
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
virtual process::Future< Nothing > prune(const std::vector< Image > &excludedImages, const hashset< std::string > &activeLayerPaths)
std::vector< std::string > layers
Definition: store.hpp:47
Definition: resolver.hpp:34
static Try< hashmap< Image::Type, process::Owned< Store > > > create(const Flags &flags, SecretResolver *secretResolver=nullptr)