17 #ifndef __PROTOBUF_UTILS_HPP__ 18 #define __PROTOBUF_UTILS_HPP__ 20 #include <initializer_list> 27 #include <google/protobuf/map.h> 57 class ObjectApprovers;
79 const google::protobuf::MessageLite& value,
80 google::protobuf::io::CodedOutputStream* output)
85 google::protobuf::internal::WireFormatLite::WriteMessage(
86 field_number, value, output);
97 const int messageTypeNumber,
const google::protobuf::Message&)
const;
100 std::vector<std::pair<int, const google::protobuf::FieldDescriptor*>>
101 unionFieldDescriptors_;
102 const google::protobuf::EnumDescriptor* typeDescriptor_;
128 template <
class ProtobufUnion>
131 static const UnionValidator validator(ProtobufUnion::descriptor());
132 return validator.
validate(message.type(), message);
137 const FrameworkInfo& framework,
155 const FrameworkID& frameworkId,
157 const TaskID& taskId,
158 const TaskState& state,
159 const TaskStatus::Source& source,
161 const std::string& message =
"",
173 const FrameworkID& frameworkId,
181 const TaskID& taskId,
182 const TaskState& state,
215 const TaskInfo& task,
216 const TaskState& state,
217 const FrameworkID& frameworkId);
233 const OperationState& state,
244 const OperationStatus& latestStatus,
251 const UUID& operationUUID,
252 const OperationStatus& status,
268 const std::string& key,
274 const google::protobuf::Map<std::string, std::string>&
map);
279 const Labels& labels);
290 const Resource::AllocationInfo& allocationInfo);
308 const google::protobuf::RepeatedPtrField<ResourceVersionUUID>&
309 resourceVersionUUIDs);
336 template <
typename Iterable>
340 switch (capability.type()) {
343 case SlaveInfo::Capability::MULTI_ROLE:
346 case SlaveInfo::Capability::HIERARCHICAL_ROLE:
347 hierarchicalRole =
true;
349 case SlaveInfo::Capability::RESERVATION_REFINEMENT:
350 reservationRefinement =
true;
352 case SlaveInfo::Capability::RESOURCE_PROVIDER:
353 resourceProvider =
true;
355 case SlaveInfo::Capability::RESIZE_VOLUME:
358 case SlaveInfo::Capability::AGENT_OPERATION_FEEDBACK:
359 agentOperationFeedback =
true;
361 case SlaveInfo::Capability::AGENT_DRAINING:
362 agentDraining =
true;
364 case SlaveInfo::Capability::TASK_RESOURCE_LIMITS:
365 taskResourceLimits =
true;
374 bool multiRole =
false;
375 bool hierarchicalRole =
false;
376 bool reservationRefinement =
false;
377 bool resourceProvider =
false;
378 bool resizeVolume =
false;
379 bool agentOperationFeedback =
false;
380 bool agentDraining =
false;
381 bool taskResourceLimits =
false;
383 google::protobuf::RepeatedPtrField<SlaveInfo::Capability>
386 google::protobuf::RepeatedPtrField<SlaveInfo::Capability> result;
388 result.Add()->set_type(SlaveInfo::Capability::MULTI_ROLE);
390 if (hierarchicalRole) {
391 result.Add()->set_type(SlaveInfo::Capability::HIERARCHICAL_ROLE);
393 if (reservationRefinement) {
394 result.Add()->set_type(SlaveInfo::Capability::RESERVATION_REFINEMENT);
396 if (resourceProvider) {
397 result.Add()->set_type(SlaveInfo::Capability::RESOURCE_PROVIDER);
400 result.Add()->set_type(SlaveInfo::Capability::RESIZE_VOLUME);
402 if (agentOperationFeedback) {
403 result.Add()->set_type(SlaveInfo::Capability::AGENT_OPERATION_FEEDBACK);
406 result.Add()->set_type(SlaveInfo::Capability::AGENT_DRAINING);
408 if (taskResourceLimits) {
409 result.Add()->set_type(SlaveInfo::Capability::TASK_RESOURCE_LIMITS);
424 const std::string& message,
425 const TaskStatus::Reason& reason);
431 const ContainerID&
id,
433 const std::string& directory);
437 const std::string& source,
438 const std::string& target,
439 unsigned long flags);
443 const std::string& source,
444 const std::string& target,
445 const std::string&
type,
446 unsigned long flags);
450 const std::string& source,
451 const std::string& target,
452 const std::string& type,
453 const std::string& options,
454 unsigned long flags);
458 const std::string& source,
459 const std::string& target);
463 const std::string& source,
464 const std::string& target);
468 const std::string& target,
469 const bool recursive);
473 const mesos::slave::ContainerMountInfo& mnt);
477 namespace maintenance {
491 std::initializer_list<MachineID> ids);
499 std::initializer_list<MachineID> ids,
508 std::initializer_list<mesos::maintenance::Window> windows);
533 google::protobuf::RepeatedPtrField<Registry::MinimumCapability>*
541 google::protobuf::RepeatedPtrField<Registry::MinimumCapability>*
552 template <
typename Iterable>
556 switch (capability.type()) {
559 case MasterInfo::Capability::AGENT_UPDATE:
562 case MasterInfo::Capability::AGENT_DRAINING:
563 agentDraining =
true;
565 case MasterInfo::Capability::QUOTA_V2:
572 bool agentUpdate =
false;
573 bool agentDraining =
false;
574 bool quotaV2 =
false;
584 const TaskState& state,
585 const TaskStatus& status);
627 namespace framework {
635 template <
typename Iterable>
639 switch (capability.type()) {
642 case FrameworkInfo::Capability::REVOCABLE_RESOURCES:
643 revocableResources =
true;
645 case FrameworkInfo::Capability::TASK_KILLING_STATE:
646 taskKillingState =
true;
648 case FrameworkInfo::Capability::GPU_RESOURCES:
651 case FrameworkInfo::Capability::SHARED_RESOURCES:
652 sharedResources =
true;
654 case FrameworkInfo::Capability::PARTITION_AWARE:
655 partitionAware =
true;
657 case FrameworkInfo::Capability::MULTI_ROLE:
660 case FrameworkInfo::Capability::RESERVATION_REFINEMENT:
661 reservationRefinement =
true;
663 case FrameworkInfo::Capability::REGION_AWARE:
671 bool revocableResources =
false;
672 bool taskKillingState =
false;
673 bool gpuResources =
false;
674 bool sharedResources =
false;
675 bool partitionAware =
false;
676 bool multiRole =
false;
677 bool reservationRefinement =
false;
678 bool regionAware =
false;
684 std::set<std::string>
getRoles(
const FrameworkInfo& frameworkInfo);
692 #endif // __PROTOBUF_UTILS_HPP__ hashmap< Option< ResourceProviderID >, UUID > parseResourceVersions(const google::protobuf::RepeatedPtrField< ResourceVersionUUID > &resourceVersionUUIDs)
UpdateOperationStatusMessage createUpdateOperationStatusMessage(const UUID &operationUUID, const OperationStatus &status, const Option< OperationStatus > &latestStatus=None(), const Option< FrameworkID > &frameworkId=None(), const Option< SlaveID > &slaveId=None())
Capabilities(const Iterable &capabilities)
Definition: protobuf_utils.hpp:553
Try< Resources > getConsumedResources(const Offer::Operation &operation)
Option< bool > getTaskHealth(const Task &task)
mesos::master::Event createFrameworkAdded(const mesos::internal::master::Framework &framework)
Option< Error > validate(const std::string &imageDir)
std::ostream & operator<<(std::ostream &stream, const Future< T > &future)
Definition: future.hpp:1826
void stripAllocationInfo(Offer::Operation *operation)
bool operator==(const std::string &s, const UPID::ID &id)
Definition: pid.hpp:226
Definition: master.hpp:27
Labels convertStringMapToLabels(const google::protobuf::Map< std::string, std::string > &map)
Option< Error > validateProtobufUnion(const ProtobufUnion &message)
Definition: protobuf_utils.hpp:129
google::protobuf::RepeatedPtrField< MachineID > createMachineList(std::initializer_list< MachineID > ids)
Helper for constructing a list of MachineID.
void injectAllocationInfo(Offer::Operation *operation, const Resource::AllocationInfo &allocationInfo)
Definition: protobuf_utils.hpp:332
Unavailability createUnavailability(const process::Time &start, const Option< Duration > &duration=None())
Helper for constructing an unavailability from a Time and Duration.
std::set< std::string > getRoles(const FrameworkInfo &frameworkInfo)
Capabilities(const Iterable &capabilities)
Definition: protobuf_utils.hpp:337
Definition: protobuf_utils.hpp:92
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
Definition: resources.hpp:83
mesos::master::Event createFrameworkUpdated(const mesos::internal::master::Framework &framework)
ContainerID getRootContainerId(const ContainerID &containerId)
mesos::maintenance::Schedule createSchedule(std::initializer_list< mesos::maintenance::Window > windows)
Helper for constructing a maintenance Schedule.
Capability
Definition: capabilities.hpp:35
Try< google::protobuf::Map< std::string, std::string > > convertLabelsToStringMap(const Labels &labels)
Operation
Definition: cgroups.hpp:444
Try< Nothing > start(const std::string &name)
Starts the slice with the given name (via 'systemctl start <name>').
Definition: protobuf_utils.hpp:548
Capabilities(const Iterable &capabilities)
Definition: protobuf_utils.hpp:636
mesos::v1::scheduler::Event Event
Definition: mesos.hpp:2852
Definition: hashmap.hpp:38
mesos::master::Event createTaskAdded(const Task &task)
DWORD pid_t
Definition: windows.hpp:181
mesos::slave::ContainerLimitation createContainerLimitation(const Resources &resources, const std::string &message, const TaskStatus::Reason &reason)
FileInfo createFileInfo(const std::string &path, const struct stat &s)
mesos::master::Event createTaskUpdated(const Task &task, const TaskState &state, const TaskStatus &status)
mesos::master::Event createAgentRemoved(const SlaveID &slaveId)
Try< Nothing > unavailability(const Unavailability &unavailability)
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
StatusUpdate createStatusUpdate(const FrameworkID &frameworkId, const TaskStatus &status, const Option< SlaveID > &slaveId)
Option< ContainerStatus > getTaskContainerStatus(const Task &task)
mesos::slave::ContainerMountInfo createContainerMount(const std::string &source, const std::string &target, const std::string &type, const std::string &options, unsigned long flags)
Definition: protobuf_utils.hpp:631
OperationStatus createOperationStatus(const OperationState &state, const Option< OperationID > &operationId=None(), const Option< std::string > &message=None(), const Option< Resources > &convertedResources=None(), const Option< id::UUID > &statusUUID=None(), const Option< SlaveID > &slaveId=None(), const Option< ResourceProviderID > &resourceProviderId=None())
Task createTask(const TaskInfo &task, const TaskState &state, const FrameworkID &frameworkId)
const int UNKNOWN
Definition: diagnosis.hpp:39
mesos::slave::ContainerFileOperation containerRenameOperation(const std::string &source, const std::string &target)
google::protobuf::RepeatedPtrField< SlaveInfo::Capability > toRepeatedPtrField() const
Definition: protobuf_utils.hpp:384
Definition: protobuf.hpp:61
mesos::master::Response::GetAgents::Agent createAgentResponse(const mesos::internal::master::Slave &slave, const Option< DrainInfo > &drainInfo, bool deactivated, const Option< process::Owned< ObjectApprovers >> &approvers=None())
Try< hashmap< std::string, uint64_t > > stat(const std::string &hierarchy, const std::string &cgroup, const std::string &file)
Operation createOperation(const Offer::Operation &info, const OperationStatus &latestStatus, const Option< FrameworkID > &frameworkId, const Option< SlaveID > &slaveId, const Option< UUID > &operationUUID=None())
Option< Error > validate(const int messageTypeNumber, const google::protobuf::Message &) const
void removeMinimumCapability(google::protobuf::RepeatedPtrField< Registry::MinimumCapability > *capabilities, const MasterInfo::Capability::Type &capability)
bool isTerminalState(const OperationState &state)
mesos::slave::ContainerFileOperation containerSymlinkOperation(const std::string &source, const std::string &target)
Iterable< V > map(F &&f, const Iterable< U, Us... > &input)
Definition: lambda.hpp:46
mesos::master::Event createAgentAdded(const mesos::internal::master::Slave &slave, const Option< DrainInfo > &drainInfo, bool deactivated)
Definition: attributes.hpp:24
bool operator!=(const std::string &s, const UPID::ID &id)
Definition: pid.hpp:232
mesos::master::Event createFrameworkRemoved(const FrameworkInfo &frameworkInfo)
Definition: executor.hpp:48
Type
Definition: capabilities.hpp:82
mesos::slave::ContainerFileOperation containerMountOperation(const mesos::slave::ContainerMountInfo &mnt)
Definition: master.hpp:122
mesos::maintenance::Window createWindow(std::initializer_list< MachineID > ids, const Unavailability &unavailability)
Helper for constructing a maintenance Window.
TimeInfo getCurrentTime()
Try< uint32_t > type(const std::string &path)
TaskStatus createTaskStatus(TaskStatus status, const id::UUID &uuid, double timestamp, const Option< TaskState > &state=None(), const Option< std::string > &message=None(), const Option< TaskStatus::Source > &source=None(), const Option< TaskStatus::Reason > &reason=None(), const Option< std::string > &data=None(), const Option< bool > &healthy=None(), const Option< CheckStatusInfo > &checkStatus=None(), const Option< Labels > &labels=None(), const Option< ContainerStatus > &containerStatus=None(), const Option< TimeInfo > &unreachableTime=None())
bool frameworkHasCapability(const FrameworkInfo &framework, FrameworkInfo::Capability::Type capability)
bool isSpeculativeOperation(const Offer::Operation &operation)
Label createLabel(const std::string &key, const Option< std::string > &value=None())
mesos::slave::ContainerState createContainerState(const Option< ExecutorInfo > &executorInfo, const Option< ContainerInfo > &containerInfo, const ContainerID &id, pid_t pid, const std::string &directory)
Definition: master.hpp:2397
MasterInfo createMasterInfo(const process::UPID &pid)
Option< CheckStatusInfo > getTaskCheckStatus(const Task &task)
void addMinimumCapability(google::protobuf::RepeatedPtrField< Registry::MinimumCapability > *capabilities, const MasterInfo::Capability::Type &capability)
ContainerID parseContainerId(const std::string &value)
UUID createUUID(const Option< id::UUID > &uuid=None())
google::protobuf::RepeatedPtrField< ResourceVersionUUID > createResourceVersions(const hashmap< Option< ResourceProviderID >, UUID > &resourceVersions)
mesos::slave::ContainerFileOperation containerMkdirOperation(const std::string &target, const bool recursive)