Apache Mesos
flags.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 __MESSAGES_FLAGS_HPP__
18 #define __MESSAGES_FLAGS_HPP__
19 
20 #include <string>
21 #include <ostream>
22 
23 #include <stout/error.hpp>
24 #include <stout/json.hpp>
25 #include <stout/protobuf.hpp>
26 #include <stout/try.hpp>
27 
28 #include <stout/flags/parse.hpp>
29 
30 #include "common/parse.hpp"
31 
32 #include "messages/flags.pb.h"
33 
34 namespace flags {
35 
36 template <>
37 inline Try<mesos::internal::ImageGcConfig> parse(const std::string& value)
38 {
39  // Convert from string or file to JSON.
40  Try<JSON::Object> json = parse<JSON::Object>(value);
41  if (json.isError()) {
42  return Error(json.error());
43  }
44 
45  return protobuf::parse<mesos::internal::ImageGcConfig>(json.get());
46 }
47 
48 
49 template <>
50 inline Try<mesos::internal::Firewall> parse(const std::string& value)
51 {
52  // Convert from string or file to JSON.
53  Try<JSON::Object> json = parse<JSON::Object>(value);
54  if (json.isError()) {
55  return Error(json.error());
56  }
57 
58  return protobuf::parse<mesos::internal::Firewall>(json.get());
59 }
60 
61 
62 template <>
63 inline Try<mesos::internal::ContainerDNSInfo> parse(const std::string& value)
64 {
65  // Convert from string or file to JSON.
66  Try<JSON::Object> json = parse<JSON::Object>(value);
67  if (json.isError()) {
68  return Error(json.error());
69  }
70 
71  return protobuf::parse<mesos::internal::ContainerDNSInfo>(json.get());
72 }
73 
74 
75 template <>
76 inline Try<mesos::internal::SlaveCapabilities> parse(const std::string& value)
77 {
78  // Convert from string or file to JSON.
79  Try<JSON::Object> json = parse<JSON::Object>(value);
80  if (json.isError()) {
81  return Error(json.error());
82  }
83 
84  return protobuf::parse<mesos::internal::SlaveCapabilities>(json.get());
85 }
86 
87 } // namespace flags {
88 
89 namespace mesos {
90 namespace internal {
91 
92 inline std::ostream& operator<<(
93  std::ostream& stream,
94  const ImageGcConfig& imageGcConfig)
95 {
96  return stream << imageGcConfig.DebugString();
97 }
98 
99 
100 inline std::ostream& operator<<(
101  std::ostream& stream,
102  const Firewall& rules)
103 {
104  return stream << rules.DebugString();
105 }
106 
107 
108 inline std::ostream& operator<<(
109  std::ostream& stream,
110  const ContainerDNSInfo& dns)
111 {
112  return stream << dns.DebugString();
113 }
114 
115 
116 inline std::ostream& operator<<(
117  std::ostream& stream,
118  const SlaveCapabilities& slaveCapabilities)
119 {
120  return stream << slaveCapabilities.DebugString();
121 }
122 
123 } // namespace internal {
124 } // namespace mesos {
125 
126 #endif // __MESSAGES_FLAGS_HPP__
Definition: errorbase.hpp:36
T & get()&
Definition: try.hpp:73
Definition: check.hpp:33
Try< mesos::ACLs > parse(const std::string &value)
Returns the OCI v1 descriptor, image index, image manifest and image configuration from the given str...
Definition: parse.hpp:36
Definition: spec.hpp:26
void json(JSON::ObjectWriter *writer, const Task &task)
static Try error(const E &e)
Definition: try.hpp:42
Definition: attributes.hpp:24
bool isError() const
Definition: try.hpp:71
std::ostream & operator<<(std::ostream &stream, const SecurePathOrValue &flag)
Definition: flag.hpp:113
Definition: parse.hpp:33