Apache Mesos
cache.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 __APPC_PROVISIONER_CACHE_HPP__
18 #define __APPC_PROVISIONER_CACHE_HPP__
19 
20 #include <map>
21 #include <string>
22 
23 #include <process/owned.hpp>
24 
25 #include <stout/hashmap.hpp>
26 
27 #include <mesos/mesos.hpp>
28 
29 #include <mesos/appc/spec.hpp>
30 
31 namespace mesos {
32 namespace internal {
33 namespace slave {
34 namespace appc {
35 
42 class Cache
43 {
44 public:
52  static Try<process::Owned<Cache>> create(const Path& storeDir);
53 
54 
59 
60 
73  Try<Nothing> add(const std::string& imageId);
74 
75 
83  Option<std::string> find(const Image::Appc& image) const;
84 
85 private:
86  struct Key
87  {
88  Key(const Image::Appc& image);
89 
90  Key(const std::string& name,
91  const std::map<std::string, std::string>& labels);
92 
93  bool operator==(const Key& other) const;
94 
95  std::string name;
96  std::map<std::string, std::string> labels;
97  };
98 
99  struct KeyHasher
100  {
101  size_t operator()(const Key& key) const;
102  };
103 
104  Cache(const Path& imagesDir);
105 
106  const Path storeDir;
107 
108  // Mappings: Key -> image id.
110 };
111 
112 } // namespace appc {
113 } // namespace slave {
114 } // namespace internal {
115 } // namespace mesos {
116 
117 #endif // __APPC_PROVISIONER_CACHE_HPP__
Try< Nothing > recover()
Recovers/rebuilds the cache from its image store directory.
bool operator==(const DockerVolume &left, const DockerVolume &right)
Definition: state.hpp:29
Definition: check.hpp:33
Definition: hashmap.hpp:38
static Try< process::Owned< Cache > > create(const Path &storeDir)
Factory method for creating cache.
Represents a POSIX or Windows file system path and offers common path manipulations.
Definition: path.hpp:212
Definition: agent.hpp:25
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
Try< Nothing > add(const std::string &imageId)
Adds an image to the cache by the image&#39;s id.
Definition: spec.hpp:28
Encapsulates Appc image cache.
Definition: cache.hpp:42
Option< std::string > find(const Image::Appc &image) const
Finds image id of an image if it is present in the cache/store.
constexpr const char * name
Definition: shell.hpp:41