F #4936:Refactor ActionManager and Timers

co-authored-by: Pavel Czerny <pczerny@opennebula.systems>
This commit is contained in:
Ruben S. MonteroandPavel Czerny committed 2020-07-24 16:00:59 +02:00
1 parent f28db525c9
commit 325db91bcb
65 files changed
+8186 -10475

No files matched your search

+134 -196
View File
@@ -17,6 +17,7 @@
#include <climits>
#include "AclManager.h"
#include "AclRule.h"
#include "PoolObjectAuth.h"
#include "SqlDB.h"
#include "OneDB.h"
@@ -65,15 +66,13 @@ AclManager::AclManager(
int _zone_id,
bool _is_federation_slave,
time_t _timer_period)
:zone_id(_zone_id), db(_db), is_federation_slave(_is_federation_slave),
timer_period(_timer_period)
: zone_id(_zone_id)
, db(_db)
, is_federation_slave(_is_federation_slave)
, timer_period(_timer_period)
{
int lastOID;
pthread_mutex_init(&mutex, 0);
am.addListener(this);
//Federation slaves do not need to init the pool
if (is_federation_slave)
{
@@ -124,29 +123,6 @@ AclManager::AclManager(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * acl_action_loop(void *arg)
{
AclManager * aclm;
if ( arg == 0 )
{
return 0;
}
NebulaLog::log("ACL",Log::INFO,"ACL Manager started.");
aclm = static_cast<AclManager *>(arg);
aclm->am.loop(aclm->timer_period);
NebulaLog::log("ACL",Log::INFO,"ACL Manager stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int AclManager::start()
{
int rc;
@@ -157,18 +133,11 @@ int AclManager::start()
if (is_federation_slave)
{
pthread_attr_t pattr;
pthread_attr_init (&pattr);
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
rc += pthread_create(&acl_thread,&pattr,acl_action_loop,(void *) this);
}
else
{
NebulaLog::log("ACL",Log::INFO,"ACL Manager started.");
timer_thread.reset(new Timer(timer_period, [this](){timer_action();}));
}
NebulaLog::log("ACL",Log::INFO,"ACL Manager started.");
return rc;
}
@@ -177,14 +146,25 @@ int AclManager::start()
void AclManager::finalize()
{
NebulaLog::info("ACL", "Stopping ACL Manager...");
if (is_federation_slave)
{
am.finalize();
timer_thread->stop();
}
else
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void AclManager::join_thread()
{
if (is_federation_slave)
{
NebulaLog::log("ACL",Log::INFO,"ACL Manager stopped.");
timer_thread->stop();
}
NebulaLog::info("ACL", "ACL Manager stopped.");
}
/* -------------------------------------------------------------------------- */
@@ -192,18 +172,12 @@ void AclManager::finalize()
AclManager::~AclManager()
{
multimap<long long, AclRule *>::iterator it;
lock_guard<std::mutex> ul(acl_mutex);
lock();
for ( it = acl_rules.begin(); it != acl_rules.end(); it++ )
for (auto& rule : acl_rules)
{
delete it->second;
delete rule.second;
}
unlock();
pthread_mutex_destroy(&mutex);
}
/* -------------------------------------------------------------------------- */
@@ -464,7 +438,7 @@ bool AclManager::match_rules_wrapper(
}
// Match against the internal rules
lock();
lock_guard<std::mutex> ul(acl_mutex);
auth = match_rules(
user_req,
@@ -478,8 +452,6 @@ bool AclManager::match_rules_wrapper(
cluster_obj_type,
acl_rules);
unlock();
return auth;
}
@@ -596,7 +568,7 @@ int AclManager::add_rule(long long user, long long resource, long long rights,
return -1;
}
lock();
lock_guard<std::mutex> ul(acl_mutex);
int lastOID = get_lastOID(db);
@@ -645,8 +617,6 @@ int AclManager::add_rule(long long user, long long resource, long long rights,
set_lastOID(db, lastOID);
unlock();
return lastOID;
@@ -673,8 +643,6 @@ error_common:
delete rule;
unlock();
return rc;
}
@@ -702,7 +670,7 @@ int AclManager::del_rule(int oid, string& error_str)
return -1;
}
lock();
lock_guard<std::mutex> ul(acl_mutex);
// Check the rule exists
found = acl_rules_oids.count(oid) > 0;
@@ -713,7 +681,6 @@ int AclManager::del_rule(int oid, string& error_str)
oss << "Rule " << oid << " does not exist";
error_str = oss.str();
unlock();
return -1;
}
@@ -744,7 +711,6 @@ int AclManager::del_rule(int oid, string& error_str)
NebulaLog::log("ACL",Log::ERROR,oss);
unlock();
return -1;
}
@@ -755,7 +721,6 @@ int AclManager::del_rule(int oid, string& error_str)
{
error_str = "SQL DB error";
unlock();
return -1;
}
@@ -766,7 +731,6 @@ int AclManager::del_rule(int oid, string& error_str)
delete rule;
unlock();
return 0;
}
@@ -780,31 +744,27 @@ int AclManager::del_rule(
long long zone,
string& error_str)
{
lock();
AclRule rule(-1, user, resource, rights, zone);
int oid = -1;
int oid = -1;
bool found = false;
multimap<long long, AclRule *>::iterator it;
pair<multimap<long long, AclRule *>::iterator,
multimap<long long, AclRule *>::iterator> index;
index = acl_rules.equal_range( user );
for ( it = index.first; (it != index.second && !found); it++)
{
found = *(it->second) == rule;
lock_guard<std::mutex> ul(acl_mutex);
if (found)
auto index = acl_rules.equal_range(user);
for (auto it = index.first; (it != index.second && !found); it++)
{
oid = it->second->get_oid();
found = *(it->second) == rule;
if (found)
{
oid = it->second->get_oid();
}
}
}
unlock();
if (oid != -1)
{
return del_rule(oid, error_str);
@@ -893,24 +853,20 @@ void AclManager::del_resource_rules(int oid, PoolObjectSQL::ObjectType obj_type)
void AclManager::del_user_matching_rules(long long user_req)
{
multimap<long long, AclRule *>::iterator it;
pair<multimap<long long, AclRule *>::iterator,
multimap<long long, AclRule *>::iterator> index;
vector<int> oids;
vector<int>::iterator oid_it;
string error_str;
lock();
index = acl_rules.equal_range( user_req );
for ( it = index.first; it != index.second; it++)
{
oids.push_back(it->second->oid);
}
lock_guard<std::mutex> ul(acl_mutex);
unlock();
auto index = acl_rules.equal_range( user_req );
for ( auto it = index.first; it != index.second; it++)
{
oids.push_back(it->second->oid);
}
}
for ( oid_it = oids.begin() ; oid_it < oids.end(); oid_it++ )
{
@@ -924,25 +880,22 @@ void AclManager::del_user_matching_rules(long long user_req)
void AclManager::del_resource_matching_rules(long long resource_req,
long long resource_mask)
{
multimap<long long, AclRule *>::iterator it;
vector<int> oids;
string error_str;
vector<int> oids;
vector<int>::iterator oid_it;
string error_str;
lock();
for ( it = acl_rules.begin(); it != acl_rules.end(); it++ )
{
if ( ( it->second->resource & resource_mask ) == resource_req )
lock_guard<std::mutex> ul(acl_mutex);
for ( auto it = acl_rules.begin(); it != acl_rules.end(); it++ )
{
oids.push_back(it->second->oid);
if ( ( it->second->resource & resource_mask ) == resource_req )
{
oids.push_back(it->second->oid);
}
}
}
unlock();
for ( oid_it = oids.begin() ; oid_it < oids.end(); oid_it++ )
for ( auto oid_it = oids.begin() ; oid_it < oids.end(); oid_it++ )
{
del_rule(*oid_it, error_str);
}
@@ -953,25 +906,22 @@ void AclManager::del_resource_matching_rules(long long resource_req,
void AclManager::del_zone_matching_rules(long long zone_req)
{
multimap<long long, AclRule *>::iterator it;
vector<int> oids;
string error_str;
vector<int> oids;
vector<int>::iterator oid_it;
string error_str;
lock();
for ( it = acl_rules.begin(); it != acl_rules.end(); it++ )
{
if ( it->second->zone == zone_req )
lock_guard<std::mutex> ul(acl_mutex);
for (auto it = acl_rules.begin(); it != acl_rules.end(); it++)
{
oids.push_back(it->second->oid);
if ( it->second->zone == zone_req )
{
oids.push_back(it->second->oid);
}
}
}
unlock();
for ( oid_it = oids.begin() ; oid_it < oids.end(); oid_it++ )
for (auto oid_it = oids.begin() ; oid_it < oids.end(); oid_it++)
{
del_rule(*oid_it, error_str);
}
@@ -994,10 +944,6 @@ void AclManager::reverse_search(int uid,
{
ostringstream oss;
multimap<long long, AclRule *>::iterator it;
pair<multimap<long long, AclRule *>::iterator,
multimap<long long, AclRule *>::iterator> index;
// Build masks for request
long long resource_oid_req = obj_type | AclRule::INDIVIDUAL_ID;
long long resource_gid_req = obj_type | AclRule::GROUP_ID;
@@ -1040,10 +986,7 @@ void AclManager::reverse_search(int uid,
// Look for the rules that match
// ---------------------------------------------------
vector<long long> user_reqs;
vector<long long>::iterator reqs_it;
set<int>::iterator g_it;
vector<long long> user_reqs;
// rules that apply to everyone
user_reqs.push_back(AclRule::ALL_ID);
@@ -1052,72 +995,72 @@ void AclManager::reverse_search(int uid,
user_reqs.push_back(AclRule::INDIVIDUAL_ID | uid);
// rules that apply to each one of the user's groups
for (g_it = user_groups.begin(); g_it != user_groups.end(); g_it++)
for (auto g_it = user_groups.begin(); g_it != user_groups.end(); g_it++)
{
user_reqs.push_back(AclRule::GROUP_ID | *g_it);
}
all = false;
for (reqs_it = user_reqs.begin(); reqs_it != user_reqs.end(); reqs_it++)
{
lock();
lock_guard<std::mutex> ul(acl_mutex);
index = acl_rules.equal_range( *reqs_it );
for ( it = index.first; it != index.second; it++)
for (auto r_it : user_reqs)
{
// Rule grants the requested rights
if ( ( ( it->second->rights & rights_req ) == rights_req )
&&
// Rule applies in this zone or in all zones
( ( it->second->zone == zone_oid_req )
||
( it->second->zone == zone_all_req )
)
)
{
if (NebulaLog::log_level() >= Log::DDEBUG)
{
oss.str("");
oss << "> Rule " << it->second->to_str();
NebulaLog::log("ACL",Log::DDEBUG,oss);
}
auto index = acl_rules.equal_range( r_it );
// Rule grants permission for all objects of this type
if ((!disable_all_acl) &&
((it->second->resource & resource_all_req) == resource_all_req))
for (auto it = index.first; it != index.second; it++)
{
// Rule grants the requested rights
if ( ( ( it->second->rights & rights_req ) == rights_req )
&&
// Rule applies in this zone or in all zones
( ( it->second->zone == zone_oid_req )
||
( it->second->zone == zone_all_req )
)
)
{
all = true;
break;
}
// Rule grants permission for all objects of a group
else if ((!disable_group_acl) &&
((it->second->resource & resource_gid_mask) == resource_gid_req))
{
gids.push_back(it->second->resource_id());
}
// Rule grants permission for all objects of a cluster
else if ((!disable_cluster_acl) &&
((it->second->resource & resource_cid_mask) == resource_cid_req))
{
cids.push_back(it->second->resource_id());
}
// Rule grants permission for an individual object
else if ((it->second->resource & resource_oid_mask) == resource_oid_req)
{
oids.push_back(it->second->resource_id());
if (NebulaLog::log_level() >= Log::DDEBUG)
{
oss.str("");
oss << "> Rule " << it->second->to_str();
NebulaLog::log("ACL",Log::DDEBUG,oss);
}
// Rule grants permission for all objects of this type
if ((!disable_all_acl) &&
((it->second->resource & resource_all_req) == resource_all_req))
{
all = true;
break;
}
// Rule grants permission for all objects of a group
else if ((!disable_group_acl) &&
((it->second->resource & resource_gid_mask) == resource_gid_req))
{
gids.push_back(it->second->resource_id());
}
// Rule grants permission for all objects of a cluster
else if ((!disable_cluster_acl) &&
((it->second->resource & resource_cid_mask) == resource_cid_req))
{
cids.push_back(it->second->resource_id());
}
// Rule grants permission for an individual object
else if ((it->second->resource & resource_oid_mask) == resource_oid_req)
{
oids.push_back(it->second->resource_id());
}
}
}
}
unlock();
if ( all == true )
{
oids.clear();
gids.clear();
cids.clear();
if ( all == true )
{
oids.clear();
gids.clear();
cids.clear();
}
}
}
}
@@ -1193,8 +1136,6 @@ int AclManager::select_cb(void *nil, int num, char **values, char **names)
int AclManager::select()
{
multimap<long long, AclRule *>::iterator it;
ostringstream oss;
int rc;
@@ -1202,20 +1143,20 @@ int AclManager::select()
set_callback(static_cast<Callbackable::Callback>(&AclManager::select_cb));
lock();
for ( it = acl_rules.begin(); it != acl_rules.end(); it++ )
{
delete it->second;
lock_guard<std::mutex> ul(acl_mutex);
for (auto it = acl_rules.begin(); it != acl_rules.end(); it++)
{
delete it->second;
}
acl_rules.clear();
acl_rules_oids.clear();
rc = db->exec_rd(oss, this);
}
acl_rules.clear();
acl_rules_oids.clear();
rc = db->exec_rd(oss,this);
unlock();
unset_callback();
return rc;
@@ -1266,22 +1207,19 @@ int AclManager::drop(int oid)
int AclManager::dump(ostringstream& oss)
{
map<int, AclRule *>::iterator it;
string xml;
lock();
lock_guard<std::mutex> ul(acl_mutex);
oss << "<ACL_POOL>";
for ( it = acl_rules_oids.begin() ; it != acl_rules_oids.end(); it++ )
for (auto& rule : acl_rules)
{
oss << it->second->to_xml(xml);
oss << rule.second->to_xml(xml);
}
oss << "</ACL_POOL>";
unlock();
return 0;
}
+83 -121
View File
@@ -120,32 +120,8 @@ void AuthRequest::add_auth(Operation op,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * authm_action_loop(void *arg)
{
AuthManager * authm;
if ( arg == nullptr )
{
return 0;
}
authm = static_cast<AuthManager *>(arg);
NebulaLog::log("AuM",Log::INFO,"Authorization Manager started.");
authm->am.loop(authm->timer_period);
NebulaLog::log("AuM",Log::INFO,"Authorization Manager stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
int AuthManager::start()
{
pthread_attr_t pattr;
using namespace std::placeholders; // for _1
register_action(AuthManagerMessages::UNDEFINED,
@@ -171,132 +147,108 @@ int AuthManager::start()
NebulaLog::log("AuM",Log::INFO,"Starting Auth Manager...");
pthread_attr_init(&pattr);
pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE);
Listener::start();
int rc = pthread_create(&authm_thread,&pattr,authm_action_loop,(void *) this);
return rc;
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void AuthManager::user_action(const ActionRequest& ar)
void AuthManager::trigger_authenticate(AuthRequest& ar)
{
const AMAction& auth_ar = static_cast<const AMAction& >(ar);
AuthRequest * request = auth_ar.request();
trigger([&] {
// ------------------------------------------------------------------------
// Get the driver
// ------------------------------------------------------------------------
if ( request == nullptr )
{
return;
}
auto authm_md = get();
switch (auth_ar.action())
{
case AMAction::AUTHENTICATE:
authenticate_action(request);
break;
if (authm_md == nullptr)
{
ar.result = false;
ar.message = "Could not find Authorization driver";
ar.notify();
case AMAction::AUTHORIZE:
authorize_action(request);
break;
}
return;
}
// ------------------------------------------------------------------------
// Queue the request
// ------------------------------------------------------------------------
add_request(&ar);
// ------------------------------------------------------------------------
// Make the request to the driver
// ---- --------------------------------------------------------------------
ostringstream oss;
oss << ar.uid << " "
<< ar.driver << " "
<< ar.username << " "
<< ar.password << " "
<< ar.session << " " << endl;
auth_msg_t msg(AuthManagerMessages::AUTHENTICATE, "", ar.id, oss.str());
authm_md->write(msg);
});
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void AuthManager::authenticate_action(AuthRequest * ar)
void AuthManager::trigger_authorize(AuthRequest& ar)
{
// ------------------------------------------------------------------------
// Get the driver
// ------------------------------------------------------------------------
trigger([&] {
// ------------------------------------------------------------------------
// Get the driver
// ------------------------------------------------------------------------
auto authm_md = get();
auto authm_md = get();
if (authm_md == nullptr)
{
ar->result = false;
ar->message = "Could not find Authorization driver";
ar->notify();
if (authm_md == nullptr)
{
ar.message = "Could not find Authorization driver";
ar.result = false;
ar.notify();
return;
}
return;
}
// ------------------------------------------------------------------------
// Queue the request
// ------------------------------------------------------------------------
auto auths = ar.get_auths();
add_request(ar);
if (auths.empty())
{
ar.message = "Empty authorization string";
ar.result = false;
ar.notify();
// ------------------------------------------------------------------------
// Make the request to the driver
// ---- --------------------------------------------------------------------
return;
}
ostringstream oss;
// ------------------------------------------------------------------------
// Queue the request
// ------------------------------------------------------------------------
oss << ar->uid << " "
<< ar->driver << " "
<< ar->username << " "
<< ar->password << " "
<< ar->session << " " << endl;
add_request(&ar);
auth_msg_t msg(AuthManagerMessages::AUTHENTICATE, "", ar->id, oss.str());
// ------------------------------------------------------------------------
// Make the request to the driver
// ------------------------------------------------------------------------
authm_md->write(msg);
}
ostringstream oss;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
oss << ar.uid << " "
<< auths << " "
<< ar.self_authorize << endl;
void AuthManager::authorize_action(AuthRequest * ar)
{
// ------------------------------------------------------------------------
// Get the driver
// ------------------------------------------------------------------------
auth_msg_t msg(AuthManagerMessages::AUTHORIZE, "", ar.id, oss.str());
auto authm_md = get();
if (authm_md == nullptr)
{
ar->message = "Could not find Authorization driver";
ar->result = false;
ar->notify();
return;
}
auto auths = ar->get_auths();
if (auths.empty())
{
ar->message = "Empty authorization string";
ar->result = false;
ar->notify();
return;
}
// ------------------------------------------------------------------------
// Queue the request
// ------------------------------------------------------------------------
add_request(ar);
// ------------------------------------------------------------------------
// Make the request to the driver
// ------------------------------------------------------------------------
ostringstream oss;
oss << ar->uid << " "
<< auths << " "
<< ar->self_authorize << endl;
auth_msg_t msg(AuthManagerMessages::AUTHORIZE, "", ar->id, oss.str());
authm_md->write(msg);
authm_md->write(msg);
});
}
/* ************************************************************************** */
@@ -358,3 +310,13 @@ int AuthManager::load_drivers(const std::vector<const VectorAttribute*>& _mads)
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void AuthManager::finalize_action()
{
timer_thread.stop();
DriverManager::stop(drivers_timeout);
}
-134
View File
@@ -1,134 +0,0 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include "ActionManager.h"
#include <ctime>
#include <errno.h>
/* ************************************************************************** */
/* ActionManager constructor & destructor */
/* ************************************************************************** */
ActionManager::ActionManager(): listener(0)
{
pthread_mutex_init(&mutex,0);
pthread_cond_init(&cond,0);
}
/* -------------------------------------------------------------------------- */
ActionManager::~ActionManager()
{
while (!actions.empty())
{
delete actions.front();
actions.pop();
}
pthread_mutex_destroy(&mutex);
pthread_cond_destroy(&cond);
}
/* ************************************************************************** */
/* NeActionManager public interface */
/* ************************************************************************** */
void ActionManager::trigger(const ActionRequest& ar )
{
lock();
actions.push(ar.clone());
pthread_cond_signal(&cond);
unlock();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static void set_timeout(struct timespec& timeout, struct timespec& _tout)
{
clock_gettime(CLOCK_REALTIME, &timeout);
timeout.tv_sec += _tout.tv_sec;
timeout.tv_nsec += _tout.tv_nsec;
while ( timeout.tv_nsec >= 1000000000 )
{
timeout.tv_sec += 1;
timeout.tv_nsec -= 1000000000;
}
}
void ActionManager::loop(struct timespec& _tout, const ActionRequest& trequest)
{
struct timespec timeout;
int finalize = 0;
int rc;
ActionRequest * action;
set_timeout(timeout, _tout);
//Action Loop, end when a finalize action is triggered to this manager
while (finalize == 0)
{
lock();
while ( actions.empty() == true )
{
if ( _tout.tv_sec != 0 || _tout.tv_nsec != 0 )
{
rc = pthread_cond_timedwait(&cond, &mutex, &timeout);
if ( rc == ETIMEDOUT )
actions.push(trequest.clone());
}
else
pthread_cond_wait(&cond,&mutex);
}
action = actions.front();
actions.pop();
unlock();
listener->_do_action(*action);
switch(action->type())
{
case ActionRequest::TIMER:
set_timeout(timeout, _tout);
break;
case ActionRequest::FINALIZE:
finalize = 1;
break;
default:
break;
}
delete action;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
-1
View File
@@ -22,7 +22,6 @@ lib_name='nebula_common'
# Sources to generate the library
source_files=[
'ActionManager.cc',
'Attribute.cc',
'ExtendedAttribute.cc',
'NebulaService.cc',
+3 -67
View File
@@ -17,83 +17,19 @@
#include "DispatchManager.h"
#include "Nebula.h"
#include "NebulaLog.h"
#include "VirtualMachine.h"
using namespace std;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * dm_action_loop(void *arg)
{
DispatchManager * dm;
if ( arg == 0 )
{
return 0;
}
dm = static_cast<DispatchManager *>(arg);
NebulaLog::log("DiM",Log::INFO,"Dispatch Manager started.");
dm->am.loop();
NebulaLog::log("DiM",Log::INFO,"Dispatch Manager stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
int DispatchManager::start()
{
int rc;
pthread_attr_t pattr;
pthread_attr_init (&pattr);
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
NebulaLog::log("DiM",Log::INFO,"Starting Dispatch Manager...");
rc = pthread_create(&dm_thread, &pattr, dm_action_loop,(void *) this);
Listener::start();
return rc;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::user_action(const ActionRequest& ar)
{
const DMAction& dm_ar = static_cast<const DMAction& >(ar);
int vid = dm_ar.vm_id();
switch (dm_ar.action())
{
case DMAction::SUSPEND_SUCCESS:
suspend_success_action(vid);
break;
case DMAction::STOP_SUCCESS:
stop_success_action(vid);
break;
case DMAction::UNDEPLOY_SUCCESS:
undeploy_success_action(vid);
break;
case DMAction::POWEROFF_SUCCESS:
poweroff_success_action(vid);
break;
case DMAction::DONE:
done_action(vid);
break;
case DMAction::RESUBMIT:
resubmit_action(vid);
break;
}
return 0;
}
/* -------------------------------------------------------------------------- */
+61 -50
View File
@@ -26,6 +26,7 @@
#include "Nebula.h"
#include "ClusterPool.h"
#include "HostPool.h"
#include "VirtualMachinePool.h"
#include "VirtualRouterPool.h"
using namespace std;
@@ -75,7 +76,7 @@ int DispatchManager::deploy(VirtualMachine * vm, const RequestAttributes& ra)
get_quota_template(vm, quota_tmpl, true);
}
lcm->trigger(LCMAction::DEPLOY, vid, ra);
lcm->trigger_deploy(vid);
}
else
{
@@ -208,17 +209,17 @@ int DispatchManager::migrate(VirtualMachine * vm, int poff_migrate,
{
switch (poff_migrate) {
case 0:
lcm->trigger(LCMAction::MIGRATE, vid, ra);
lcm->trigger_migrate(vid, ra);
break;
case 1:
lcm->trigger(LCMAction::POFF_MIGRATE, vid, ra);
lcm->trigger_migrate_poweroff(vid, ra);
break;
case 2:
lcm->trigger(LCMAction::POFF_HARD_MIGRATE, vid, ra);
lcm->trigger_migrate_poweroff_hard(vid, ra);
break;
default: /* Defaults to <5.8 behavior */
lcm->trigger(LCMAction::MIGRATE, vid, ra);
lcm->trigger_migrate(vid, ra);
break;
}
}
@@ -260,7 +261,7 @@ int DispatchManager::live_migrate(VirtualMachine * vm,
if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
lcm->trigger(LCMAction::LIVE_MIGRATE, vid, ra);
lcm->trigger_live_migrate(vid, ra);
}
else
{
@@ -406,7 +407,7 @@ int DispatchManager::terminate(int vid, bool hard, const RequestAttributes& ra,
case VirtualMachine::POWEROFF:
case VirtualMachine::STOPPED:
case VirtualMachine::UNDEPLOYED:
lcm->trigger(LCMAction::SHUTDOWN, vid, ra);
lcm->trigger_shutdown(vid, false, ra);
vm->unlock();
break;
@@ -427,14 +428,7 @@ int DispatchManager::terminate(int vid, bool hard, const RequestAttributes& ra,
{
case VirtualMachine::RUNNING:
case VirtualMachine::UNKNOWN:
if (hard)
{
lcm->trigger(LCMAction::CANCEL, vid, ra);
}
else
{
lcm->trigger(LCMAction::SHUTDOWN, vid, ra);
}
lcm->trigger_shutdown(vid, hard, ra);
break;
case VirtualMachine::BOOT_FAILURE:
@@ -451,7 +445,7 @@ int DispatchManager::terminate(int vid, bool hard, const RequestAttributes& ra,
case VirtualMachine::PROLOG_RESUME_FAILURE:
case VirtualMachine::PROLOG_UNDEPLOY_FAILURE:
case VirtualMachine::PROLOG_MIGRATE_UNKNOWN_FAILURE:
lcm->trigger(LCMAction::DELETE, vid, ra);
lcm->trigger_delete(vid, ra);
break;
default:
@@ -497,11 +491,11 @@ int DispatchManager::undeploy(int vid, bool hard, const RequestAttributes& ra,
{
if (hard)
{
lcm->trigger(LCMAction::UNDEPLOY_HARD, vid, ra);
lcm->trigger_undeploy_hard(vid, ra);
}
else
{
lcm->trigger(LCMAction::UNDEPLOY, vid, ra);
lcm->trigger_undeploy(vid, ra);
}
}
else
@@ -551,11 +545,11 @@ int DispatchManager::poweroff(int vid, bool hard, const RequestAttributes& ra,
{
if (hard)
{
lcm->trigger(LCMAction::POWEROFF_HARD, vid, ra);
lcm->trigger_poweroff_hard(vid, ra);
}
else
{
lcm->trigger(LCMAction::POWEROFF, vid, ra);
lcm->trigger_poweroff(vid, ra);
}
}
else
@@ -720,7 +714,7 @@ int DispatchManager::stop(int vid, const RequestAttributes& ra,
(vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING ))
{
lcm->trigger(LCMAction::STOP, vid, ra);
lcm->trigger_stop(vid, ra);
}
else
{
@@ -766,7 +760,7 @@ int DispatchManager::suspend(int vid, const RequestAttributes& ra,
if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
lcm->trigger(LCMAction::SUSPEND, vid, ra);
lcm->trigger_suspend(vid, ra);
}
else
{
@@ -828,13 +822,13 @@ int DispatchManager::resume(int vid, const RequestAttributes& ra,
}
else if (vm->get_state() == VirtualMachine::SUSPENDED)
{
lcm->trigger(LCMAction::RESTORE, vid, ra);
lcm->trigger_restore(vid, ra);
}
else if ( vm->get_state() == VirtualMachine::POWEROFF ||
(vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::UNKNOWN))
{
lcm->trigger(LCMAction::RESTART, vid, ra);
lcm->trigger_restart(vid, ra);
}
else
{
@@ -893,11 +887,11 @@ int DispatchManager::reboot(int vid, bool hard, const RequestAttributes& ra,
{
if (hard)
{
vmm->trigger(VMMAction::RESET, vid);
vmm->trigger_reset(vid);
}
else
{
vmm->trigger(VMMAction::REBOOT, vid);
vmm->trigger_reboot(vid);
}
vm->set_resched(false); //Rebooting cancels re-scheduling actions
@@ -1016,11 +1010,11 @@ int DispatchManager::recover(VirtualMachine * vm, bool success,
case VirtualMachine::CLONING_FAILURE:
if (success)
{
lcm->trigger(LCMAction::DISK_LOCK_SUCCESS, vid, ra);
lcm->trigger_disk_lock_success(vid);
}
else
{
lcm->trigger(LCMAction::DISK_LOCK_FAILURE, vid, ra);
lcm->trigger_disk_lock_failure(vid);
}
break;
@@ -1126,11 +1120,11 @@ int DispatchManager::delete_vm(VirtualMachine * vm, const RequestAttributes& ra,
if (is_public_host)
{
vmm->trigger(VMMAction::CLEANUP, vid);
vmm->trigger_cleanup(vid, false);
}
else
{
tm->trigger(TMAction::EPILOG_DELETE, vid);
tm->trigger_epilog_delete(vm);
}
free_vm_resources(vm, true);
@@ -1140,11 +1134,11 @@ int DispatchManager::delete_vm(VirtualMachine * vm, const RequestAttributes& ra,
case VirtualMachine::UNDEPLOYED:
if (is_public_host)
{
vmm->trigger(VMMAction::CLEANUP, vid);
vmm->trigger_cleanup(vid, false);
}
else
{
tm->trigger(TMAction::EPILOG_DELETE, vid);
tm->trigger_epilog_delete(vm);
}
free_vm_resources(vm, true);
@@ -1159,7 +1153,7 @@ int DispatchManager::delete_vm(VirtualMachine * vm, const RequestAttributes& ra,
break;
case VirtualMachine::ACTIVE:
lcm->trigger(LCMAction::DELETE, vid, ra);
lcm->trigger_delete(vid, ra);
vm->unlock();
break;
@@ -1174,6 +1168,23 @@ int DispatchManager::delete_vm(VirtualMachine * vm, const RequestAttributes& ra,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int DispatchManager::delete_vm(int vid, const RequestAttributes& ra,
std::string& error_str)
{
VirtualMachine * vm = vmpool->get(vid);
if ( vm == nullptr )
{
error_str = "Virtual machine does not exist";
return -1;
}
return delete_vm(vm, ra, error_str);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int DispatchManager::delete_recreate(VirtualMachine * vm,
const RequestAttributes& ra, string& error)
{
@@ -1242,7 +1253,7 @@ int DispatchManager::delete_recreate(VirtualMachine * vm,
break;
case VirtualMachine::ACTIVE: //Cleanup VM resources before PENDING
lcm->trigger(LCMAction::DELETE_RECREATE, vm->get_oid(), ra);
lcm->trigger_delete_recreate(vm->get_oid(), ra);
break;
case VirtualMachine::DONE:
@@ -1411,11 +1422,11 @@ int DispatchManager::attach(int vid, VirtualMachineTemplate * tmpl,
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
{
vmm->trigger(VMMAction::ATTACH, vid);
vmm->trigger_attach(vid);
}
else
{
tm->trigger(TMAction::PROLOG_ATTACH, vid);
tm->trigger_prolog_attach(vm);
}
vmpool->update(vm);
@@ -1479,14 +1490,14 @@ int DispatchManager::detach(int vid, int disk_id, const RequestAttributes& ra,
{
vm->set_state(VirtualMachine::HOTPLUG);
vmm->trigger(VMMAction::DETACH, vid);
vmm->trigger_detach(vid);
}
else
{
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::HOTPLUG_EPILOG_POWEROFF);
tm->trigger(TMAction::EPILOG_DETACH, vid);
tm->trigger_epilog_detach(vm);
}
vmpool->update(vm);
@@ -1540,7 +1551,7 @@ int DispatchManager::snapshot_create(int vid, string& name, int& snap_id,
vm->unlock();
vmm->trigger(VMMAction::SNAPSHOT_CREATE, vid);
vmm->trigger_snapshot_create(vid);
return 0;
}
@@ -1603,7 +1614,7 @@ int DispatchManager::snapshot_revert(int vid, int snap_id,
vm->unlock();
vmm->trigger(VMMAction::SNAPSHOT_REVERT, vid);
vmm->trigger_snapshot_revert(vid);
return 0;
}
@@ -1675,7 +1686,7 @@ int DispatchManager::snapshot_delete(int vid, int snap_id,
vm->unlock();
vmm->trigger(VMMAction::SNAPSHOT_DELETE, vid);
vmm->trigger_snapshot_delete(vid);
return 0;
}
@@ -1781,7 +1792,7 @@ int DispatchManager::attach_nic(int vid, VirtualMachineTemplate* tmpl,
if (vm->get_state() == VirtualMachine::ACTIVE)
{
vmm->trigger(VMMAction::ATTACH_NIC, vid);
vmm->trigger_attach_nic(vid);
}
else
{
@@ -1890,7 +1901,7 @@ int DispatchManager::detach_nic(int vid, int nic_id, const RequestAttributes& ra
vm->unlock();
vmm->trigger(VMMAction::DETACH_NIC, vid);
vmm->trigger_detach_nic(vid);
}
else
{
@@ -1984,12 +1995,12 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name,
{
case VirtualMachine::POWEROFF:
case VirtualMachine::SUSPENDED:
tm->trigger(TMAction::SNAPSHOT_CREATE, vid);
tm->trigger_snapshot_create(vid);
break;
case VirtualMachine::ACTIVE:
vmm->trigger(VMMAction::DISK_SNAPSHOT_CREATE, vid);
vmm->trigger_disk_snapshot_create(vid);
break;
default: break;
@@ -2080,7 +2091,7 @@ int DispatchManager::disk_snapshot_revert(int vid, int did, int snap_id,
vm->unlock();
tm->trigger(TMAction::SNAPSHOT_REVERT, vid);
tm->trigger_snapshot_revert(vid);
return 0;
}
@@ -2171,7 +2182,7 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id,
close_cp_history(vmpool, vm, VMActions::DISK_SNAPSHOT_DELETE_ACTION, ra);
tm->trigger(TMAction::SNAPSHOT_DELETE, vid);
tm->trigger_snapshot_delete(vid);
vmpool->update(vm);
@@ -2254,11 +2265,11 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size,
{
case VirtualMachine::POWEROFF:
case VirtualMachine::UNDEPLOYED:
tm->trigger(TMAction::RESIZE, vid);
tm->trigger_resize(vid);
break;
case VirtualMachine::ACTIVE:
vmm->trigger(VMMAction::DISK_RESIZE, vid);
vmm->trigger_disk_resize(vid);
break;
default: break;
@@ -2303,7 +2314,7 @@ int DispatchManager::live_updateconf(int vid, const RequestAttributes& ra, strin
vm->set_resched(false);
// Trigger UPDATE CONF action
vmm->trigger(VMMAction::UPDATE_CONF, vid);
vmm->trigger_update_conf(vid);
vmpool->update(vm);
vmpool->update_search(vm);
+259 -264
View File
@@ -18,319 +18,314 @@
#include "NebulaLog.h"
#include "Quotas.h"
#include "Nebula.h"
#include "VirtualMachinePool.h"
using namespace std;
void DispatchManager::suspend_success_action(int vid)
void DispatchManager::trigger_suspend_success(int vid)
{
VirtualMachine * vm;
VirtualMachineTemplate quota_tmpl;
string error_str;
trigger([this, vid] {
VirtualMachineTemplate quota_tmpl;
string error_str;
int uid, gid;
int uid, gid;
vm = vmpool->get(vid);
VirtualMachine * vm = vmpool->get(vid);
if ( vm == 0 )
{
return;
}
if ((vm->get_state() == VirtualMachine::ACTIVE) &&
(vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND ||
vm->get_lcm_state() == VirtualMachine::PROLOG_MIGRATE_SUSPEND ||
vm->get_lcm_state() == VirtualMachine::PROLOG_MIGRATE_SUSPEND_FAILURE||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_SUSPENDED ||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_REVERT_SUSPENDED||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED))
{
get_quota_template(vm, quota_tmpl, true);
vm->set_state(VirtualMachine::SUSPENDED);
vm->set_state(VirtualMachine::LCM_INIT);
vmpool->update(vm);
}
else
{
ostringstream oss;
oss << "suspend_success action received but VM " << vid
<< " not in ACTIVE state";
NebulaLog::log("DiM",Log::ERROR,oss);
vm->unlock();
return;
}
uid = vm->get_uid();
gid = vm->get_gid();
vm->unlock();
Quotas::vm_del(uid, gid, &quota_tmpl);
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::stop_success_action(int vid)
{
VirtualMachine * vm;
VirtualMachineTemplate quota_tmpl;
string error_str;
int uid, gid;
vm = vmpool->get(vid);
if ( vm == 0 )
{
return;
}
if ((vm->get_state() == VirtualMachine::ACTIVE) &&
(vm->get_lcm_state() == VirtualMachine::EPILOG_STOP ||
vm->get_lcm_state() == VirtualMachine::PROLOG_RESUME))
{
get_quota_template(vm, quota_tmpl, true);
vm->set_state(VirtualMachine::STOPPED);
vm->set_state(VirtualMachine::LCM_INIT);
//Set history action field to perform the right TM command on resume
if (vm->get_action() == VMActions::NONE_ACTION)
if (vm == nullptr)
{
vm->set_internal_action(VMActions::STOP_ACTION);
vmpool->update_history(vm);
return;
}
vmpool->update(vm);
}
else
{
ostringstream oss;
oss << "stop_success action received but VM " << vid
<< " not in ACTIVE state";
NebulaLog::log("DiM",Log::ERROR,oss);
vm->unlock();
return;
}
uid = vm->get_uid();
gid = vm->get_gid();
vm->unlock();
Quotas::vm_del(uid, gid, &quota_tmpl);
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::undeploy_success_action(int vid)
{
VirtualMachine * vm;
VirtualMachineTemplate quota_tmpl;
string error_str;
int uid, gid;
vm = vmpool->get(vid);
if ( vm == 0 )
{
return;
}
if ((vm->get_state() == VirtualMachine::ACTIVE) &&
(vm->get_lcm_state() == VirtualMachine::EPILOG_UNDEPLOY ||
vm->get_lcm_state() == VirtualMachine::DISK_RESIZE_UNDEPLOYED ||
vm->get_lcm_state() == VirtualMachine::PROLOG_UNDEPLOY))
{
get_quota_template(vm, quota_tmpl, true);
vm->set_state(VirtualMachine::UNDEPLOYED);
vm->set_state(VirtualMachine::LCM_INIT);
//Set history action field to perform the right TM command on resume
if (vm->get_action() == VMActions::NONE_ACTION)
if ((vm->get_state() == VirtualMachine::ACTIVE) &&
(vm->get_lcm_state() == VirtualMachine::SAVE_SUSPEND ||
vm->get_lcm_state() == VirtualMachine::PROLOG_MIGRATE_SUSPEND ||
vm->get_lcm_state() == VirtualMachine::PROLOG_MIGRATE_SUSPEND_FAILURE||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_SUSPENDED ||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_REVERT_SUSPENDED||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED))
{
vm->set_internal_action(VMActions::UNDEPLOY_ACTION);
get_quota_template(vm, quota_tmpl, true);
vmpool->update_history(vm);
vm->set_state(VirtualMachine::SUSPENDED);
vm->set_state(VirtualMachine::LCM_INIT);
vmpool->update(vm);
}
else
{
ostringstream oss;
oss << "suspend_success action received but VM " << vid
<< " not in ACTIVE state";
NebulaLog::log("DiM",Log::ERROR,oss);
vm->unlock();
return;
}
vmpool->update(vm);
}
else
{
ostringstream oss;
oss << "undeploy_success action received but VM " << vid
<< " not in ACTIVE state";
NebulaLog::log("DiM",Log::ERROR,oss);
uid = vm->get_uid();
gid = vm->get_gid();
vm->unlock();
return;
}
uid = vm->get_uid();
gid = vm->get_gid();
vm->unlock();
Quotas::vm_del(uid, gid, &quota_tmpl);
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::poweroff_success_action(int vid)
{
VirtualMachine * vm;
VirtualMachineTemplate quota_tmpl;
string error_str;
int uid, gid;
vm = vmpool->get(vid);
if ( vm == 0 )
{
return;
}
VirtualMachine::LcmState prev_state = vm->get_lcm_state();
if ((vm->get_state() == VirtualMachine::ACTIVE) &&
(vm->get_lcm_state() == VirtualMachine::SHUTDOWN_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::HOTPLUG_PROLOG_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::HOTPLUG_EPILOG_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::PROLOG_MIGRATE_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::DISK_RESIZE_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::PROLOG_MIGRATE_POWEROFF_FAILURE))
{
get_quota_template(vm, quota_tmpl, true);
vm->set_state(VirtualMachine::POWEROFF);
vm->set_state(VirtualMachine::LCM_INIT);
vmpool->update(vm);
}
else
{
ostringstream oss;
oss << "poweroff_success action received but VM " << vid
<< " not in ACTIVE state";
NebulaLog::log("DiM",Log::ERROR,oss);
vm->unlock();
return;
}
uid = vm->get_uid();
gid = vm->get_gid();
vm->unlock();
if (prev_state != VirtualMachine::DISK_SNAPSHOT_POWEROFF &&
prev_state != VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF &&
prev_state != VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF)
{
Quotas::vm_del(uid, gid, &quota_tmpl);
}
return;
});
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::done_action(int vid)
void DispatchManager::trigger_stop_success(int vid)
{
VirtualMachine * vm;
string error_str;
trigger([this, vid] {
VirtualMachineTemplate quota_tmpl;
string error_str;
VirtualMachine::LcmState lcm_state;
VirtualMachine::VmState dm_state;
int uid, gid;
vm = vmpool->get(vid);
VirtualMachine * vm = vmpool->get(vid);
if ( vm == 0 )
{
return;
}
if (vm == nullptr)
{
return;
}
lcm_state = vm->get_lcm_state();
dm_state = vm->get_state();
if ((vm->get_state() == VirtualMachine::ACTIVE) &&
(vm->get_lcm_state() == VirtualMachine::EPILOG_STOP ||
vm->get_lcm_state() == VirtualMachine::PROLOG_RESUME))
{
get_quota_template(vm, quota_tmpl, true);
if ((dm_state == VirtualMachine::ACTIVE) &&
(lcm_state == VirtualMachine::EPILOG ||
lcm_state == VirtualMachine::CLEANUP_DELETE))
{
free_vm_resources(vm, true);
}
else
{
ostringstream oss;
vm->set_state(VirtualMachine::STOPPED);
oss << "done action received but VM " << vid << " not in ACTIVE state";
NebulaLog::log("DiM",Log::ERROR,oss);
vm->set_state(VirtualMachine::LCM_INIT);
//Set history action field to perform the right TM command on resume
if (vm->get_action() == VMActions::NONE_ACTION)
{
vm->set_internal_action(VMActions::STOP_ACTION);
vmpool->update_history(vm);
}
vmpool->update(vm);
}
else
{
ostringstream oss;
oss << "stop_success action received but VM " << vid
<< " not in ACTIVE state";
NebulaLog::log("DiM",Log::ERROR,oss);
vm->unlock();
return;
}
uid = vm->get_uid();
gid = vm->get_gid();
vm->unlock();
}
return;
Quotas::vm_del(uid, gid, &quota_tmpl);
});
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::resubmit_action(int vid)
void DispatchManager::trigger_undeploy_success(int vid)
{
VirtualMachine * vm;
trigger([this, vid] {
VirtualMachineTemplate quota_tmpl;
string error_str;
vm = vmpool->get(vid);
int uid, gid;
if ( vm == 0 )
{
return;
}
VirtualMachine * vm = vmpool->get(vid);
if (vm->get_lcm_state() == VirtualMachine::CLEANUP_RESUBMIT)
{
// Automatic requirements are not recalculated on purpose
if (vm == nullptr)
{
return;
}
vm->set_state(VirtualMachine::LCM_INIT);
if ((vm->get_state() == VirtualMachine::ACTIVE) &&
(vm->get_lcm_state() == VirtualMachine::EPILOG_UNDEPLOY ||
vm->get_lcm_state() == VirtualMachine::DISK_RESIZE_UNDEPLOYED ||
vm->get_lcm_state() == VirtualMachine::PROLOG_UNDEPLOY))
{
get_quota_template(vm, quota_tmpl, true);
vm->set_state(VirtualMachine::PENDING);
vm->set_state(VirtualMachine::UNDEPLOYED);
vm->set_deploy_id(""); //reset the deploy-id
vm->set_state(VirtualMachine::LCM_INIT);
vmpool->update(vm);
//Set history action field to perform the right TM command on resume
if (vm->get_action() == VMActions::NONE_ACTION)
{
vm->set_internal_action(VMActions::UNDEPLOY_ACTION);
vmpool->update_history(vm);
}
vmpool->update(vm);
}
else
{
ostringstream oss;
oss << "undeploy_success action received but VM " << vid
<< " not in ACTIVE state";
NebulaLog::log("DiM",Log::ERROR,oss);
vm->unlock();
return;
}
uid = vm->get_uid();
gid = vm->get_gid();
vm->unlock();
}
Quotas::vm_del(uid, gid, &quota_tmpl);
});
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::trigger_poweroff_success(int vid)
{
trigger([this, vid] {
VirtualMachineTemplate quota_tmpl;
string error_str;
int uid, gid;
VirtualMachine * vm = vmpool->get(vid);
if (vm == nullptr)
{
return;
}
VirtualMachine::LcmState prev_state = vm->get_lcm_state();
if ((vm->get_state() == VirtualMachine::ACTIVE) &&
(vm->get_lcm_state() == VirtualMachine::SHUTDOWN_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::HOTPLUG_PROLOG_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::HOTPLUG_EPILOG_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::PROLOG_MIGRATE_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::DISK_RESIZE_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC_POWEROFF ||
vm->get_lcm_state() == VirtualMachine::PROLOG_MIGRATE_POWEROFF_FAILURE))
{
get_quota_template(vm, quota_tmpl, true);
vm->set_state(VirtualMachine::POWEROFF);
vm->set_state(VirtualMachine::LCM_INIT);
vmpool->update(vm);
}
else
{
ostringstream oss;
oss << "poweroff_success action received but VM " << vid
<< " not in ACTIVE state";
NebulaLog::log("DiM",Log::ERROR,oss);
vm->unlock();
return;
}
uid = vm->get_uid();
gid = vm->get_gid();
vm->unlock();
if (prev_state != VirtualMachine::DISK_SNAPSHOT_POWEROFF &&
prev_state != VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF &&
prev_state != VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF)
{
Quotas::vm_del(uid, gid, &quota_tmpl);
}
});
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::trigger_done(int vid)
{
trigger([this, vid] {
string error_str;
VirtualMachine::LcmState lcm_state;
VirtualMachine::VmState dm_state;
VirtualMachine * vm = vmpool->get(vid);
if (vm == nullptr)
{
return;
}
lcm_state = vm->get_lcm_state();
dm_state = vm->get_state();
if ((dm_state == VirtualMachine::ACTIVE) &&
(lcm_state == VirtualMachine::EPILOG ||
lcm_state == VirtualMachine::CLEANUP_DELETE))
{
free_vm_resources(vm, true);
}
else
{
ostringstream oss;
oss << "done action received but VM " << vid << " not in ACTIVE state";
NebulaLog::log("DiM",Log::ERROR,oss);
vm->unlock();
}
});
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::trigger_resubmit(int vid)
{
trigger([this, vid] {
VirtualMachine * vm = vmpool->get(vid);
if (vm == nullptr)
{
return;
}
if (vm->get_lcm_state() == VirtualMachine::CLEANUP_RESUBMIT)
{
// Automatic requirements are not recalculated on purpose
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_state(VirtualMachine::PENDING);
vm->set_deploy_id(""); //reset the deploy-id
vmpool->update(vm);
vm->unlock();
}
});
}
/* -------------------------------------------------------------------------- */
+1
View File
@@ -17,6 +17,7 @@
#include "Group.h"
#include "Nebula.h"
#include "AclManager.h"
#include "AclRule.h"
#include "OneDB.h"
#include <sstream>
+1 -1
View File
@@ -262,7 +262,7 @@ int HookLog::retry(int hkid, int exeid, std::string& err_msg)
string message = HookManager::format_message(args64, host, hkid);
hm->trigger(HMAction::RETRY, message);
hm->trigger_retry(message);
return 0;
}
+23 -66
View File
@@ -24,33 +24,8 @@ const char * HookManager::hook_driver_name = "hook_exe";
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * hm_action_loop(void *arg)
{
HookManager * hm;
if ( arg == nullptr )
{
return 0;
}
NebulaLog::log("HKM",Log::INFO,"Hook Manager started.");
hm = static_cast<HookManager *>(arg);
hm->am.loop();
NebulaLog::log("HKM",Log::INFO,"Hook Manager stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int HookManager::start()
{
pthread_attr_t pattr;
using namespace std::placeholders; // for _1
register_action(HookManagerMessages::UNDEFINED,
@@ -74,12 +49,9 @@ int HookManager::start()
NebulaLog::log("HKM",Log::INFO,"Starting Hook Manager...");
pthread_attr_init(&pattr);
pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE);
Listener::start();
int rc = pthread_create(&hm_thread,&pattr,hm_action_loop,(void *) this);
return rc;
return 0;
}
/* -------------------------------------------------------------------------- */
@@ -120,52 +92,37 @@ int HookManager::load_drivers(const std::vector<const VectorAttribute*>& _mads)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void HookManager::user_action(const ActionRequest& ar)
void HookManager::trigger_send_event(const std::string& message)
{
const HMAction& hm_ar = static_cast<const HMAction& >(ar);
const std::string& message = hm_ar.message();
trigger([this, message] {
auto hmd = get();
switch (hm_ar.action())
{
case HMAction::SEND_EVENT:
send_event_action(message);
break;
case HMAction::RETRY:
retry_action(message);
break;
}
if ( hmd == nullptr )
{
return;
}
hook_msg_t msg(HookManagerMessages::EXECUTE, "", -1, message);
hmd->write(msg);
});
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void HookManager::send_event_action(const std::string& message)
void HookManager::trigger_retry(const std::string& message)
{
auto hmd = get();
trigger([this, message] {
auto hmd = get();
if ( hmd == nullptr )
{
return;
}
if ( hmd == nullptr )
{
return;
}
hook_msg_t msg(HookManagerMessages::EXECUTE, "", -1, message);
hmd->write(msg);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void HookManager::retry_action(const std::string& message)
{
auto hmd = get();
if ( hmd == nullptr )
{
return;
}
hook_msg_t msg(HookManagerMessages::RETRY, "", -1, message);
hmd->write(msg);
hook_msg_t msg(HookManagerMessages::RETRY, "", -1, message);
hmd->write(msg);
});
}
/* -------------------------------------------------------------------------- */
+1
View File
@@ -17,6 +17,7 @@
#include "HookStateVM.h"
#include "VirtualMachine.h"
#include "NebulaUtil.h"
#include "SSLUtil.h"
using namespace std;
+2 -2
View File
@@ -102,7 +102,7 @@ int HostPool::allocate (
{
std::string event = HookStateHost::format_message(host);
Nebula::instance().get_hm()->trigger(HMAction::SEND_EVENT, event);
Nebula::instance().get_hm()->trigger_send_event(event);
auto *im = Nebula::instance().get_im();
im->update_host(host);
@@ -148,7 +148,7 @@ int HostPool::update(PoolObjectSQL * objsql)
{
std::string event = HookStateHost::format_message(host);
Nebula::instance().get_hm()->trigger(HMAction::SEND_EVENT, event);
Nebula::instance().get_hm()->trigger_send_event(event);
}
host->set_prev_state();
+31 -51
View File
@@ -31,6 +31,8 @@ int InformationManager::start()
using namespace std::placeholders; // for _1
NebulaLog::info("InM", "Starting Information Manager...");
register_action(InformationManagerMessages::UNDEFINED,
&InformationManager::_undefined);
@@ -51,16 +53,6 @@ int InformationManager::start()
return -1;
}
NebulaLog::info("InM", "Starting Information Manager...");
im_thread = std::thread([&] {
NebulaLog::info("InM", "Information Manager started.");
am.loop();
NebulaLog::info("InM", "Information Manager stopped.");
});
auto rftm = Nebula::instance().get_raftm();
raft_status(rftm->get_state());
@@ -265,7 +257,7 @@ void InformationManager::_host_state(unique_ptr<im_msg_t> msg)
for (const auto& vmid : host->get_vm_ids())
{
lcm->trigger(LCMAction::MONITOR_DONE, vmid);
lcm->trigger_monitor_done(vmid);
}
}
else
@@ -334,10 +326,12 @@ void InformationManager::_host_system(unique_ptr<im_msg_t> msg)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static LCMAction::Actions test_and_trigger(const string& state_str,
VirtualMachine::VmState state, VirtualMachine::LcmState lcm_state,
string& vm_message)
static void test_and_trigger(const string& state_str, VirtualMachine * vm)
{
auto state = vm->get_state();
auto lcm_state = vm->get_lcm_state();
auto lcm = Nebula::instance().get_lcm();
if (state_str == "RUNNING")
{
if (state == VirtualMachine::POWEROFF ||
@@ -356,7 +350,8 @@ static LCMAction::Actions test_and_trigger(const string& state_str,
lcm_state == VirtualMachine::BOOT_UNDEPLOY_FAILURE ||
lcm_state == VirtualMachine::BOOT_FAILURE)))
{
return LCMAction::MONITOR_POWERON;
lcm->trigger_monitor_poweron(vm->get_oid());
return;
}
}
else if (state_str == "FAILURE")
@@ -365,9 +360,12 @@ static LCMAction::Actions test_and_trigger(const string& state_str,
(lcm_state == VirtualMachine::RUNNING ||
lcm_state == VirtualMachine::UNKNOWN))
{
vm_message = "VM running but monitor state is ERROR.";
lcm->trigger_monitor_done(vm->get_oid());
return LCMAction::MONITOR_DONE;
vm->log("VMM", Log::INFO,
"VM running but monitor state is ERROR.");
return;
}
}
else if (state_str == "SUSPENDED")
@@ -376,9 +374,12 @@ static LCMAction::Actions test_and_trigger(const string& state_str,
(lcm_state == VirtualMachine::RUNNING ||
lcm_state == VirtualMachine::UNKNOWN))
{
vm_message = "VM running but monitor state is PAUSED.";
lcm->trigger_monitor_suspend(vm->get_oid());
return LCMAction::MONITOR_SUSPEND;
vm->log("VMM", Log::INFO,
"VM running but monitor state is PAUSED.");
return;
}
}
else if (state_str == "POWEROFF")
@@ -390,11 +391,10 @@ static LCMAction::Actions test_and_trigger(const string& state_str,
lcm_state == VirtualMachine::SHUTDOWN_POWEROFF ||
lcm_state == VirtualMachine::SHUTDOWN_UNDEPLOY))
{
return LCMAction::MONITOR_POWEROFF;
lcm->trigger_monitor_poweroff(vm->get_oid());
return;
}
}
return LCMAction::NONE;
}
@@ -424,7 +424,6 @@ void InformationManager::_vm_state(unique_ptr<im_msg_t> msg)
string deploy_id;
string state_str;
string vm_msg;
vector<VectorAttribute*> vms;
tmpl.get("VM", vms);
@@ -483,18 +482,7 @@ void InformationManager::_vm_state(unique_ptr<im_msg_t> msg)
/* ------------------------------------------------------------------ */
/* Apply state changes */
/* ------------------------------------------------------------------ */
LCMAction::Actions action = test_and_trigger(state_str, vm->get_state(),
vm->get_lcm_state(), vm_msg);
if ( action != LCMAction::NONE )
{
lcm->trigger(action, vm->get_oid());
if ( !vm_msg.empty() )
{
vm->log("VMM", Log::INFO, vm_msg);
}
}
test_and_trigger(state_str, vm);
vm->unlock();
}
@@ -562,26 +550,18 @@ void InformationManager::_vm_state(unique_ptr<im_msg_t> msg)
continue;
}
LCMAction::Actions action;
if ( missing_state == "POWEROFF" )
{
action = LCMAction::MONITOR_POWEROFF;
}
else if ( missing_state == "UNKNOWN" )
{
action = LCMAction::MONITOR_DONE;
}
else
{
action = LCMAction::MONITOR_POWEROFF;
}
NebulaLog::debug("InM", "VM_STATE update from host: " +
to_string(msg->oid()) + ". VM id: " + to_string(vm->get_oid()) +
", state: " + missing_state);
lcm->trigger(action, vm->get_oid());
if (missing_state == "UNKNOWN")
{
lcm->trigger_monitor_done(vm->get_oid());
}
else
{
lcm->trigger_monitor_poweroff(vm->get_oid());
}
vm->unlock();
}
+2 -2
View File
@@ -848,7 +848,7 @@ void Image::set_state(ImageState _state)
for (set<int>::iterator i = vms.begin(); i != vms.end(); i++)
{
lcm->trigger(LCMAction::DISK_LOCK_FAILURE, *i);
lcm->trigger_disk_lock_failure(*i);
}
}
else if (state == LOCKED)
@@ -918,7 +918,7 @@ void Image::set_state_unlock()
for (set<int>::iterator i = vms.begin(); i != vms.end(); i++)
{
lcm->trigger(LCMAction::DISK_LOCK_SUCCESS, *i);
lcm->trigger_disk_lock_success(*i);
}
}
}
+2 -33
View File
@@ -27,29 +27,6 @@ const char * ImageManager::image_driver_name = "image_exe";
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * image_action_loop(void *arg)
{
ImageManager * im;
if ( arg == 0 )
{
return 0;
}
NebulaLog::log("ImM",Log::INFO,"Image Manager started.");
im = static_cast<ImageManager *>(arg);
im->am.loop(im->timer_period);
NebulaLog::log("ImM",Log::INFO,"Image Manager stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ImageManager::load_drivers(const std::vector<const VectorAttribute*>& _mads)
{
const VectorAttribute * vattr = 0;
@@ -87,9 +64,6 @@ int ImageManager::load_drivers(const std::vector<const VectorAttribute*>& _mads)
int ImageManager::start()
{
int rc;
pthread_attr_t pattr;
using namespace std::placeholders; // for _1
register_action(ImageManagerMessages::UNDEFINED,
@@ -135,18 +109,13 @@ int ImageManager::start()
return -1;
}
pthread_attr_init(&pattr);
pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE);
rc = pthread_create(&imagem_thread,&pattr,image_action_loop,(void *) this);
return rc;
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ImageManager::timer_action(const ActionRequest& ar)
void ImageManager::timer_action()
{
static int mark = 0;
static int tics = monitor_period;
+1 -1
View File
@@ -314,7 +314,7 @@ void ImageManager::_mkfs(unique_ptr<image_msg_t> msg)
goto error_save_state;
}
tm->trigger(TMAction::SAVEAS_HOT, vm_id);
tm->trigger_saveas_hot(vm_id);
vmpool->update(vm);
+28 -84
View File
@@ -24,35 +24,10 @@ using std::string;
const char * IPAMManager::ipam_driver_name = "ipam_exe";
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * ipamm_action_loop(void *arg)
{
IPAMManager * ipamm;
if ( arg == nullptr )
{
return 0;
}
ipamm = static_cast<IPAMManager *>(arg);
NebulaLog::log("IPM",Log::INFO,"IPAM Manager started.");
ipamm->am.loop(ipamm->timer_period);
NebulaLog::log("IPM",Log::INFO,"IPAM Manager stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
int IPAMManager::start()
{
pthread_attr_t pattr;
using namespace std::placeholders; // for _1
register_action(IPAMManagerMessages::UNDEFINED,
@@ -85,110 +60,79 @@ int IPAMManager::start()
NebulaLog::log("IPM",Log::INFO,"Starting IPAM Manager...");
pthread_attr_init(&pattr);
pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE);
Listener::start();
int rc = pthread_create(&ipamm_thread, &pattr, ipamm_action_loop, (void *)this);
return rc;
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void IPAMManager::user_action(const ActionRequest& ar)
{
const IPMAction& ipam_ar = static_cast<const IPMAction&>(ar);
IPAMRequest * request = ipam_ar.request();
if ( request == nullptr )
{
return;
}
switch(ipam_ar.action())
{
case IPMAction::REGISTER_ADDRESS_RANGE:
register_address_range_action(request);
break;
case IPMAction::UNREGISTER_ADDRESS_RANGE:
unregister_address_range_action(request);
break;
case IPMAction::ALLOCATE_ADDRESS:
allocate_address_action(request);
break;
case IPMAction::GET_ADDRESS:
get_address_action(request);
break;
case IPMAction::FREE_ADDRESS:
free_address_action(request);
break;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void IPAMManager::send_request(IPAMManagerMessages type, IPAMRequest * ir)
void IPAMManager::send_request(IPAMManagerMessages type, IPAMRequest& ir)
{
auto ipammd = get();
if (ipammd == nullptr)
{
ir->result = false;
ir->message = "Could not find the IPAM driver";
ir.result = false;
ir.message = "Could not find the IPAM driver";
ir->notify();
ir.notify();
return;
}
add_request(ir);
add_request(&ir);
string action_data;
ipam_msg_t msg(type, "", ir->id, ir->to_xml64(action_data));
ipam_msg_t msg(type, "", ir.id, ir.to_xml64(action_data));
ipammd->write(msg);
}
/* -------------------------------------------------------------------------- */
void IPAMManager::register_address_range_action(IPAMRequest * ir)
void IPAMManager::trigger_register_address_range(IPAMRequest& ir)
{
send_request(IPAMManagerMessages::REGISTER_ADDRESS_RANGE, ir);
trigger([&] {
send_request(IPAMManagerMessages::REGISTER_ADDRESS_RANGE, ir);
});
}
/* -------------------------------------------------------------------------- */
void IPAMManager::unregister_address_range_action(IPAMRequest * ir)
void IPAMManager::trigger_unregister_address_range(IPAMRequest& ir)
{
send_request(IPAMManagerMessages::UNREGISTER_ADDRESS_RANGE, ir);
trigger([&] {
send_request(IPAMManagerMessages::UNREGISTER_ADDRESS_RANGE, ir);
});
}
/* -------------------------------------------------------------------------- */
void IPAMManager::get_address_action(IPAMRequest * ir)
void IPAMManager::trigger_get_address(IPAMRequest& ir)
{
send_request(IPAMManagerMessages::GET_ADDRESS, ir);
trigger([&] {
send_request(IPAMManagerMessages::GET_ADDRESS, ir);
});
}
/* -------------------------------------------------------------------------- */
void IPAMManager::allocate_address_action(IPAMRequest * ir)
void IPAMManager::trigger_allocate_address(IPAMRequest& ir)
{
send_request(IPAMManagerMessages::ALLOCATE_ADDRESS, ir);
trigger([&] {
send_request(IPAMManagerMessages::ALLOCATE_ADDRESS, ir);
});
}
/* -------------------------------------------------------------------------- */
void IPAMManager::free_address_action(IPAMRequest * ir)
void IPAMManager::trigger_free_address(IPAMRequest& ir)
{
send_request(IPAMManagerMessages::FREE_ADDRESS, ir);
trigger([&] {
send_request(IPAMManagerMessages::FREE_ADDRESS, ir);
});
}
/* ************************************************************************** */
+1111 -1105
View File
File diff suppressed because it is too large. Load diff
+2 -250
View File
@@ -19,44 +19,15 @@
#include "NebulaLog.h"
#include "Request.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * lcm_action_loop(void *arg)
{
LifeCycleManager * lcm;
if ( arg == 0 )
{
return 0;
}
lcm = static_cast<LifeCycleManager *>(arg);
NebulaLog::log("LCM",Log::INFO,"Life-cycle Manager started.");
lcm->am.loop();
NebulaLog::log("LCM",Log::INFO,"Life-cycle Manager stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
int LifeCycleManager::start()
{
int rc;
pthread_attr_t pattr;
pthread_attr_init(&pattr);
pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE);
NebulaLog::log("LCM",Log::INFO,"Starting Life-cycle Manager...");
rc = pthread_create(&lcm_thread,&pattr,lcm_action_loop,(void *) this);
Listener::start();
return rc;
return 0;
}
/* -------------------------------------------------------------------------- */
@@ -80,222 +51,3 @@ void LifeCycleManager::init_managers()
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::trigger(LCMAction::Actions action, int vid,
const RequestAttributes& ra)
{
LCMAction lcm_ar(action, vid, ra.uid, ra.gid, ra.req_id);
am.trigger(lcm_ar);
}
void LifeCycleManager::trigger(LCMAction::Actions action, int vid)
{
LCMAction lcm_ar(action, vid, -1, -1, -1);
am.trigger(lcm_ar);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void LifeCycleManager::user_action(const ActionRequest& ar)
{
const LCMAction& la = static_cast<const LCMAction& >(ar);
int vid = la.vm_id();
switch (la.action())
{
// -------------------------------------------------------------------------
// Internal Actions, triggered by OpenNebula components & drivers
// -------------------------------------------------------------------------
case LCMAction::SAVE_SUCCESS:
save_success_action(vid);
break;
case LCMAction::SAVE_FAILURE:
save_failure_action(vid);
break;
case LCMAction::DEPLOY_SUCCESS:
deploy_success_action(vid);
break;
case LCMAction::DEPLOY_FAILURE:
deploy_failure_action(vid);
break;
case LCMAction::SHUTDOWN_SUCCESS:
shutdown_success_action(vid);
break;
case LCMAction::SHUTDOWN_FAILURE:
shutdown_failure_action(vid);
break;
case LCMAction::CANCEL_SUCCESS:
shutdown_success_action(vid);
break;
case LCMAction::CANCEL_FAILURE:
shutdown_failure_action(vid);
break;
case LCMAction::MONITOR_SUSPEND:
monitor_suspend_action(vid);
break;
case LCMAction::MONITOR_DONE:
monitor_done_action(vid);
break;
case LCMAction::MONITOR_POWEROFF:
monitor_poweroff_action(vid);
break;
case LCMAction::MONITOR_POWERON:
monitor_poweron_action(vid);
break;
case LCMAction::PROLOG_SUCCESS:
prolog_success_action(vid);
break;
case LCMAction::PROLOG_FAILURE:
prolog_failure_action(vid);
break;
case LCMAction::EPILOG_SUCCESS:
epilog_success_action(vid);
break;
case LCMAction::EPILOG_FAILURE:
epilog_failure_action(vid);
break;
case LCMAction::ATTACH_SUCCESS:
attach_success_action(vid);
break;
case LCMAction::ATTACH_FAILURE:
attach_failure_action(vid);
break;
case LCMAction::DETACH_SUCCESS:
detach_success_action(vid);
break;
case LCMAction::DETACH_FAILURE:
detach_failure_action(vid);
break;
case LCMAction::SAVEAS_SUCCESS:
saveas_success_action(vid);
break;
case LCMAction::SAVEAS_FAILURE:
saveas_failure_action(vid);
break;
case LCMAction::ATTACH_NIC_SUCCESS:
attach_nic_success_action(vid);
break;
case LCMAction::ATTACH_NIC_FAILURE:
attach_nic_failure_action(vid);
break;
case LCMAction::DETACH_NIC_SUCCESS:
detach_nic_success_action(vid);
break;
case LCMAction::DETACH_NIC_FAILURE:
detach_nic_failure_action(vid);
break;
case LCMAction::CLEANUP_SUCCESS:
cleanup_callback_action(vid);
break;
case LCMAction::CLEANUP_FAILURE:
cleanup_callback_action(vid);
break;
case LCMAction::SNAPSHOT_CREATE_SUCCESS:
snapshot_create_success(vid);
break;
case LCMAction::SNAPSHOT_CREATE_FAILURE:
snapshot_create_failure(vid);
break;
case LCMAction::SNAPSHOT_REVERT_SUCCESS:
snapshot_revert_success(vid);
break;
case LCMAction::SNAPSHOT_REVERT_FAILURE:
snapshot_revert_failure(vid);
break;
case LCMAction::SNAPSHOT_DELETE_SUCCESS:
snapshot_delete_success(vid);
break;
case LCMAction::SNAPSHOT_DELETE_FAILURE:
snapshot_delete_failure(vid);
break;
case LCMAction::DISK_SNAPSHOT_SUCCESS:
disk_snapshot_success(vid);
break;
case LCMAction::DISK_SNAPSHOT_FAILURE:
disk_snapshot_failure(vid);
break;
case LCMAction::DISK_LOCK_SUCCESS:
disk_lock_success(vid);
break;
case LCMAction::DISK_LOCK_FAILURE:
disk_lock_failure(vid);
break;
case LCMAction::DISK_RESIZE_SUCCESS:
disk_resize_success(vid);
break;
case LCMAction::DISK_RESIZE_FAILURE:
disk_resize_failure(vid);
break;
case LCMAction::UPDATE_CONF_SUCCESS:
update_conf_success(vid);
break;
case LCMAction::UPDATE_CONF_FAILURE:
update_conf_failure(vid);
break;
// -------------------------------------------------------------------------
// External Actions, triggered by user requests
// -------------------------------------------------------------------------
case LCMAction::DEPLOY:
deploy_action(la);
break;
case LCMAction::SUSPEND:
suspend_action(la);
break;
case LCMAction::RESTORE:
restore_action(la);
break;
case LCMAction::STOP:
stop_action(la);
break;
case LCMAction::CANCEL:
shutdown_action(la, true);
break;
case LCMAction::MIGRATE:
migrate_action(la);
break;
case LCMAction::POFF_MIGRATE:
migrate_action(la);
break;
case LCMAction::POFF_HARD_MIGRATE:
migrate_action(la);
break;
case LCMAction::LIVE_MIGRATE:
live_migrate_action(la);
break;
case LCMAction::SHUTDOWN:
shutdown_action(la, false);
break;
case LCMAction::UNDEPLOY:
undeploy_action(la, false);
break;
case LCMAction::UNDEPLOY_HARD:
undeploy_action(la, true);
break;
case LCMAction::RESTART:
restart_action(la);
break;
case LCMAction::DELETE:
delete_action(la);
break;
case LCMAction::DELETE_RECREATE:
delete_recreate_action(la);
break;
case LCMAction::POWEROFF:
poweroff_action(la);
break;
case LCMAction::POWEROFF_HARD:
poweroff_hard_action(la);
break;
case LCMAction::UPDATESG:
updatesg_action(la);
break;
case LCMAction::NONE:
break;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
+2193 -2140
View File
File diff suppressed because it is too large. Load diff
+11 -44
View File
@@ -28,37 +28,14 @@ const char * MarketPlaceManager::market_driver_name = "market_exe";
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * marketplace_action_loop(void *arg)
{
MarketPlaceManager * mpm;
if ( arg == nullptr )
{
return 0;
}
NebulaLog::log("MKP", Log::INFO, "Marketplace Manager started.");
mpm = static_cast<MarketPlaceManager *>(arg);
mpm->am.loop(mpm->timer_period);
NebulaLog::log("MKP", Log::INFO, "Marketplace Manager stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
MarketPlaceManager::MarketPlaceManager(
time_t _timer_period,
time_t _monitor_period,
const string& _mad_location):
DriverManager(_mad_location),
timer_period(_timer_period),
monitor_period(_monitor_period),
imagem(0),
raftm(0)
const string& _mad_location)
: DriverManager(_mad_location)
, timer_thread(_timer_period, [this](){timer_action();})
, timer_period(_timer_period)
, monitor_period(_monitor_period)
{
Nebula& nd = Nebula::instance();
@@ -66,9 +43,7 @@ MarketPlaceManager::MarketPlaceManager(
apppool = nd.get_apppool();
dspool = nd.get_dspool();
ipool = nd.get_ipool();
am.addListener(this);
};
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@@ -122,11 +97,10 @@ void MarketPlaceManager::init_managers()
int MarketPlaceManager::start()
{
int rc;
pthread_attr_t pattr;
using namespace std::placeholders; // for _1
NebulaLog::log("MKP",Log::INFO,"Starting Marketplace Manager...");
register_action(MarketPlaceManagerMessages::UNDEFINED,
&MarketPlaceManager::_undefined);
@@ -143,21 +117,14 @@ int MarketPlaceManager::start()
&MarketPlaceManager::_log);
string error;
if ( DriverManager::start(error) != 0 )
{
NebulaLog::error("MKP", error);
return -1;
}
NebulaLog::log("MKP",Log::INFO,"Starting Marketplace Manager...");
pthread_attr_init(&pattr);
pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE);
rc = pthread_create(&marketm_thread, &pattr, marketplace_action_loop,
(void *) this);
return rc;
return 0;
}
/* -------------------------------------------------------------------------- */
@@ -185,7 +152,7 @@ string MarketPlaceManager::format_message(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void MarketPlaceManager::timer_action(const ActionRequest& ar)
void MarketPlaceManager::timer_action()
{
static int mark = 0;
static int tics = monitor_period - 5; //first monitor in 5 secs
+8 -33
View File
@@ -845,16 +845,6 @@ void Nebula::start(bool bootstrap_only)
throw;
}
if (!cache)
{
rc = raftm->start();
if ( rc != 0 )
{
throw runtime_error("Could not start the Raft Consensus Manager");
}
}
// ---- FedReplica Manager ----
if (!cache)
{
@@ -867,19 +857,12 @@ void Nebula::start(bool bootstrap_only)
throw;
}
rc = frm->start();
if ( is_federation_master() && solo )
{
// Replica threads are started on master in solo mode.
// HA start/stop the replica threads on leader/follower states
frm->start_replica_threads();
}
if ( rc != 0 )
{
throw runtime_error("Could not start the Federation Replica Manager");
}
}
// ---- Virtual Machine Manager ----
@@ -893,7 +876,6 @@ void Nebula::start(bool bootstrap_only)
nebula_configuration->get("VM_MAD", vmm_mads);
vmm = new VirtualMachineManager(
timer_period,
vm_limit,
mad_location);
@@ -1202,20 +1184,15 @@ void Nebula::start(bool bootstrap_only)
marketm->finalize();
ipamm->finalize();
frm->finalize();
//sleep to wait drivers???
pthread_join(vmm->get_thread_id(),0);
pthread_join(lcm->get_thread_id(),0);
pthread_join(tm->get_thread_id(),0);
pthread_join(dm->get_thread_id(),0);
vmm->join_thread();
lcm->join_thread();
tm->join_thread();
dm->join_thread();
im->join_thread();
pthread_join(hm->get_thread_id(),0);
pthread_join(imagem->get_thread_id(),0);
pthread_join(marketm->get_thread_id(),0);
pthread_join(ipamm->get_thread_id(),0);
pthread_join(frm->get_thread_id(),0);
hm->join_thread();
ipamm->join_thread();
}
raftm->finalize();
@@ -1224,13 +1201,11 @@ void Nebula::start(bool bootstrap_only)
rm->finalize();
authm->finalize();
pthread_join(rm->get_thread_id(),0);
pthread_join(authm->get_thread_id(),0);
pthread_join(raftm->get_thread_id(),0);
authm->join_thread();
if (is_federation_slave())
{
pthread_join(aclm->get_thread_id(),0);
aclm->join_thread();
}
+1
View File
@@ -17,6 +17,7 @@
#include "PoolObjectSQL.h"
#include "PoolObjectAuth.h"
#include "NebulaUtil.h"
#include "SSLUtil.h"
#include "Nebula.h"
#include "Clusterable.h"
#include "ClusterableSingle.h"
+10 -85
View File
@@ -33,10 +33,7 @@ const time_t FedReplicaManager::xmlrpc_timeout_ms = 10000;
FedReplicaManager::FedReplicaManager(LogDB * d): ReplicaManager(), logdb(d)
{
pthread_mutex_init(&mutex, 0);
am.addListener(this);
};
}
/* -------------------------------------------------------------------------- */
@@ -57,7 +54,7 @@ FedReplicaManager::~FedReplicaManager()
{
stop_replica_threads();
}
};
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@@ -65,83 +62,28 @@ FedReplicaManager::~FedReplicaManager()
uint64_t FedReplicaManager::apply_log_record(uint64_t index, uint64_t prev,
const std::string& sql)
{
uint64_t rc;
pthread_mutex_lock(&mutex);
lock_guard<mutex> ul(fed_mutex);
uint64_t last_index = logdb->last_federated();
if ( prev != last_index )
{
rc = last_index;
pthread_mutex_unlock(&mutex);
return rc;
return last_index;
}
std::ostringstream oss(sql);
if ( logdb->exec_federated_wr(oss, index) != 0 )
{
pthread_mutex_unlock(&mutex);
return UINT64_MAX;
}
pthread_mutex_unlock(&mutex);
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * frm_loop(void *arg)
{
FedReplicaManager * fedrm;
if ( arg == 0 )
{
return 0;
}
fedrm = static_cast<FedReplicaManager *>(arg);
NebulaLog::log("FRM",Log::INFO,"Federation Replica Manger started.");
fedrm->am.loop();
NebulaLog::log("FRM",Log::INFO,"Federation Replica Manger stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
int FedReplicaManager::start()
{
int rc;
pthread_attr_t pattr;
pthread_attr_init (&pattr);
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
NebulaLog::log("FRM",Log::INFO,"Starting Federation Replica Manager...");
rc = pthread_create(&frm_thread, &pattr, frm_loop,(void *) this);
return rc;
}
/* -------------------------------------------------------------------------- */
void FedReplicaManager::finalize_action(const ActionRequest& ar)
{
NebulaLog::log("FRM", Log::INFO, "Federation Replica Manager...");
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void FedReplicaManager::update_zones(std::vector<int>& zone_ids)
{
Nebula& nd = Nebula::instance();
@@ -156,7 +98,7 @@ void FedReplicaManager::update_zones(std::vector<int>& zone_ids)
return;
}
pthread_mutex_lock(&mutex);
lock_guard<mutex> ul(fed_mutex);
uint64_t last_index = logdb->last_federated();
@@ -192,8 +134,6 @@ void FedReplicaManager::update_zones(std::vector<int>& zone_ids)
}
}
}
pthread_mutex_unlock(&mutex);
}
/* -------------------------------------------------------------------------- */
@@ -219,7 +159,7 @@ void FedReplicaManager::add_zone(int zone_id)
zone->unlock();
pthread_mutex_lock(&mutex);
lock_guard<mutex> ul(fed_mutex);
int last_index = logdb->last_federated();
@@ -232,8 +172,6 @@ void FedReplicaManager::add_zone(int zone_id)
NebulaLog::log("FRM", Log::INFO, oss);
add_replica_thread(zone_id);
pthread_mutex_unlock(&mutex);
}
/* -------------------------------------------------------------------------- */
@@ -244,7 +182,7 @@ void FedReplicaManager::delete_zone(int zone_id)
std::map<int, ZoneServers *>::iterator it;
pthread_mutex_lock(&mutex);
lock_guard<mutex> ul(fed_mutex);
it = zones.find(zone_id);
@@ -262,8 +200,6 @@ void FedReplicaManager::delete_zone(int zone_id)
NebulaLog::log("FRM", Log::INFO, oss);
delete_replica_thread(zone_id);
pthread_mutex_unlock(&mutex);
};
/* -------------------------------------------------------------------------- */
@@ -280,13 +216,12 @@ ReplicaThread * FedReplicaManager::thread_factory(int zone_id)
int FedReplicaManager::get_next_record(int zone_id, std::string& zedp,
LogDBRecord& lr, std::string& error)
{
pthread_mutex_lock(&mutex);
lock_guard<mutex> ul(fed_mutex);
std::map<int, ZoneServers *>::iterator it = zones.find(zone_id);
if ( it == zones.end() )
{
pthread_mutex_unlock(&mutex);
return -1;
}
@@ -308,7 +243,6 @@ int FedReplicaManager::get_next_record(int zone_id, std::string& zedp,
if ( zs->next == UINT64_MAX ) //no new records
{
pthread_mutex_unlock(&mutex);
return -2;
}
@@ -322,8 +256,6 @@ int FedReplicaManager::get_next_record(int zone_id, std::string& zedp,
error = oss.str();
pthread_mutex_unlock(&mutex);
return -1;
}
@@ -339,8 +271,6 @@ int FedReplicaManager::get_next_record(int zone_id, std::string& zedp,
error = oss.str();
}
pthread_mutex_unlock(&mutex);
return rc;
}
@@ -349,13 +279,12 @@ int FedReplicaManager::get_next_record(int zone_id, std::string& zedp,
void FedReplicaManager::replicate_success(int zone_id)
{
pthread_mutex_lock(&mutex);
lock_guard<mutex> ul(fed_mutex);
std::map<int, ZoneServers *>::iterator it = zones.find(zone_id);
if ( it == zones.end() )
{
pthread_mutex_unlock(&mutex);
return;
}
@@ -369,15 +298,13 @@ void FedReplicaManager::replicate_success(int zone_id)
{
ReplicaManager::replicate(zone_id);
}
pthread_mutex_unlock(&mutex);
}
/* -------------------------------------------------------------------------- */
void FedReplicaManager::replicate_failure(int zone_id, uint64_t last_zone)
{
pthread_mutex_lock(&mutex);
lock_guard<mutex> ul(fed_mutex);
std::map<int, ZoneServers *>::iterator it = zones.find(zone_id);
@@ -397,8 +324,6 @@ void FedReplicaManager::replicate_failure(int zone_id, uint64_t last_zone)
ReplicaManager::replicate(zone_id);
}
}
pthread_mutex_unlock(&mutex);
}
+235 -341
View File
@@ -55,18 +55,21 @@ static unsigned int get_zone_servers(std::map<int, std::string>& _s);
RaftManager::RaftManager(int id, const VectorAttribute * leader_hook_mad,
const VectorAttribute * follower_hook_mad, time_t log_purge,
long long bcast, long long elect, time_t xmlrpc,
const string& remotes_location):server_id(id), term(0), num_servers(0),
reconciling(false), commit(0), leader_hook(0), follower_hook(0)
const string& remotes_location)
: server_id(id)
, term(0)
, num_servers(0)
, reconciling(false)
, timer_thread(timer_period_ms / 1000.0, [this](){timer_action();})
, commit(0)
, leader_hook(0)
, follower_hook(0)
{
Nebula& nd = Nebula::instance();
LogDB * logdb = nd.get_logdb();
std::string raft_xml, cmd, arg;
pthread_mutex_init(&mutex, 0);
am.addListener(this);
// -------------------------------------------------------------------------
// Initialize Raft variables:
// - state
@@ -105,16 +108,16 @@ RaftManager::RaftManager(int id, const VectorAttribute * leader_hook_mad,
num_servers = get_zone_servers(servers);
if ( server_id == -1 )
{
if ( server_id == -1 )
{
NebulaLog::log("ONE", Log::INFO, "oned started in solo mode.");
state = SOLO;
}
else
{
state = SOLO;
}
else
{
NebulaLog::log("RCM", Log::INFO, "oned started in follower mode");
state = FOLLOWER;
}
state = FOLLOWER;
}
// -------------------------------------------------------------------------
// Initialize Raft timers
@@ -182,55 +185,13 @@ RaftManager::RaftManager(int id, const VectorAttribute * leader_hook_mad,
}
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * raft_manager_loop(void *arg)
void RaftManager::finalize()
{
RaftManager * raftm;
struct timespec timeout;
if ( arg == 0 )
{
return 0;
}
raftm = static_cast<RaftManager *>(arg);
timeout.tv_sec = 0;
timeout.tv_nsec = raftm->timer_period_ms * 1000000;
NebulaLog::log("RCM",Log::INFO,"Raft Consensus Manager started.");
raftm->am.loop(timeout);
NebulaLog::log("RCM",Log::INFO,"Raft Consensus Manager stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
int RaftManager::start()
{
int rc;
pthread_attr_t pattr;
pthread_attr_init (&pattr);
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
NebulaLog::log("RCM",Log::INFO,"Starting Raft Consensus Manager...");
rc = pthread_create(&raft_thread, &pattr, raft_manager_loop,(void *) this);
return rc;
}
/* -------------------------------------------------------------------------- */
void RaftManager::finalize_action(const ActionRequest& ar)
{
NebulaLog::log("RCM", Log::INFO, "Raft Consensus Manager...");
timer_thread.stop();
if (is_leader())
{
@@ -258,7 +219,7 @@ int RaftManager::get_leader_endpoint(std::string& endpoint)
{
int rc;
pthread_mutex_lock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
if ( leader_id == -1 )
{
@@ -281,8 +242,6 @@ int RaftManager::get_leader_endpoint(std::string& endpoint)
}
}
pthread_mutex_unlock(&mutex);
return rc;
}
@@ -293,18 +252,17 @@ void RaftManager::add_server(int follower_id, const std::string& endpoint)
{
std::ostringstream oss;
LogDB * logdb = Nebula::instance().get_logdb();
LogDB * logdb = Nebula::instance().get_logdb();
unsigned int log_term;
unsigned int log_term;
uint64_t log_index;
logdb->get_last_record_index(log_index, log_term);
pthread_mutex_lock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
if ( state != LEADER )
{
pthread_mutex_unlock(&mutex);
return;
}
@@ -312,21 +270,19 @@ void RaftManager::add_server(int follower_id, const std::string& endpoint)
servers.insert(std::make_pair(follower_id, endpoint));
next.insert(std::make_pair(follower_id, log_index + 1));
next.insert(std::make_pair(follower_id, log_index + 1));
match.insert(std::make_pair(follower_id, 0));
match.insert(std::make_pair(follower_id, 0));
oss << "Starting replication and heartbeat threads for follower: "
<< follower_id;
NebulaLog::log("RCM", Log::INFO, oss);
replica_manager.add_replica_thread(follower_id);
replica_manager.add_replica_thread(follower_id);
heartbeat_manager.add_replica_thread(follower_id);
pthread_mutex_unlock(&mutex);
};
heartbeat_manager.add_replica_thread(follower_id);
}
/* -------------------------------------------------------------------------- */
@@ -335,32 +291,29 @@ void RaftManager::delete_server(int follower_id)
std::ostringstream oss;
std::map<int, std::string> _servers;
pthread_mutex_lock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
if ( state != LEADER )
{
pthread_mutex_unlock(&mutex);
return;
}
num_servers--;
servers.erase(follower_id);
next.erase(follower_id);
next.erase(follower_id);
match.erase(follower_id);
match.erase(follower_id);
oss << "Stopping replication and heartbeat threads for follower: "
<< follower_id;
NebulaLog::log("RCM", Log::INFO, oss);
replica_manager.delete_replica_thread(follower_id);
replica_manager.delete_replica_thread(follower_id);
heartbeat_manager.delete_replica_thread(follower_id);
pthread_mutex_unlock(&mutex);
};
heartbeat_manager.delete_replica_thread(follower_id);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@@ -368,32 +321,6 @@ void RaftManager::delete_server(int follower_id)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * reconciling_thread(void *arg)
{
Nebula& nd = Nebula::instance();
LogDB * logdb = nd.get_logdb();
RaftManager * rm = nd.get_raftm();
uint64_t * index = static_cast<uint64_t *>(arg);
NebulaLog::log("RCM", Log::INFO, "Replicating log to followers");
logdb->replicate(*index);
NebulaLog::log("RCM", Log::INFO, "Leader log replicated");
pthread_mutex_lock(&(rm->mutex));
rm->reconciling = false;
pthread_mutex_unlock(&(rm->mutex));
free(index);
return 0;
}
void RaftManager::leader()
{
Nebula& nd = Nebula::instance();
@@ -414,68 +341,68 @@ void RaftManager::leader()
logdb->setup_index(_applied, index);
pthread_mutex_lock(&mutex);
if ( state != CANDIDATE )
{
pthread_mutex_unlock(&mutex);
return;
}
std::lock_guard<mutex> lock(raft_mutex);
oss << "Becoming leader of the zone. Last log record: " << index << " last "
<< "applied record: " << _applied;
NebulaLog::log("RCM", Log::INFO, oss);
next.clear();
match.clear();
requests.clear();
if ( leader_hook != 0 )
{
leader_hook->execute();
}
state = LEADER;
commit = _applied;
leader_id = server_id;
if ( _applied < index )
{
reconciling = true;
_next_index = index;
}
else
{
_next_index = index + 1;
}
for (it = servers.begin(); it != servers.end() ; ++it )
{
if ( it->first == server_id )
if ( state != CANDIDATE )
{
continue;
return;
}
next.insert(std::make_pair(it->first, _next_index));
oss << "Becoming leader of the zone. Last log record: " << index << " last "
<< "applied record: " << _applied;
match.insert(std::make_pair(it->first, 0));
NebulaLog::log("RCM", Log::INFO, oss);
_follower_ids.push_back(it->first);
next.clear();
match.clear();
requests.clear();
if ( leader_hook != 0 )
{
leader_hook->execute();
}
state = LEADER;
commit = _applied;
leader_id = server_id;
if ( _applied < index )
{
reconciling = true;
_next_index = index;
}
else
{
_next_index = index + 1;
}
for (it = servers.begin(); it != servers.end() ; ++it )
{
if ( it->first == server_id )
{
continue;
}
next.insert(std::make_pair(it->first, _next_index));
match.insert(std::make_pair(it->first, 0));
_follower_ids.push_back(it->first);
}
replica_manager.start_replica_threads(_follower_ids);
heartbeat_manager.start_replica_threads(_follower_ids);
heartbeat_manager.replicate();
clock_gettime(CLOCK_REALTIME, &last_heartbeat);
}
replica_manager.start_replica_threads(_follower_ids);
heartbeat_manager.start_replica_threads(_follower_ids);
heartbeat_manager.replicate();
clock_gettime(CLOCK_REALTIME, &last_heartbeat);
pthread_mutex_unlock(&mutex);
aclm->reload_rules();
auto im = nd.get_im();
@@ -488,19 +415,23 @@ void RaftManager::leader()
if ( _applied < index )
{
pthread_attr_t pattr;
pthread_t thid;
std::thread t([this, _next_index] {
Nebula& nd = Nebula::instance();
pthread_attr_init (&pattr);
pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED);
LogDB * logdb = nd.get_logdb();
uint64_t * _index = (uint64_t *) malloc(sizeof(uint64_t));
NebulaLog::log("RCM", Log::INFO, "Replicating log to followers");
*_index = _next_index;
logdb->replicate(_next_index);
pthread_create(&thid, &pattr, reconciling_thread, (void *) _index);
NebulaLog::log("RCM", Log::INFO, "Leader log replicated");
pthread_attr_destroy(&pattr);
std::lock_guard<mutex> lock(raft_mutex);
reconciling = false;
});
t.detach();
}
NebulaLog::log("RCM", Log::INFO, "oned is now the leader of the zone");
@@ -522,44 +453,44 @@ void RaftManager::follower(unsigned int _term)
logdb->setup_index(lapplied, lindex);
pthread_mutex_lock(&mutex);
if ( state == LEADER && follower_hook != 0 )
{
follower_hook->execute();
std::lock_guard<mutex> lock(raft_mutex);
if ( state == LEADER && follower_hook != 0 )
{
follower_hook->execute();
}
replica_manager.stop_replica_threads();
heartbeat_manager.stop_replica_threads();
state = FOLLOWER;
if ( _term > term )
{
term = _term;
votedfor = -1;
raft_state.replace("VOTEDFOR", votedfor);
raft_state.replace("TERM", term);
raft_state.to_xml(raft_state_xml);
}
commit = lapplied;
leader_id = -1;
auto im = nd.get_im();
im->raft_status(state);
NebulaLog::log("RCM", Log::INFO, "oned is set to follower mode");
next.clear();
match.clear();
requests.clear();
}
replica_manager.stop_replica_threads();
heartbeat_manager.stop_replica_threads();
state = FOLLOWER;
if ( _term > term )
{
term = _term;
votedfor = -1;
raft_state.replace("VOTEDFOR", votedfor);
raft_state.replace("TERM", term);
raft_state.to_xml(raft_state_xml);
}
commit = lapplied;
leader_id = -1;
auto im = nd.get_im();
im->raft_status(state);
NebulaLog::log("RCM", Log::INFO, "oned is set to follower mode");
next.clear();
match.clear();
requests.clear();
pthread_mutex_unlock(&mutex);
if ( nd.is_federation_master() )
{
frm->stop_replica_threads();
@@ -576,7 +507,7 @@ void RaftManager::follower(unsigned int _term)
void RaftManager::replicate_log(ReplicaRequest * request)
{
pthread_mutex_lock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
if ( state != LEADER )
{
@@ -584,7 +515,6 @@ void RaftManager::replicate_log(ReplicaRequest * request)
requests.remove(request->index());
pthread_mutex_unlock(&mutex);
return;
}
@@ -622,8 +552,6 @@ void RaftManager::replicate_log(ReplicaRequest * request)
requests.set(request->index(), request);
}
pthread_mutex_unlock(&mutex);
}
/* -------------------------------------------------------------------------- */
@@ -639,19 +567,18 @@ void RaftManager::replicate_success(int follower_id)
Nebula& nd = Nebula::instance();
LogDB * logdb = nd.get_logdb();
unsigned int db_lterm;
unsigned int db_lterm;
uint64_t db_lindex;
logdb->get_last_record_index(db_lindex, db_lterm);
pthread_mutex_lock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
next_it = next.find(follower_id);
match_it = match.find(follower_id);
if ( next_it == next.end() || match_it == match.end() )
{
pthread_mutex_unlock(&mutex);
return;
}
@@ -670,8 +597,6 @@ void RaftManager::replicate_success(int follower_id)
{
replica_manager.replicate(follower_id);
}
pthread_mutex_unlock(&mutex);
}
/* -------------------------------------------------------------------------- */
@@ -681,7 +606,7 @@ void RaftManager::replicate_failure(int follower_id)
{
std::map<int, uint64_t>::iterator next_it;
pthread_mutex_lock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
next_it = next.find(follower_id);
@@ -697,8 +622,6 @@ void RaftManager::replicate_failure(int follower_id)
{
replica_manager.replicate(follower_id);
}
pthread_mutex_unlock(&mutex);
}
/* -------------------------------------------------------------------------- */
@@ -709,13 +632,11 @@ void RaftManager::replicate_failure(int follower_id)
void RaftManager::update_last_heartbeat(int _leader_id)
{
pthread_mutex_lock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
leader_id = _leader_id;
clock_gettime(CLOCK_REALTIME, &last_heartbeat);
pthread_mutex_unlock(&mutex);
clock_gettime(CLOCK_REALTIME, &last_heartbeat);
}
/* -------------------------------------------------------------------------- */
@@ -723,9 +644,7 @@ void RaftManager::update_last_heartbeat(int _leader_id)
uint64_t RaftManager::update_commit(uint64_t leader_commit, uint64_t index)
{
uint64_t _commit;
pthread_mutex_lock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
if ( leader_commit > commit )
{
@@ -739,11 +658,7 @@ uint64_t RaftManager::update_commit(uint64_t leader_commit, uint64_t index)
}
}
_commit = commit;
pthread_mutex_unlock(&mutex);
return _commit;
return commit;
}
/* -------------------------------------------------------------------------- */
@@ -756,23 +671,21 @@ int RaftManager::update_votedfor(int _votedfor)
std::string raft_state_xml;
pthread_mutex_lock(&mutex);
if ( votedfor != -1 && votedfor != _votedfor )
{
pthread_mutex_unlock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
return -1;
if ( votedfor != -1 && votedfor != _votedfor )
{
return -1;
}
votedfor = _votedfor;
raft_state.replace("VOTEDFOR", votedfor);
raft_state.to_xml(raft_state_xml);
}
votedfor = _votedfor;
raft_state.replace("VOTEDFOR", votedfor);
raft_state.to_xml(raft_state_xml);
pthread_mutex_unlock(&mutex);
logdb->update_raft_state(raft_state_name, raft_state_xml);
return 0;
@@ -781,7 +694,7 @@ int RaftManager::update_votedfor(int _votedfor)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RaftManager::timer_action(const ActionRequest& ar)
void RaftManager::timer_action()
{
static int mark_tics = 0;
static int purge_tics = 0;
@@ -824,7 +737,7 @@ void RaftManager::timer_action(const ActionRequest& ar)
clock_gettime(CLOCK_REALTIME, &the_time);
pthread_mutex_lock(&mutex);
std::unique_lock<mutex> lock(raft_mutex);
if ( state == LEADER ) // Send the heartbeat
{
@@ -837,12 +750,6 @@ void RaftManager::timer_action(const ActionRequest& ar)
heartbeat_manager.replicate();
clock_gettime(CLOCK_REALTIME, &last_heartbeat);
pthread_mutex_unlock(&mutex);
}
else
{
pthread_mutex_unlock(&mutex);
}
}
else if ( state == FOLLOWER )
@@ -858,18 +765,13 @@ void RaftManager::timer_action(const ActionRequest& ar)
state = CANDIDATE;
pthread_mutex_unlock(&mutex);
lock.unlock();
request_vote();
}
else
{
pthread_mutex_unlock(&mutex);
}
}
else //SOLO or CANDIDATE, do nothing
{
pthread_mutex_unlock(&mutex);
}
return;
@@ -916,35 +818,34 @@ void RaftManager::request_vote()
/* ------------------------------------------------------------------ */
/* Initialize election variables */
/* ------------------------------------------------------------------ */
pthread_mutex_lock(&mutex);
if ( state != CANDIDATE )
{
pthread_mutex_unlock(&mutex);
break;
std::lock_guard<mutex> lock(raft_mutex);
if ( state != CANDIDATE )
{
break;
}
servers = _servers;
num_servers = _num_servers;
term = term + 1;
votedfor = server_id;
leader_id = -1;
raft_state.replace("TERM", term);
raft_state.replace("VOTEDFOR", votedfor);
raft_state.to_xml(raft_state_xml);
votes2go = num_servers / 2;
granted_votes = 0;
_term = term;
_server_id = server_id;
}
servers = _servers;
num_servers = _num_servers;
term = term + 1;
votedfor = server_id;
leader_id = -1;
raft_state.replace("TERM", term);
raft_state.replace("VOTEDFOR", votedfor);
raft_state.to_xml(raft_state_xml);
votes2go = num_servers / 2;
granted_votes = 0;
_term = term;
_server_id = server_id;
pthread_mutex_unlock(&mutex);
logdb->update_raft_state(raft_state_name, raft_state_xml);
logdb->get_last_record_index(lindex, lterm);
@@ -1016,22 +917,21 @@ void RaftManager::request_vote()
/* ------------------------------------------------------------------ */
/* Timeout for a new election process (blocking timer thread) */
/* ------------------------------------------------------------------ */
pthread_mutex_lock(&mutex);
if ( state != CANDIDATE )
{
pthread_mutex_unlock(&mutex);
break;
std::lock_guard<mutex> lock(raft_mutex);
if ( state != CANDIDATE )
{
break;
}
votedfor = -1;
raft_state.replace("VOTEDFOR", votedfor);
raft_state.to_xml(raft_state_xml);
}
votedfor = -1;
raft_state.replace("VOTEDFOR", votedfor);
raft_state.to_xml(raft_state_xml);
pthread_mutex_unlock(&mutex);
logdb->update_raft_state(raft_state_name, raft_state_xml);
ms = one_util::random<float>(0, 1) * (election_timeout.tv_sec * 1000
@@ -1053,10 +953,10 @@ void RaftManager::request_vote()
/* -------------------------------------------------------------------------- */
int RaftManager::xmlrpc_replicate_log(int follower_id, LogDBRecord * lr,
bool& success, unsigned int& fterm, std::string& error)
bool& success, unsigned int& fterm, std::string& error)
{
int _server_id;
uint64_t _commit;
int _server_id;
uint64_t _commit;
unsigned int _term;
std::string xmlrpc_secret;
@@ -1066,28 +966,27 @@ int RaftManager::xmlrpc_replicate_log(int follower_id, LogDBRecord * lr,
std::map<int, std::string>::iterator it;
int xml_rc = 0;
int xml_rc = 0;
pthread_mutex_lock(&mutex);
it = servers.find(follower_id);
if ( it == servers.end() )
{
error = "Cannot find follower end point";
pthread_mutex_unlock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
return -1;
it = servers.find(follower_id);
if ( it == servers.end() )
{
error = "Cannot find follower end point";
return -1;
}
follower_edp = it->second;
_commit = commit;
_term = term;
_server_id = server_id;
}
follower_edp = it->second;
_commit = commit;
_term = term;
_server_id = server_id;
pthread_mutex_unlock(&mutex);
// -------------------------------------------------------------------------
// Get parameters to call append entries on follower
// -------------------------------------------------------------------------
@@ -1153,7 +1052,7 @@ int RaftManager::xmlrpc_request_vote(int follower_id, uint64_t lindex,
unsigned int lterm, bool& success, unsigned int& fterm,
std::string& error)
{
int _server_id;
int _server_id;
unsigned int _term;
std::string xmlrpc_secret;
@@ -1163,27 +1062,26 @@ int RaftManager::xmlrpc_request_vote(int follower_id, uint64_t lindex,
std::map<int, std::string>::iterator it;
int xml_rc = 0;
int xml_rc = 0;
pthread_mutex_lock(&mutex);
it = servers.find(follower_id);
if ( it == servers.end() )
{
error = "Cannot find follower end point";
pthread_mutex_unlock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
return -1;
it = servers.find(follower_id);
if ( it == servers.end() )
{
error = "Cannot find follower end point";
return -1;
}
follower_edp = it->second;
_term = term;
_server_id = server_id;
}
follower_edp = it->second;
_term = term;
_server_id = server_id;
pthread_mutex_unlock(&mutex);
// -------------------------------------------------------------------------
// Get parameters to call append entries on follower
// -------------------------------------------------------------------------
@@ -1251,7 +1149,7 @@ std::string& RaftManager::to_xml(std::string& raft_xml)
logdb->get_last_record_index(lindex, lterm);
pthread_mutex_lock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
oss << "<RAFT>"
<< "<SERVER_ID>" << server_id << "</SERVER_ID>"
@@ -1260,11 +1158,11 @@ std::string& RaftManager::to_xml(std::string& raft_xml)
<< "<VOTEDFOR>" << votedfor << "</VOTEDFOR>"
<< "<COMMIT>" << commit << "</COMMIT>";
if ( state == SOLO )
{
if ( state == SOLO )
{
oss << "<LOG_INDEX>-1</LOG_INDEX>"
<< "<LOG_TERM>-1</LOG_TERM>";
}
}
else
{
oss << "<LOG_INDEX>" << lindex << "</LOG_INDEX>"
@@ -1282,8 +1180,6 @@ std::string& RaftManager::to_xml(std::string& raft_xml)
oss << "</RAFT>";
pthread_mutex_unlock(&mutex);
raft_xml = oss.str();
return raft_xml;
@@ -1296,14 +1192,14 @@ void RaftManager::reset_index(int follower_id)
{
std::map<int, uint64_t>::iterator next_it;
unsigned int log_term;
unsigned int log_term;
uint64_t log_index;
LogDB * logdb = Nebula::instance().get_logdb();
LogDB * logdb = Nebula::instance().get_logdb();
logdb->get_last_record_index(log_index, log_term);
pthread_mutex_lock(&mutex);
std::lock_guard<mutex> lock(raft_mutex);
next_it = next.find(follower_id);
@@ -1311,8 +1207,6 @@ void RaftManager::reset_index(int follower_id)
{
next_it->second = log_index + 1;
}
pthread_mutex_unlock(&mutex);
}
/* -------------------------------------------------------------------------- */
+1 -1
View File
@@ -451,7 +451,7 @@ void Request::execute(
if (!event.empty())
{
hm->trigger(HMAction::SEND_EVENT, event);
hm->trigger_send_event(event);
}
if ( log_method_call )
+6 -37
View File
@@ -93,36 +93,12 @@ RequestManager::RequestManager(
Request::set_call_log_format(call_log_format);
xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, message_size);
am.addListener(this);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * rm_action_loop(void *arg)
{
RequestManager * rm;
if ( arg == 0 )
{
return 0;
}
NebulaLog::log("ReM",Log::INFO,"Request Manager started.");
rm = static_cast<RequestManager *>(arg);
rm->am.loop();
NebulaLog::log("ReM",Log::INFO,"Request Manager stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/**
* Connection class is used to pass arguments to connection threads.
*/
@@ -320,7 +296,6 @@ int RequestManager::setup_socket()
int RequestManager::start()
{
pthread_attr_t pattr;
ostringstream oss;
NebulaLog::log("ReM",Log::INFO,"Starting Request Manager...");
@@ -334,13 +309,9 @@ int RequestManager::start()
register_xml_methods();
pthread_attr_init (&pattr);
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
pthread_create(&rm_thread,&pattr,rm_action_loop,(void *)this);
pthread_attr_init (&pattr);
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
pthread_attr_t pattr;
pthread_attr_init(&pattr);
pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE);
oss << "Starting XML-RPC server, port " << port << " ...";
NebulaLog::log("ReM",Log::INFO,oss);
@@ -1240,10 +1211,8 @@ void RequestManager::register_xml_methods()
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RequestManager::finalize_action(const ActionRequest& ar)
void RequestManager::finalize()
{
NebulaLog::log("ReM",Log::INFO,"Stopping Request Manager...");
pthread_cancel(rm_xml_server_thread);
pthread_join(rm_xml_server_thread,0);
+1
View File
@@ -16,6 +16,7 @@
#include "RequestManagerAcl.h"
#include "AclManager.h"
#include "AclRule.h"
using namespace std;
+1 -1
View File
@@ -67,7 +67,7 @@ void SecurityGroupCommit::request_execute(xmlrpc_c::paramList const& paramList,
sg->unlock();
lcm->trigger(LCMAction::UPDATESG, oid, att);
lcm->trigger_updatesg(oid);
success_response(oid, att);
+1
View File
@@ -17,6 +17,7 @@
#include "RequestManagerSystem.h"
#include "Nebula.h"
#include "LogDB.h"
#include "SSLUtil.h"
using namespace std;
+30 -45
View File
@@ -26,24 +26,31 @@
#include "VirtualMachinePoolXML.h"
#include "VirtualNetworkPoolXML.h"
#include "SchedulerPolicy.h"
#include "ActionManager.h"
#include "Listener.h"
#include "AclXML.h"
#include "MonitorXML.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * scheduler_action_loop(void *arg);
class SchedulerTemplate;
/**
* The Scheduler class. It represents the scheduler ...
*/
class Scheduler: public ActionListener
class Scheduler
{
public:
void start();
void finalize()
{
if (timer_thread.get())
{
timer_thread->stop();
}
}
virtual void register_policies(const SchedulerTemplate& conf){};
static Scheduler& instance(Scheduler* the_sched=0)
@@ -66,18 +73,6 @@ public:
protected:
Scheduler():
acls(0),
upool(0),
hpool(0),
clpool(0),
dspool(0),
img_dspool(0),
vmpool(0),
vm_roles_pool(0),
vnetpool(0),
vmgpool(0),
vmapool(0),
hmonpool(0),
timer(0),
one_xmlrpc(""),
machines_limit(0),
@@ -86,8 +81,7 @@ protected:
mem_ds_scale(0),
diff_vnets(false)
{
am.addListener(this);
};
}
virtual ~Scheduler()
{
@@ -107,30 +101,30 @@ protected:
delete vmgpool;
delete acls;
};
}
// ---------------------------------------------------------------
// Pools
// ---------------------------------------------------------------
AclXML * acls;
UserPoolXML * upool;
AclXML * acls = nullptr;
UserPoolXML * upool = nullptr;
HostPoolXML * hpool;
ClusterPoolXML * clpool;
HostPoolXML * hpool = nullptr;
ClusterPoolXML * clpool = nullptr;
SystemDatastorePoolXML * dspool;
ImageDatastorePoolXML * img_dspool;
SystemDatastorePoolXML * dspool = nullptr;
ImageDatastorePoolXML * img_dspool = nullptr;
VirtualMachinePoolXML * vmpool;
VirtualMachineRolePoolXML * vm_roles_pool;
VirtualMachinePoolXML * vmpool = nullptr;
VirtualMachineRolePoolXML * vm_roles_pool = nullptr;
VirtualNetworkPoolXML * vnetpool;
VirtualNetworkPoolXML * vnetpool = nullptr;
VMGroupPoolXML * vmgpool;
VMGroupPoolXML * vmgpool = nullptr;
VirtualMachineActionsPoolXML* vmapool;
VirtualMachineActionsPoolXML* vmapool = nullptr;
MonitorPoolXML * hmonpool;
MonitorPoolXML * hmonpool = nullptr;
// ---------------------------------------------------------------
// Scheduler Policies
@@ -183,11 +177,9 @@ protected:
virtual void do_vm_groups();
private:
Scheduler(Scheduler const&){};
Scheduler(Scheduler const&) = delete;
Scheduler& operator=(Scheduler const&){return *this;};
friend void * scheduler_action_loop(void *arg);
Scheduler& operator=(Scheduler const&) = delete;
// ---------------------------------------------------------------
// Scheduling Policies
@@ -239,24 +231,17 @@ private:
/**
* oned runtime configuration values
*/
Template oned_conf;
Template oned_conf;
// ---------------------------------------------------------------
// Timer to periodically schedule and dispatch VMs
// ---------------------------------------------------------------
pthread_t sched_thread;
ActionManager am;
std::unique_ptr<Timer> timer_thread;
// -------------------------------------------------------------------------
// Action Listener interface
// -------------------------------------------------------------------------
void timer_action(const ActionRequest& ar);
void finalize_action(const ActionRequest& ar)
{
NebulaLog::log("SCHED",Log::INFO,"Stopping the scheduler...");
};
void timer_action();
};
#endif /*SCHEDULER_H_*/
+1
View File
@@ -15,6 +15,7 @@
/* -------------------------------------------------------------------------- */
#include "AclXML.h"
#include "AclRule.h"
#include "ObjectXML.h"
#include <vector>
+3 -43
View File
@@ -77,33 +77,8 @@ static double profile(bool start, const string& message="")
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
extern "C" void * scheduler_action_loop(void *arg)
{
Scheduler * sched;
if ( arg == 0 )
{
return 0;
}
sched = static_cast<Scheduler *>(arg);
NebulaLog::log("SCHED",Log::INFO,"Scheduler loop started.");
sched->am.loop(sched->timer);
NebulaLog::log("SCHED",Log::INFO,"Scheduler loop stopped.");
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Scheduler::start()
{
int rc;
ifstream file;
ostringstream oss;
@@ -111,8 +86,6 @@ void Scheduler::start()
unsigned int live_rescheds;
pthread_attr_t pattr;
// -----------------------------------------------------------
// Configuration File
// -----------------------------------------------------------
@@ -375,18 +348,7 @@ void Scheduler::start()
NebulaLog::log("SCHED",Log::INFO,"Starting scheduler loop...");
pthread_attr_init (&pattr);
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
rc = pthread_create(&sched_thread,&pattr,scheduler_action_loop,(void *) this);
if ( rc != 0 )
{
NebulaLog::log("SCHED",Log::ERROR,
"Could not start scheduler loop, exiting");
return;
}
timer_thread.reset(new Timer(timer, [this](){timer_action();}));
// -----------------------------------------------------------
// Wait for a SIGTERM or SIGINT signal
@@ -399,9 +361,7 @@ void Scheduler::start()
sigwait(&mask, &signal);
am.finalize();
pthread_join(sched_thread,0);
finalize();
xmlCleanupParser();
@@ -1835,7 +1795,7 @@ void Scheduler::do_vm_groups()
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Scheduler::timer_action(const ActionRequest& ar)
void Scheduler::timer_action()
{
int rc;
+1 -1
View File
@@ -450,7 +450,7 @@ int SecurityGroup::post_update_template(string& error)
commit(false);
Nebula::instance().get_lcm()->trigger(LCMAction::UPDATESG, oid);
Nebula::instance().get_lcm()->trigger_updatesg(oid);
return 0;
}
+1 -1
View File
@@ -16,7 +16,7 @@
#include "LogDB.h"
#include "Nebula.h"
#include "NebulaUtil.h"
#include "SSLUtil.h"
#include "ZoneServer.h"
#include "Callbackable.h"
#include "RaftManager.h"
+1445 -1536
View File
File diff suppressed because it is too large. Load diff
+14 -18
View File
@@ -44,8 +44,6 @@ void TransferManager::_transfer(unique_ptr<transfer_msg_t> msg)
LifeCycleManager * lcm = Nebula::instance().get_lcm();
LCMAction::Actions lcm_action;
int id = msg->oid();
// Get the VM from the pool
@@ -77,28 +75,28 @@ void TransferManager::_transfer(unique_ptr<transfer_msg_t> msg)
case VirtualMachine::PROLOG_MIGRATE_POWEROFF:
case VirtualMachine::PROLOG_MIGRATE_SUSPEND:
case VirtualMachine::PROLOG_MIGRATE_UNKNOWN:
lcm_action = LCMAction::PROLOG_SUCCESS;
lcm->trigger_prolog_success(id);
break;
case VirtualMachine::EPILOG:
case VirtualMachine::EPILOG_STOP:
case VirtualMachine::EPILOG_UNDEPLOY:
case VirtualMachine::CLEANUP_RESUBMIT:
lcm_action = LCMAction::EPILOG_SUCCESS;
lcm->trigger_epilog_success(id);
break;
case VirtualMachine::HOTPLUG_SAVEAS:
case VirtualMachine::HOTPLUG_SAVEAS_POWEROFF:
case VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED:
lcm_action = LCMAction::SAVEAS_SUCCESS;
lcm->trigger_saveas_success(id);
break;
case VirtualMachine::HOTPLUG_PROLOG_POWEROFF:
lcm_action = LCMAction::ATTACH_SUCCESS;
lcm->trigger_attach_success(id);
break;
case VirtualMachine::HOTPLUG_EPILOG_POWEROFF:
lcm_action = LCMAction::DETACH_SUCCESS;
lcm->trigger_detach_success(id);
break;
case VirtualMachine::DISK_SNAPSHOT_POWEROFF:
@@ -108,12 +106,12 @@ void TransferManager::_transfer(unique_ptr<transfer_msg_t> msg)
case VirtualMachine::DISK_SNAPSHOT_REVERT_SUSPENDED:
case VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED:
case VirtualMachine::DISK_SNAPSHOT_DELETE:
lcm_action = LCMAction::DISK_SNAPSHOT_SUCCESS;
lcm->trigger_disk_snapshot_success(id);
break;
case VirtualMachine::DISK_RESIZE_POWEROFF:
case VirtualMachine::DISK_RESIZE_UNDEPLOYED:
lcm_action = LCMAction::DISK_RESIZE_SUCCESS;
lcm->trigger_disk_resize_success(id);
break;
default:
@@ -146,28 +144,28 @@ void TransferManager::_transfer(unique_ptr<transfer_msg_t> msg)
case VirtualMachine::PROLOG_MIGRATE_POWEROFF:
case VirtualMachine::PROLOG_MIGRATE_SUSPEND:
case VirtualMachine::PROLOG_MIGRATE_UNKNOWN:
lcm_action = LCMAction::PROLOG_FAILURE;
lcm->trigger_prolog_failure(id);
break;
case VirtualMachine::EPILOG:
case VirtualMachine::EPILOG_STOP:
case VirtualMachine::EPILOG_UNDEPLOY:
case VirtualMachine::CLEANUP_RESUBMIT:
lcm_action = LCMAction::EPILOG_FAILURE;
lcm->trigger_epilog_failure(id);
break;
case VirtualMachine::HOTPLUG_SAVEAS:
case VirtualMachine::HOTPLUG_SAVEAS_POWEROFF:
case VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED:
lcm_action = LCMAction::SAVEAS_FAILURE;
lcm->trigger_saveas_failure(id);
break;
case VirtualMachine::HOTPLUG_PROLOG_POWEROFF:
lcm_action = LCMAction::ATTACH_FAILURE;
lcm->trigger_attach_failure(id);
break;
case VirtualMachine::HOTPLUG_EPILOG_POWEROFF:
lcm_action = LCMAction::DETACH_FAILURE;
lcm->trigger_detach_failure(id);
break;
case VirtualMachine::DISK_SNAPSHOT_POWEROFF:
@@ -177,12 +175,12 @@ void TransferManager::_transfer(unique_ptr<transfer_msg_t> msg)
case VirtualMachine::DISK_SNAPSHOT_REVERT_SUSPENDED:
case VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED:
case VirtualMachine::DISK_SNAPSHOT_DELETE:
lcm_action = LCMAction::DISK_SNAPSHOT_FAILURE;
lcm->trigger_disk_snapshot_failure(id);
break;
case VirtualMachine::DISK_RESIZE_POWEROFF:
case VirtualMachine::DISK_RESIZE_UNDEPLOYED:
lcm_action = LCMAction::DISK_RESIZE_FAILURE;
lcm->trigger_disk_resize_failure(id);
break;
default:
@@ -190,8 +188,6 @@ void TransferManager::_transfer(unique_ptr<transfer_msg_t> msg)
}
}
lcm->trigger(lcm_action, id);
vm->unlock();
return;
+4 -4
View File
@@ -778,7 +778,7 @@ bool UserPool::authenticate_internal(User * user,
{
ar.add_authenticate(auth_driver,username,password,token);
authm->trigger(AMAction::AUTHENTICATE,&ar);
authm->trigger_authenticate(ar);
ar.wait();
@@ -1134,7 +1134,7 @@ bool UserPool::authenticate_server(User * user,
server_password,
second_token);
authm->trigger(AMAction::AUTHENTICATE,&ar);
authm->trigger_authenticate(ar);
ar.wait();
if (ar.result!=true) //User was not authenticated
@@ -1239,7 +1239,7 @@ bool UserPool::authenticate_external(const string& username,
ar.add_authenticate(default_auth, username,"-",token);
authm->trigger(AMAction::AUTHENTICATE, &ar);
authm->trigger_authenticate(ar);
ar.wait();
if (ar.result != true) //User was not authenticated
@@ -1416,7 +1416,7 @@ int UserPool::authorize(AuthRequest& ar)
}
else
{
authm->trigger(AMAction::AUTHORIZE,&ar);
authm->trigger_authorize(ar);
ar.wait();
if (ar.result==true)
+1
View File
@@ -17,6 +17,7 @@
#include "Vdc.h"
#include "Nebula.h"
#include "AclManager.h"
#include "AclRule.h"
using namespace std;
+1 -1
View File
@@ -1065,7 +1065,7 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
//-------------------------------------------------------------------------
if ( state == VirtualMachine::CLONING )
{
Nebula::instance().get_lcm()->trigger(LCMAction::DISK_LOCK_SUCCESS,oid);
Nebula::instance().get_lcm()->trigger_disk_lock_success(oid);
}
return 0;
+2 -2
View File
@@ -65,7 +65,7 @@ int VirtualMachinePool::update(PoolObjectSQL * objsql)
{
std::string event = HookStateVM::format_message(vm);
Nebula::instance().get_hm()->trigger(HMAction::SEND_EVENT, event);
Nebula::instance().get_hm()->trigger_send_event(event);
}
vm->set_prev_state();
@@ -203,7 +203,7 @@ int VirtualMachinePool::allocate(
{
std::string event = HookStateVM::format_message(vm);
Nebula::instance().get_hm()->trigger(HMAction::SEND_EVENT, event);
Nebula::instance().get_hm()->trigger_send_event(event);
vm->unlock();
}
File diff suppressed because it is too large. Load diff
+39 -41
View File
@@ -131,7 +131,7 @@ void VirtualMachineManager::_deploy(unique_ptr<vm_msg_t> msg)
return;
}
LCMAction::Actions action = LCMAction::DEPLOY_SUCCESS;
void (LifeCycleManager::*action)(int) = &LifeCycleManager::trigger_deploy_success;
if (msg->status() == "SUCCESS")
{
@@ -149,7 +149,7 @@ void VirtualMachineManager::_deploy(unique_ptr<vm_msg_t> msg)
}
else
{
action = LCMAction::DEPLOY_FAILURE;
action = &LifeCycleManager::trigger_deploy_failure;
log_error(vm, msg->payload(), "Empty deploy ID for virtual machine");
}
@@ -159,13 +159,13 @@ void VirtualMachineManager::_deploy(unique_ptr<vm_msg_t> msg)
}
else
{
action = LCMAction::DEPLOY_FAILURE;
action = &LifeCycleManager::trigger_deploy_failure;
log_error(id, msg->payload(), "Error deploying virtual machine");
}
LifeCycleManager * lcm = Nebula::instance().get_lcm();
lcm->trigger(action, msg->oid());
(lcm->*action)(msg->oid());
}
/* -------------------------------------------------------------------------- */
@@ -184,13 +184,13 @@ void VirtualMachineManager::_shutdown(unique_ptr<vm_msg_t> msg)
if (msg->status() == "SUCCESS")
{
lcm->trigger(LCMAction::SHUTDOWN_SUCCESS, id);
lcm->trigger_shutdown_success(id);
}
else
{
log_error(id, msg->payload(), "Error shutting down VM");
lcm->trigger(LCMAction::SHUTDOWN_FAILURE, msg->oid());
lcm->trigger_shutdown_failure(msg->oid());
}
}
@@ -262,13 +262,13 @@ void VirtualMachineManager::_cancel(unique_ptr<vm_msg_t> msg)
if (msg->status() == "SUCCESS")
{
lcm->trigger(LCMAction::CANCEL_SUCCESS, id);
lcm->trigger_shutdown_success(id);
}
else
{
log_error(msg->oid(), msg->payload(), "Error canceling VM");
lcm->trigger(LCMAction::CANCEL_FAILURE, id);
lcm->trigger_shutdown_failure(id);
}
}
@@ -293,15 +293,13 @@ void VirtualMachineManager::_cleanup(unique_ptr<vm_msg_t> msg)
vm->log("VMM", Log::INFO, "Host successfully cleaned.");
vm->unlock();
lcm->trigger(LCMAction::CLEANUP_SUCCESS, id);
}
else
{
log_error(id, msg->payload(), "Error cleaning Host");
lcm->trigger(LCMAction::CLEANUP_FAILURE, id);
}
lcm->trigger_cleanup_callback(id);
}
/* -------------------------------------------------------------------------- */
@@ -327,13 +325,13 @@ void VirtualMachineManager::_save(unique_ptr<vm_msg_t> msg)
if (msg->status() == "SUCCESS")
{
lcm->trigger(LCMAction::SAVE_SUCCESS, id);
lcm->trigger_save_success(id);
}
else
{
log_error(id, msg->payload(), "Error saving VM state");
lcm->trigger(LCMAction::SAVE_FAILURE, id);
lcm->trigger_save_failure(id);
}
}
@@ -353,13 +351,13 @@ void VirtualMachineManager::_restore(unique_ptr<vm_msg_t> msg)
if (msg->status() == "SUCCESS")
{
lcm->trigger(LCMAction::DEPLOY_SUCCESS, id);
lcm->trigger_deploy_success(id);
}
else
{
log_error(id, msg->payload(), "Error restoring VM");
lcm->trigger(LCMAction::DEPLOY_FAILURE, id);
lcm->trigger_deploy_failure(id);
}
}
@@ -379,13 +377,13 @@ void VirtualMachineManager::_migrate(unique_ptr<vm_msg_t> msg)
if (msg->status() == "SUCCESS")
{
lcm->trigger(LCMAction::DEPLOY_SUCCESS, id);
lcm->trigger_deploy_success(id);
}
else
{
log_error(msg->oid(), msg->payload(), "Error live migrating VM");
lcm->trigger(LCMAction::DEPLOY_FAILURE, id);
lcm->trigger_deploy_failure(id);
}
}
@@ -411,13 +409,13 @@ void VirtualMachineManager::_attachdisk(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::ATTACH_SUCCESS, id);
lcm->trigger_attach_success(id);
}
else
{
log_error(id, msg->payload(), "Error attaching new VM Disk");
lcm->trigger(LCMAction::ATTACH_FAILURE, id);
lcm->trigger_attach_failure(id);
}
}
@@ -443,13 +441,13 @@ void VirtualMachineManager::_detachdisk(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::DETACH_SUCCESS, id);
lcm->trigger_detach_success(id);
}
else
{
log_error(id, msg->payload(), "Error detaching VM Disk");
lcm->trigger(LCMAction::DETACH_FAILURE, id);
lcm->trigger_detach_failure(id);
}
}
@@ -475,13 +473,13 @@ void VirtualMachineManager::_attachnic(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::ATTACH_NIC_SUCCESS, id);
lcm->trigger_attach_nic_success(id);
}
else
{
log_error(id, msg->payload(), "Error attaching new VM NIC");
lcm->trigger(LCMAction::ATTACH_NIC_FAILURE, id);
lcm->trigger_attach_nic_failure(id);
}
}
@@ -507,13 +505,13 @@ void VirtualMachineManager::_detachnic(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::DETACH_NIC_SUCCESS, id);
lcm->trigger_detach_nic_success(id);
}
else
{
log_error(id, msg->payload(), "Error detaching VM NIC");
lcm->trigger(LCMAction::DETACH_NIC_FAILURE, id);
lcm->trigger_detach_nic_failure(id);
}
}
@@ -548,13 +546,13 @@ void VirtualMachineManager::_snapshotcreate(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::SNAPSHOT_CREATE_SUCCESS, id);
lcm->trigger_snapshot_create_success(id);
}
else
{
log_error(msg->oid(), msg->payload(), "Error creating new VM Snapshot");
lcm->trigger(LCMAction::SNAPSHOT_CREATE_FAILURE, id);
lcm->trigger_snapshot_create_failure(id);
}
}
@@ -580,13 +578,13 @@ void VirtualMachineManager::_snapshotrevert(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::SNAPSHOT_REVERT_SUCCESS, id);
lcm->trigger_snapshot_revert_success(id);
}
else
{
log_error(id, msg->payload(), "Error reverting VM Snapshot");
lcm->trigger(LCMAction::SNAPSHOT_REVERT_FAILURE, id);
lcm->trigger_snapshot_revert_failure(id);
}
}
@@ -612,13 +610,13 @@ void VirtualMachineManager::_snapshotdelete(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::SNAPSHOT_DELETE_SUCCESS, id);
lcm->trigger_snapshot_delete_success(id);
}
else
{
log_error(id, msg->payload(), "Error deleting VM Snapshot");
lcm->trigger(LCMAction::SNAPSHOT_DELETE_FAILURE, id);
lcm->trigger_snapshot_delete_failure(id);
}
}
@@ -644,13 +642,13 @@ void VirtualMachineManager::_disksnapshotcreate(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::DISK_SNAPSHOT_SUCCESS, id);
lcm->trigger_disk_snapshot_success(id);
}
else
{
log_error(id, msg->payload(), "Error creating new disk snapshot");
lcm->trigger(LCMAction::DISK_SNAPSHOT_FAILURE, id);
lcm->trigger_disk_snapshot_failure(id);
}
}
@@ -676,13 +674,13 @@ void VirtualMachineManager::_disksnapshotrevert(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::DISK_SNAPSHOT_SUCCESS, id);
lcm->trigger_disk_snapshot_success(id);
}
else
{
log_error(id, msg->payload(), "Error reverting disk snapshot");
lcm->trigger(LCMAction::DISK_SNAPSHOT_FAILURE, id);
lcm->trigger_disk_snapshot_failure(id);
}
}
@@ -708,13 +706,13 @@ void VirtualMachineManager::_resizedisk(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::DISK_RESIZE_SUCCESS, id);
lcm->trigger_disk_resize_success(id);
}
else
{
log_error(id, msg->payload(), "Error resizing disk");
lcm->trigger(LCMAction::DISK_RESIZE_FAILURE, id);
lcm->trigger_disk_resize_failure(id);
}
}
@@ -740,13 +738,13 @@ void VirtualMachineManager::_updateconf(unique_ptr<vm_msg_t> msg)
vm->unlock();
lcm->trigger(LCMAction::UPDATE_CONF_SUCCESS, id);
lcm->trigger_update_conf_success(id);
}
else
{
log_error(id, msg->payload(), "Error updating conf for VM");
lcm->trigger(LCMAction::UPDATE_CONF_FAILURE, id);
lcm->trigger_update_conf_failure(id);
}
}
@@ -816,7 +814,7 @@ void VirtualMachineManager::_updatesg(unique_ptr<vm_msg_t> msg)
vm->unlock();
}
lcm->trigger(LCMAction::UPDATESG, sgid);
lcm->trigger_updatesg(sgid);
return;
}
+4 -4
View File
@@ -30,7 +30,7 @@ int AddressRangeIPAM::from_vattr(VectorAttribute * attr, std::string& error_msg)
IPAMRequest ir(attr);
ipamm->trigger(IPMAction::REGISTER_ADDRESS_RANGE, &ir);
ipamm->trigger_register_address_range(ir);
ir.wait();
@@ -69,7 +69,7 @@ int AddressRangeIPAM::allocate_addr(unsigned int index, unsigned int rsize,
IPAMRequest ir(this, address_xml);
ipamm->trigger(IPMAction::ALLOCATE_ADDRESS, &ir);
ipamm->trigger_allocate_address(ir);
ir.wait();
@@ -103,7 +103,7 @@ int AddressRangeIPAM::get_addr(unsigned int& index, unsigned int rsize,
IPAMRequest ir(this, address_xml);
ipamm->trigger(IPMAction::GET_ADDRESS, &ir);
ipamm->trigger_get_address(ir);
ir.wait();
@@ -160,7 +160,7 @@ int AddressRangeIPAM::free_addr(unsigned int index, std::string& error_msg)
IPAMRequest ir(this, address_xml);
ipamm->trigger(IPMAction::FREE_ADDRESS, &ir);
ipamm->trigger_free_address(ir);
ir.wait();
+2 -2
View File
@@ -218,7 +218,7 @@ int AddressRangePool::rm_ar(unsigned int ar_id, bool force, string& error_msg)
IPAMRequest ir(ar_ptr);
ipamm->trigger(IPMAction::UNREGISTER_ADDRESS_RANGE, &ir);
ipamm->trigger_unregister_address_range(ir);
ir.wait();
@@ -256,7 +256,7 @@ int AddressRangePool::rm_ars(string& error_msg)
IPAMRequest ir(it->second->attr);
ipamm->trigger(IPMAction::UNREGISTER_ADDRESS_RANGE, &ir);
ipamm->trigger_unregister_address_range(ir);
ir.wait();