From a4cf0cc387a099687fbc0eef4e79d418dac35cb6 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 11 Dec 2015 15:53:19 +0100 Subject: [PATCH] feautre #4217: API, OCA and command line tools for marketplace apps. Fix minor bugs --- include/MarketPlaceApp.h | 40 +++++++++++++++++++--- include/MarketPlaceAppPool.h | 3 -- include/MarketPlacePool.h | 4 +-- include/Nebula.h | 19 ++++++++--- include/RequestManagerAllocate.h | 38 ++++++++++++++++++++- include/RequestManagerChmod.h | 21 +++++++++++- include/RequestManagerChown.h | 25 +++++++++++++- include/RequestManagerDelete.h | 19 ++++++++++- include/RequestManagerInfo.h | 21 ++++++++++-- include/RequestManagerPoolInfoFilter.h | 23 +++++++++++-- include/RequestManagerRename.h | 28 ++++++++++++++-- include/RequestManagerUpdateTemplate.h | 23 +++++++++++-- install.sh | 9 ++++- src/cli/etc/onemarket.yaml | 4 +-- src/cli/one_helper/onemarket_helper.rb | 6 ++-- src/market/MarketPlaceApp.cc | 45 ++++++++++++++----------- src/market/MarketPlaceAppPool.cc | 9 +++-- src/nebula/Nebula.cc | 5 ++- src/oca/ruby/opennebula.rb | 2 ++ src/oca/ruby/opennebula/image_pool.rb | 1 - src/oca/ruby/opennebula/marketplace.rb | 13 +++----- src/rm/Request.cc | 2 ++ src/rm/RequestManager.cc | 46 ++++++++++++++++++++++++++ src/rm/RequestManagerAllocate.cc | 46 ++++++++++++++++++++++++++ src/rm/RequestManagerRename.cc | 38 +++++++++++++++++++++ 25 files changed, 421 insertions(+), 69 deletions(-) diff --git a/include/MarketPlaceApp.h b/include/MarketPlaceApp.h index 92ba1ff6cc..720353a811 100644 --- a/include/MarketPlaceApp.h +++ b/include/MarketPlaceApp.h @@ -69,6 +69,30 @@ public: */ int from_xml(const std::string &xml_str); + /** + * Returns the marketplace ID + */ + int get_market_id() const + { + return market_id; + }; + + /** + * Returns the marketplace name + */ + const std::string& get_market_name() const + { + return market_name; + }; + + /** + * Updates the marketplace name + */ + void set_market_name(const std::string& name) + { + market_name = name; + }; + private: friend class MarketPlaceAppPool; @@ -77,9 +101,9 @@ private: // MarketPlaceApp Attributes // ************************************************************************* /** - * Size of this app + * Publishing date */ - std::string date; + time_t date; /** * Source URL for the marketplace app @@ -119,12 +143,12 @@ private: /** * Marketplace ID that holds this app */ - int mp_id; + int market_id; /** * Marketplace name */ - std::string mp_name; + std::string market_name; /** * Marketplace App state @@ -204,6 +228,14 @@ private: * @return 0 on success */ int post_update_template(std::string& error); + + /** + * Factory method for marketplace app templates + */ + Template * get_new_template() const + { + return new MarketPlaceAppTemplate; + } }; #endif /*MARKETPLACEAPP_H*/ diff --git a/include/MarketPlaceAppPool.h b/include/MarketPlaceAppPool.h index 4eb859de94..6a2a0e6640 100644 --- a/include/MarketPlaceAppPool.h +++ b/include/MarketPlaceAppPool.h @@ -42,8 +42,6 @@ public: * @param apptemplate MarketPlaceApp definition template * @param mp_id of the MarketPlace to store de App * @param mp_name of the MarketPlace - * @param origin an opaque string with the origin of the App. Used by - * the MARKET_MAD. * @param oid the id assigned to the MarketPlace * @param error_str Returns the error reason, if any * @@ -58,7 +56,6 @@ public: MarketPlaceAppTemplate * apptemplate, int mp_id, const std::string& mp_name, - const std::string& origin, int * oid, std::string& error_str); diff --git a/include/MarketPlacePool.h b/include/MarketPlacePool.h index c95a4a39a7..9b21829800 100644 --- a/include/MarketPlacePool.h +++ b/include/MarketPlacePool.h @@ -95,8 +95,8 @@ public: return name; }; - /** Update a particular MarketPlaceApp - * @param zone pointer to Zone + /** Update a particular MarketPlace + * @param objsql points to the market * @return 0 on success */ int update(PoolObjectSQL * objsql); diff --git a/include/Nebula.h b/include/Nebula.h index ad2bb79da2..7ca5724ada 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -36,6 +36,7 @@ #include "VdcPool.h" #include "VirtualRouterPool.h" #include "MarketPlacePool.h" +#include "MarketPlaceAppPool.h" #include "VirtualMachineManager.h" #include "LifeCycleManager.h" @@ -143,10 +144,16 @@ public: return vrouterpool; }; - MarketPlacePool * get_mppool() + MarketPlacePool * get_marketpool() { - return mppool; + return marketpool; }; + + MarketPlaceAppPool * get_apppool() + { + return apppool; + }; + // -------------------------------------------------------------- // Manager Accessors // -------------------------------------------------------------- @@ -669,7 +676,7 @@ private: system_db(0), db(0), vmpool(0), hpool(0), vnpool(0), upool(0), ipool(0), gpool(0), tpool(0), dspool(0), clpool(0), docpool(0), zonepool(0), - secgrouppool(0), vdcpool(0), vrouterpool(0), mppool(0), + secgrouppool(0), vdcpool(0), vrouterpool(0), marketpool(0), apppool(0), lcm(0), vmm(0), im(0), tm(0), dm(0), rm(0), hm(0), authm(0), aclm(0), imagem(0) { @@ -720,7 +727,8 @@ private: delete secgrouppool; delete vdcpool; delete vrouterpool; - delete mppool; + delete marketpool; + delete apppool; delete vmm; delete lcm; delete im; @@ -801,7 +809,8 @@ private: SecurityGroupPool * secgrouppool; VdcPool * vdcpool; VirtualRouterPool * vrouterpool; - MarketPlacePool * mppool; + MarketPlacePool * marketpool; + MarketPlaceAppPool * apppool; // --------------------------------------------------------------- // Nebula Managers diff --git a/include/RequestManagerAllocate.h b/include/RequestManagerAllocate.h index bdc0c7f001..08aced6a80 100644 --- a/include/RequestManagerAllocate.h +++ b/include/RequestManagerAllocate.h @@ -631,7 +631,7 @@ public: true) { Nebula& nd = Nebula::instance(); - pool = nd.get_mppool(); + pool = nd.get_marketpool(); auth_object = PoolObjectSQL::MARKETPLACE; }; @@ -651,6 +651,42 @@ public: RequestAttributes& att); }; +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class MarketPlaceAppAllocate : public RequestManagerAllocate +{ +public: + MarketPlaceAppAllocate(): + RequestManagerAllocate("MarketPlaceAppAllocate", + "Allocates a new marketplace app", + "A:ssi", + true) + { + Nebula& nd = Nebula::instance(); + pool = nd.get_apppool(); + mppool = nd.get_marketpool(); + auth_object = PoolObjectSQL::MARKETPLACEAPP; + }; + + ~MarketPlaceAppAllocate(){}; + + /* --------------------------------------------------------------------- */ + + Template * get_object_template() + { + return new MarketPlaceAppTemplate; + }; + + int pool_allocate(xmlrpc_c::paramList const& _paramList, + Template * tmpl, + int& id, + string& error_str, + RequestAttributes& att); +private: + MarketPlacePool * mppool; +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/RequestManagerChmod.h b/include/RequestManagerChmod.h index 5aa0c874d9..a48474a7da 100644 --- a/include/RequestManagerChmod.h +++ b/include/RequestManagerChmod.h @@ -200,7 +200,7 @@ public: "Changes permission bits of a marketplace") { Nebula& nd = Nebula::instance(); - pool = nd.get_mppool(); + pool = nd.get_marketpool(); auth_object = PoolObjectSQL::MARKETPLACE; }; @@ -208,6 +208,25 @@ public: }; +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class MarketPlaceAppChmod: public RequestManagerChmod +{ +public: + MarketPlaceAppChmod(): + RequestManagerChmod("MarketPlaceAppChmod", + "Changes permission bits of a marketplace app") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_apppool(); + auth_object = PoolObjectSQL::MARKETPLACEAPP; + }; + + ~MarketPlaceAppChmod(){}; + +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/RequestManagerChown.h b/include/RequestManagerChown.h index e6944626f5..4f069cab93 100644 --- a/include/RequestManagerChown.h +++ b/include/RequestManagerChown.h @@ -303,7 +303,7 @@ public: "Changes ownership of a marketplace") { Nebula& nd = Nebula::instance(); - pool = nd.get_mppool(); + pool = nd.get_marketpool(); auth_object = PoolObjectSQL::MARKETPLACE; }; @@ -315,6 +315,29 @@ public: }; }; +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class MarketPlaceAppChown: public RequestManagerChown +{ +public: + MarketPlaceAppChown(): + RequestManagerChown("MarketPlaceAppChown", + "Changes ownership of a marketplace app") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_apppool(); + auth_object = PoolObjectSQL::MARKETPLACEAPP; + }; + + ~MarketPlaceAppChown(){}; + + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return static_cast(pool)->get(name, uid, lock); + }; +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/RequestManagerDelete.h b/include/RequestManagerDelete.h index 4cdbab0061..ea560d553e 100644 --- a/include/RequestManagerDelete.h +++ b/include/RequestManagerDelete.h @@ -383,13 +383,30 @@ public: "Deletes a marketplace") { Nebula& nd = Nebula::instance(); - pool = nd.get_mppool(); + pool = nd.get_marketpool(); auth_object = PoolObjectSQL::MARKETPLACE; }; ~MarketPlaceDelete(){}; }; +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class MarketPlaceAppDelete : public RequestManagerDelete +{ +public: + MarketPlaceAppDelete(): + RequestManagerDelete("MarketPlaceAppDelete", + "Deletes a marketplace app") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_apppool(); + auth_object = PoolObjectSQL::MARKETPLACEAPP; + }; + + ~MarketPlaceAppDelete(){}; +}; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/RequestManagerInfo.h b/include/RequestManagerInfo.h index 50399a5c06..d50b5cf7b7 100644 --- a/include/RequestManagerInfo.h +++ b/include/RequestManagerInfo.h @@ -344,16 +344,33 @@ class MarketPlaceInfo : public RequestManagerInfo public: MarketPlaceInfo(): RequestManagerInfo("MarketPlaceInfo", - "Returns MarketPlace information") + "Returns marketplace information") { Nebula& nd = Nebula::instance(); - pool = nd.get_mppool(); + pool = nd.get_marketpool(); auth_object = PoolObjectSQL::MARKETPLACE; }; ~MarketPlaceInfo(){}; }; +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class MarketPlaceAppInfo : public RequestManagerInfo +{ +public: + MarketPlaceAppInfo(): + RequestManagerInfo("MarketPlaceAppInfo", + "Returns marketplace app information") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_apppool(); + auth_object = PoolObjectSQL::MARKETPLACEAPP; + }; + + ~MarketPlaceAppInfo(){}; +}; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/RequestManagerPoolInfoFilter.h b/include/RequestManagerPoolInfoFilter.h index 43b7908e44..c0ac51a9f5 100644 --- a/include/RequestManagerPoolInfoFilter.h +++ b/include/RequestManagerPoolInfoFilter.h @@ -518,11 +518,11 @@ class MarketPlacePoolInfo : public RequestManagerPoolInfoFilter public: MarketPlacePoolInfo(): RequestManagerPoolInfoFilter("MarketPlacePoolInfo", - "Returns the market place pool", + "Returns the marketplace pool", "A:s") { Nebula& nd = Nebula::instance(); - pool = nd.get_mppool(); + pool = nd.get_marketpool(); auth_object = PoolObjectSQL::MARKETPLACE; }; @@ -531,4 +531,23 @@ public: void request_execute(xmlrpc_c::paramList const& pl, RequestAttributes& att); }; +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +class MarketPlaceAppPoolInfo : public RequestManagerPoolInfoFilter +{ +public: + MarketPlaceAppPoolInfo(): + RequestManagerPoolInfoFilter("MarketPlacePoolInfo", + "Returns the market place pool", + "A:siii") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_apppool(); + auth_object = PoolObjectSQL::MARKETPLACEAPP; + }; + + ~MarketPlaceAppPoolInfo(){}; +}; + #endif diff --git a/include/RequestManagerRename.h b/include/RequestManagerRename.h index 4a5113a5d4..e726589d73 100644 --- a/include/RequestManagerRename.h +++ b/include/RequestManagerRename.h @@ -366,7 +366,7 @@ public: RequestManagerRename("MarketPlaceRename", "Renames a marketplace") { Nebula& nd = Nebula::instance(); - pool = nd.get_mppool(); + pool = nd.get_marketpool(); auth_object = PoolObjectSQL::MARKETPLACE; }; @@ -377,9 +377,31 @@ public: return static_cast(pool)->get(name, lock); }; - //TODO implement batch rename for MarketPlaceApps - //void batch_rename(int oid); + void batch_rename(int oid); }; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class MarketPlaceAppRename: public RequestManagerRename +{ +public: + MarketPlaceAppRename(): + RequestManagerRename("MarketPlaceRename", "Renames a marketplace app") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_apppool(); + auth_object = PoolObjectSQL::MARKETPLACEAPP; + }; + + ~MarketPlaceAppRename(){}; + + PoolObjectSQL * get(const string& name, int uid, bool lock) + { + return static_cast(pool)->get(name, uid, lock); + }; +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/RequestManagerUpdateTemplate.h b/include/RequestManagerUpdateTemplate.h index 3f281575b4..c3f0bf9085 100644 --- a/include/RequestManagerUpdateTemplate.h +++ b/include/RequestManagerUpdateTemplate.h @@ -312,15 +312,34 @@ class MarketPlaceUpdateTemplate : public RequestManagerUpdateTemplate public: MarketPlaceUpdateTemplate(): RequestManagerUpdateTemplate("MarketPlaceUpdateTemplate", - "Updates a virtual router template") + "Updates a marketplace template") { Nebula& nd = Nebula::instance(); - pool = nd.get_mppool(); + pool = nd.get_marketpool(); auth_object = PoolObjectSQL::MARKETPLACE; }; ~MarketPlaceUpdateTemplate(){}; }; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + +class MarketPlaceAppUpdateTemplate : public RequestManagerUpdateTemplate +{ +public: + MarketPlaceAppUpdateTemplate(): + RequestManagerUpdateTemplate("MarketPlaceUpdateTemplate", + "Updates a marketplace app template") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_apppool(); + auth_object = PoolObjectSQL::MARKETPLACEAPP; + }; + + ~MarketPlaceAppUpdateTemplate(){}; +}; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/install.sh b/install.sh index 715f8a7641..d5e6141842 100755 --- a/install.sh +++ b/install.sh @@ -586,6 +586,7 @@ BIN_FILES="src/nebula/oned \ src/cli/onevdc \ src/cli/onevrouter \ src/cli/onemarket \ + src/cli/onemarketapp \ src/cli/onevcenter \ src/onedb/onedb \ src/mad/utils/tty_expect \ @@ -1382,7 +1383,9 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/opennebula/acl_pool.rb \ src/oca/ruby/opennebula/virtual_router_pool.rb \ src/oca/ruby/opennebula/virtual_router.rb \ src/oca/ruby/opennebula/marketplace_pool.rb \ - src/oca/ruby/opennebula/marketplace.rb" + src/oca/ruby/opennebula/marketplace.rb \ + src/oca/ruby/opennebula/marketplaceapp_pool.rb \ + src/oca/ruby/opennebula/marketplaceapp.rb" #------------------------------------------------------------------------------- # Common Cloud Files @@ -1534,6 +1537,7 @@ ONE_CLI_LIB_FILES="src/cli/one_helper/onegroup_helper.rb \ src/cli/one_helper/oneacct_helper.rb \ src/cli/one_helper/onesecgroup_helper.rb \ src/cli/one_helper/onevrouter_helper.rb \ + src/cli/one_helper/onemarketapp_helper.rb \ src/cli/one_helper/onemarket_helper.rb" CLI_BIN_FILES="src/cli/onevm \ @@ -1554,6 +1558,7 @@ CLI_BIN_FILES="src/cli/onevm \ src/cli/oneshowback \ src/cli/onevdc \ src/cli/onevrouter \ + src/cli/onemarketapp \ src/cli/onemarket" CLI_CONF_FILES="src/cli/etc/onegroup.yaml \ @@ -1572,6 +1577,7 @@ CLI_CONF_FILES="src/cli/etc/onegroup.yaml \ src/cli/etc/oneshowback.yaml \ src/cli/etc/onevdc.yaml \ src/cli/etc/onevrouter.yaml \ + src/cli/etc/onemarketapp.yaml \ src/cli/etc/onemarket.yaml" #----------------------------------------------------------------------------- @@ -1846,6 +1852,7 @@ MAN_FILES="share/man/oneacct.1.gz \ share/man/onevdc.1.gz \ share/man/onevrouter.1.gz \ share/man/onemarket.1.gz \ + share/man/onemarketapp.1.gz \ share/man/econe-allocate-address.1.gz \ share/man/econe-associate-address.1.gz \ share/man/econe-attach-volume.1.gz \ diff --git a/src/cli/etc/onemarket.yaml b/src/cli/etc/onemarket.yaml index 43cfb67b8b..b57e69f7dc 100644 --- a/src/cli/etc/onemarket.yaml +++ b/src/cli/etc/onemarket.yaml @@ -17,7 +17,7 @@ :size: 5 :left: true -:MARKETAPPS: +:APPS: :desc: Number of Marketplace Apps :size: 6 @@ -36,6 +36,6 @@ - :NAME - :SIZE - :AVAIL -- :MARKETAPPS +- :APPS - :TYPE - :MAD diff --git a/src/cli/one_helper/onemarket_helper.rb b/src/cli/one_helper/onemarket_helper.rb index aca83be377..328e943cfa 100644 --- a/src/cli/one_helper/onemarket_helper.rb +++ b/src/cli/one_helper/onemarket_helper.rb @@ -17,7 +17,7 @@ require 'one_helper' class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper - DATASTORE = { + MARKETPLACE = { :name => "marketplace", :short => "-m id|name", :large => "--marketplace id|name" , @@ -60,7 +60,7 @@ class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper end end - column :MARKETAPPS, "Number of marketplace apps", :size=>6 do |d| + column :APPS, "Number of marketplace apps", :size=>6 do |d| if d["MARKETPLACEAPPS"]["ID"].nil? "0" else @@ -77,7 +77,7 @@ class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper d["MARKET_MAD"] end - default :ID, :NAME, :SIZE, :AVAIL, :MARKETAPPS, :TYPE, :MAD + default :ID, :NAME, :SIZE, :AVAIL, :APPS, :TYPE, :MAD end table diff --git a/src/market/MarketPlaceApp.cc b/src/market/MarketPlaceApp.cc index a2e163386a..279dfa6321 100644 --- a/src/market/MarketPlaceApp.cc +++ b/src/market/MarketPlaceApp.cc @@ -52,8 +52,8 @@ MarketPlaceApp::MarketPlaceApp( publisher(""), version(""), apptemplate64(""), - mp_id(-1), - mp_name(""), + market_id(-1), + market_name(""), state(INIT) { if (app_template != 0) @@ -81,11 +81,6 @@ int MarketPlaceApp::insert(SqlDB *db, string& error_str) { std::ostringstream oss; - std::string attr; - - char str[26]; - time_t the_time = time(NULL); - // ------------------------------------------------------------------------- // Check default marketplace app attributes // ------------------------------------------------------------------------- @@ -94,36 +89,41 @@ int MarketPlaceApp::insert(SqlDB *db, string& error_str) erase_template_attribute("NAME", name); //Atrributes updated after export - remove_template_attribute("ORIGIN"); remove_template_attribute("SOURCE"); remove_template_attribute("SIZE"); remove_template_attribute("CHECKSUM"); - ctime_r(&(the_time), str); - date = str; + date = time(NULL); //Known attributes + //ORIGIN //DESCRIPTION //APPTEMPLATE64 //PUBLISHER //VERSION + erase_template_attribute("ORIGIN", origin); + + if (origin.empty()) + { + goto error_origin; + } get_template_attribute("DESCRIPTION", description); get_template_attribute("APPTEMPLATE64", apptemplate64); - get_template_attribute("PUBLISHER", attr); + get_template_attribute("PUBLISHER", publisher); - if (attr.empty()) + if (publisher.empty()) { publisher = uname; } - get_template_attribute("VERSION", attr); + get_template_attribute("VERSION", version); - if (!attr.empty()) + if (version.empty()) { - version = attr; + version = "0.0"; } state = LOCKED; @@ -131,6 +131,11 @@ int MarketPlaceApp::insert(SqlDB *db, string& error_str) //-------------------------------------------------------------------------- return insert_replace(db, false, error_str); + +error_origin: + error_str = "Missing ORIGIN for the MARKETPLACEAPP"; + NebulaLog::log("MRK", Log::ERROR, error_str); + return -1; } /* --------------------------------------------------------------------------- */ @@ -241,8 +246,8 @@ std::string& MarketPlaceApp::to_xml(std::string& xml) const "" << publisher << "" << "" << version << "" << "" << apptemplate64 << "" << - "" << mp_id << "" << - "" << mp_name << "" << + "" << market_id << "" << + "" << market_name << "" << "" << state << "" << perms_to_xml(perm_str) << obj_template->to_xml(template_xml) << @@ -272,7 +277,7 @@ int MarketPlaceApp::from_xml(const std::string &xml_str) rc += xpath(uname, "/MARKETPLACEAPP/UNAME", "not_found"); rc += xpath(gname, "/MARKETPLACEAPP/GNAME", "not_found"); rc += xpath(name, "/MARKETPLACEAPP/NAME", "not_found"); - rc += xpath(date, "/MARKETPLACEAPP/DATE", "not_found"); + rc += xpath(date, "/MARKETPLACEAPP/DATE", -1); rc += xpath(source, "/MARKETPLACEAPP/SOURCE","not_found"); rc += xpath(origin, "/MARKETPLACEAPP/ORIGIN","not_found"); rc += xpath(istate, "/MARKETPLACEAPP/STATE", -1); @@ -282,8 +287,8 @@ int MarketPlaceApp::from_xml(const std::string &xml_str) rc += xpath(checksum, "/MARKETPLACEAPP/CHECKSUM", "not_found"); rc += xpath(publisher, "/MARKETPLACEAPP/PUBLISHER", "not_found"); rc += xpath(apptemplate64,"/MARKETPLACEAPP/APPTEMPLATE64", "not_found"); - rc += xpath(mp_name, "/MARKETPLACEAPP/MARKETPLACE", "not_found"); - rc += xpath(mp_id, "/MARKETPLACEAPP/MARKETPLACE_ID", -1); + rc += xpath(market_name, "/MARKETPLACEAPP/MARKETPLACE", "not_found"); + rc += xpath(market_id, "/MARKETPLACEAPP/MARKETPLACE_ID", -1); state = static_cast(istate); diff --git a/src/market/MarketPlaceAppPool.cc b/src/market/MarketPlaceAppPool.cc index 4b798c576d..12fee4a354 100644 --- a/src/market/MarketPlaceAppPool.cc +++ b/src/market/MarketPlaceAppPool.cc @@ -29,7 +29,6 @@ int MarketPlaceAppPool:: allocate( MarketPlaceAppTemplate * apptemplate, int mp_id, const std::string& mp_name, - const std::string& origin, int * oid, std::string& error_str) { @@ -42,10 +41,10 @@ int MarketPlaceAppPool:: allocate( mp = new MarketPlaceApp(uid, gid, uname, gname, umask, apptemplate); - mp->mp_id = mp_id; - mp->mp_name = mp_name; - mp->state = MarketPlaceApp::INIT; - mp->origin = origin; + mp->market_id = mp_id; + mp->market_name = mp_name; + + mp->state = MarketPlaceApp::INIT; // ------------------------------------------------------------------------- // Check name & duplicates diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 465ec65bec..a69c4dd312 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -348,6 +348,7 @@ void Nebula::start(bool bootstrap_only) rc += SecurityGroupPool::bootstrap(db); rc += VirtualRouterPool::bootstrap(db); rc += MarketPlacePool::bootstrap(db); + rc += MarketPlaceAppPool::bootstrap(db); // Create the system tables only if bootstrap went well if (rc == 0) @@ -493,8 +494,10 @@ void Nebula::start(bool bootstrap_only) docpool = new DocumentPool(db); zonepool= new ZonePool(db, is_federation_slave()); vdcpool = new VdcPool(db, is_federation_slave()); + vrouterpool = new VirtualRouterPool(db); - mppool = new MarketPlacePool(db); + marketpool = new MarketPlacePool(db); + apppool = new MarketPlaceAppPool(db); nebula_configuration->get("VM_HOOK", vm_hooks); nebula_configuration->get("HOST_HOOK", host_hooks); diff --git a/src/oca/ruby/opennebula.rb b/src/oca/ruby/opennebula.rb index f545391c6c..6eea9d95ff 100644 --- a/src/oca/ruby/opennebula.rb +++ b/src/oca/ruby/opennebula.rb @@ -60,6 +60,8 @@ require 'opennebula/virtual_router' require 'opennebula/virtual_router_pool' require 'opennebula/marketplace' require 'opennebula/marketplace_pool' +require 'opennebula/marketplaceapp' +require 'opennebula/marketplaceapp_pool' module OpenNebula diff --git a/src/oca/ruby/opennebula/image_pool.rb b/src/oca/ruby/opennebula/image_pool.rb index 5316ffcbdb..89402cdbd3 100644 --- a/src/oca/ruby/opennebula/image_pool.rb +++ b/src/oca/ruby/opennebula/image_pool.rb @@ -23,7 +23,6 @@ module OpenNebula # Constants and Class attribute accessors ####################################################################### - IMAGE_POOL_METHODS = { :info => "imagepool.info" } diff --git a/src/oca/ruby/opennebula/marketplace.rb b/src/oca/ruby/opennebula/marketplace.rb index c0b6910f58..3b83dc1f82 100644 --- a/src/oca/ruby/opennebula/marketplace.rb +++ b/src/oca/ruby/opennebula/marketplace.rb @@ -67,16 +67,16 @@ module OpenNebula # XML-RPC Methods for the MarketPlace Object ####################################################################### - # Retrieves the information of the given MarketPlace. + # Retrieves the information of the given marketplace. def info() super(MARKETPLACE_METHODS[:info], 'MARKETPLACE') end alias_method :info!, :info - # Allocates a new MarketPlace in OpenNebula + # Allocates a new marketplace in OpenNebula # - # @param description [String] The template of the MarketPlace. + # @param description [String] The template of the marketplace. # # @return [Integer, OpenNebula::Error] the new ID in case of # success, error otherwise @@ -84,7 +84,7 @@ module OpenNebula super(MARKETPLACE_METHODS[:allocate], description) end - # Deletes the MarketPlace + # Deletes the marketplace def delete() super(MARKETPLACE_METHODS[:delete]) end @@ -161,11 +161,6 @@ module OpenNebula SHORT_MARKETPLACE_TYPES[type_str] end - # Returns the state of the marketplace (numeric value) - def state - self['STATE'].to_i - end - # Returns whether or not the marketplace app with id 'id' is part of # this marketplace def contains(id) diff --git a/src/rm/Request.cc b/src/rm/Request.cc index 3075da89e4..840d01ba53 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -629,6 +629,8 @@ string Request::object_name(PoolObjectSQL::ObjectType ob) case PoolObjectSQL::MARKETPLACEAPP: return "marketplaceapp"; } + + return "unknown"; }; /* -------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 28a57fa80c..14417a70e6 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -949,6 +949,52 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.marketpool.info", marketpool_info); + /* MarketPlaceApp related methods */ + + xmlrpc_c::method * marketapp_allocate_pt; + xmlrpc_c::method * marketapp_update_pt; + xmlrpc_c::method * marketapp_delete_pt; + xmlrpc_c::method * marketapp_chmod_pt; + xmlrpc_c::method * marketapp_chown_pt; + + if (nebula.is_federation_slave()) + { + marketapp_allocate_pt = new RequestManagerProxy("one.marketapp.allocate"); + marketapp_update_pt = new RequestManagerProxy("one.marketapp.update"); + marketapp_delete_pt = new RequestManagerProxy("one.marketapp.delete"); + marketapp_chmod_pt = new RequestManagerProxy("one.marketapp.chmod"); + marketapp_chown_pt = new RequestManagerProxy("one.marketapp.chown"); + } + else + { + marketapp_allocate_pt = new MarketPlaceAppAllocate(); + marketapp_update_pt = new MarketPlaceAppUpdateTemplate(); + marketapp_delete_pt = new MarketPlaceAppDelete(); + marketapp_chmod_pt = new MarketPlaceAppChmod(); + marketapp_chown_pt = new MarketPlaceAppChown(); + } + + xmlrpc_c::methodPtr marketapp_allocate(marketapp_allocate_pt); + xmlrpc_c::methodPtr marketapp_update(marketapp_update_pt); + xmlrpc_c::methodPtr marketapp_delete(marketapp_delete_pt); + xmlrpc_c::methodPtr marketapp_chmod(marketapp_chmod_pt); + xmlrpc_c::methodPtr marketapp_chown(marketapp_chown_pt); + + xmlrpc_c::methodPtr marketapp_info(new MarketPlaceAppInfo()); + xmlrpc_c::methodPtr marketapp_rename(new MarketPlaceAppRename()); + xmlrpc_c::methodPtr marketapppool_info(new MarketPlaceAppPoolInfo()); + + RequestManagerRegistry.addMethod("one.marketapp.allocate", marketapp_allocate); + RequestManagerRegistry.addMethod("one.marketapp.update", marketapp_update); + RequestManagerRegistry.addMethod("one.marketapp.delete", marketapp_delete); + RequestManagerRegistry.addMethod("one.marketapp.chmod", marketapp_chmod); + RequestManagerRegistry.addMethod("one.marketapp.chown", marketapp_chown); + + RequestManagerRegistry.addMethod("one.marketapp.info", marketapp_info); + RequestManagerRegistry.addMethod("one.marketapp.rename", marketapp_rename); + + RequestManagerRegistry.addMethod("one.marketapppool.info", marketapppool_info); + /* System related methods */ RequestManagerRegistry.addMethod("one.system.version", system_version); RequestManagerRegistry.addMethod("one.system.config", system_config); diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 8cea628295..999048f88b 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -810,3 +810,49 @@ int MarketPlaceAllocate::pool_allocate( ttmpl, &id, error_str); } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int MarketPlaceAppAllocate::pool_allocate( + xmlrpc_c::paramList const& paramList, + Template * tmpl, + int& id, + string& error_str, + RequestAttributes& att) +{ + MarketPlaceAppPool * appool = static_cast(pool); + MarketPlaceAppTemplate * ttmpl = static_cast(tmpl); + + int mp_id = xmlrpc_c::value_int(paramList.getInt(2)); + + MarketPlace * mp = mppool->get(mp_id, true); + + if ( mp == 0 ) + { + error_str = "Cannot find associated MARKETPLACE"; + return -1; + } + + std::string mp_name = mp->get_name(); + + mp->unlock(); + + int rc = appool->allocate(att.uid, att.gid, att.uname, att.gname, att.umask, + ttmpl, mp_id, mp_name, &id, error_str); + + if (rc < 0) + { + return rc; + } + + mp = mppool->get(mp_id, true); + + if ( mp != 0 ) // TODO: error otherwise or leave app in ERROR? + { + mp->add_marketapp(id); + + mppool->update(mp); + + mp->unlock(); + } +} diff --git a/src/rm/RequestManagerRename.cc b/src/rm/RequestManagerRename.cc index 27722a0ea2..81b819cb92 100644 --- a/src/rm/RequestManagerRename.cc +++ b/src/rm/RequestManagerRename.cc @@ -302,3 +302,41 @@ void HostRename::batch_rename(int oid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ + +void MarketPlaceRename::batch_rename(int oid) +{ + MarketPlace * market = static_cast(pool)->get(oid, true); + + if (market == 0) + { + return; + } + + const std::set & apps = market->get_marketapp_ids(); + + std::set::iterator it; + + std::string market_name = market->get_name(); + + market->unlock(); + + MarketPlaceApp * app; + MarketPlaceAppPool * apppool = Nebula::instance().get_apppool(); + + for (it = apps.begin(); it != apps.end(); it++) + { + app = apppool->get(*it, true); + + if (app != 0) + { + if (app->get_market_id() == oid) + { + app->set_market_name(market_name); + apppool->update(app); + } + + app->unlock(); + } + } +} +