Apache Mesos
message.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 __RESOURCE_PROVIDER_MESSAGE_HPP__
18 #define __RESOURCE_PROVIDER_MESSAGE_HPP__
19 
20 #include <ostream>
21 #include <vector>
22 
23 #include <mesos/mesos.hpp>
24 #include <mesos/resources.hpp>
25 
26 #include <stout/check.hpp>
27 #include <stout/hashmap.hpp>
28 #include <stout/jsonify.hpp>
29 #include <stout/option.hpp>
30 #include <stout/protobuf.hpp>
31 #include <stout/unreachable.hpp>
32 #include <stout/uuid.hpp>
33 
34 #include "messages/messages.hpp"
35 
36 namespace mesos {
37 namespace internal {
38 
40 {
41  enum class Type
42  {
43  SUBSCRIBE,
46  DISCONNECT,
47  REMOVE
48  };
49 
50  friend std::ostream& operator<<(std::ostream& stream, const Type& type) {
51  switch (type) {
52  case Type::SUBSCRIBE:
53  return stream << "SUBSCRIBE";
54  case Type::UPDATE_STATE:
55  return stream << "UPDATE_STATE";
57  return stream << "UPDATE_OPERATION_STATUS";
58  case Type::DISCONNECT:
59  return stream << "DISCONNECT";
60  case Type::REMOVE:
61  return stream << "REMOVE";
62  }
63 
64  UNREACHABLE();
65  }
66 
67  struct Subscribe
68  {
69  ResourceProviderInfo info;
70  };
71 
72  struct UpdateState
73  {
74  ResourceProviderID resourceProviderId;
78  };
79 
81  {
82  UpdateOperationStatusMessage update;
83  };
84 
85  struct Disconnect
86  {
87  ResourceProviderID resourceProviderId;
88  };
89 
90  struct Remove
91  {
92  ResourceProviderID resourceProviderId;
93  };
94 
96 
102 };
103 
104 
105 inline std::ostream& operator<<(
106  std::ostream& stream,
107  const ResourceProviderMessage& resourceProviderMessage)
108 {
109  stream << stringify(resourceProviderMessage.type) << ": ";
110 
111  switch (resourceProviderMessage.type) {
114  resourceProviderMessage.subscribe;
115 
116  CHECK_SOME(subscribe);
117 
118  return stream << subscribe->info;
119  }
122  updateState = resourceProviderMessage.updateState;
123 
124  CHECK_SOME(updateState);
125 
126  return stream
127  << updateState->resourceProviderId << " "
128  << updateState->totalResources;
129  }
130 
134  resourceProviderMessage.updateOperationStatus;
135 
136  CHECK_SOME(updateOperationStatus);
137 
138  return stream
139  << "(uuid: "
140  << updateOperationStatus->update.operation_uuid()
141  << ") for framework "
142  << updateOperationStatus->update.framework_id()
143  << " (latest state: "
144  << updateOperationStatus->update.latest_status().state()
145  << ", status update state: "
146  << updateOperationStatus->update.status().state() << ")";
147  }
148 
151  resourceProviderMessage.disconnect;
152 
153  CHECK_SOME(disconnect);
154 
155  return stream
156  << "resource provider "
157  << disconnect->resourceProviderId;
158  }
159 
162  resourceProviderMessage.remove;
163 
164  CHECK_SOME(remove);
165 
166  return stream
167  << "resource provider "
168  << remove->resourceProviderId;
169  }
170  }
171 
172  UNREACHABLE();
173 }
174 
175 } // namespace internal {
176 } // namespace mesos {
177 
178 #endif // __RESOURCE_PROVIDER_MESSAGE_HPP__
Option< UpdateState > updateState
Definition: message.hpp:98
Definition: option.hpp:29
Option< Remove > remove
Definition: message.hpp:101
Definition: resources.hpp:83
friend std::ostream & operator<<(std::ostream &stream, const Type &type)
Definition: message.hpp:50
ResourceProviderID resourceProviderId
Definition: message.hpp:87
ResourceProviderID resourceProviderId
Definition: message.hpp:74
hashmap< UUID, Operation > operations
Definition: message.hpp:77
#define CHECK_SOME(expression)
Definition: check.hpp:50
Type type
Definition: message.hpp:95
Option< Disconnect > disconnect
Definition: message.hpp:100
ResourceProviderInfo info
Definition: message.hpp:69
Definition: agent.hpp:25
Option< Subscribe > subscribe
Definition: message.hpp:97
Option< UpdateOperationStatus > updateOperationStatus
Definition: message.hpp:99
#define UNREACHABLE()
Definition: unreachable.hpp:22
Definition: attributes.hpp:24
ResourceProviderID resourceProviderId
Definition: message.hpp:92
UpdateOperationStatusMessage update
Definition: message.hpp:82
std::string stringify(int flags)
Resources totalResources
Definition: message.hpp:76