Apache Mesos
slave.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 __SLAVE_HPP__
18 #define __SLAVE_HPP__
19 
20 #include <stdint.h>
21 
22 #include <list>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include <mesos/attributes.hpp>
28 #include <mesos/resources.hpp>
29 #include <mesos/type_utils.hpp>
30 
31 #include <mesos/agent/agent.hpp>
32 
34 
36 
38 
40 
44 
46 
47 #include <process/http.hpp>
48 #include <process/future.hpp>
49 #include <process/owned.hpp>
50 #include <process/limiter.hpp>
51 #include <process/process.hpp>
52 #include <process/protobuf.hpp>
53 #include <process/shared.hpp>
54 #include <process/sequence.hpp>
55 
56 #include <stout/boundedhashmap.hpp>
57 #include <stout/bytes.hpp>
59 #include <stout/linkedhashmap.hpp>
60 #include <stout/hashmap.hpp>
61 #include <stout/hashset.hpp>
62 #include <stout/option.hpp>
63 #include <stout/os.hpp>
64 #include <stout/path.hpp>
65 #include <stout/recordio.hpp>
66 #include <stout/uuid.hpp>
67 
68 #include "common/http.hpp"
70 #include "common/recordio.hpp"
71 
72 #include "files/files.hpp"
73 
74 #include "internal/evolve.hpp"
75 
76 #include "messages/messages.hpp"
77 
80 
81 #include "slave/constants.hpp"
83 #include "slave/flags.hpp"
84 #include "slave/gc.hpp"
85 #include "slave/http.hpp"
86 #include "slave/metrics.hpp"
87 #include "slave/paths.hpp"
88 #include "slave/state.hpp"
89 
90 // `REGISTERING` is used as an enum value, but it's actually defined as a
91 // constant in the Windows SDK.
92 #ifdef __WINDOWS__
93 #undef REGISTERING
94 #undef REGISTERED
95 #endif // __WINDOWS__
96 
97 namespace mesos {
98 
99 // Forward declarations.
100 class Authorizer;
101 class DiskProfileAdaptor;
102 
103 namespace internal {
104 namespace slave {
105 
106 // Some forward declarations.
107 class TaskStatusUpdateManager;
108 class Executor;
109 class Framework;
110 
111 struct HttpConnection;
112 struct ResourceProvider;
113 
114 
115 class Slave : public ProtobufProcess<Slave>
116 {
117 public:
118  Slave(const std::string& id,
119  const Flags& flags,
121  Containerizer* containerizer,
122  Files* files,
123  GarbageCollector* gc,
124  TaskStatusUpdateManager* taskStatusUpdateManager,
125  mesos::slave::ResourceEstimator* resourceEstimator,
126  mesos::slave::QoSController* qosController,
127  mesos::SecretGenerator* secretGenerator,
128  const Option<Authorizer*>& authorizer);
129 
130  ~Slave() override;
131 
132  void shutdown(const process::UPID& from, const std::string& message);
133 
134  void registered(
135  const process::UPID& from,
136  const SlaveID& slaveId,
137  const MasterSlaveConnection& connection);
138 
139  void reregistered(
140  const process::UPID& from,
141  const SlaveID& slaveId,
142  const std::vector<ReconcileTasksMessage>& reconciliations,
143  const MasterSlaveConnection& connection);
144 
145  void doReliableRegistration(Duration maxBackoff);
146 
147  // TODO(mzhu): Combine this with `runTask()' and replace all `runTask()'
148  // mock with `run()` mock.
150  const process::UPID& from,
151  RunTaskMessage&& runTaskMessage);
152 
153  // Made 'virtual' for Slave mocking.
154  virtual void runTask(
155  const process::UPID& from,
156  const FrameworkInfo& frameworkInfo,
157  const FrameworkID& frameworkId,
158  const process::UPID& pid,
159  const TaskInfo& task,
160  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
162 
163  void run(
164  const FrameworkInfo& frameworkInfo,
165  ExecutorInfo executorInfo,
166  Option<TaskInfo> task,
167  Option<TaskGroupInfo> taskGroup,
168  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
169  const process::UPID& pid,
170  const Option<bool>& launchExecutor);
171 
172  // Made 'virtual' for Slave mocking.
173  //
174  // This function returns a future so that we can encapsulate a task(group)
175  // launch operation (from agent receiving the run message to the completion
176  // of `_run()`) into a single future. This includes all the asynchronous
177  // steps (currently two: unschedule GC and task authorization) prior to the
178  // executor launch.
180  const FrameworkInfo& frameworkInfo,
181  const ExecutorInfo& executorInfo,
182  const Option<TaskInfo>& task,
183  const Option<TaskGroupInfo>& taskGroup,
184  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
185  const Option<bool>& launchExecutor);
186 
187  // Made 'virtual' for Slave mocking.
188  virtual void __run(
189  const FrameworkInfo& frameworkInfo,
190  const ExecutorInfo& executorInfo,
191  const Option<TaskInfo>& task,
192  const Option<TaskGroupInfo>& taskGroup,
193  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
194  const Option<bool>& launchExecutor);
195 
196  // This is called when the resource limits of the container have
197  // been updated for the given tasks and task groups. If the update is
198  // successful, we flush the given tasks to the executor by sending
199  // RunTaskMessages or `LAUNCH_GROUP` events.
200  //
201  // Made 'virtual' for Slave mocking.
202  virtual void ___run(
203  const process::Future<Nothing>& future,
204  const FrameworkID& frameworkId,
205  const ExecutorID& executorId,
206  const ContainerID& containerId,
207  const std::vector<TaskInfo>& tasks,
208  const std::vector<TaskGroupInfo>& taskGroups);
209 
210  // TODO(mzhu): Combine this with `runTaskGroup()' and replace all
211  // `runTaskGroup()' mock with `run()` mock.
213  const process::UPID& from,
214  RunTaskGroupMessage&& runTaskGroupMessage);
215 
216  // Made 'virtual' for Slave mocking.
217  virtual void runTaskGroup(
218  const process::UPID& from,
219  const FrameworkInfo& frameworkInfo,
220  const ExecutorInfo& executorInfo,
221  const TaskGroupInfo& taskGroupInfo,
222  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
223  const Option<bool>& launchExecutor);
224 
225  // Made 'virtual' for Slave mocking.
226  virtual void killTask(
227  const process::UPID& from,
228  const KillTaskMessage& killTaskMessage);
229 
230  // Made 'virtual' for Slave mocking.
231  virtual void shutdownExecutor(
232  const process::UPID& from,
233  const FrameworkID& frameworkId,
234  const ExecutorID& executorId);
235 
236  // Shut down an executor. This is a two phase process. First, an
237  // executor receives a shut down message (shut down phase), then
238  // after a configurable timeout the slave actually forces a kill
239  // (kill phase, via the isolator) if the executor has not
240  // exited.
241  //
242  // Made 'virtual' for Slave mocking.
243  virtual void _shutdownExecutor(Framework* framework, Executor* executor);
244 
245  void shutdownFramework(
246  const process::UPID& from,
247  const FrameworkID& frameworkId);
248 
249  void schedulerMessage(
250  const SlaveID& slaveId,
251  const FrameworkID& frameworkId,
252  const ExecutorID& executorId,
253  const std::string& data);
254 
255  void updateFramework(
256  const UpdateFrameworkMessage& message);
257 
258  void checkpointResources(
259  std::vector<Resource> checkpointedResources,
260  bool changeTotal);
261 
263  const std::vector<Resource>& checkpointedResources);
264 
265  void applyOperation(const ApplyOperationMessage& message);
266 
267  // Reconciles pending operations with the master. This is necessary to handle
268  // cases in which operations were dropped in transit, or in which an agent's
269  // `UpdateSlaveMessage` was sent at the same time as an operation was en route
270  // from the master to the agent.
271  void reconcileOperations(const ReconcileOperationsMessage& message);
272 
273  void subscribe(
274  HttpConnection http,
275  const executor::Call::Subscribe& subscribe,
276  Framework* framework,
277  Executor* executor);
278 
279  void registerExecutor(
280  const process::UPID& from,
281  const FrameworkID& frameworkId,
282  const ExecutorID& executorId);
283 
284  // Called when an executor reregisters with a recovering slave.
285  // 'tasks' : Unacknowledged tasks (i.e., tasks that the executor
286  // driver never received an ACK for.)
287  // 'updates' : Unacknowledged updates.
288  void reregisterExecutor(
289  const process::UPID& from,
290  const FrameworkID& frameworkId,
291  const ExecutorID& executorId,
292  const std::vector<TaskInfo>& tasks,
293  const std::vector<StatusUpdate>& updates);
294 
295  void _reregisterExecutor(
296  const process::Future<Nothing>& future,
297  const FrameworkID& frameworkId,
298  const ExecutorID& executorId,
299  const ContainerID& containerId);
300 
301  void executorMessage(
302  const SlaveID& slaveId,
303  const FrameworkID& frameworkId,
304  const ExecutorID& executorId,
305  const std::string& data);
306 
307  void ping(const process::UPID& from, bool connected);
308 
309  // Handles the task status update.
310  // NOTE: If 'pid' is a valid UPID an ACK is sent to this pid
311  // after the update is successfully handled. If pid == UPID()
312  // no ACK is sent. The latter is used by the slave to send
313  // status updates it generated (e.g., TASK_LOST). If pid == None()
314  // an ACK is sent to the corresponding HTTP based executor.
315  // NOTE: StatusUpdate is passed by value because it is modified
316  // to ensure source field is set.
317  void statusUpdate(StatusUpdate update, const Option<process::UPID>& pid);
318 
319  // Called when the slave receives a `StatusUpdate` from an executor
320  // and the slave needs to retrieve the container status for the
321  // container associated with the executor.
322  void _statusUpdate(
323  StatusUpdate update,
324  const Option<process::UPID>& pid,
325  const ExecutorID& executorId,
326  const Option<process::Future<ContainerStatus>>& containerStatus);
327 
328  // Continue handling the status update after optionally updating the
329  // container's resources.
330  void __statusUpdate(
331  const Option<process::Future<Nothing>>& future,
332  const StatusUpdate& update,
333  const Option<process::UPID>& pid,
334  const ExecutorID& executorId,
335  const ContainerID& containerId,
336  bool checkpoint);
337 
338  // This is called when the task status update manager finishes
339  // handling the update. If the handling is successful, an
340  // acknowledgment is sent to the executor.
341  void ___statusUpdate(
342  const process::Future<Nothing>& future,
343  const StatusUpdate& update,
344  const Option<process::UPID>& pid);
345 
346  // This is called by task status update manager to forward a status
347  // update to the master. Note that the latest state of the task is
348  // added to the update before forwarding.
349  void forward(StatusUpdate update);
350 
352  const process::UPID& from,
353  const SlaveID& slaveId,
354  const FrameworkID& frameworkId,
355  const TaskID& taskId,
356  const std::string& uuid);
357 
359  const process::Future<bool>& future,
360  const TaskID& taskId,
361  const FrameworkID& frameworkId,
362  const UUID& uuid);
363 
365  const process::UPID& from,
366  const AcknowledgeOperationStatusMessage& acknowledgement);
367 
368  void executorLaunched(
369  const FrameworkID& frameworkId,
370  const ExecutorID& executorId,
371  const ContainerID& containerId,
373 
374  // Made 'virtual' for Slave mocking.
375  virtual void executorTerminated(
376  const FrameworkID& frameworkId,
377  const ExecutorID& executorId,
378  const process::Future<Option<
379  mesos::slave::ContainerTermination>>& termination);
380 
381  // NOTE: Pulled these to public to make it visible for testing.
382  // TODO(vinod): Make tests friends to this class instead.
383 
384  // Garbage collects the directories based on the current disk usage.
385  // TODO(vinod): Instead of making this function public, we need to
386  // mock both GarbageCollector (and pass it through slave's constructor)
387  // and os calls.
389 
390  // Garbage collect image layers based on the disk usage of image
391  // store.
393 
394  // Invoked whenever the detector detects a change in masters.
395  // Made public for testing purposes.
396  void detected(const process::Future<Option<MasterInfo>>& _master);
397 
398  enum State
399  {
400  RECOVERING, // Slave is doing recovery.
401  DISCONNECTED, // Slave is not connected to the master.
402  RUNNING, // Slave has (re-)registered.
403  TERMINATING, // Slave is shutting down.
404  } state;
405 
406  // Describes information about agent recovery.
408  {
409  // Flag to indicate if recovery, including reconciling
410  // (i.e., reconnect/kill) with executors is finished.
412 
413  // Flag to indicate that HTTP based executors can
414  // subscribe with the agent. We allow them to subscribe
415  // after the agent recovers the containerizer.
416  bool reconnect = false;
417  } recoveryInfo;
418 
419  // TODO(benh): Clang requires members to be public in order to take
420  // their address which we do in tests (for things like
421  // FUTURE_DISPATCH).
422 // protected:
423  void initialize() override;
424  void finalize() override;
425  void exited(const process::UPID& pid) override;
426 
428  const FrameworkID& frameworkId,
429  const ExecutorID& executorId,
430  const ContainerID& containerId);
431 
432  // If an executor is launched for a task group, `taskInfo` would not be set.
433  void launchExecutor(
434  const Option<process::Future<Secret>>& future,
435  const FrameworkID& frameworkId,
436  const ExecutorID& executorId,
437  const Option<TaskInfo>& taskInfo);
438 
439  void fileAttached(const process::Future<Nothing>& result,
440  const std::string& path,
441  const std::string& virtualPath);
442 
443  Nothing detachFile(const std::string& path);
444 
445  // TODO(qianzhang): This is a workaround to make the default executor task's
446  // volume directory visible in MESOS UI. It handles two cases:
447  // 1. The task has disk resources specified. In this case any disk resources
448  // specified for the task are mounted on the top level container since
449  // currently all resources of nested containers are merged in the top
450  // level executor container. To make sure the task can access any volumes
451  // specified in its disk resources from its sandbox, a workaround was
452  // introduced to the default executor in MESOS-7225, i.e., adding a
453  // `SANDBOX_PATH` volume with type `PARENT` to the corresponding nested
454  // container. This volume gets translated into a bind mount in the nested
455  // container's mount namespace, which is not visible in Mesos UI because
456  // it operates in the host namespace. See MESOS-8279 for details.
457  // 2. The executor has disk resources specified and the task's ContainerInfo
458  // has a `SANDBOX_PATH` volume with type `PARENT` specified to share the
459  // executor's disk volume. Similar to the first case, this `SANDBOX_PATH`
460  // volume gets translated into a bind mount which is not visible in Mesos
461  // UI. See MESOS-8565 for details.
462  //
463  // To make the task's volume directory visible in Mesos UI, here we attach the
464  // executor's volume directory to it so that it can be accessed via the /files
465  // endpoint. So when users browse task's volume directory in Mesos UI, what
466  // they actually browse is the executor's volume directory. Note when calling
467  // `Files::attach()`, the third argument `authorized` is not specified because
468  // it is already specified when we do the attach for the executor's sandbox
469  // and it also applies to the executor's tasks. Note that for the second case
470  // we can not do the attach when the task's ContainerInfo has a `SANDBOX_PATH`
471  // volume with type `PARENT` but the executor has NO disk resources, because
472  // in such case the attach will fail due to the executor's volume directory
473  // not existing which will actually be created by the `volume/sandbox_path`
474  // isolator when launching the nested container. But if the executor has disk
475  // resources, then we will not have this issue since the executor's volume
476  // directory will be created by the `filesystem/linux` isolator when launching
477  // the executor before we do the attach.
479  const ExecutorInfo& executorInfo,
480  const ContainerID& executorContainerId,
481  const Task& task);
482 
483  // TODO(qianzhang): Remove the task's volume directory from the /files
484  // endpoint. This is a workaround for MESOS-8279 and MESOS-8565.
486  const ExecutorInfo& executorInfo,
487  const ContainerID& executorContainerId,
488  const std::vector<Task>& tasks);
489 
490  // Triggers a re-detection of the master when the slave does
491  // not receive a ping.
493 
494  // Made virtual for testing purpose.
495  virtual void authenticate(Duration minTimeout, Duration maxTimeout);
496 
497  // Helper routines to lookup a framework/executor.
498  Framework* getFramework(const FrameworkID& frameworkId) const;
499 
501  const FrameworkID& frameworkId,
502  const ExecutorID& executorId) const;
503 
504  Executor* getExecutor(const ContainerID& containerId) const;
505 
506  // Returns the ExecutorInfo associated with a TaskInfo. If the task has no
507  // ExecutorInfo, then we generate an ExecutorInfo corresponding to the
508  // command executor.
509  ExecutorInfo getExecutorInfo(
510  const FrameworkInfo& frameworkInfo,
511  const TaskInfo& task) const;
512 
513  // Shuts down the executor if it did not register yet.
515  const FrameworkID& frameworkId,
516  const ExecutorID& executorId,
517  const ContainerID& containerId);
518 
519  // Cleans up all un-reregistered executors during recovery.
521 
522  // This function returns the max age of executor/slave directories allowed,
523  // given a disk usage. This value could be used to tune gc.
524  Duration age(double usage);
525 
526  // Checks the current disk usage and schedules for gc as necessary.
527  void checkDiskUsage();
528 
529  // Checks the current container image disk usage and trigger image
530  // gc if necessary.
531  void checkImageDiskUsage();
532 
533  // Recovers the slave, task status update manager and isolator.
535 
536  // This is called after 'recover()'. If 'flags.reconnect' is
537  // 'reconnect', the slave attempts to reconnect to any old live
538  // executors. Otherwise, the slave attempts to shutdown/kill them.
540 
541  // This is a helper to call recover() on the containerizer at the end of
542  // recover() and before __recover().
543  // TODO(idownes): Remove this when we support defers to objects.
545  const Option<state::SlaveState>& state);
546 
547  // This is called when recovery finishes.
548  // Made 'virtual' for Slave mocking.
549  virtual void __recover(const process::Future<Nothing>& future);
550 
551  // Helper to recover a framework from the specified state.
552  void recoverFramework(
553  const state::FrameworkState& state,
554  const hashset<ExecutorID>& executorsToRecheckpoint,
555  const hashmap<ExecutorID, hashset<TaskID>>& tasksToRecheckpoint);
556 
557  // Removes and garbage collects the executor.
558  void removeExecutor(Framework* framework, Executor* executor);
559 
560  // Removes and garbage collects the framework.
561  // Made 'virtual' for Slave mocking.
562  virtual void removeFramework(Framework* framework);
563 
564  // Schedules a 'path' for gc based on its modification time.
565  process::Future<Nothing> garbageCollect(const std::string& path);
566 
567  // Called when the slave was signaled from the specified user.
568  void signaled(int signal, int uid);
569 
570  // Made 'virtual' for Slave mocking.
571  virtual void qosCorrections();
572 
573  // Made 'virtual' for Slave mocking.
574  virtual void _qosCorrections(
576  mesos::slave::QoSCorrection>>& correction);
577 
578  // Returns the resource usage information for all executors.
580 
581  // Handle the second phase of shutting down an executor for those
582  // executors that have not properly shutdown within a timeout.
584  const FrameworkID& frameworkId,
585  const ExecutorID& executorId,
586  const ContainerID& containerId);
587 
588 private:
589  friend class Executor;
590  friend class Framework;
591  friend class Http;
592 
593  friend struct Metrics;
594 
595  Slave(const Slave&) = delete;
596  Slave& operator=(const Slave&) = delete;
597 
598  void _authenticate(Duration currentMinTimeout, Duration currentMaxTimeout);
599 
600  // Process creation of persistent volumes (for CREATE) and/or deletion
601  // of persistent volumes (for DESTROY) as a part of handling
602  // checkpointed resources, and commit the checkpointed resources on
603  // successful completion of all the operations.
604  Try<Nothing> syncCheckpointedResources(
605  const Resources& newCheckpointedResources);
606 
607  process::Future<bool> authorizeTask(
608  const TaskInfo& task,
609  const FrameworkInfo& frameworkInfo);
610 
611  process::Future<bool> authorizeLogAccess(
613 
614  process::Future<bool> authorizeSandboxAccess(
616  const FrameworkID& frameworkId,
617  const ExecutorID& executorId);
618 
619  void sendExecutorTerminatedStatusUpdate(
620  const TaskID& taskId,
621  const process::Future<Option<
622  mesos::slave::ContainerTermination>>& termination,
623  const FrameworkID& frameworkId,
624  const Executor* executor);
625 
626  void sendExitedExecutorMessage(
627  const FrameworkID& frameworkId,
628  const ExecutorID& executorId,
629  const Option<int>& status = None());
630 
631  // Forwards the current total of oversubscribed resources.
632  void forwardOversubscribed();
633  void _forwardOversubscribed(
634  const process::Future<Resources>& oversubscribable);
635 
636  // Helper functions to generate `UpdateSlaveMessage` for either
637  // just updates to resource provider-related information, or both
638  // resource provider-related information and oversubscribed
639  // resources.
640  UpdateSlaveMessage generateResourceProviderUpdate() const;
641  UpdateSlaveMessage generateUpdateSlaveMessage() const;
642 
643  void handleResourceProviderMessage(
645 
646  void addOperation(Operation* operation);
647 
648  // Transitions the operation, and recovers resource if the operation becomes
649  // terminal.
650  void updateOperation(
651  Operation* operation,
652  const UpdateOperationStatusMessage& update);
653 
654  // Update the `latest_status` of the operation if it is not terminal.
655  void updateOperationLatestStatus(
656  Operation* operation,
657  const OperationStatus& status);
658 
659  void removeOperation(Operation* operation);
660 
661  Operation* getOperation(const UUID& uuid) const;
662 
663  void addResourceProvider(ResourceProvider* resourceProvider);
664  ResourceProvider* getResourceProvider(const ResourceProviderID& id) const;
665 
666  void apply(Operation* operation);
667 
668  // Publish all resources that are needed to run the current set of
669  // tasks and executors on the agent.
670  // NOTE: The `additionalResources` parameter is for publishing
671  // additional task resources when launching executors. Consider
672  // removing this parameter once we revisited MESOS-600.
673  process::Future<Nothing> publishResources(
674  const Option<Resources>& additionalResources = None());
675 
676  // PullGauge methods.
677  double _frameworks_active()
678  {
679  return static_cast<double>(frameworks.size());
680  }
681 
682  double _uptime_secs()
683  {
684  return (process::Clock::now() - startTime).secs();
685  }
686 
687  double _registered()
688  {
689  return master.isSome() ? 1 : 0;
690  }
691 
692  double _tasks_staging();
693  double _tasks_starting();
694  double _tasks_running();
695  double _tasks_killing();
696 
697  double _executors_registering();
698  double _executors_running();
699  double _executors_terminating();
700 
701  double _executor_directory_max_allowed_age_secs();
702 
703  double _resources_total(const std::string& name);
704  double _resources_used(const std::string& name);
705  double _resources_percent(const std::string& name);
706 
707  double _resources_revocable_total(const std::string& name);
708  double _resources_revocable_used(const std::string& name);
709  double _resources_revocable_percent(const std::string& name);
710 
711  // Checks whether the two `SlaveInfo` objects are considered
712  // compatible based on the value of the `--configuration_policy`
713  // flag.
714  Try<Nothing> compatible(
715  const SlaveInfo& previous,
716  const SlaveInfo& current) const;
717 
718  void initializeResourceProviderManager(
719  const Flags& flags,
720  const SlaveID& slaveId);
721 
722  protobuf::master::Capabilities requiredMasterCapabilities;
723 
724  const Flags flags;
725 
726  const Http http;
727 
728  SlaveInfo info;
729 
730  protobuf::slave::Capabilities capabilities;
731 
732  // Resources that are checkpointed by the slave.
733  Resources checkpointedResources;
734 
735  // The current total resources of the agent, i.e., `info.resources()` with
736  // checkpointed resources applied and resource provider resources.
737  Resources totalResources;
738 
740 
742 
743  // Note that these frameworks are "completed" only in that
744  // they no longer have any active tasks or executors on this
745  // particular agent.
746  //
747  // TODO(bmahler): Implement a more accurate framework lifecycle
748  // in the agent code, ideally the master can inform the agent
749  // when a framework is actually completed, and the agent can
750  // perhaps store a cache of "idle" frameworks. See MESOS-7890.
752 
754 
755  Containerizer* containerizer;
756 
757  Files* files;
758 
760 
761  process::Time startTime;
762 
763  GarbageCollector* gc;
764 
765  TaskStatusUpdateManager* taskStatusUpdateManager;
766 
767  // Master detection future.
769 
770  // Master's ping timeout value, updated on reregistration.
771  Duration masterPingTimeout;
772 
773  // Timer for triggering re-detection when no ping is received from
774  // the master.
775  process::Timer pingTimer;
776 
777  // Timer for triggering agent (re)registration after detecting a new master.
778  process::Timer agentRegistrationTimer;
779 
780  // Root meta directory containing checkpointed data.
781  const std::string metaDir;
782 
783  // Indicates the number of errors ignored in "--no-strict" recovery mode.
784  unsigned int recoveryErrors;
785 
786  Option<Credential> credential;
787 
788  // Authenticatee name as supplied via flags.
789  std::string authenticateeName;
790 
791  Authenticatee* authenticatee;
792 
793  // Indicates if an authentication attempt is in progress.
794  Option<process::Future<bool>> authenticating;
795 
796  // Indicates if the authentication is successful.
797  bool authenticated;
798 
799  // Indicates if a new authentication attempt should be enforced.
800  bool reauthenticate;
801 
802  // Maximum age of executor directories. Will be recomputed
803  // periodically every flags.disk_watch_interval.
804  Duration executorDirectoryMaxAllowedAge;
805 
806  mesos::slave::ResourceEstimator* resourceEstimator;
807 
808  mesos::slave::QoSController* qosController;
809 
810  std::shared_ptr<DiskProfileAdaptor> diskProfileAdaptor;
811 
812  mesos::SecretGenerator* secretGenerator;
813 
814  const Option<Authorizer*> authorizer;
815 
816  // The most recent estimate of the total amount of oversubscribed
817  // (allocated and oversubscribable) resources.
818  Option<Resources> oversubscribedResources;
819 
820  process::Owned<ResourceProviderManager> resourceProviderManager;
821  process::Owned<LocalResourceProviderDaemon> localResourceProviderDaemon;
822 
823  // Local resource providers known by the agent.
825 
826  // Used to establish the relationship between the operation and the
827  // resources that the operation is operating on. Each resource
828  // provider will keep a resource version UUID, and change it when it
829  // believes that the resources from this resource provider are out
830  // of sync from the master's view. The master will keep track of
831  // the last known resource version UUID for each resource provider,
832  // and attach the resource version UUID in each operation it sends
833  // out. The resource provider should reject operations that have a
834  // different resource version UUID than that it maintains, because
835  // this means the operation is operating on resources that might
836  // have already been invalidated.
837  UUID resourceVersion;
838 
839  // Keeps track of the following:
840  // (1) Pending operations for resources from the agent.
841  // (2) Pending operations or terminal operations that have
842  // unacknowledged status updates for resource provider
843  // provided resources.
844  hashmap<UUID, Operation*> operations;
845 };
846 
847 
848 // Represents the streaming HTTP connection to an executor.
850 {
852  ContentType _contentType)
853  : writer(_writer),
854  contentType(_contentType),
855  encoder(lambda::bind(serialize, contentType, lambda::_1)) {}
856 
857  // Converts the message to an Event before sending.
858  template <typename Message>
859  bool send(const Message& message)
860  {
861  // We need to evolve the internal 'message' into a
862  // 'v1::executor::Event'.
863  return writer.write(encoder.encode(evolve(message)));
864  }
865 
866  bool close()
867  {
868  return writer.close();
869  }
870 
872  {
873  return writer.readerClosed();
874  }
875 
879 };
880 
881 
882 std::ostream& operator<<(std::ostream& stream, const Executor& executor);
883 
884 
885 // Information describing an executor.
886 class Executor
887 {
888 public:
889  Executor(
890  Slave* slave,
891  const FrameworkID& frameworkId,
892  const ExecutorInfo& info,
893  const ContainerID& containerId,
894  const std::string& directory,
895  const Option<std::string>& user,
896  bool checkpoint);
897 
898  ~Executor();
899 
900  // Note that these tasks will also be tracked within `queuedTasks`.
901  void enqueueTaskGroup(const TaskGroupInfo& taskGroup);
902 
903  void enqueueTask(const TaskInfo& task);
904  Option<TaskInfo> dequeueTask(const TaskID& taskId);
905  Task* addLaunchedTask(const TaskInfo& task);
906  void completeTask(const TaskID& taskId);
907  void checkpointExecutor();
908  void checkpointTask(const TaskInfo& task);
909  void checkpointTask(const Task& task);
910 
911  void recoverTask(const state::TaskState& state, bool recheckpointTask);
912 
913  Try<Nothing> updateTaskState(const TaskStatus& status);
914 
915  // Returns true if there are any queued/launched/terminated tasks.
916  bool incompleteTasks();
917 
918  // Returns true if the agent ever sent any tasks to this executor.
919  // More precisely, this function returns whether either:
920  //
921  // (1) There are terminated/completed tasks with a
922  // SOURCE_EXECUTOR status.
923  //
924  // (2) `launchedTasks` is not empty.
925  //
926  // If this function returns false and there are no queued tasks,
927  // we probably (see TODO below) have killed or dropped all of its
928  // initial tasks, in which case the agent will shut down the executor.
929  //
930  // TODO(mzhu): Note however, that since we look through the cache
931  // of completed tasks, we can have false positives when a task
932  // that was delivered to the executor has been evicted from the
933  // completed task cache by tasks that have been killed by the
934  // agent before delivery. This should be fixed.
935  //
936  // NOTE: This function checks whether any tasks has ever been sent,
937  // this does not necessarily mean the executor has ever received
938  // any tasks. Specifically, tasks in `launchedTasks` may be dropped
939  // before received by the executor if the agent restarts.
940  bool everSentTask() const;
941 
942  // Sends a message to the connected executor.
943  template <typename Message>
944  void send(const Message& message)
945  {
946  if (state == REGISTERING || state == TERMINATED) {
947  LOG(WARNING) << "Attempting to send message to disconnected"
948  << " executor " << *this << " in state " << state;
949  }
950 
951  if (http.isSome()) {
952  if (!http->send(message)) {
953  LOG(WARNING) << "Unable to send event to executor " << *this
954  << ": connection closed";
955  }
956  } else if (pid.isSome()) {
957  slave->send(pid.get(), message);
958  } else {
959  LOG(WARNING) << "Unable to send event to executor " << *this
960  << ": unknown connection type";
961  }
962  }
963 
964  // Returns true if this executor is generated by Mesos for a command
965  // task (either command executor for MesosContainerizer or docker
966  // executor for DockerContainerizer).
967  bool isGeneratedForCommandTask() const;
968 
969  // Closes the HTTP connection.
970  void closeHttpConnection();
971 
972  // Returns the task group associated with the task.
973  Option<TaskGroupInfo> getQueuedTaskGroup(const TaskID& taskId);
974 
976 
977  enum State
978  {
979  REGISTERING, // Executor is launched but not (re-)registered yet.
980  RUNNING, // Executor has (re-)registered.
981  TERMINATING, // Executor is being shutdown/killed.
982  TERMINATED, // Executor has terminated but there might be pending updates.
983  } state;
984 
985  // We store the pointer to 'Slave' to get access to its methods
986  // variables. One could imagine 'Executor' as being an inner class
987  // of the 'Slave' class.
989 
990  const ExecutorID id;
991  const ExecutorInfo info;
992 
993  const FrameworkID frameworkId;
994 
995  const ContainerID containerId;
996 
997  const std::string directory;
998 
999  // The sandbox will be owned by this user and the executor will
1000  // run as this user. This can be set to None when --switch_user
1001  // is false or when compiled for Windows.
1003 
1004  const bool checkpoint;
1005 
1006  // An Executor can either be connected via HTTP or by libprocess
1007  // message passing. The following are the possible states:
1008  //
1009  // Agent State Executor State http pid Executor Type
1010  // ----------- -------------- ---- ---- -------------
1011  // RECOVERING REGISTERING None UPID() Unknown
1012  // REGISTERING None Some Libprocess
1013  // REGISTERING None None HTTP
1014  //
1015  // * REGISTERING None None Not known yet
1016  // * * None Some Libprocess
1017  // * * Some None HTTP
1020 
1021  // Tasks can be found in one of the following four data structures:
1022  //
1023  // TODO(bmahler): Make these private to enforce that the task
1024  // lifecycle helper functions are not being bypassed, and provide
1025  // public views into them.
1026 
1027  // Not yet launched tasks. This also includes tasks from `queuedTaskGroups`.
1029 
1030  // Not yet launched task groups. This is needed for correctly sending
1031  // TASK_KILLED status updates for all tasks in the group if any of the
1032  // tasks were killed before the executor could register with the agent.
1033  std::vector<TaskGroupInfo> queuedTaskGroups;
1034 
1035  // Running.
1037 
1038  // Terminated but pending updates.
1040 
1041  // Terminated and updates acked.
1042  // NOTE: We use a shared pointer for Task because clang doesn't like
1043  // stout's implementation of circular_buffer with Task (the Boost code
1044  // used internally by stout attempts to do some memset's which are unsafe).
1045  circular_buffer<std::shared_ptr<Task>> completedTasks;
1046 
1047  // When the slave initiates a destroy of the container, we expect a
1048  // termination to occur. The 'pendingTermation' indicates why the
1049  // slave initiated the destruction and will influence the
1050  // information sent in the status updates for any remaining
1051  // non-terminal tasks.
1053 
1054 private:
1055  Executor(const Executor&) = delete;
1056  Executor& operator=(const Executor&) = delete;
1057 
1058  bool isGeneratedForCommandTask_;
1059 };
1060 
1061 
1062 // Information about a framework.
1064 {
1065 public:
1066  Framework(
1067  Slave* slave,
1068  const Flags& slaveFlags,
1069  const FrameworkInfo& info,
1070  const Option<process::UPID>& pid);
1071 
1072  ~Framework();
1073 
1074  // Returns whether the framework is idle, where idle is
1075  // defined as having no activity:
1076  // (1) The framework has no non-terminal tasks and executors.
1077  // (2) All status updates have been acknowledged.
1078  //
1079  // TODO(bmahler): The framework should also not be considered
1080  // idle if there are unacknowledged updates for "pending" tasks.
1081  bool idle() const;
1082 
1083  void checkpointFramework() const;
1084 
1085  const FrameworkID id() const { return info.id(); }
1086 
1087  Try<Executor*> addExecutor(const ExecutorInfo& executorInfo);
1088  Executor* getExecutor(const ExecutorID& executorId) const;
1089  Executor* getExecutor(const TaskID& taskId) const;
1090 
1091  void destroyExecutor(const ExecutorID& executorId);
1092 
1093  void recoverExecutor(
1094  const state::ExecutorState& state,
1095  bool recheckpointExecutor,
1096  const hashset<TaskID>& tasksToRecheckpoint);
1097 
1098  void addPendingTask(
1099  const ExecutorID& executorId,
1100  const TaskInfo& task);
1101 
1102  // Note that these tasks will also be tracked within `pendingTasks`.
1103  void addPendingTaskGroup(
1104  const ExecutorID& executorId,
1105  const TaskGroupInfo& taskGroup);
1106 
1107  bool hasTask(const TaskID& taskId) const;
1108  bool isPending(const TaskID& taskId) const;
1109 
1110  // Returns the task group associated with a pending task.
1111  Option<TaskGroupInfo> getTaskGroupForPendingTask(const TaskID& taskId);
1112 
1113  // Returns whether the pending task was removed.
1114  bool removePendingTask(const TaskID& taskId);
1115 
1116  Option<ExecutorID> getExecutorIdForPendingTask(const TaskID& taskId) const;
1117 
1118  Resources allocatedResources() const;
1119 
1120  enum State
1121  {
1122  RUNNING, // First state of a newly created framework.
1123  TERMINATING, // Framework is shutting down in the cluster.
1124  } state;
1125 
1126  // We store the pointer to 'Slave' to get access to its methods and
1127  // variables. One could imagine 'Framework' being an inner class of
1128  // the 'Slave' class.
1130 
1131  FrameworkInfo info;
1132 
1134 
1135  // Frameworks using the scheduler driver will have a 'pid',
1136  // which allows us to send executor messages directly to the
1137  // driver. Frameworks using the HTTP API (in 0.24.0) will
1138  // not have a 'pid', in which case executor messages are
1139  // sent through the master.
1141 
1142  // Executors can be found in one of the following
1143  // data structures:
1144  //
1145  // TODO(bmahler): Make these private to enforce that
1146  // the executors lifecycle helper functions are not
1147  // being bypassed, and provide public views into them.
1148 
1149  // Executors with pending tasks.
1151 
1152  // Sequences in this map are used to enforce the order of tasks launched on
1153  // each executor.
1154  //
1155  // Note on the lifecycle of the sequence: if the corresponding executor struct
1156  // has not been created, we tie the lifecycle of the sequence to the first
1157  // task in the sequence (which must have the `launch_executor` flag set to
1158  // true modulo MESOS-3870). If the task fails to launch before creating the
1159  // executor struct, we will delete the sequence. Once the executor struct is
1160  // created, we tie the lifecycle of the sequence to the executor struct.
1161  //
1162  // TODO(mzhu): Create the executor struct early and put the sequence in it.
1164 
1165  // Pending task groups. This is needed for correctly sending
1166  // TASK_KILLED status updates for all tasks in the group if
1167  // any of the tasks are killed while pending.
1168  std::vector<TaskGroupInfo> pendingTaskGroups;
1169 
1170  // Current running executors.
1172 
1173  circular_buffer<process::Owned<Executor>> completedExecutors;
1174 
1175 private:
1176  Framework(const Framework&) = delete;
1177  Framework& operator=(const Framework&) = delete;
1178 };
1179 
1180 
1182 {
1184  const ResourceProviderInfo& _info,
1185  const Resources& _totalResources,
1186  const Option<UUID>& _resourceVersion)
1187  : info(_info),
1188  totalResources(_totalResources),
1189  resourceVersion(_resourceVersion) {}
1190 
1191  void addOperation(Operation* operation);
1192  void removeOperation(Operation* operation);
1193 
1194  ResourceProviderInfo info;
1196 
1197  // Used to establish the relationship between the operation and the
1198  // resources that the operation is operating on. Each resource
1199  // provider will keep a resource version UUID, and change it when it
1200  // believes that the resources from this resource provider are out
1201  // of sync from the master's view. The master will keep track of
1202  // the last known resource version UUID for each resource provider,
1203  // and attach the resource version UUID in each operation it sends
1204  // out. The resource provider should reject operations that have a
1205  // different resource version UUID than that it maintains, because
1206  // this means the operation is operating on resources that might
1207  // have already been invalidated.
1209 
1210  // Pending operations or terminal operations that have
1211  // unacknowledged status updates.
1213 };
1214 
1215 
1229 std::map<std::string, std::string> executorEnvironment(
1230  const Flags& flags,
1231  const ExecutorInfo& executorInfo,
1232  const std::string& directory,
1233  const SlaveID& slaveId,
1234  const process::PID<Slave>& slavePid,
1235  const Option<Secret>& authenticationToken,
1236  bool checkpoint);
1237 
1238 
1239 std::ostream& operator<<(std::ostream& stream, Executor::State state);
1240 std::ostream& operator<<(std::ostream& stream, Framework::State state);
1241 std::ostream& operator<<(std::ostream& stream, Slave::State state);
1242 
1243 } // namespace slave {
1244 } // namespace internal {
1245 } // namespace mesos {
1246 
1247 #endif // __SLAVE_HPP__
void schedulerMessage(const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const std::string &data)
struct mesos::internal::slave::Slave::RecoveryInfo recoveryInfo
Definition: path.hpp:26
virtual process::Future< ResourceUsage > usage()
void executorMessage(const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const std::string &data)
circular_buffer< process::Owned< Executor > > completedExecutors
Definition: slave.hpp:1173
Try< uid_t > uid(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:215
Definition: nothing.hpp:16
ContentType
Definition: http.hpp:43
Definition: http.hpp:42
Definition: option.hpp:28
Try< bool > update(const std::string &link, const Handle &parent, uint16_t protocol, const action::Mirror &mirror)
State
Definition: slave.hpp:977
circular_buffer< std::shared_ptr< Task > > completedTasks
Definition: slave.hpp:1045
void _reregisterExecutor(const process::Future< Nothing > &future, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
Duration age(double usage)
Definition: master.hpp:27
const Option< std::string > user
Definition: slave.hpp:1002
std::ostream & operator<<(std::ostream &stream, const MesosContainerizerProcess::State &state)
const ExecutorInfo info
Definition: slave.hpp:991
virtual void removeFramework(Framework *framework)
Definition: check.hpp:33
void send(const Message &message)
Definition: slave.hpp:944
virtual void shutdownExecutor(const process::UPID &from, const FrameworkID &frameworkId, const ExecutorID &executorId)
void detachTaskVolumeDirectories(const ExecutorInfo &executorInfo, const ContainerID &executorContainerId, const std::vector< Task > &tasks)
void run(const FrameworkInfo &frameworkInfo, ExecutorInfo executorInfo, Option< TaskInfo > task, Option< TaskGroupInfo > taskGroup, const std::vector< ResourceVersionUUID > &resourceVersionUuids, const process::UPID &pid, const Option< bool > &launchExecutor)
void _checkDiskUsage(const process::Future< double > &usage)
Framework * getFramework(const FrameworkID &frameworkId) const
Definition: hashset.hpp:53
virtual void ___run(const process::Future< Nothing > &future, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId, const std::vector< TaskInfo > &tasks, const std::vector< TaskGroupInfo > &taskGroups)
Definition: protobuf_utils.hpp:261
void _statusUpdateAcknowledgement(const process::Future< bool > &future, const TaskID &taskId, const FrameworkID &frameworkId, const UUID &uuid)
ResourceProvider(const ResourceProviderInfo &_info, const Resources &_totalResources, const Option< UUID > &_resourceVersion)
Definition: slave.hpp:1183
void removeExecutor(Framework *framework, Executor *executor)
process::Future< Nothing > _recoverContainerizer(const Option< state::SlaveState > &state)
process::Future< Nothing > closed() const
Definition: slave.hpp:871
Result< std::string > user(Option< uid_t > uid=None())
Definition: su.hpp:284
hashmap< ExecutorID, process::Sequence > taskLaunchSequences
Definition: slave.hpp:1163
v1::AgentID evolve(const SlaveID &slaveId)
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
Option< UUID > resourceVersion
Definition: slave.hpp:1208
Definition: resources.hpp:81
friend class Executor
Definition: slave.hpp:589
void handleRunTaskGroupMessage(const process::UPID &from, RunTaskGroupMessage &&runTaskGroupMessage)
virtual void runTaskGroup(const process::UPID &from, const FrameworkInfo &frameworkInfo, const ExecutorInfo &executorInfo, const TaskGroupInfo &taskGroupInfo, const std::vector< ResourceVersionUUID > &resourceVersionUuids, const Option< bool > &launchExecutor)
bool reconnect
Definition: slave.hpp:416
virtual void executorTerminated(const FrameworkID &frameworkId, const ExecutorID &executorId, const process::Future< Option< mesos::slave::ContainerTermination >> &termination)
Definition: lambda.hpp:30
Option< process::UPID > pid
Definition: slave.hpp:1140
Definition: files.hpp:73
void subscribe(HttpConnection http, const executor::Call::Subscribe &subscribe, Framework *framework, Executor *executor)
hashmap< ExecutorID, hashmap< TaskID, TaskInfo > > pendingTasks
Definition: slave.hpp:1150
enum mesos::internal::slave::Slave::State state
Operation
Definition: cgroups.hpp:458
void _checkImageDiskUsage(const process::Future< double > &usage)
void reregisterExecutor(const process::UPID &from, const FrameworkID &frameworkId, const ExecutorID &executorId, const std::vector< TaskInfo > &tasks, const std::vector< StatusUpdate > &updates)
Definition: flags.hpp:39
Slave * slave
Definition: slave.hpp:1129
Definition: duration.hpp:32
Option< mesos::slave::ContainerTermination > pendingTermination
Definition: slave.hpp:1052
std::map< std::string, std::string > executorEnvironment(const Flags &flags, const ExecutorInfo &executorInfo, const std::string &directory, const SlaveID &slaveId, const process::PID< Slave > &slavePid, const Option< Secret > &authenticationToken, bool checkpoint)
Returns a map of environment variables necessary in order to launch an executor.
void recoverFramework(const state::FrameworkState &state, const hashset< ExecutorID > &executorsToRecheckpoint, const hashmap< ExecutorID, hashset< TaskID >> &tasksToRecheckpoint)
Definition: protobuf_utils.hpp:384
void send(const process::UPID &to, const google::protobuf::Message &message)
Definition: protobuf.hpp:118
bool isSome() const
Definition: option.hpp:115
Definition: task_status_update_manager.hpp:58
LinkedHashMap< TaskID, TaskInfo > queuedTasks
Definition: slave.hpp:1028
void statusUpdateAcknowledgement(const process::UPID &from, const SlaveID &slaveId, const FrameworkID &frameworkId, const TaskID &taskId, const std::string &uuid)
const bool checkpoint
Definition: slave.hpp:1004
void signaled(int signal, int uid)
bool close()
Definition: slave.hpp:866
ContentType contentType
Definition: slave.hpp:877
virtual void _shutdownExecutor(Framework *framework, Executor *executor)
void checkpointResourcesMessage(const std::vector< Resource > &checkpointedResources)
Definition: hashmap.hpp:38
process::Future< Nothing > garbageCollect(const std::string &path)
void finalize() override
Invoked when a process is terminated.
void operationStatusAcknowledgement(const process::UPID &from, const AcknowledgeOperationStatusMessage &acknowledgement)
Definition: resource_estimator.hpp:37
process::Future< Secret > generateSecret(const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
hashmap< std::string, MessageHandler > message
Definition: process.hpp:451
Resources allocatedResources(const Resources &resources, const std::string &role)
Definition: containerizer.hpp:59
void shutdownExecutorTimeout(const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
void attachTaskVolumeDirectory(const ExecutorInfo &executorInfo, const ContainerID &executorContainerId, const Task &task)
Definition: slave.hpp:115
void registered(const process::UPID &from, const SlaveID &slaveId, const MasterSlaveConnection &connection)
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
Option< HttpConnection > http
Definition: slave.hpp:1018
void pingTimeout(process::Future< Option< MasterInfo >> future)
void handleRunTaskMessage(const process::UPID &from, RunTaskMessage &&runTaskMessage)
Definition: http.hpp:340
const ContainerID containerId
Definition: slave.hpp:995
Option< process::UPID > pid
Definition: slave.hpp:1019
ExecutorInfo getExecutorInfo(const FrameworkInfo &frameworkInfo, const TaskInfo &task) const
void forward(StatusUpdate update)
Definition: protobuf_utils.hpp:455
void reconcileOperations(const ReconcileOperationsMessage &message)
Definition: spec.hpp:26
const FrameworkID id() const
Definition: slave.hpp:1085
void launchExecutor(const Option< process::Future< Secret >> &future, const FrameworkID &frameworkId, const ExecutorID &executorId, const Option< TaskInfo > &taskInfo)
void initialize() override
Invoked when a process gets spawned.
const T & get() const &
Definition: option.hpp:118
protobuf::framework::Capabilities capabilities
Definition: slave.hpp:1133
process::Future< Nothing > _recover()
virtual process::Future< Nothing > _run(const FrameworkInfo &frameworkInfo, const ExecutorInfo &executorInfo, const Option< TaskInfo > &task, const Option< TaskGroupInfo > &taskGroup, const std::vector< ResourceVersionUUID > &resourceVersionUuids, const Option< bool > &launchExecutor)
void exited(const process::UPID &pid) override
Invoked when a linked process has exited.
ResourceProviderInfo info
Definition: slave.hpp:1194
The SecretGenerator interface represents a mechanism to create a secret from a principal.
Definition: secret_generator.hpp:34
Definition: protobuf.hpp:100
const ExecutorID id
Definition: slave.hpp:990
HttpConnection(const process::http::Pipe::Writer &_writer, ContentType _contentType)
Definition: slave.hpp:851
State
Definition: slave.hpp:1120
::recordio::Encoder< v1::executor::Event > encoder
Definition: slave.hpp:878
void executorLaunched(const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId, const process::Future< Containerizer::LaunchResult > &future)
Definition: time.hpp:23
void reregistered(const process::UPID &from, const SlaveID &slaveId, const std::vector< ReconcileTasksMessage > &reconciliations, const MasterSlaveConnection &connection)
void fileAttached(const process::Future< Nothing > &result, const std::string &path, const std::string &virtualPath)
std::vector< TaskGroupInfo > pendingTaskGroups
Definition: slave.hpp:1168
Try< std::vector< Entry > > list(const std::string &hierarchy, const std::string &cgroup)
void _statusUpdate(StatusUpdate update, const Option< process::UPID > &pid, const ExecutorID &executorId, const Option< process::Future< ContainerStatus >> &containerStatus)
Definition: boundedhashmap.hpp:27
const FrameworkID frameworkId
Definition: slave.hpp:993
void detected(const process::Future< Option< MasterInfo >> &_master)
Try< Nothing > checkpoint(const std::string &path, const std::string &message)
Definition: state.hpp:123
#define flags
Definition: decoder.hpp:18
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:279
hashmap< ExecutorID, Executor * > executors
Definition: slave.hpp:1171
Definition: none.hpp:27
Definition: attributes.hpp:24
Slave * slave
Definition: slave.hpp:988
LinkedHashMap< TaskID, Task * > launchedTasks
Definition: slave.hpp:1036
process::Future< Nothing > recover(const Try< state::State > &state)
void ___statusUpdate(const process::Future< Nothing > &future, const StatusUpdate &update, const Option< process::UPID > &pid)
Definition: timer.hpp:30
void shutdownFramework(const process::UPID &from, const FrameworkID &frameworkId)
void applyOperation(const ApplyOperationMessage &message)
Nothing detachFile(const std::string &path)
virtual void killTask(const process::UPID &from, const KillTaskMessage &killTaskMessage)
bool send(const Message &message)
Definition: slave.hpp:859
friend class Framework
Definition: slave.hpp:590
virtual void __recover(const process::Future< Nothing > &future)
Slave(const std::string &id, const Flags &flags, mesos::master::detector::MasterDetector *detector, Containerizer *containerizer, Files *files, GarbageCollector *gc, TaskStatusUpdateManager *taskStatusUpdateManager, mesos::slave::ResourceEstimator *resourceEstimator, mesos::slave::QoSController *qosController, mesos::SecretGenerator *secretGenerator, const Option< Authorizer * > &authorizer)
Resources totalResources
Definition: slave.hpp:1195
std::vector< TaskGroupInfo > queuedTaskGroups
Definition: slave.hpp:1033
An abstraction of a Master detector which can be used to detect the leading master from a group...
Definition: detector.hpp:38
static Time now()
The current clock time for either the current process that makes this call or the global clock time i...
hashmap< UUID, Operation * > operations
Definition: slave.hpp:1212
virtual void __run(const FrameworkInfo &frameworkInfo, const ExecutorInfo &executorInfo, const Option< TaskInfo > &task, const Option< TaskGroupInfo > &taskGroup, const std::vector< ResourceVersionUUID > &resourceVersionUuids, const Option< bool > &launchExecutor)
void ping(const process::UPID &from, bool connected)
Definition: metrics.hpp:32
void checkpointResources(std::vector< Resource > checkpointedResources, bool changeTotal)
void __statusUpdate(const Option< process::Future< Nothing >> &future, const StatusUpdate &update, const Option< process::UPID > &pid, const ExecutorID &executorId, const ContainerID &containerId, bool checkpoint)
void doReliableRegistration(Duration maxBackoff)
Try< Nothing > bind(int_fd s, const Address &address)
Definition: network.hpp:46
process::Promise< Nothing > recovered
Definition: slave.hpp:411
Definition: qos_controller.hpp:44
std::string serialize(ContentType contentType, const google::protobuf::Message &message)
const std::string directory
Definition: slave.hpp:997
void statusUpdate(StatusUpdate update, const Option< process::UPID > &pid)
URI http(const std::string &host, const std::string &path="/", const Option< int > &port=None(), const Option< std::string > &query=None(), const Option< std::string > &fragment=None(), const Option< std::string > &user=None(), const Option< std::string > &password=None())
Creates an http URI with the given parameters.
Definition: http.hpp:35
State
Definition: slave.hpp:398
virtual void authenticate(Duration minTimeout, Duration maxTimeout)
virtual void runTask(const process::UPID &from, const FrameworkInfo &frameworkInfo, const FrameworkID &frameworkId, const process::UPID &pid, const TaskInfo &task, const std::vector< ResourceVersionUUID > &resourceVersionUuids, const Option< bool > &launchExecutor)
FrameworkInfo info
Definition: slave.hpp:1131
Definition: owned.hpp:36
process::http::Pipe::Writer writer
Definition: slave.hpp:876
void shutdown(const process::UPID &from, const std::string &message)
Definition: slave.hpp:886
virtual void _qosCorrections(const process::Future< std::list< mesos::slave::QoSCorrection >> &correction)
Executor * getExecutor(const FrameworkID &frameworkId, const ExecutorID &executorId) const
Definition: parse.hpp:33
void registerExecutor(const process::UPID &from, const FrameworkID &frameworkId, const ExecutorID &executorId)
PID< MetricsProcess > metrics
void updateFramework(const UpdateFrameworkMessage &message)
LinkedHashMap< TaskID, Task * > terminatedTasks
Definition: slave.hpp:1039
constexpr const char * name
Definition: shell.hpp:43
void registerExecutorTimeout(const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
Definition: slave.hpp:1063
Definition: authenticatee.hpp:29