/
DAGManScheduler.cpp
167 lines (137 loc) · 6.92 KB
/
DAGManScheduler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
* Copyright (c) 2017-2018. The WRENCH Team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include "DAGManScheduler.h"
#include "wrench/services/compute/htcondor/HTCondorService.h"
#include "PegasusSimulationTimestampTypes.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(HTCondorSchedd, "Log category for HTCondor Scheduler Daemon");
namespace wrench {
namespace pegasus {
/**
* @brief Constructor
*
* @param file_registry_service: a pointer to the file registry service
* @param storage_services: a set of storage services available for the scheduler
*/
DAGManScheduler::DAGManScheduler(FileRegistryService *file_registry_service,
const std::set<StorageService *> &storage_services)
: file_registry_service(file_registry_service), storage_services(storage_services) {}
/**
* @brief Destructor
*/
DAGManScheduler::~DAGManScheduler() {}
/**
* @brief Schedule and run a set of ready tasks on available HTCondor resources
*
* @param compute_services: a set of compute services available to run jobs
* @param tasks: a map of (ready) workflow tasks
*
* @throw std::runtime_error
*/
void DAGManScheduler::scheduleTasks(const std::set<ComputeService *> &compute_services,
const std::vector<WorkflowTask *> &tasks) {
WRENCH_INFO("There are %ld ready tasks to schedule", tasks.size());
// TODO: select htcondor service based on condor queue name
auto htcondor_service = (HTCondorService *) *(compute_services.begin());
unsigned long scheduled_tasks = 0;
for (auto task : tasks) {
WorkflowJob *job = nullptr;
if (task->getTaskType() == WorkflowTask::TaskType::TRANSFER) {
// data stage in/out task
std::map<WorkflowFile *, StorageService *> file_locations;
std::set<std::tuple<WorkflowFile *, StorageService *, StorageService *>> pre_file_copies;
std::set<std::tuple<WorkflowFile *, StorageService *, StorageService *>> post_file_copies;
// input files
for (auto input_file : task->getInputFiles()) {
// finding storage service
auto src_dest = (*task->getFileTransfers().find(input_file)).second;
StorageService *src =
src_dest.first == "local" ? htcondor_service->getLocalStorageService() : nullptr;
StorageService *dest =
src_dest.second == "local" ? htcondor_service->getLocalStorageService() : nullptr;
for (auto storage_service : this->storage_services) {
if (!src && storage_service->getHostname() == src_dest.first) {
src = storage_service;
} else if (!dest && storage_service->getHostname() == src_dest.second) {
dest = storage_service;
}
}
if (src != dest) {
pre_file_copies.insert(std::make_tuple(input_file, src, dest));
}
file_locations.insert(std::make_pair(input_file, dest));
}
// output files
for (auto output_file : task->getOutputFiles()) {
// finding storage service
auto src_dest = (*task->getFileTransfers().find(output_file)).second;
StorageService *src =
src_dest.first == "local" ? htcondor_service->getLocalStorageService() : nullptr;
StorageService *dest =
src_dest.second == "local" ? htcondor_service->getLocalStorageService() : nullptr;
for (auto storage_service : this->storage_services) {
if (!src && storage_service->getHostname() == src_dest.first) {
src = storage_service;
} else if (!dest && storage_service->getHostname() == src_dest.second) {
dest = storage_service;
}
}
if (src != dest) {
post_file_copies.insert(std::make_tuple(output_file, src, dest));
}
file_locations.insert(std::make_pair(output_file, dest));
}
// creating and submitting job
job = (WorkflowJob *) this->getJobManager()->createStandardJob({task},
file_locations,
pre_file_copies,
post_file_copies, {});
} else { // regular compute task
// input/output files
std::map<WorkflowFile *, StorageService *> file_locations;
for (auto f : task->getInputFiles()) {
file_locations.insert(std::make_pair(f, htcondor_service->getLocalStorageService()));
}
for (auto f : task->getOutputFiles()) {
file_locations.insert(std::make_pair(f, htcondor_service->getLocalStorageService()));
}
// create job start event
this->simulation->getOutput().addTimestamp<SimulationTimestampJobSubmitted>(
new SimulationTimestampJobSubmitted(task));
// creating job for execution
job = (WorkflowJob *) this->getJobManager()->createStandardJob(task, file_locations);
}
WRENCH_INFO("Scheduling task: %s", task->getID().c_str());
this->getJobManager()->submitJob(job, htcondor_service);
// create job scheduled event
this->simulation->getOutput().addTimestamp<SimulationTimestampJobScheduled>(
new SimulationTimestampJobScheduled(task));
WRENCH_INFO("Scheduled task: %s", task->getID().c_str());
scheduled_tasks++;
}
WRENCH_INFO("Done with scheduling tasks as standard jobs: %ld tasks scheduled out of %ld", scheduled_tasks,
tasks.size());
}
/**
* @brief
*
* @param simulation: a pointer to the simulation object
*/
void DAGManScheduler::setSimuation(wrench::Simulation *simulation) {
this->simulation = simulation;
}
/**
* @brief:
*
* @param monitor_callback_mailbox
*/
void DAGManScheduler::setMonitorCallbackMailbox(std::string monitor_callback_mailbox) {
this->monitor_callback_mailbox = monitor_callback_mailbox;
}
}
}