MCPcopy Create free account
hub / github.com/apache/mesos / addTask

Method addTask

src/master/framework.cpp:148–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146
147
148void Framework::addTask(Task* task)
149{
150 CHECK(!tasks.contains(task->task_id()))
151 << "Duplicate task " << task->task_id()
152 << " of framework " << task->framework_id();
153
154 // Verify that Resource.AllocationInfo is set,
155 // this should be guaranteed by the master.
156 foreach (const Resource& resource, task->resources()) {
157 CHECK(resource.has_allocation_info());
158 }
159
160 tasks[task->task_id()] = task;
161
162 // Unreachable tasks should be added via `addUnreachableTask`.
163 CHECK(task->state() != TASK_UNREACHABLE)
164 << "Task '" << task->task_id() << "' of framework " << id()
165 << " added in TASK_UNREACHABLE state";
166
167 // Since we track terminal but unacknowledged tasks within
168 // `tasks` rather than `completedTasks`, we need to handle
169 // them here: don't count them as consuming resources.
170 //
171 // TODO(bmahler): Users currently get confused because
172 // terminal tasks can show up as "active" tasks in the UI and
173 // endpoints. Ideally, we show the terminal unacknowledged
174 // tasks as "completed" as well.
175 if (!protobuf::isTerminalState(task->state())) {
176 // Note that we explicitly convert from protobuf to `Resources` once
177 // and then use the result for calculations to avoid performance penalty
178 // for multiple conversions and validations implied by `+=` with protobuf
179 // arguments.
180 // Conversion is safe, as resources have already passed validation.
181 const Resources resources = task->resources();
182 totalUsedResources += resources;
183 usedResources[task->slave_id()] += resources;
184
185 // It's possible that we're not tracking the task's role for
186 // this framework if the role is absent from the framework's
187 // set of roles. In this case, we track the role's allocation
188 // for this framework.
189 CHECK(!task->resources().empty());
190 const std::string& role =
191 task->resources().begin()->allocation_info().role();
192
193 if (!isTrackedUnderRole(role)) {
194 trackUnderRole(role);
195 }
196 }
197
198 metrics.incrementTaskState(task->state());
199
200 if (!master->subscribers.subscribed.empty()) {
201 master->subscribers.send(
202 protobuf::master::event::createTaskAdded(*task),
203 info);
204 }
205}

Callers

nothing calls this directly

Calls 9

isTerminalStateFunction · 0.85
createTaskAddedFunction · 0.85
incrementTaskStateMethod · 0.80
sendMethod · 0.65
containsMethod · 0.45
stateMethod · 0.45
resourcesMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected