| 153 | taskResources.allocate(role); |
| 154 | |
| 155 | foreach (const Offer& offer, offers) { |
| 156 | LOG(INFO) << "Received offer " << offer.id() << " from agent " |
| 157 | << offer.slave_id() << " (" << offer.hostname() << ") " |
| 158 | << "with " << offer.resources(); |
| 159 | |
| 160 | Resources resources(offer.resources()); |
| 161 | |
| 162 | // If we've already launched the task, or if the offer is not |
| 163 | // big enough, reject the offer. |
| 164 | if (taskActive || !resources.toUnreserved().contains(taskResources)) { |
| 165 | Filters filters; |
| 166 | filters.set_refuse_seconds(600); |
| 167 | |
| 168 | LOG(INFO) << "Declining offer " << offer.id() << ": " |
| 169 | << (taskActive ? "a task is already running" |
| 170 | : "offer does not fit"); |
| 171 | |
| 172 | driver->declineOffer(offer.id(), filters); |
| 173 | continue; |
| 174 | } |
| 175 | |
| 176 | int taskId = tasksLaunched++; |
| 177 | |
| 178 | // The task sleeps for the amount of seconds specified by the |
| 179 | // pre_sleep_duration flag, ramps up the disk usage up to the limit |
| 180 | // specified by `--use_disk_limit` and then sleeps for |
| 181 | // post_sleep_duration more seconds. |
| 182 | static const string command = |
| 183 | "sleep " + stringify(flags.pre_sleep_duration.secs()) + |
| 184 | " && dd if=/dev/zero of=file bs=1K count=" + |
| 185 | stringify(flags.disk_use_limit.bytes() / Bytes::KILOBYTES) + |
| 186 | " && sleep " + stringify(flags.post_sleep_duration.secs()); |
| 187 | |
| 188 | TaskInfo task; |
| 189 | task.set_name(flags.name + " Task"); |
| 190 | task.mutable_task_id()->set_value(stringify(taskId)); |
| 191 | task.mutable_slave_id()->MergeFrom(offer.slave_id()); |
| 192 | task.mutable_resources()->CopyFrom(taskResources); |
| 193 | task.mutable_command()->set_shell(true); |
| 194 | task.mutable_command()->set_value(command); |
| 195 | |
| 196 | LOG(INFO) << "Starting task " << taskId; |
| 197 | |
| 198 | driver->launchTasks(offer.id(), {task}); |
| 199 | |
| 200 | taskActive = true; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | void statusUpdate(SchedulerDriver* driver, const TaskStatus& status) |
nothing calls this directly
no test coverage detected