diff --git a/include/ActionSet.h b/include/ActionSet.h index 585f455aee..a8c73ad24f 100644 --- a/include/ActionSet.h +++ b/include/ActionSet.h @@ -42,7 +42,12 @@ public: /* Set the action in the set */ void set(T action) { - action_set += 1 << static_cast(action); + action_set |= 1 << static_cast(action); + }; + + void clear(T action) + { + action_set &= (~ (1 << static_cast(action))); }; /** diff --git a/include/MarketPlace.h b/include/MarketPlace.h index 55ea95d723..f66c837b42 100644 --- a/include/MarketPlace.h +++ b/include/MarketPlace.h @@ -106,8 +106,31 @@ public: return supported_actions.is_set(action); } + /** + * @return true if this is a public (external) marketplace + */ bool is_public() const; + /** + * Disbale de monitor action for this marketplace + * @return true if the monitor was enabled + */ + bool disable_monitor() + { + bool enabled = supported_actions.is_set(MarketPlaceApp::MONITOR); + + supported_actions.clear(MarketPlaceApp::MONITOR); + + return enabled; + } + /** + * Enable the monitor action + */ + void enable_monitor() + { + supported_actions.set(MarketPlaceApp::MONITOR); + } + private: friend class MarketPlacePool; diff --git a/src/market/MarketPlaceAppPool.cc b/src/market/MarketPlaceAppPool.cc index 28184a9489..52c959ccc5 100644 --- a/src/market/MarketPlaceAppPool.cc +++ b/src/market/MarketPlaceAppPool.cc @@ -161,7 +161,6 @@ int MarketPlaceAppPool::drop(PoolObjectSQL * objsql, std::string& error_msg) std::ostringstream oss("Cannot drop marketapp at federation master: ", std::ios::ate); - try { client->call(client->get_endpoint(), diff --git a/src/market/MarketPlacePool.cc b/src/market/MarketPlacePool.cc index 7c34392fe6..52bbda4345 100644 --- a/src/market/MarketPlacePool.cc +++ b/src/market/MarketPlacePool.cc @@ -211,20 +211,6 @@ int MarketPlacePool::drop(PoolObjectSQL * objsql, std::string& error_msg) return -1; } - MarketPlace *mp = static_cast(objsql); - - if( !mp->is_public() && mp->marketapps.size() > 0 ) - { - std::ostringstream oss; - - oss << "MarketPlace " << mp->get_oid() << " is not empty."; - error_msg = oss.str(); - - NebulaLog::log("MARKETPLACE", Log::ERROR, error_msg); - - return -3; - } - return PoolSQL::drop(objsql, error_msg); } diff --git a/src/rm/RequestManagerDelete.cc b/src/rm/RequestManagerDelete.cc index b70bce68a9..519b2150fb 100644 --- a/src/rm/RequestManagerDelete.cc +++ b/src/rm/RequestManagerDelete.cc @@ -576,18 +576,30 @@ int MarketPlaceAppDelete::drop(int oid, PoolObjectSQL * object, string& emsg) int MarketPlaceDelete::drop(int oid, PoolObjectSQL * object, string& emsg) { - MarketPlace * mp = static_cast(object); - set apps = mp->get_marketapp_ids(); + MarketPlace * mp = static_cast(object); + std::set apps = mp->get_marketapp_ids(); + bool can_del = mp->is_public() || apps.empty(); + int mp_id = mp->get_oid(); - int rc = pool->drop(object, emsg); - - object->unlock(); - - if ( rc != 0 || apps.empty() ) + if( !can_del ) { - return rc; + std::ostringstream oss; + + oss << object_name(PoolObjectSQL::MARKETPLACE) << " " + << mp->get_oid() << " is not empty."; + emsg = oss.str(); + + mp->unlock(); + + return -1; } + bool old_monitor = mp->disable_monitor(); + + mp->unlock(); + + int rc = 0; + Nebula& nd = Nebula::instance(); MarketPlaceApp * app; @@ -619,6 +631,28 @@ int MarketPlaceDelete::drop(int oid, PoolObjectSQL * object, string& emsg) app->unlock(); } + MarketPlacePool* mppool = static_cast(pool); + + mp = mppool->get(mp_id, true); + + if (mp == 0) + { + emsg = "MarketPlace no longer exists"; + + return -1; + } + + if ( rc == 0 ) + { + mppool->drop(mp, emsg); + } + else if (old_monitor) + { + mp->enable_monitor(); + } + + mp->unlock(); + return rc; }