diff --git a/include/MarketPlace.h b/include/MarketPlace.h index e1caee13e2..833fee370f 100644 --- a/include/MarketPlace.h +++ b/include/MarketPlace.h @@ -28,41 +28,6 @@ class MarketPlace : public PoolObjectSQL, ObjectCollection { public: - /** - * MarketPlace container types - */ - enum MarketPlaceType - { - UNKNOWN = 0, /** < Unknown types */ - IMAGE_MP = 1, /** < Image MarketPlace */ - VMTEMPLATE_MP = 2, /** < VM Template MarketPlace */ - FLOW_MP = 3 /** < Flow MarketPlace */ - }; - - /** - * Return the string representation of a MarketPlaceType - * @param ob the type - * @return the string - */ - static string type_to_str(MarketPlaceType ob) - { - switch (ob) - { - case IMAGE_MP: return "IMAGE_MP"; break; - case VMTEMPLATE_MP: return "VMTEMPLATE_MP"; break; - case FLOW_MP: return "FLOW_MP"; break; - default: return ""; - } - }; - - /** - * Return the string representation of a MarketPlaceType, By default it will - * return IMAGE_MP. - * @param str_type string representing the type - * @return the MarketPlaceType - */ - static MarketPlaceType str_to_type(string& str_type); - /** * Function to print the MarketPlace object into a string in XML format * @param xml the resulting XML string @@ -115,15 +80,6 @@ public: return market_mad; }; - /** - * Returns the marketplace type - * @return marketplace type - */ - MarketPlaceType get_type() const - { - return type; - }; - /** * Set monitor information for the MarketPlace * @param total_mb @@ -150,11 +106,6 @@ private: */ string market_mad; - /** - * The marketplace type - */ - MarketPlaceType type; - /** * Total capacity in MB */ diff --git a/include/MarketPlaceApp.h b/include/MarketPlaceApp.h index 720353a811..d66fb19fdc 100644 --- a/include/MarketPlaceApp.h +++ b/include/MarketPlaceApp.h @@ -28,6 +28,9 @@ class MarketPlaceApp : public PoolObjectSQL { public: + /** + * MarketPlaceApp states + */ enum MarketPlaceAppState { INIT = 0, /** < Initialization state */ @@ -53,6 +56,40 @@ public: } }; + /** + * MarketPlaceApp container types + */ + enum MarketPlaceAppType + { + UNKNOWN = 0, /** < Unknown types */ + IMAGE = 1, /** < Image MarketPlace App*/ + VMTEMPLATE = 2, /** < VM Template MarketPlace App*/ + FLOW = 3 /** < Flow MarketPlace App*/ + }; + + /** + * Return the string representation of a MarketPlaceType + * @param ob the type + * @return the string + */ + static string type_to_str(MarketPlaceAppType ob) + { + switch (ob) + { + case IMAGE: return "IMAGE"; break; + case VMTEMPLATE: return "VMTEMPLATE"; break; + case FLOW: return "FLOW"; break; + default: return ""; + } + }; + + /** + * Return the string representation of a MarketPlaceType, By default it will + * return IMAGE_MP. + * @param str_type string representing the type + * @return the MarketPlaceType + */ + static MarketPlaceAppType str_to_type(string& str_type); /** * Function to print the MarketPlaceApp object into a string in XML format @@ -93,6 +130,15 @@ public: market_name = name; }; + /** + * Returns the marketplace app type + * @return marketplace app type + */ + MarketPlaceAppType get_type() const + { + return type; + }; + private: friend class MarketPlaceAppPool; @@ -155,6 +201,11 @@ private: */ MarketPlaceAppState state; + /** + * The marketplace type + */ + MarketPlaceAppType type; + /** * Origin of this App */ diff --git a/include/MarketPlacePool.h b/include/MarketPlacePool.h index 9b21829800..f796860664 100644 --- a/include/MarketPlacePool.h +++ b/include/MarketPlacePool.h @@ -135,6 +135,17 @@ public: limit); }; + /** + * Lists the Datastore ids + * @param oids a vector with the oids of the objects. + * + * @return 0 on success + */ + int list(std::vector& oids) + { + return PoolSQL::list(oids, MarketPlace::table); + } + private: /** diff --git a/src/cli/etc/onemarket.yaml b/src/cli/etc/onemarket.yaml index b57e69f7dc..7d6bfca2a6 100644 --- a/src/cli/etc/onemarket.yaml +++ b/src/cli/etc/onemarket.yaml @@ -21,11 +21,6 @@ :desc: Number of Marketplace Apps :size: 6 -:TYPE: - :desc: Marketplace type - :size: 4 - :left: true - :MAD: :desc: Marketplace driver :size: 7 @@ -37,5 +32,4 @@ - :SIZE - :AVAIL - :APPS -- :TYPE - :MAD diff --git a/src/cli/etc/onemarketapp.yaml b/src/cli/etc/onemarketapp.yaml index e832aa256e..4c40749109 100644 --- a/src/cli/etc/onemarketapp.yaml +++ b/src/cli/etc/onemarketapp.yaml @@ -31,6 +31,11 @@ :desc: Publishing date for the marketplace app :size: 15 +:TYPE: + :desc: Marketplace app type + :size: 4 + :left: true + :MARKET: :desc: Name of the marketplace :size: 10 @@ -44,4 +49,5 @@ - :SIZE - :STAT - :DATE +- :TYPE - :MARKET diff --git a/src/cli/one_helper/onemarket_helper.rb b/src/cli/one_helper/onemarket_helper.rb index 328e943cfa..7f584cfb3d 100644 --- a/src/cli/one_helper/onemarket_helper.rb +++ b/src/cli/one_helper/onemarket_helper.rb @@ -98,46 +98,45 @@ class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper OpenNebula::MarketPlacePool.new(@client) end - def format_resource(datastore, options = {}) + def format_resource(market, options = {}) str="%-15s: %-20s" str_h1="%-80s" - CLIHelper.print_header(str_h1 % "MARKETPLACE #{datastore['ID']} INFORMATION") - puts str % ["ID", datastore.id.to_s] - puts str % ["NAME", datastore.name] - puts str % ["USER", datastore['UNAME']] - puts str % ["GROUP", datastore['GNAME']] - puts str % ["TYPE", datastore.type_str] + CLIHelper.print_header(str_h1 % "MARKETPLACE #{market['ID']} INFORMATION") + puts str % ["ID", market.id.to_s] + puts str % ["NAME", market.name] + puts str % ["USER", market['UNAME']] + puts str % ["GROUP", market['GNAME']] - puts str % ["MARKET_MAD", datastore['MARKET_MAD']] + puts str % ["MARKET_MAD", market['MARKET_MAD']] puts CLIHelper.print_header(str_h1 % "MARKETPLACE CAPACITY", false) - puts str % ["TOTAL:", OpenNebulaHelper.unit_to_str(datastore['TOTAL_MB'].to_i,{},'M')] - puts str % ["FREE:", OpenNebulaHelper.unit_to_str(datastore['FREE_MB'].to_i, {},'M')] - puts str % ["USED: ", OpenNebulaHelper.unit_to_str(datastore['USED_MB'].to_i, {},'M')] + puts str % ["TOTAL:", OpenNebulaHelper.unit_to_str(market['TOTAL_MB'].to_i,{},'M')] + puts str % ["FREE:", OpenNebulaHelper.unit_to_str(market['FREE_MB'].to_i, {},'M')] + puts str % ["USED: ", OpenNebulaHelper.unit_to_str(market['USED_MB'].to_i, {},'M')] puts CLIHelper.print_header(str_h1 % "PERMISSIONS",false) ["OWNER", "GROUP", "OTHER"].each { |e| mask = "---" - mask[0] = "u" if datastore["PERMISSIONS/#{e}_U"] == "1" - mask[1] = "m" if datastore["PERMISSIONS/#{e}_M"] == "1" - mask[2] = "a" if datastore["PERMISSIONS/#{e}_A"] == "1" + mask[0] = "u" if market["PERMISSIONS/#{e}_U"] == "1" + mask[1] = "m" if market["PERMISSIONS/#{e}_M"] == "1" + mask[2] = "a" if market["PERMISSIONS/#{e}_A"] == "1" puts str % [e, mask] } puts CLIHelper.print_header(str_h1 % "MARKETPLACE TEMPLATE", false) - puts datastore.template_str + puts market.template_str puts CLIHelper.print_header("%-15s" % "MARKETAPPS") - datastore.marketapp_ids.each do |id| + market.marketapp_ids.each do |id| puts "%-15s" % [id] end end diff --git a/src/cli/one_helper/onemarketapp_helper.rb b/src/cli/one_helper/onemarketapp_helper.rb index 2a86b3c600..0973acd55b 100644 --- a/src/cli/one_helper/onemarketapp_helper.rb +++ b/src/cli/one_helper/onemarketapp_helper.rb @@ -64,11 +64,16 @@ class OneMarketPlaceAppHelper < OpenNebulaHelper::OneHelper OpenNebulaHelper.time_to_str(d["DATE"]) end + column :TYPE, "Marketplace app type", :left, :size=>4 do |d| + type = MarketPlaceApp::MARKETPLACEAPP_TYPES[d["TYPE"].to_i] + MarketPlaceApp::SHORT_MARKETPLACEAPP_TYPES[type] + end + column :MARKET, "Name of the marketplace", :left, :size=>10 do |d| d["MARKETPLACE"] end - default :ID,:NAME,:PUBLISHER,:VERSION,:SIZE,:STAT,:DATE,:MARKET + default :ID,:NAME,:PUBLISHER,:VERSION,:SIZE,:STAT,:DATE,:TYPE,:MARKET end table @@ -96,6 +101,7 @@ class OneMarketPlaceAppHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "MARKETPLACE APP #{app['ID']} INFORMATION") puts str % ["ID", app.id.to_s] puts str % ["NAME", app.name] + puts str % ["TYPE", app.type_str] puts str % ["USER", app['UNAME']] puts str % ["GROUP", app['GNAME']] puts str % ["MARKETPLACE", app['MARKETPLACE']] diff --git a/src/market/MarketPlace.cc b/src/market/MarketPlace.cc index 4b6ecf680c..e53916edd3 100644 --- a/src/market/MarketPlace.cc +++ b/src/market/MarketPlace.cc @@ -47,7 +47,6 @@ MarketPlace::MarketPlace( PoolObjectSQL(-1, MARKETPLACE, "", uid, gid, uname, gname, table), ObjectCollection("MARKETPLACEAPPS"), market_mad(""), - type(IMAGE_MP), total_mb(0), free_mb(0), used_mb(0) @@ -77,8 +76,6 @@ int MarketPlace::insert(SqlDB *db, string& error_str) { std::ostringstream oss; - std::string s_mp_type; - // ------------------------------------------------------------------------- // Check default marketplace attributes // ------------------------------------------------------------------------- @@ -93,15 +90,6 @@ int MarketPlace::insert(SqlDB *db, string& error_str) goto error_mad; } - erase_template_attribute("TYPE", s_mp_type); - - type = str_to_type(s_mp_type); - - if ( type == UNKNOWN ) - { - goto error_type; - } - //-------------------------------------------------------------------------- return insert_replace(db, false, error_str); @@ -109,12 +97,9 @@ int MarketPlace::insert(SqlDB *db, string& error_str) error_mad: error_str = "No marketplace driver (MARKET_MAD) in template."; goto error_common; -error_type: - error_str = "Unknown marketplace type: " + s_mp_type; - goto error_common; error_common: - NebulaLog::log("MARKETPLACE", Log::ERROR, error_str); + NebulaLog::log("MKP", Log::ERROR, error_str); return -1; } @@ -220,7 +205,6 @@ std::string& MarketPlace::to_xml(std::string& xml) const "" << uname << "" << "" << gname << "" << "" << name << "" << - "" << type << "" << ""<"<< "" << total_mb << "" << "" << free_mb << "" << @@ -241,7 +225,6 @@ std::string& MarketPlace::to_xml(std::string& xml) const int MarketPlace::from_xml(const std::string &xml_str) { int rc = 0; - int itype; std::vector content; // Initialize the internal XML object @@ -254,7 +237,6 @@ int MarketPlace::from_xml(const std::string &xml_str) rc += xpath(uname, "/MARKETPLACE/UNAME", "not_found"); rc += xpath(gname, "/MARKETPLACE/GNAME", "not_found"); rc += xpath(name, "/MARKETPLACE/NAME", "not_found"); - rc += xpath(itype, "/MARKETPLACE/TYPE", -1); rc += xpath(market_mad, "/MARKETPLACE/MARKET_MAD", "not_found"); @@ -262,8 +244,6 @@ int MarketPlace::from_xml(const std::string &xml_str) rc += xpath(free_mb, "/MARKETPLACE/FREE_MB", 0); rc += xpath(used_mb, "/MARKETPLACE/USED_MB", 0); - type = static_cast(itype); - // ----- Permissions ----- rc += perms_from_xml(); @@ -306,28 +286,8 @@ int MarketPlace::from_xml(const std::string &xml_str) int MarketPlace::post_update_template(string& error) { - std::string new_s_type; std::string new_market_mad; - MarketPlaceType new_type; - - // ------------------------------------------------------------------------- - // Sanitize TYPE and MARKET_MAD attributes - // ------------------------------------------------------------------------- - erase_template_attribute("TYPE", new_s_type); - - new_type = str_to_type(new_s_type); - - if ( new_type == UNKNOWN ) - { - error = "Unknown marketplace type: " + new_s_type; - return -1; - } - - type = new_type; - - add_template_attribute("TYPE", type_to_str(type)); - erase_template_attribute("MARKET_MAD", new_market_mad); if (!new_market_mad.empty()) @@ -340,26 +300,3 @@ int MarketPlace::post_update_template(string& error) return 0; } -/* --------------------------------------------------------------------------- */ -/* --------------------------------------------------------------------------- */ - -MarketPlace::MarketPlaceType MarketPlace::str_to_type(string& str_type) -{ - one_util::toupper(str_type); - - if ( str_type == "IMAGE_MP" ) - { - return IMAGE_MP; - } - else if ( str_type == "VMTEMPLATE_MP" ) - { - return VMTEMPLATE_MP; - } - else if ( str_type == "FLOW_MP" ) - { - return FLOW_MP; - } - - return UNKNOWN; -} - diff --git a/src/market/MarketPlaceApp.cc b/src/market/MarketPlaceApp.cc index 279dfa6321..eddaacee40 100644 --- a/src/market/MarketPlaceApp.cc +++ b/src/market/MarketPlaceApp.cc @@ -54,7 +54,8 @@ MarketPlaceApp::MarketPlaceApp( apptemplate64(""), market_id(-1), market_name(""), - state(INIT) + state(INIT), + type(IMAGE) { if (app_template != 0) { @@ -95,6 +96,8 @@ int MarketPlaceApp::insert(SqlDB *db, string& error_str) date = time(NULL); + type = IMAGE; + //Known attributes //ORIGIN //DESCRIPTION @@ -134,7 +137,7 @@ int MarketPlaceApp::insert(SqlDB *db, string& error_str) error_origin: error_str = "Missing ORIGIN for the MARKETPLACEAPP"; - NebulaLog::log("MRK", Log::ERROR, error_str); + NebulaLog::log("MKP", Log::ERROR, error_str); return -1; } @@ -249,6 +252,7 @@ std::string& MarketPlaceApp::to_xml(std::string& xml) const "" << market_id << "" << "" << market_name << "" << "" << state << "" << + "" << type << "" << perms_to_xml(perm_str) << obj_template->to_xml(template_xml) << ""; @@ -265,6 +269,7 @@ int MarketPlaceApp::from_xml(const std::string &xml_str) { int rc = 0; int istate; + int itype; std::vector content; // Initialize the internal XML object @@ -281,6 +286,7 @@ int MarketPlaceApp::from_xml(const std::string &xml_str) rc += xpath(source, "/MARKETPLACEAPP/SOURCE","not_found"); rc += xpath(origin, "/MARKETPLACEAPP/ORIGIN","not_found"); rc += xpath(istate, "/MARKETPLACEAPP/STATE", -1); + rc += xpath(itype, "/MARKETPLACEAPP/TYPE", -1); rc += xpath(description, "/MARKETPLACEAPP/DESCRIPTION", "not_found"); rc += xpath(size_mb, "/MARKETPLACEAPP/SIZE", -1); rc += xpath(version, "/MARKETPLACEAPP/VERSION", "not_found"); @@ -291,6 +297,7 @@ int MarketPlaceApp::from_xml(const std::string &xml_str) rc += xpath(market_id, "/MARKETPLACEAPP/MARKETPLACE_ID", -1); state = static_cast(istate); + type = static_cast(itype); // ----- Permissions ----- rc += perms_from_xml(); @@ -341,3 +348,26 @@ int MarketPlaceApp::post_update_template(string& error) return 0; } +/* --------------------------------------------------------------------------- */ +/* --------------------------------------------------------------------------- */ + +MarketPlaceApp::MarketPlaceAppType MarketPlaceApp::str_to_type(string& str_type) +{ + one_util::toupper(str_type); + + if ( str_type == "IMAGE" ) + { + return IMAGE; + } + else if ( str_type == "VMTEMPLATE" ) + { + return VMTEMPLATE; + } + else if ( str_type == "FLOW" ) + { + return FLOW; + } + + return UNKNOWN; +} + diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index a69c4dd312..5d3474578c 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -910,6 +910,8 @@ void Nebula::start(bool bootstrap_only) lcm->init_managers(); + marketm->init_managers(); + // ---- Start the Request Manager ---- rc = rm->start(); diff --git a/src/oca/ruby/opennebula/marketplace.rb b/src/oca/ruby/opennebula/marketplace.rb index 3b83dc1f82..439f42c5a7 100644 --- a/src/oca/ruby/opennebula/marketplace.rb +++ b/src/oca/ruby/opennebula/marketplace.rb @@ -32,15 +32,6 @@ module OpenNebula :rename => "market.rename" } - MARKETPLACE_TYPES=%w{UNKNOWN IMAGE_MP VMTEMPLATE_MP FLOW_MP} - - SHORT_MARKETPLACE_TYPES = { - "UNKNOWN" => "unk", - "IMAGE_MP" => "img", - "VMTEMPLATE_MP"=> "tpl", - "FLOW_MP" => "flo" - } - # Creates a MarketPlace description with just its identifier # this method should be used to create plain MarketPlace objects. # +id+ the id of the user @@ -146,21 +137,6 @@ module OpenNebula # Helpers to get information # --------------------------------------------------------------------- - # Returns the marketplace type - def type - self['TYPE'].to_i - end - - # Returns the marketplace type (string value) - def type_str - MARKETPLACE_TYPES[type] - end - - # Returns the marketplace type (string value) - def short_type_str - SHORT_MARKETPLACE_TYPES[type_str] - end - # Returns whether or not the marketplace app with id 'id' is part of # this marketplace def contains(id) diff --git a/src/oca/ruby/opennebula/marketplaceapp.rb b/src/oca/ruby/opennebula/marketplaceapp.rb index e1df6721eb..94c44c068c 100644 --- a/src/oca/ruby/opennebula/marketplaceapp.rb +++ b/src/oca/ruby/opennebula/marketplaceapp.rb @@ -41,6 +41,14 @@ module OpenNebula "ERROR" => "err", } + MARKETPLACEAPP_TYPES=%w{UNKNOWN IMAGE VMTEMPLATE FLOW} + + SHORT_MARKETPLACEAPP_TYPES = { + "UNKNOWN" => "unk", + "IMAGE" => "img", + "VMTEMPLATE"=> "tpl", + "FLOW" => "flo" + } # Creates a MarketPlace description with just its identifier # this method should be used to create plain MarketPlace objects. # +id+ the id of the user @@ -147,6 +155,21 @@ module OpenNebula # Helpers to get information # --------------------------------------------------------------------- + # Returns the marketplace app type + def type + self['TYPE'].to_i + end + + # Returns the marketplace app type (string value) + def type_str + MARKETPLACEAPP_TYPES[type] + end + + # Returns the marketplace app type (string value) + def short_type_str + SHORT_MARKETPLACEAPP_TYPES[type_str] + end + # Returns the state of the marketplace app (numeric value) def state self['STATE'].to_i diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 999048f88b..93c3929f0a 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -855,4 +855,6 @@ int MarketPlaceAppAllocate::pool_allocate( mp->unlock(); } + + return rc; }