1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

F #5005: Fix action queue. Update new action classes

This commit is contained in:
Ruben S. Montero 2017-02-08 12:24:42 +01:00
parent d143012eb6
commit 04e4991d4d
9 changed files with 63 additions and 12 deletions

View File

@ -35,7 +35,6 @@ public:
*/
enum Type
{
NONE,
FINALIZE,
TIMER,
USER
@ -48,7 +47,12 @@ public:
ActionRequest(Type __type): _type(__type){};
ActionRequest(): _type(NONE){};
virtual ~ActionRequest(){};
virtual ActionRequest * clone() const
{
return new ActionRequest(_type);
}
protected:
Type _type;
@ -108,9 +112,6 @@ private:
case ActionRequest::USER:
user_action(ar);
break;
case ActionRequest::NONE:
break;
}
}
};
@ -188,7 +189,7 @@ private:
/**
* Queue of pending actions, processed in a FIFO manner
*/
std::queue<ActionRequest> actions;
std::queue<ActionRequest *> actions;
/**
* Action synchronization is implemented using the pthread library,

View File

@ -46,6 +46,9 @@ public:
AMAction(Actions a, AuthRequest *r):ActionRequest(ActionRequest::USER),
_action(a), _request(r){};
AMAction(const AMAction& o):ActionRequest(o._type), _action(o._action),
_request(o._request){};
Actions action() const
{
return _action;
@ -56,6 +59,11 @@ public:
return _request;
}
ActionRequest * clone() const
{
return new AMAction(*this);
}
private:
Actions _action;

View File

@ -53,6 +53,9 @@ public:
DMAction(Actions a, int v):ActionRequest(ActionRequest::USER),
_action(a), _vm_id(v){};
DMAction(const DMAction& o):ActionRequest(o._type), _action(o._action),
_vm_id(o._vm_id){};
Actions action() const
{
return _action;
@ -63,6 +66,11 @@ public:
return _vm_id;
}
ActionRequest * clone() const
{
return new DMAction(*this);
}
private:
Actions _action;

View File

@ -45,6 +45,9 @@ public:
IPMAction(Actions a, IPAMRequest *r):ActionRequest(ActionRequest::USER),
_action(a), _request(r){};
IPMAction(const IPMAction& o):ActionRequest(o._type), _action(o._action),
_request(o._request){};
Actions action() const
{
return _action;
@ -55,6 +58,11 @@ public:
return _request;
}
ActionRequest * clone() const
{
return new IPMAction(*this);
}
private:
Actions _action;

View File

@ -107,6 +107,9 @@ public:
ActionRequest(ActionRequest::USER), _action(a), _vm_id(v), _uid(u),
_gid(g), _req_id(r){};
LCMAction(const LCMAction& o):ActionRequest(o._type), _action(o._action),
_vm_id(o._vm_id), _uid(o._uid), _gid(o._gid), _req_id(o._req_id){};
Actions action() const
{
return _action;
@ -132,6 +135,11 @@ public:
return _req_id;
}
ActionRequest * clone() const
{
return new LCMAction(*this);
}
private:
Actions _action;

View File

@ -61,6 +61,9 @@ public:
TMAction(Actions a, int v):ActionRequest(ActionRequest::USER),
_action(a), _vm_id(v){};
TMAction(const TMAction& o):ActionRequest(o._type), _action(o._action),
_vm_id(o._vm_id){};
Actions action() const
{
return _action;
@ -71,6 +74,11 @@ public:
return _vm_id;
}
ActionRequest * clone() const
{
return new TMAction(*this);
}
private:
Actions _action;

View File

@ -65,6 +65,9 @@ public:
VMMAction(Actions a, int v):ActionRequest(ActionRequest::USER),
_action(a), _vm_id(v){};
VMMAction(const VMMAction& o):ActionRequest(o._type), _action(o._action),
_vm_id(o._vm_id){};
Actions action() const
{
return _action;
@ -75,6 +78,11 @@ public:
return _vm_id;
}
ActionRequest * clone() const
{
return new VMMAction(*this);
}
private:
Actions _action;

View File

@ -160,7 +160,7 @@ int AuthManager::start()
void AuthManager::user_action(const ActionRequest& ar)
{
const AMAction& auth_ar = static_cast<const AMAction& >(ar);
AuthRequest * request = auth_ar.request();
AuthRequest * request = auth_ar.request();
if ( request == 0 )
{

View File

@ -45,7 +45,7 @@ void ActionManager::trigger(const ActionRequest& ar )
{
lock();
actions.push(ar);
actions.push(ar.clone());
pthread_cond_signal(&cond);
@ -62,7 +62,7 @@ void ActionManager::loop(time_t timer, const ActionRequest& trequest)
int finalize = 0;
int rc;
ActionRequest action;
ActionRequest * action;
timeout.tv_sec = time(NULL) + timer;
timeout.tv_nsec = 0;
@ -79,7 +79,7 @@ void ActionManager::loop(time_t timer, const ActionRequest& trequest)
rc = pthread_cond_timedwait(&cond,&mutex, &timeout);
if ( rc == ETIMEDOUT )
actions.push(trequest);
actions.push(trequest.clone());
}
else
pthread_cond_wait(&cond,&mutex);
@ -90,9 +90,9 @@ void ActionManager::loop(time_t timer, const ActionRequest& trequest)
unlock();
listener->_do_action(action);
listener->_do_action(*action);
switch(action.type())
switch(action->type())
{
case ActionRequest::TIMER:
timeout.tv_sec = time(NULL) + timer;
@ -106,6 +106,8 @@ void ActionManager::loop(time_t timer, const ActionRequest& trequest)
default:
break;
}
delete action;
}
}