GreenCloud Simulator
cloudtask.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
2 /*
3  */
4 
5 #ifndef lint
6 static const char rcsid[] =
7  "@(#) $Header: /cvsroot/nsnam/ns-2/common/taskobject.cc,v 1.43 $";
8 #endif
9 
10 #include "cloudtask.h"
11 #include "taskalloc.h"
12 #include "corescheduler.h"
13 #include "resourceprovider.h"
14 #include "clouduser.h"
15 
16 CloudTask::CloudTask() : id_(0), scheduled_(false), started_(false), failed_(false), output_(0), intercom_(0)
17 {
18  isTask = true;
19 }
20 
21 
22 CloudTask::CloudTask(unsigned int size, double duration, std::vector<Resource*> demand, CloudUser* clouduser) :
23 ResourceConsumer(size, demand, true, false),id_(0), scheduled_(false), started_(false), failed_(false), user_(clouduser), output_(0), intercom_(0)
24 {
25 
26  currProcRate_=0.0;
27  deadline_ = Scheduler::instance().clock() + duration;
28  isTask = true;
29  for(unsigned int rd = 0; rd < res_demands.size();rd++){
30  if(res_demands.at(rd)->getType()==Computing){
31  for(unsigned int cap = 0; cap < res_demands.at(rd)->capacity.size();cap++){
32  task_allocations_.push_back(new TaskAlloc(this,rd,cap));
33  }
34  }
35  }
36 
37 }
38 
40 {
41  std::vector <ResDemand*>::iterator iter;
42  for (iter = res_demands.begin() ; iter!=res_demands.end(); iter++)
43  {
44  delete (*iter);
45  }
46 }
47 
48 void CloudTask::setMIPS(int rd, int cap,double mips) {
49  res_demands.at(rd)->capacity.at(cap) = mips;
50 }
51 
52 double CloudTask::getMIPS(int rd, int cap) {
53  if(res_demands.at(rd)->getType() != Computing){
54  std::cerr << "MIPS requested for non-Computing resource";
55  abort();
56  }
57  return res_demands.at(rd)->capacity.at(cap);}
58 
60 // std::cerr << "Task\t" << id_ <<"\tfailed on provider:\t" << provider->id_ <<"\n";
61  failed_ = true;
62  if(this->started_==true){
63  provider->releaseAllocation(this);
64  }
65  provider->tskFailed_++;
67  task_allocations_.clear();
68 }
69 
71  std::vector<TaskAlloc*>::iterator iter;
72  for(iter = task_allocations_.begin(); iter!=task_allocations_.end(); iter++){
73  if((*iter)->getCoreScheduler()!=NULL){
74  (*iter)->getCoreScheduler()->removeTaskAlloc((*iter));
75  }
76  }
77 }
79  task_allocations_.erase(remove(task_allocations_.begin(),task_allocations_.end(),ta),
80  task_allocations_.end()); /*erase-remove idiom*/
81 }
82 
84  std::vector <ResDemand*>::iterator u_res;
85 
86  /* //Check if all computational load is finished */
87  if(task_allocations_.size()>0){
88  return false;
89  } else {
90  return true;
91  }
92 }
93 
94 
96  std::vector <ResDemand*>::iterator u_res;
97  std::cerr << "Capacities: ";
98  for (u_res = res_demands.begin() ; u_res!=res_demands.end(); u_res++)
99  {
100  if((*u_res)->getType()==Computing){
101  std::vector <Capacity>::iterator cap;
102  for(cap=(*u_res)->capacity.begin();cap!=(*u_res)->capacity.end();cap++){
103  std::cerr << (*cap) << " ";
104  }
105  }
106  }
107  std::cerr << "\n";
108 }
109 
110 
bool scheduled_
Definition: cloudtask.h:52
double getMIPS(int rd, int cap)
Definition: cloudtask.cc:52
static const char rcsid[]
Definition: cloudtask.cc:6
bool failed_
Definition: cloudtask.h:55
bool isFinished()
Definition: cloudtask.cc:83
virtual ~CloudTask()
Definition: cloudtask.cc:39
std::vector< ResDemand * > res_demands
int id_
Definition: cloudtask.h:51
std::vector< TaskAlloc * > task_allocations_
Definition: cloudtask.h:60
double deadline_
Definition: cloudtask.h:54
int output_
Definition: cloudtask.h:67
int intercom_
Definition: cloudtask.h:68
void fail(ResourceProvider *provider)
Definition: cloudtask.cc:59
void releaseAllTaskAllocs()
Definition: cloudtask.cc:70
void removeTaskAlloc(TaskAlloc *ta)
Definition: cloudtask.cc:78
bool releaseAllocation(ResourceConsumer *rc)
void printCompCapacites()
Definition: cloudtask.cc:95
CloudUser * user_
Definition: cloudtask.h:65
bool started_
Definition: cloudtask.h:53
void setMIPS(int rd, int cap, double mips)
Definition: cloudtask.cc:48