diff --git a/include/MarketPlace.h b/include/MarketPlace.h index da8630feb9..e1caee13e2 100644 --- a/include/MarketPlace.h +++ b/include/MarketPlace.h @@ -231,6 +231,14 @@ private: return insert_replace(db, true, error_str); } + /** + * Factory method for marketplace templates + */ + Template * get_new_template() const + { + return new MarketPlaceTemplate; + } + /** * Child classes can process the new template set with replace_template or * append_template with this method diff --git a/include/MarketPlaceApp.h b/include/MarketPlaceApp.h new file mode 100644 index 0000000000..92ba1ff6cc --- /dev/null +++ b/include/MarketPlaceApp.h @@ -0,0 +1,210 @@ +/* ------------------------------------------------------------------------ */ +/* Copyright 2002-2015, 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. */ +/* -------------------------------------------------------------------------*/ + +#ifndef MARKETPLACEAPP_H_ +#define MARKETPLACEAPP_H_ + +#include "PoolSQL.h" +#include "ObjectCollection.h" +#include "MarketPlaceAppTemplate.h" + +/** + * The MarketPlaceApp class. It represents an abstract application for + * OpenNebula objects (Image, VM Templates or Flows) + */ +class MarketPlaceApp : public PoolObjectSQL +{ +public: + enum MarketPlaceAppState + { + INIT = 0, /** < Initialization state */ + READY = 1, /** < Ready to use */ + LOCKED = 2, /** < Operation in process */ + ERROR = 3, /** < Error state the operation failed*/ + }; + + /** + * Returns the string representation of an MarketplaceApp State + * @param state The state + * @return the string representation + */ + static string state_to_str(MarketPlaceAppState state) + { + switch(state) + { + case INIT: return "INIT"; break; + case READY: return "READY"; break; + case LOCKED: return "LOCKED"; break; + case ERROR: return "ERROR"; break; + default: return ""; + } + }; + + + /** + * Function to print the MarketPlaceApp object into a string in XML format + * @param xml the resulting XML string + * @return a reference to the generated string + */ + string& to_xml(std::string& xml) const; + + /** + * Rebuilds the object from an xml formatted string + * @param xml_str The xml-formatted string + * + * @return 0 on success, -1 otherwise + */ + int from_xml(const std::string &xml_str); + +private: + + friend class MarketPlaceAppPool; + + // ************************************************************************* + // MarketPlaceApp Attributes + // ************************************************************************* + /** + * Size of this app + */ + std::string date; + + /** + * Source URL for the marketplace app + */ + std::string source; + + /** + * Source URL for the marketplace app + */ + std::string checksum; + + /** + * Size of this app + */ + long long size_mb; + + /** + * Description of the App + */ + std::string description; + + /** + * User sharing the app + */ + std::string publisher; + + /** + * Version of the app + */ + std::string version; + + /** + * App template to import it + */ + std::string apptemplate64; + + /** + * Marketplace ID that holds this app + */ + int mp_id; + + /** + * Marketplace name + */ + std::string mp_name; + + /** + * Marketplace App state + */ + MarketPlaceAppState state; + + /** + * Origin of this App + */ + std::string origin; + + // ************************************************************************* + // Constructor + // ************************************************************************* + MarketPlaceApp( + int uid, + int gid, + const std::string& uname, + const std::string& gname, + int umask, + MarketPlaceAppTemplate* app_template); + + virtual ~MarketPlaceApp(); + + // ************************************************************************* + // DataBase implementation (Private) + // ************************************************************************* + + static const char * db_names; + + static const char * db_bootstrap; + + static const char * table; + + /** + * Execute an INSERT or REPLACE Sql query. + * @param db The SQL DB + * @param replace Execute an INSERT or a REPLACE + * @param error_str Returns the error reason, if any + * @return 0 one success + */ + int insert_replace(SqlDB *db, bool replace, std::string& error_str); + + /** + * Bootstraps the database table(s) associated to the MarketPlace + * @return 0 on success + */ + static int bootstrap(SqlDB * db) + { + ostringstream oss(db_bootstrap); + + return db->exec(oss); + }; + + /** + * Writes the MarketPlace in the database. + * @param db pointer to the db + * @return 0 on success + */ + int insert(SqlDB *db, std::string& error_str); + + /** + * Writes/updates the MarketPlace's data fields in the database. + * @param db pointer to the db + * @return 0 on success + */ + int update(SqlDB *db) + { + std::string error_str; + return insert_replace(db, true, error_str); + } + + /** + * Child classes can process the new template set with replace_template or + * append_template with this method + * @param error string describing the error if any + * @return 0 on success + */ + int post_update_template(std::string& error); +}; + +#endif /*MARKETPLACEAPP_H*/ + diff --git a/include/MarketPlaceAppPool.h b/include/MarketPlaceAppPool.h new file mode 100644 index 0000000000..4eb859de94 --- /dev/null +++ b/include/MarketPlaceAppPool.h @@ -0,0 +1,133 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2015, 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. */ +/* -------------------------------------------------------------------------- */ + +#ifndef MARKETPLACEAPP_POOL_H_ +#define MARKETPLACEAPP_POOL_H_ + +#include "MarketPlaceApp.h" + +class SqlDB; + +class MarketPlaceAppPool : public PoolSQL +{ +public: + MarketPlaceAppPool(SqlDB * db):PoolSQL(db,MarketPlaceApp::table,true,true){}; + + ~MarketPlaceAppPool(){}; + + /* ---------------------------------------------------------------------- */ + /* Methods for DB management */ + /* ---------------------------------------------------------------------- */ + + /** + * Allocates a new MarketPlaceApp, writing it in the pool database. + * @param uid the user id of the MarketPlace owner + * @param gid the id of the group this object is assigned to + * @param uname name of the user + * @param gname name of the group + * @param umask permissions umask + * @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 + * + * @return the oid assigned to the object, -1 in case of failure + */ + int allocate( + int uid, + int gid, + const std::string& uname, + const std::string& gname, + int umask, + MarketPlaceAppTemplate * apptemplate, + int mp_id, + const std::string& mp_name, + const std::string& origin, + int * oid, + std::string& error_str); + + /** + * Function to get a MarketPlaceApp from the pool + * @param oid MarketPlaceApp unique id + * @param lock locks the MarketPlaceApp mutex + * @return a pointer to the MarketPlaceApp, 0 if not loaded + */ + MarketPlaceApp * get(int oid, bool lock) + { + return static_cast(PoolSQL::get(oid,lock)); + }; + + /** + * Gets an object from the pool (if needed the object is loaded from the + * database). + * @param name of the object + * @param uid id of owner + * @param lock locks the object if true + * + * @return a pointer to the object, 0 in case of failure + */ + MarketPlaceApp * get(const std::string& name, int uid, bool lock) + { + return static_cast(PoolSQL::get(name, uid, lock)); + }; + + /** + * Bootstraps the database table(s) associated to the MarketPlace pool + * @return 0 on success + */ + static int bootstrap(SqlDB * _db) + { + return MarketPlaceApp::bootstrap(_db); + }; + + /** + * Dumps the MarketPlace pool in XML format. A filter can be also added to + * the query + * @param oss the output stream to dump the pool contents + * @param where filter for the objects, defaults to all + * @param limit parameters used for pagination + * + * @return 0 on success + */ + int dump(std::ostringstream& oss, const std::string& where, + const std::string& limit) + { + return PoolSQL::dump(oss, "MARKETPLACEAPP_POOL", MarketPlaceApp::table, + where, limit); + }; + + /** Update a particular MarketPlaceApp + * @param zone pointer to Zone + * @return 0 on success + */ + int update(PoolObjectSQL * objsql); + +private: + + /** + * Factory method to produce objects + * @return a pointer to the new object + */ + PoolObjectSQL * create() + { + return new MarketPlaceApp(-1,-1,"","", 0, 0); + }; +}; + +#endif /*MARKETPLACE_POOL_H_*/ diff --git a/include/MarketPlaceAppTemplate.h b/include/MarketPlaceAppTemplate.h new file mode 100644 index 0000000000..a91d961785 --- /dev/null +++ b/include/MarketPlaceAppTemplate.h @@ -0,0 +1,37 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2015, 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. */ +/* -------------------------------------------------------------------------- */ + +#ifndef MARKETPLACEAPP_TEMPLATE_H_ +#define MARKETPLACEAPP_TEMPLATE_H_ + +#include "Template.h" + +/** + * Datastore Template class + */ +class MarketPlaceAppTemplate : public Template +{ +public: + MarketPlaceAppTemplate(): + Template(false,'=',"TEMPLATE"){}; + + ~MarketPlaceAppTemplate(){}; +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +#endif /*MARKETPLACEAPP_TEMPLATE_H_*/ diff --git a/include/MarketPlacePool.h b/include/MarketPlacePool.h index 4119ba96d4..c95a4a39a7 100644 --- a/include/MarketPlacePool.h +++ b/include/MarketPlacePool.h @@ -95,40 +95,20 @@ public: return name; }; - /** Update a particular MarketPlace - * @param user pointer to MarketPlace + /** Update a particular MarketPlaceApp + * @param zone pointer to Zone * @return 0 on success */ - int update(MarketPlace * mp) - { - return mp->update(db); - }; + int update(PoolObjectSQL * objsql); /** - * Drops the MarketPlac data in the data base. The object mutex SHOULD be + * Drops the MarketPlace data in the data base. The object mutex SHOULD be * locked. * @param objsql a pointer to the MarketPlace object * @param error_msg Error reason, if any * @return 0 on success, -1 DB error -3 MarketPlace's App ID set not empty */ - int drop(PoolObjectSQL * objsql, std::string& error_msg) - { - MarketPlace *mp = static_cast(objsql); - - if( mp->get_collection_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); - } + int drop(PoolObjectSQL * objsql, std::string& error_msg); /** * Bootstraps the database table(s) associated to the MarketPlace pool diff --git a/src/acl/AclRule.cc b/src/acl/AclRule.cc index 7b5075389e..67a1b9cae1 100644 --- a/src/acl/AclRule.cc +++ b/src/acl/AclRule.cc @@ -28,7 +28,7 @@ const long long AclRule::CLUSTER_ID = 0x0000000800000000LL; const long long AclRule::NONE_ID = 0x1000000000000000LL; -const int AclRule::num_pool_objects = 15; +const int AclRule::num_pool_objects = 16; const PoolObjectSQL::ObjectType AclRule::pool_objects[] = { PoolObjectSQL::VM, PoolObjectSQL::HOST, @@ -44,7 +44,8 @@ const PoolObjectSQL::ObjectType AclRule::pool_objects[] = { PoolObjectSQL::SECGROUP, PoolObjectSQL::VDC, PoolObjectSQL::VROUTER, - PoolObjectSQL::MARKETPLACE + PoolObjectSQL::MARKETPLACE, + PoolObjectSQL::MARKETPLACEAPP }; const int AclRule::num_auth_operations = 4; @@ -60,7 +61,7 @@ const long long AclRule::INVALID_CLUSTER_OBJECTS = PoolObjectSQL::TEMPLATE | PoolObjectSQL::GROUP | PoolObjectSQL::ACL | PoolObjectSQL::CLUSTER | PoolObjectSQL::DOCUMENT | PoolObjectSQL::ZONE | PoolObjectSQL::SECGROUP | PoolObjectSQL::VDC | PoolObjectSQL::VROUTER | - PoolObjectSQL::MARKETPLACE; + PoolObjectSQL::MARKETPLACE | PoolObjectSQL::MARKETPLACEAPP; const long long AclRule::INVALID_GROUP_OBJECTS = PoolObjectSQL::HOST | PoolObjectSQL::GROUP | PoolObjectSQL::CLUSTER | @@ -225,7 +226,7 @@ bool AclRule::malformed(string& error_str) const oss << "when using the ALL bit, [resource] ID must be 0"; } - if ( (resource & 0xFFFF000000000LL) == 0 ) + if ( (resource & 0xFFFFFFF000000000LL) == 0 ) { if ( error ) { @@ -236,7 +237,7 @@ bool AclRule::malformed(string& error_str) const oss << "[resource] type is missing"; } - if ( (resource & 0xFFF0000000000000LL) != 0 ) + if ( (resource & 0xFFE0000000000000LL) != 0 ) { if ( error ) { diff --git a/src/cli/etc/oneacl.yaml b/src/cli/etc/oneacl.yaml index 7b0c0d6817..f08817d68b 100644 --- a/src/cli/etc/oneacl.yaml +++ b/src/cli/etc/oneacl.yaml @@ -9,9 +9,9 @@ :size: 8 :right: true -:RES_VHNIUTGDCOZSvRM: +:RES_VHNIUTGDCOZSvRMA: :desc: Which resource the rule applies to - :size: 19 + :size: 20 :RID: :desc: Resource ID @@ -31,7 +31,7 @@ :default: - :ID - :USER -- :RES_VHNIUTGDCOZSvRM +- :RES_VHNIUTGDCOZSvRMA - :RID - :OPE_UMAC - :ZONE diff --git a/src/cli/one_helper/oneacl_helper.rb b/src/cli/one_helper/oneacl_helper.rb index 8eec5727da..c552c83628 100644 --- a/src/cli/one_helper/oneacl_helper.rb +++ b/src/cli/one_helper/oneacl_helper.rb @@ -44,7 +44,7 @@ private def self.resource_mask(str) resource_type=str.split("/")[0] - mask = "---------------" + mask = "----------------" resource_type.split("+").each{|type| case type @@ -78,6 +78,8 @@ private mask[13] = "R" when "MARKETPLACE" mask[14] = "M" + when "MARKETPLACEAPP" + mask[15] = "A" end } mask @@ -117,8 +119,8 @@ private d['STRING'].split(" ")[0] end - column :RES_VHNIUTGDCOZSvRM, "Resource to which the rule applies", - :size => 19 do |d| + column :RES_VHNIUTGDCOZSvRMA, "Resource to which the rule applies", + :size => 20 do |d| OneAclHelper::resource_mask d['STRING'].split(" ")[1] end @@ -135,7 +137,7 @@ private OneAclHelper::right_mask d['STRING'].split(" ")[2] end - default :ID, :USER, :RES_VHNIUTGDCOZSvRM, :RID, :OPE_UMAC, :ZONE + default :ID, :USER, :RES_VHNIUTGDCOZSvRMA, :RID, :OPE_UMAC, :ZONE end table diff --git a/src/market/MarketPlaceApp.cc b/src/market/MarketPlaceApp.cc new file mode 100644 index 0000000000..a2e163386a --- /dev/null +++ b/src/market/MarketPlaceApp.cc @@ -0,0 +1,338 @@ +/* ------------------------------------------------------------------------ */ +/* Copyright 2002-2015, 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 +#include "MarketPlaceApp.h" +#include "NebulaLog.h" +#include "NebulaUtil.h" + +/* ************************************************************************ */ +/* MarketPlaceApp:: Database Definition */ +/* ************************************************************************ */ + +const char * MarketPlaceApp::table = "marketplaceapp_pool"; + +const char * MarketPlaceApp::db_names = + "oid, name, body, uid, gid, owner_u, group_u, other_u"; + +const char * MarketPlaceApp::db_bootstrap = + "CREATE TABLE IF NOT EXISTS marketplaceapp_pool (oid INTEGER PRIMARY KEY, " + "name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, " + "owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name,uid))"; + +/* ************************************************************************ */ +/* MarketPlaceApp:: Constructor / Destructor */ +/* ************************************************************************ */ + +MarketPlaceApp::MarketPlaceApp( + int uid, + int gid, + const std::string& uname, + const std::string& gname, + int umask, + MarketPlaceAppTemplate * app_template): + PoolObjectSQL(-1, MARKETPLACEAPP, "", uid, gid, uname, gname, table), + source(""), + checksum(""), + size_mb(0), + description(""), + publisher(""), + version(""), + apptemplate64(""), + mp_id(-1), + mp_name(""), + state(INIT) +{ + if (app_template != 0) + { + obj_template = app_template; + } + else + { + obj_template = new MarketPlaceAppTemplate; + } + + set_umask(umask); +}; + +MarketPlaceApp::~MarketPlaceApp() +{ + delete obj_template; +}; + +/* ************************************************************************ */ +/* MartketPlaceApp:: Database Access Functions */ +/* ************************************************************************ */ + +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 + // ------------------------------------------------------------------------- + + //MarketPlaceAppPool::allocate checks NAME + 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; + + //Known attributes + //DESCRIPTION + //APPTEMPLATE64 + //PUBLISHER + //VERSION + + get_template_attribute("DESCRIPTION", description); + + get_template_attribute("APPTEMPLATE64", apptemplate64); + + get_template_attribute("PUBLISHER", attr); + + if (attr.empty()) + { + publisher = uname; + } + + get_template_attribute("VERSION", attr); + + if (!attr.empty()) + { + version = attr; + } + + state = LOCKED; + + //-------------------------------------------------------------------------- + + return insert_replace(db, false, error_str); +} + +/* --------------------------------------------------------------------------- */ +/* --------------------------------------------------------------------------- */ + +int MarketPlaceApp::insert_replace(SqlDB *db, bool replace, string& error_str) +{ + std::ostringstream oss; + + int rc; + std::string xml_body; + + char * sql_name; + char * sql_xml; + + sql_name = db->escape_str(name.c_str()); + + if ( sql_name == 0 ) + { + goto error_name; + } + + sql_xml = db->escape_str(to_xml(xml_body).c_str()); + + if ( sql_xml == 0 ) + { + goto error_body; + } + + if ( validate_xml(sql_xml) != 0 ) + { + goto error_xml; + } + + if ( replace ) + { + oss << "REPLACE"; + } + else + { + oss << "INSERT"; + } + + // Construct the SQL statement to Insert or Replace + oss <<" INTO "<exec(oss); + + db->free_str(sql_name); + db->free_str(sql_xml); + + return rc; + +error_xml: + db->free_str(sql_name); + db->free_str(sql_xml); + + error_str = "Error transforming the marketplace app to XML."; + + goto error_common; + +error_body: + db->free_str(sql_name); + goto error_generic; + +error_name: + goto error_generic; + +error_generic: + error_str = "Error inserting marketplace app in DB."; +error_common: + return -1; +} + +/* --------------------------------------------------------------------------- */ +/* --------------------------------------------------------------------------- */ + +/* *************************************************************************** */ +/* MartketPlaceApp :: Template Functions */ +/* *************************************************************************** */ +std::string& MarketPlaceApp::to_xml(std::string& xml) const +{ + std::ostringstream oss; + std::string template_xml; + std::string perm_str; + + oss << "" + "" << oid << "" << + "" << uid << "" << + "" << gid << "" << + "" << uname << "" << + "" << gname << "" << + "" << date << "" << + "" << name << "" << + "" << origin << "" << + "" << source << "" << + "" << checksum << "" << + "" << size_mb << "" << + "" << description << "" << + "" << publisher << "" << + "" << version << "" << + "" << apptemplate64 << "" << + "" << mp_id << "" << + "" << mp_name << "" << + "" << state << "" << + perms_to_xml(perm_str) << + obj_template->to_xml(template_xml) << + ""; + + xml = oss.str(); + + return xml; +} + +/* --------------------------------------------------------------------------- */ +/* --------------------------------------------------------------------------- */ + +int MarketPlaceApp::from_xml(const std::string &xml_str) +{ + int rc = 0; + int istate; + std::vector content; + + // Initialize the internal XML object + update_from_str(xml_str); + + // ----- MARKETPLACEAPP base attributes ----- + rc += xpath(oid, "/MARKETPLACEAPP/ID", -1); + rc += xpath(uid, "/MARKETPLACEAPP/UID", -1); + rc += xpath(gid, "/MARKETPLACEAPP/GID", -1); + 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(source, "/MARKETPLACEAPP/SOURCE","not_found"); + rc += xpath(origin, "/MARKETPLACEAPP/ORIGIN","not_found"); + rc += xpath(istate, "/MARKETPLACEAPP/STATE", -1); + rc += xpath(description, "/MARKETPLACEAPP/DESCRIPTION", "not_found"); + rc += xpath(size_mb, "/MARKETPLACEAPP/SIZE", -1); + rc += xpath(version, "/MARKETPLACEAPP/VERSION", "not_found"); + 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); + + state = static_cast(istate); + + // ----- Permissions ----- + rc += perms_from_xml(); + + // ----- TEMPLATE ----- + ObjectXML::get_nodes("/MARKETPLACEAPP/TEMPLATE", content); + + if (content.empty()) + { + return -1; + } + + rc += obj_template->from_xml_node(content[0]); + + ObjectXML::free_nodes(content); + + if (rc != 0) + { + return -1; + } + + return 0; +} + +/* --------------------------------------------------------------------------- */ +/* --------------------------------------------------------------------------- */ + +int MarketPlaceApp::post_update_template(string& error) +{ + std::string n_description; + std::string n_apptemplate64; + std::string n_publisher; + std::string n_version; + + // ------------------------------------------------------------------------- + // Update well known attributes + // ------------------------------------------------------------------------- + get_template_attribute("DESCRIPTION", n_description); + get_template_attribute("APPTEMPLATE64", n_apptemplate64); + get_template_attribute("PUBLISHER", n_publisher); + get_template_attribute("VERSION", n_version); + + description = n_description; + apptemplate64 = n_apptemplate64; + publisher = n_publisher; + version = n_version; + + return 0; +} + diff --git a/src/market/MarketPlaceAppPool.cc b/src/market/MarketPlaceAppPool.cc new file mode 100644 index 0000000000..4b798c576d --- /dev/null +++ b/src/market/MarketPlaceAppPool.cc @@ -0,0 +1,102 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2015, 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 "MarketPlaceAppPool.h" +#include "Nebula.h" + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int MarketPlaceAppPool:: allocate( + int uid, + int gid, + const std::string& uname, + const std::string& gname, + int umask, + MarketPlaceAppTemplate * apptemplate, + int mp_id, + const std::string& mp_name, + const std::string& origin, + int * oid, + std::string& error_str) +{ + MarketPlaceApp * mp; + MarketPlaceApp * mp_aux = 0; + + std::string name; + + std::ostringstream oss; + + 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; + + // ------------------------------------------------------------------------- + // Check name & duplicates + // ------------------------------------------------------------------------- + + mp->get_template_attribute("NAME", name); + + if ( !PoolObjectSQL::name_is_valid(name, error_str) ) + { + goto error_name; + } + + mp_aux = get(name, uid, false); + + if( mp_aux != 0 ) + { + goto error_duplicated; + } + + *oid = PoolSQL::allocate(mp, error_str); + + return *oid; + +error_duplicated: + oss << "NAME is already taken by MARKETPLACEAPP " << mp_aux->get_oid(); + error_str = oss.str(); + +error_name: + delete mp; + *oid = -1; + + return *oid; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int MarketPlaceAppPool::update(PoolObjectSQL * objsql) +{ + if (Nebula::instance().is_federation_slave()) + { + NebulaLog::log("ONE",Log::ERROR, + "MarketPlaceAppPool::update called, but this " + "OpenNebula is a federation slave"); + + return -1; + } + + return PoolSQL::update(objsql); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + diff --git a/src/market/MarketPlacePool.cc b/src/market/MarketPlacePool.cc index e57f7423fe..512c2f547d 100644 --- a/src/market/MarketPlacePool.cc +++ b/src/market/MarketPlacePool.cc @@ -15,6 +15,7 @@ /* -------------------------------------------------------------------------- */ #include "MarketPlacePool.h" +#include "Nebula.h" /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -61,7 +62,7 @@ int MarketPlacePool::allocate( return *oid; error_duplicated: - oss << "NAME is already taken by MARKETPLACE " << mp_aux->get_oid() << "."; + oss << "NAME is already taken by MARKETPLACE " << mp_aux->get_oid(); error_str = oss.str(); error_name: @@ -71,3 +72,45 @@ error_name: return *oid; } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int MarketPlacePool::drop(PoolObjectSQL * objsql, std::string& error_msg) +{ + MarketPlace *mp = static_cast(objsql); + + if( mp->get_collection_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); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int MarketPlacePool::update(PoolObjectSQL * objsql) +{ + if (Nebula::instance().is_federation_slave()) + { + NebulaLog::log("ONE",Log::ERROR, + "MarketPlacePool::update called, but this " + "OpenNebula is a federation slave"); + + return -1; + } + + return PoolSQL::update(objsql); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + diff --git a/src/market/SConstruct b/src/market/SConstruct index 2bb765fc9e..5f5ebd67da 100644 --- a/src/market/SConstruct +++ b/src/market/SConstruct @@ -23,7 +23,9 @@ lib_name='nebula_marketplace' # Sources to generate the library source_files=[ 'MarketPlace.cc', - 'MarketPlacePool.cc' + 'MarketPlacePool.cc', + 'MarketPlaceApp.cc', + 'MarketPlaceAppPool.cc' ] # Build library diff --git a/src/oca/java/src/org/opennebula/client/acl/Acl.java b/src/oca/java/src/org/opennebula/client/acl/Acl.java index acbb33672a..682b09fa3e 100644 --- a/src/oca/java/src/org/opennebula/client/acl/Acl.java +++ b/src/oca/java/src/org/opennebula/client/acl/Acl.java @@ -72,7 +72,8 @@ public class Acl extends PoolElement{ tmpResources.put("SECGROUP" , 0x0001000000000000L); tmpResources.put("VDC" , 0x0002000000000000L); tmpResources.put("VROUTER" , 0x0004000000000000L); - tmpResources.put("MARKETPLACE", 0x0008000000000000L); + tmpResources.put("MARKETPLACE", 0x0008000000000000L); + tmpResources.put("MARKETPLACEAPP", 0x0010000000000000L); RESOURCES = Collections.unmodifiableMap(tmpResources); diff --git a/src/oca/ruby/opennebula/acl.rb b/src/oca/ruby/opennebula/acl.rb index 6aa8fddb81..3ce77198e5 100644 --- a/src/oca/ruby/opennebula/acl.rb +++ b/src/oca/ruby/opennebula/acl.rb @@ -35,6 +35,7 @@ module OpenNebula # VDC # VROUTER # MARKETPLACE + # MARKETPLACEAPP # RIGHTS -> + separated list # USE # MANAGE @@ -51,21 +52,22 @@ module OpenNebula RESOURCES = { - "VM" => 0x1000000000, - "HOST" => 0x2000000000, - "NET" => 0x4000000000, - "IMAGE" => 0x8000000000, - "USER" => 0x10000000000, - "TEMPLATE" => 0x20000000000, - "GROUP" => 0x40000000000, - "DATASTORE" => 0x100000000000, - "CLUSTER" => 0x200000000000, - "DOCUMENT" => 0x400000000000, - "ZONE" => 0x800000000000, - "SECGROUP" => 0x1000000000000, - "VDC" => 0x2000000000000, - "VROUTER" => 0x4000000000000, - "MARKETPLACE" => 0x8000000000000 + "VM" => 0x1000000000, + "HOST" => 0x2000000000, + "NET" => 0x4000000000, + "IMAGE" => 0x8000000000, + "USER" => 0x10000000000, + "TEMPLATE" => 0x20000000000, + "GROUP" => 0x40000000000, + "DATASTORE" => 0x100000000000, + "CLUSTER" => 0x200000000000, + "DOCUMENT" => 0x400000000000, + "ZONE" => 0x800000000000, + "SECGROUP" => 0x1000000000000, + "VDC" => 0x2000000000000, + "VROUTER" => 0x4000000000000, + "MARKETPLACE" => 0x8000000000000, + "MARKETPLACEAPP"=> 0x10000000000000 } RIGHTS = diff --git a/src/rm/Request.cc b/src/rm/Request.cc index adc66860fe..3075da89e4 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -626,6 +626,8 @@ string Request::object_name(PoolObjectSQL::ObjectType ob) return "virtual router"; case PoolObjectSQL::MARKETPLACE: return "marketplace"; + case PoolObjectSQL::MARKETPLACEAPP: + return "marketplaceapp"; } };