4 #include <unordered_set>
24 typedef std::unordered_set<Software, Software::Hash>
SoftwareSet;
47 template <
class Container>
54 typedef std::set<Job*, IdLess<Job>>
JobSet;
57 IMachine(
const std::string& machineName,
uint maxJobs,
double totalRAM,
double totalDiskSpace) :
68 void SetName(
const std::string& name);
105 void Print(std::ostream& os = std::cout)
const override;
108 static void PrintHeader(std::ostream& os = std::cout);
139 template <
class Container>
147 for( ; !_currentJobs.empty() && !found; _currentJobs.pop())
149 if (_currentJobs.top() && _currentJobs.top()->GetId() == id)
153 Job* j = _currentJobs.top();
156 _currentJobs.push(j);
159 temp.push(_currentJobs.top());
162 while (!temp.empty())
164 _currentJobs.push(temp.top());
192 const value_type&
top()
const {
return front(); }
198 template <
class Container>
201 if (name.size() != 0)
204 if (_name.length() > _maxNameLength)
205 _maxNameLength = _name.length();
209 template <
class Container>
212 if (val < _currentJobs.size())
218 template <
class Container>
221 if (val < GetInUseRAM())
227 template <
class Container>
230 if (val < GetInUseDiskSpace())
233 _totalDiskSpace = val;
236 template <
class Container>
242 Container temp(_currentJobs);
245 while (!temp.empty())
247 res.push_back(temp.top());
253 template <
class Container>
258 if (_currentJobs.size() >= _maxJobs)
277 for (
const auto& it : requiredSoftware)
278 if (!SoftwareMeetsRequirements(it))
284 job->
SetId(_lastJobId);
285 _currentJobs.push(job);
295 template <
class Container>
300 auto it = std::find_if(vec.begin(), vec.end(), [id](
const Job* j) {
return j->GetId() == id; });
308 template <
class Container>
312 Container temp(_currentJobs);
317 for( ; !temp.empty(); temp.pop())
319 if (temp.top() && temp.top()->GetId() == id)
324 temp.top()->Finish();
332 template <
class Container>
337 for(Container temp(_currentJobs); !temp.empty(); temp.pop())
339 temp.top()->Finish();
344 template <
class Container>
354 for (Container temp(_currentJobs); !temp.empty(); temp.pop())
355 temp.top()->Save(bb);
358 for (
auto sw : _availableSoftware)
364 template <
class Container>
369 for (; !_currentJobs.empty(); _currentJobs.pop())
371 _currentJobs.top()->Update(diff);
373 if (_currentJobs.top()->Finished())
375 sLog(
Console)->Log(
"Job %s removed from machine %s.", _currentJobs.top()->GetName().c_str(), _name.c_str());
376 Container::value_type tempJob = _currentJobs.top();
377 _inUseRAM -= tempJob->GetRequiredRAM();
378 _inUseDiskSpace -= tempJob->GetRequiredDiskSpace();
382 temp.push(_currentJobs.top());
385 while (!temp.empty())
387 _currentJobs.push(temp.top());
394 template <
class Container>
397 os <<
"| " << std::setfill(
'0') << std::setw(4) << std::right << _id <<
" | "
398 << std::setfill(
' ') << std::setw(_maxNameLength) << std::left << _name
400 <<
" | " << std::setw(5) << std::left << GetAvailableRAM() <<
" / " << std::right << std::setw(5) << _totalRAM
401 <<
" | " << std::setw(5) << std::left << GetAvailableDiskSpace() <<
" / " << std::right << std::setw(5) << _totalDiskSpace
402 <<
" | " << std::setw(4) << std::left << _currentJobs.size() <<
" / " << std::right << std::setw(4) << _maxJobs <<
" |\n"
403 <<
"---------" << std::string(_maxNameLength,
'-') <<
"------------------------------------------------\n";
406 template <
class Container>
409 os <<
"---------" << std::string(_maxNameLength,
'-') <<
"------------------------------------------------\n"
410 <<
"| Id | " << std::setw(_maxNameLength) <<
"Name" <<
" | RAM (MB) | Disk (MB) | Jobs |\n"
411 <<
"---------" << std::string(_maxNameLength,
'-') <<
"------------------------------------------------\n";
414 template <
class Container>
427 for (
uint32 i = 0; i < jobCount; ++i)
436 for (
uint32 i = 0; i < softwareCount; ++i)