Apache Mesos
evolve.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 __INTERNAL_EVOLVE_HPP__
18 #define __INTERNAL_EVOLVE_HPP__
19 
20 #include <google/protobuf/message.h>
21 
22 #include <mesos/agent/agent.hpp>
23 
24 #include <mesos/mesos.hpp>
25 #include <mesos/resources.hpp>
26 
27 #include <mesos/master/master.hpp>
28 
30 
31 #include <mesos/master/master.hpp>
32 
34 
36 
38 
39 #include <mesos/v1/mesos.hpp>
40 #include <mesos/v1/resources.hpp>
41 
42 #include <mesos/v1/agent/agent.hpp>
43 
45 
47 
49 
51 
53 
54 #include <stout/foreach.hpp>
55 #include <stout/json.hpp>
56 
57 #include "messages/messages.hpp"
58 
59 namespace mesos {
60 namespace internal {
61 
62 // Helpers for evolving types between versions. Please add as necessary!
63 v1::AgentID evolve(const SlaveID& slaveId);
64 v1::AgentInfo evolve(const SlaveInfo& slaveInfo);
65 v1::DomainInfo evolve(const DomainInfo& domainInfo);
66 v1::ExecutorID evolve(const ExecutorID& executorId);
67 v1::ExecutorInfo evolve(const ExecutorInfo& executorInfo);
68 v1::FileInfo evolve(const FileInfo& fileInfo);
69 v1::FrameworkID evolve(const FrameworkID& frameworkId);
70 v1::FrameworkInfo evolve(const FrameworkInfo& frameworkInfo);
71 v1::InverseOffer evolve(const InverseOffer& inverseOffer);
72 v1::KillPolicy evolve(const KillPolicy& killPolicy);
73 v1::MachineID evolve(const MachineID& machineId);
74 v1::MasterInfo evolve(const MasterInfo& masterInfo);
75 v1::Offer evolve(const Offer& offer);
76 v1::OfferID evolve(const OfferID& offerId);
77 v1::Resource evolve(const Resource& resource);
78 v1::ResourceProviderID evolve(const ResourceProviderID& resourceProviderId);
79 v1::Resources evolve(const Resources& resources);
80 v1::Task evolve(const Task& task);
81 v1::TaskID evolve(const TaskID& taskId);
82 v1::TaskInfo evolve(const TaskInfo& taskInfo);
83 v1::TaskStatus evolve(const TaskStatus& status);
84 
86 v1::agent::ProcessIO evolve(const mesos::agent::ProcessIO& processIO);
87 v1::agent::Response evolve(const mesos::agent::Response& response);
88 
89 v1::maintenance::ClusterStatus evolve(
90  const maintenance::ClusterStatus& cluster);
91 v1::maintenance::Schedule evolve(const maintenance::Schedule& schedule);
92 
93 v1::master::Response evolve(const mesos::master::Response& response);
94 
95 
98  const mesos::resource_provider::Event& event);
99 
100 
102 
103 
104 // Helper for repeated field evolving to 'T1' from 'T2'.
105 template <typename T1, typename T2>
106 google::protobuf::RepeatedPtrField<T1> evolve(
107  google::protobuf::RepeatedPtrField<T2> t2s)
108 {
109  google::protobuf::RepeatedPtrField<T1> t1s;
110 
111  foreach (const T2& t2, t2s) {
112  t1s.Add()->CopyFrom(evolve(t2));
113  }
114 
115  return t1s;
116 }
117 
118 
120 
121 
122 // Helper functions that evolve old style internal messages to a
123 // v1::scheduler::Event.
124 v1::scheduler::Event evolve(const ExitedExecutorMessage& message);
125 v1::scheduler::Event evolve(const ExecutorToFrameworkMessage& message);
126 v1::scheduler::Event evolve(const FrameworkErrorMessage& message);
127 v1::scheduler::Event evolve(const FrameworkRegisteredMessage& message);
128 v1::scheduler::Event evolve(const FrameworkReregisteredMessage& message);
129 v1::scheduler::Event evolve(const InverseOffersMessage& message);
130 v1::scheduler::Event evolve(const LostSlaveMessage& message);
131 v1::scheduler::Event evolve(const ResourceOffersMessage& message);
132 v1::scheduler::Event evolve(const RescindInverseOfferMessage& message);
133 v1::scheduler::Event evolve(const RescindResourceOfferMessage& message);
134 v1::scheduler::Event evolve(const StatusUpdateMessage& message);
135 
138 
139 
140 // Helper functions that evolve old style internal messages to a
141 // v1::Executor::Event.
142 v1::executor::Event evolve(const ExecutorRegisteredMessage& message);
143 v1::executor::Event evolve(const FrameworkToExecutorMessage& message);
144 v1::executor::Event evolve(const KillTaskMessage& message);
145 v1::executor::Event evolve(const RunTaskMessage& message);
146 v1::executor::Event evolve(const ShutdownExecutorMessage& message);
147 v1::executor::Event evolve(const StatusUpdateAcknowledgementMessage& message);
148 
149 
151 
152 
153 // Before the v1 API we had REST endpoints that returned JSON. The JSON was not
154 // specified in any formal way, i.e., there were no protobufs which captured the
155 // structure. As part of the v1 API we introduced the Call/Response protobufs
156 // (see v1/master.proto and v1/agent.proto). This evolve variant transforms a
157 // JSON object that would have been returned from a particular REST endpoint to
158 // a `Response` protobuf suitable for returning from the new v1 API endpoints.
159 
160 // Declaration of helper functions for evolving JSON objects used in master's
161 // REST endpoints pre v1 API.
162 template <v1::master::Response::Type T>
163 v1::master::Response evolve(const JSON::Object& object);
164 
165 
166 // Declaration of helper functions for evolving JSON objects used in agent's
167 // REST endpoints pre v1 API.
168 template <v1::agent::Response::Type T>
169 v1::agent::Response evolve(const JSON::Object& object);
170 
171 template <v1::agent::Response::Type T>
172 v1::agent::Response evolve(const JSON::Array& array);
173 
174 } // namespace internal {
175 } // namespace mesos {
176 
177 #endif // __INTERNAL_EVOLVE_HPP__
v1::AgentID evolve(const SlaveID &slaveId)
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
mesos::v1::scheduler::Call Call
Definition: mesos.hpp:2564
Definition: json.hpp:194
Definition: json.hpp:154
mesos::v1::scheduler::Event Event
Definition: mesos.hpp:2565
Try< Nothing > schedule(const mesos::maintenance::Schedule &schedule, const hashmap< MachineID, Machine > &machines)
Performs the following checks on the new maintenance schedule: