softwarecontainer  0.18.0-739e8d7 2017-05-04
cgroupsgateway.h
1 /*
2  * Copyright (C) 2016-2017 Pelagicore AB
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
9  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
11  * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
12  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
13  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
14  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15  * SOFTWARE.
16  *
17  * For further information see LICENSE
18  */
19 
20 
21 #pragma once
22 
23 #include "gateway/gateway.h"
24 #include "cgroupsparser.h"
25 #include "softwarecontainererror.h"
26 
27 namespace softwarecontainer {
28 
33 class CgroupsGateway: public Gateway
34 {
35  LOG_DECLARE_CLASS_CONTEXT("CGRO", "Cgroups gateway");
36 
37 public:
38  static constexpr const char *ID = "cgroups";
39 
40  CgroupsGateway(std::shared_ptr<ContainerAbstractInterface> container);
41  ~CgroupsGateway() { }
42 
43  bool readConfigElement(const json_t *element) override;
44  bool activateGateway() override;
45  bool teardownGateway() override;
46 
47 private:
48  CGroupsParser m_parser;
49 };
50 
52 {
53 public:
55  m_message("Cgroups Gateway exception")
56  {
57  }
58 
59  CgroupsGatewayError(const std::string &message):
60  m_message(message)
61  {
62  }
63 
64  virtual const char *what() const throw()
65  {
66  return m_message.c_str();
67  }
68 
69 protected:
70  std::string m_message;
71 };
72 
74 {
75 public:
77  CgroupsGatewayError("Range error is occurred when trying to limit memory")
78  {
79  }
80 
81  LimitRangeError(const std::string &message):
82  CgroupsGatewayError(message)
83  {
84  }
85 };
86 
88 {
89 public:
91  CgroupsGatewayError("The configuration being applied has a bad suffix")
92  {
93  }
94 
95  BadSuffixError(const std::string &message):
96  CgroupsGatewayError(message)
97  {
98  }
99 };
100 
102 {
103 public:
104  JSonError():
105  CgroupsGatewayError("A configuration error has occured")
106  {
107  }
108 
109  JSonError(const std::string &message):
110  CgroupsGatewayError(message)
111  {
112  }
113 };
114 
116 {
117 public:
119  CgroupsGatewayError("The given value is invalid")
120  {
121  }
122  InvalidInputError(const std::string &message):
123  CgroupsGatewayError(message)
124  {
125  }
126 };
127 
128 } // namespace softwarecontainer
bool readConfigElement(const json_t *element) override
Gateway specific parsing of config elements.
The cgroups gateway sets cgroups related settings for the container.
Gateway base class for SoftwareContainer.
Definition: gateway.h:61
Developers guide to adding a config item: