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::OperationStatus evolve(const OperationStatus& status);
78 v1::Resource evolve(const Resource& resource);
79 v1::ResourceProviderID evolve(const ResourceProviderID& resourceProviderId);
80 v1::Resources evolve(const Resources& resources);
81 v1::Task evolve(const Task& task);
82 v1::TaskID evolve(const TaskID& taskId);
83 v1::TaskInfo evolve(const TaskInfo& taskInfo);
84 v1::TaskStatus evolve(const TaskStatus& status);
85 v1::UUID evolve(const UUID& uuid);
86 
87 
89 v1::agent::ProcessIO evolve(const agent::ProcessIO& processIO);
91 
92 
93 v1::maintenance::ClusterStatus evolve(
94  const maintenance::ClusterStatus& cluster);
95 v1::maintenance::Schedule evolve(const maintenance::Schedule& schedule);
96 
97 
100 
101 
102 // Helper for repeated field evolving to 'T1' from 'T2'.
103 template <typename T1, typename T2>
104 google::protobuf::RepeatedPtrField<T1> evolve(
105  const google::protobuf::RepeatedPtrField<T2>& t2s)
106 {
107  google::protobuf::RepeatedPtrField<T1> t1s;
108  t1s.Reserve(t2s.size());
109 
110  foreach (const T2& t2, t2s) {
111  *t1s.Add() = evolve(t2);
112  }
113 
114  return t1s;
115 }
116 
117 
121 
122 
123 // Helper functions that evolve old style internal messages to a
124 // v1::scheduler::Event.
125 v1::scheduler::Event evolve(const ExitedExecutorMessage& message);
126 v1::scheduler::Event evolve(const ExecutorToFrameworkMessage& message);
127 v1::scheduler::Event evolve(const FrameworkErrorMessage& message);
128 v1::scheduler::Event evolve(const FrameworkRegisteredMessage& message);
129 v1::scheduler::Event evolve(const FrameworkReregisteredMessage& message);
130 v1::scheduler::Event evolve(const InverseOffersMessage& message);
131 v1::scheduler::Event evolve(const LostSlaveMessage& message);
132 v1::scheduler::Event evolve(const ResourceOffersMessage& message);
133 v1::scheduler::Event evolve(const RescindInverseOfferMessage& message);
134 v1::scheduler::Event evolve(const RescindResourceOfferMessage& message);
135 v1::scheduler::Event evolve(const StatusUpdateMessage& message);
136 v1::scheduler::Event evolve(const UpdateOperationStatusMessage& message);
137 
138 
141 
142 
143 // Helper functions that evolve old style internal messages to a
144 // v1::Executor::Event.
145 v1::executor::Event evolve(const ExecutorRegisteredMessage& message);
146 v1::executor::Event evolve(const FrameworkToExecutorMessage& message);
147 v1::executor::Event evolve(const KillTaskMessage& message);
148 v1::executor::Event evolve(const RunTaskMessage& message);
149 v1::executor::Event evolve(const ShutdownExecutorMessage& message);
150 v1::executor::Event evolve(const StatusUpdateAcknowledgementMessage& message);
151 
152 
155 
156 
157 // Before the v1 API we had REST endpoints that returned JSON. The JSON was not
158 // specified in any formal way, i.e., there were no protobufs which captured the
159 // structure. As part of the v1 API we introduced the Call/Response protobufs
160 // (see v1/master.proto and v1/agent.proto). This evolve variant transforms a
161 // JSON object that would have been returned from a particular REST endpoint to
162 // a `Response` protobuf suitable for returning from the new v1 API endpoints.
163 
164 // Declaration of helper functions for evolving JSON objects used in master's
165 // REST endpoints pre v1 API.
166 template <v1::master::Response::Type T>
168 
169 
170 // Declaration of helper functions for evolving JSON objects used in agent's
171 // REST endpoints pre v1 API.
172 template <v1::agent::Response::Type T>
174 
175 
176 template <v1::agent::Response::Type T>
178 
179 } // namespace internal {
180 } // namespace mesos {
181 
182 #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:2616
Definition: json.hpp:198
Definition: json.hpp:158
mesos::v1::scheduler::Event Event
Definition: mesos.hpp:2617
Definition: spec.hpp:26
Definition: attributes.hpp:24
mesos::v1::scheduler::Response Response
Definition: mesos.hpp:2619
Try< Nothing > schedule(const mesos::maintenance::Schedule &schedule, const hashmap< MachineID, Machine > &machines)
Performs the following checks on the new maintenance schedule: