Apache Mesos
operation.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 __STATUS_UPDATE_MANAGER_OPERATION_HPP__
18 #define __STATUS_UPDATE_MANAGER_OPERATION_HPP__
19 
20 #include <list>
21 
22 #include <mesos/mesos.hpp>
23 
24 #include <process/future.hpp>
25 #include <process/owned.hpp>
26 #include <process/process.hpp>
27 
28 #include <stout/hashmap.hpp>
29 #include <stout/lambda.hpp>
30 #include <stout/uuid.hpp>
31 
32 #include "messages/messages.hpp"
33 
35 
36 namespace mesos {
37 namespace internal {
38 
39 typedef StatusUpdateManagerProcess<
40  id::UUID,
41  UpdateOperationStatusRecord,
42  UpdateOperationStatusMessage>::State OperationStatusUpdateManagerState;
43 
45 {
46 public:
47  // NOTE: Unless first paused, the status update manager will forward updates
48  // as soon as possible; for example, during recovery or as soon as the first
49  // status update is processed.
51 
53 
55  const OperationStatusUpdateManager& that) = delete;
57  const OperationStatusUpdateManager& that) = delete;
58 
59  // Expects two callbacks:
60  // `forward`: called in order to forward an operation status update to its
61  // recipient.
62  // `getPath`: called in order to generate the path of a status update stream
63  // file, given the operation's `operation_uuid`.
64  void initialize(
65  const lambda::function<
66  void(const UpdateOperationStatusMessage&)>& forward,
67  const lambda::function<const std::string(const id::UUID&)>& getPath);
68 
69  // Checkpoints the update if necessary and reliably sends the update.
70  //
71  // Returns whether the update is handled successfully (e.g. checkpointed).
73  const UpdateOperationStatusMessage& update,
74  bool checkpoint = true);
75 
76  // Checkpoints the acknowledgement to disk if necessary.
77  // Also, sends the next pending status update, if any.
78  //
79  // Returns:
80  // - `true`: if the ACK is handled successfully (e.g., checkpointed)
81  // and the status update stream is not terminated.
82  // - `false`: same as above except the status update stream is terminated.
83  // - A `Failure`: if there are any errors (e.g., duplicate, checkpointing).
85  const id::UUID& operationUuid,
86  const id::UUID& statusUuid);
87 
88  // Recover status updates. The provided list of operation_uuids is used as the
89  // source of truth for which checkpointed files should be recovered from.
90  //
91  // Returns the recovered state, including a map from operation ID to the
92  // stream state recovered for the status file.
93  //
94  // The stream state will be `None` if:
95  //
96  // * The status updates file didn't exist.
97  // * The status updates file was empty.
98  //
99  // The stream state contains all the status updates (both acknowledged and
100  // pending) added to the stream.
101  //
102  // This struct also contains a count of the recoverable errors found during
103  // non-strict recovery.
105  const std::list<id::UUID>& operationUuids,
106  bool strict);
107 
108  // Closes all the status update streams corresponding to this framework.
109  //
110  // NOTE: This stops retrying any pending status updates for this framework,
111  // but does NOT garbage collect any checkpointed state. The caller is
112  // responsible for garbage collection after this method has returned.
113  void cleanup(const FrameworkID& frameworkId);
114 
115  // Stop forwarding status updates until `resume()` is called.
116  void pause();
117 
118  // Resume forwarding status updates until `pause()` is called.
119  void resume();
120 
121 private:
124  id::UUID,
125  UpdateOperationStatusRecord,
126  UpdateOperationStatusMessage>> process;
127 };
128 
129 } // namespace internal {
130 } // namespace mesos {
131 
132 #endif // __STATUS_UPDATE_MANAGER_OPERATION_HPP__
Try< Nothing > checkpoint(const std::string &path, const std::string &message, bool sync, bool downgradeResources)
Definition: state.hpp:123
StatusUpdateManagerProcess< id::UUID, UpdateOperationStatusRecord, UpdateOperationStatusMessage >::State OperationStatusUpdateManagerState
Definition: operation.hpp:42
void initialize(const lambda::function< void(const UpdateOperationStatusMessage &)> &forward, const lambda::function< const std::string(const id::UUID &)> &getPath)
Definition: status_update_manager_process.hpp:78
process::Future< bool > acknowledgement(const id::UUID &operationUuid, const id::UUID &statusUuid)
Definition: uuid.hpp:35
Definition: agent.hpp:25
void cleanup(const FrameworkID &frameworkId)
process::Future< OperationStatusUpdateManagerState > recover(const std::list< id::UUID > &operationUuids, bool strict)
Definition: attributes.hpp:24
Definition: executor.hpp:48
OperationStatusUpdateManager & operator=(const OperationStatusUpdateManager &that)=delete
process::Future< Nothing > update(const UpdateOperationStatusMessage &update, bool checkpoint=true)
Definition: owned.hpp:36