mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
F #4977: Move missing monitor map logic to monitor_action()
This commit is contained in:
parent
843446a113
commit
6368bb51fc
@ -73,13 +73,14 @@ public:
|
||||
* @param template to generate app with the from_template64 function
|
||||
* @param mp_id of the MarketPlace to store de App
|
||||
* @param mp_name of the MarketPlace
|
||||
* @param app_id of the imported app
|
||||
* @param error_str Returns the error reason, if any
|
||||
*
|
||||
* @return the oid assigned to the object, -1 in case of failure, -2
|
||||
* already imported
|
||||
*/
|
||||
int import(const std::string& t64, int mp_id, const std::string& mp_name,
|
||||
std::string& error_str);
|
||||
int& app_id, std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a MarketPlaceApp from the pool
|
||||
@ -147,43 +148,29 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Erease map element
|
||||
* Check an element into map
|
||||
* @param map_id of the app
|
||||
* @return true if the app has to be deleted
|
||||
*/
|
||||
void drop_map_check(const std::string& name){
|
||||
if (map_check.find( name ) != map_check.end()){
|
||||
map<std::string,int>::iterator it;
|
||||
it=map_check.find(name);
|
||||
map_check.erase (it);
|
||||
}
|
||||
}
|
||||
bool test_map_check(int map_id);
|
||||
|
||||
/**
|
||||
* Check an element into map
|
||||
* Resets the counter of missing monitors of an app
|
||||
* @param app_id of the app
|
||||
*/
|
||||
bool test_map_check(const std::string& name){
|
||||
map_check[name]++;
|
||||
if (map_check[name] > 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
map<std::string, int> map_check;
|
||||
void reset_map_check(int app_id);
|
||||
|
||||
|
||||
void insert_map_check(const std::string& name){
|
||||
map_check.insert(make_pair(name, -1));
|
||||
}
|
||||
void reset_map_check(const std::string& name){
|
||||
if (name != "") {
|
||||
if (map_check.find( name ) != map_check.end()){
|
||||
map_check[name] = -1;
|
||||
}
|
||||
else{
|
||||
insert_map_check(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
|
||||
/**
|
||||
* Hash to store the number of times an app was missing from monitor data
|
||||
*/
|
||||
map<int, int> map_check;
|
||||
|
||||
/**
|
||||
* Max number of monitor that an app may be missing before deleting it
|
||||
*/
|
||||
static const int MAX_MISSING_MONITORS;
|
||||
};
|
||||
|
||||
#endif /*MARKETPLACE_POOL_H_*/
|
||||
|
@ -128,11 +128,6 @@ int MarketPlaceAppPool:: allocate(
|
||||
|
||||
*oid = PoolSQL::allocate(mp, error_str);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Insert id into map_check
|
||||
// --------------------------------------------------------------------------
|
||||
insert_map_check(name);
|
||||
|
||||
return *oid;
|
||||
|
||||
error_duplicated:
|
||||
@ -188,8 +183,6 @@ int MarketPlaceAppPool::drop(PoolObjectSQL * objsql, std::string& error_msg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
drop_map_check(objsql->get_name());
|
||||
|
||||
return PoolSQL::drop(objsql, error_msg);
|
||||
}
|
||||
|
||||
@ -197,7 +190,7 @@ int MarketPlaceAppPool::drop(PoolObjectSQL * objsql, std::string& error_msg)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int MarketPlaceAppPool::import(const std::string& t64, int mp_id,
|
||||
const std::string& mp_name, std::string& error_str)
|
||||
const std::string& mp_name, int& app_id, std::string& error_str)
|
||||
{
|
||||
// -------------------------------------------------------------------------
|
||||
// Build the marketplace app object
|
||||
@ -236,7 +229,8 @@ int MarketPlaceAppPool::import(const std::string& t64, int mp_id,
|
||||
|
||||
if( mp_aux != 0 ) //Marketplace app already imported
|
||||
{
|
||||
reset_map_check(app->name);
|
||||
app_id = mp_aux->oid;
|
||||
|
||||
if ( mp_aux->version != app->version || mp_aux->md5 != app->md5 )
|
||||
{
|
||||
mp_aux->from_template64(t64, error_str);
|
||||
@ -256,15 +250,17 @@ int MarketPlaceAppPool::import(const std::string& t64, int mp_id,
|
||||
// -------------------------------------------------------------------------
|
||||
if (Nebula::instance().is_federation_slave())
|
||||
{
|
||||
int oid = master_allocate(app, error_str);
|
||||
app_id = master_allocate(app, error_str);
|
||||
|
||||
app->lock();
|
||||
delete app;
|
||||
|
||||
return oid;
|
||||
return app_id;
|
||||
}
|
||||
insert_map_check(app->name);
|
||||
return PoolSQL::allocate(app, error_str);
|
||||
|
||||
app_id = PoolSQL::allocate(app, error_str);
|
||||
|
||||
return app_id;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -316,4 +312,39 @@ int MarketPlaceAppPool::update(PoolObjectSQL * objsql)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
const int MarketPlaceAppPool::MAX_MISSING_MONITORS = 3;
|
||||
|
||||
bool MarketPlaceAppPool::test_map_check(int app_id)
|
||||
{
|
||||
map<int, int>::iterator it = map_check.find(app_id);
|
||||
|
||||
if ( it == map_check.end() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
it->second++;
|
||||
|
||||
bool to_delete = it->second >= MAX_MISSING_MONITORS;
|
||||
|
||||
if ( to_delete )
|
||||
{
|
||||
map_check.erase(it);
|
||||
}
|
||||
|
||||
return to_delete;
|
||||
}
|
||||
|
||||
void MarketPlaceAppPool::reset_map_check(int app_id)
|
||||
{
|
||||
map<int, int>::iterator it = map_check.find(app_id);
|
||||
|
||||
if ( it == map_check.end() )
|
||||
{
|
||||
map_check.insert(make_pair(app_id, -1));
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second = -1;
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,6 @@ static void monitor_action(
|
||||
return;
|
||||
}
|
||||
|
||||
std::string name;
|
||||
MarketPlace * market = marketpool->get(id, true);
|
||||
|
||||
if (market == 0 )
|
||||
@ -128,7 +127,8 @@ static void monitor_action(
|
||||
return;
|
||||
}
|
||||
|
||||
name = market->get_name();
|
||||
set<int> apps_mp = market->get_marketapp_ids();
|
||||
std::string name = market->get_name();
|
||||
|
||||
market->update_monitor(monitor_data);
|
||||
|
||||
@ -143,7 +143,8 @@ static void monitor_action(
|
||||
|
||||
for (int i=0; i< num ; i++)
|
||||
{
|
||||
int rc = apppool->import(apps[i]->value(), id, name, err);
|
||||
int app_id;
|
||||
int rc = apppool->import(apps[i]->value(), id, name, app_id, err);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
@ -162,37 +163,37 @@ static void monitor_action(
|
||||
market->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
apppool->reset_map_check(app_id);
|
||||
|
||||
apps_mp.erase(app_id);
|
||||
}
|
||||
MarketPlaceApp *mp_app = nullptr;
|
||||
std::string error;
|
||||
std::string source;
|
||||
int rc_del;
|
||||
market = marketpool->get(id, true);
|
||||
set<int> apps_mp = market->get_marketapp_ids();
|
||||
market->unlock();
|
||||
|
||||
for (set<int>::iterator i = apps_mp.begin(); i != apps_mp.end(); i++) {
|
||||
mp_app = apppool->get(*i, true);
|
||||
if ( mp_app != 0 )
|
||||
{
|
||||
if(apppool->test_map_check(mp_app->get_name())){ //delete app
|
||||
market = marketpool->get(id, true);
|
||||
for (set<int>::iterator i = apps_mp.begin(); i != apps_mp.end(); ++i)
|
||||
{
|
||||
if (apppool->test_map_check(*i)) //delete app
|
||||
{
|
||||
std::string error;
|
||||
|
||||
source = mp_app->get_source();
|
||||
rc_del = apppool->drop(mp_app, error);
|
||||
MarketPlaceApp * app = apppool->get(*i, true);
|
||||
|
||||
market->del_marketapp(*i);
|
||||
marketpool->update(market);
|
||||
|
||||
market->unlock();
|
||||
if ( rc_del < 0 )
|
||||
{
|
||||
oss << " Error removing app from DB: " << error
|
||||
<< ". Remove app manually, source is: " << source;
|
||||
}
|
||||
if ( app == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = apppool->drop(app, error);
|
||||
|
||||
app->unlock();
|
||||
|
||||
market = marketpool->get(id, true);
|
||||
|
||||
market->del_marketapp(*i);
|
||||
|
||||
marketpool->update(market);
|
||||
|
||||
market->unlock();
|
||||
}
|
||||
mp_app->unlock();
|
||||
}
|
||||
|
||||
oss << "Marketplace " << name << " (" << id << ") successfully monitored.";
|
||||
|
Loading…
Reference in New Issue
Block a user