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