diff --git a/SConstruct b/SConstruct index 4768983bf4..5401320d0e 100644 --- a/SConstruct +++ b/SConstruct @@ -155,6 +155,11 @@ else: shutil.rmtree('src/nebula/.xmlrpc_test', True) shutil.rmtree('src/scheduler/.xmlrpc_test', True) + +# libxml2 +main_env.ParseConfig('xml2-config --libs --cflags') + + # SCONS scripts to build build_scripts=[ 'src/sql/SConstruct', diff --git a/include/ClusterPool.h b/include/ClusterPool.h index 6d6a4d9546..c7964d8752 100644 --- a/include/ClusterPool.h +++ b/include/ClusterPool.h @@ -73,7 +73,7 @@ private: * @param clid the id assigned to the cluster * @return the id assigned to the cluster or -1 in case of failure */ - int allocate(int * clid, string name, SqlDB *db); + int allocate(int * clid, string name, SqlDB *db, string& error_str); /** * Returns the xml representation of the given cluster diff --git a/include/History.h b/include/History.h index 802f6033d8..c6bf8da437 100644 --- a/include/History.h +++ b/include/History.h @@ -165,7 +165,7 @@ private: * @param db pointer to the database. * @return 0 on success. */ - int insert(SqlDB * db); + int insert(SqlDB * db, string& error_str); /** * Reads the history record from the DB @@ -173,7 +173,7 @@ private: * @return 0 on success. */ int select(SqlDB * db); - + /** * Updates the history record * @param db pointer to the database. @@ -187,11 +187,11 @@ private: * @return 0 on success. */ int drop(SqlDB * db); - + /** - * Execute an INSERT or REPLACE Sql query. + * Execute an INSERT or REPLACE Sql query. * @param db The SQL DB - * @param replace Execute an INSERT or a REPLACE + * @param replace Execute an INSERT or a REPLACE * @return 0 on success */ int insert_replace(SqlDB *db, bool replace); diff --git a/include/Host.h b/include/Host.h index ad0ee87265..ca6295305a 100644 --- a/include/Host.h +++ b/include/Host.h @@ -18,8 +18,8 @@ #define HOST_H_ #include "PoolSQL.h" -#include "HostShare.h" #include "HostTemplate.h" +#include "HostShare.h" #include "ClusterPool.h" using namespace std; @@ -454,11 +454,9 @@ private: { ostringstream oss_host(Host::db_bootstrap); ostringstream oss_share(HostShare::db_bootstrap); - ostringstream oss_templ(HostTemplate::db_bootstrap); db->exec(oss_host); db->exec(oss_share); - db->exec(oss_templ); }; protected: @@ -489,7 +487,8 @@ protected: TM_MAD = 5, LAST_MON_TIME = 6, CLUSTER = 7, - LIMIT = 8 + TEMPLATE = 8, + LIMIT = 9 }; static const char * db_names; @@ -510,7 +509,7 @@ protected: * @param db pointer to the db * @return 0 on success */ - virtual int insert(SqlDB *db); + virtual int insert(SqlDB *db, string& error_str); /** * Writes/updates the Hosts data fields in the database. diff --git a/include/HostPool.h b/include/HostPool.h index 0e51a0050e..4fbd9cf9c1 100644 --- a/include/HostPool.h +++ b/include/HostPool.h @@ -48,10 +48,11 @@ public: */ int allocate ( int * oid, - string hostname, - string im_mad_name, - string vmm_mad_name, - string tm_mad_name); + const string& hostname, + const string& im_mad_name, + const string& vmm_mad_name, + const string& tm_mad_name, + string& error_str); /** * Function to get a Host from the pool, if the object is not in memory @@ -169,9 +170,9 @@ public: * @param clid the id assigned to the cluster * @return the id assigned to the cluster or -1 in case of failure */ - int allocate_cluster(int * clid, string name) + int allocate_cluster(int * clid, const string& name, string& error_str) { - return cluster_pool.allocate(clid, name, db); + return cluster_pool.allocate(clid, name, db, error_str); }; /** diff --git a/include/HostShare.h b/include/HostShare.h index 419d487a56..d7b6a12078 100644 --- a/include/HostShare.h +++ b/include/HostShare.h @@ -182,7 +182,7 @@ private: * @param db pointer to the db * @return 0 on success */ - int insert(SqlDB * db); + int insert(SqlDB * db, string& error_str); /** * Writes/updates the HostShare data fields in the database. @@ -197,13 +197,13 @@ private: * @return 0 on success */ int drop(SqlDB * db); - + /** - * Execute an INSERT or REPLACE Sql query. + * Execute an INSERT or REPLACE Sql query. * @param db The SQL DB - * @param replace Execute an INSERT or a REPLACE + * @param replace Execute an INSERT or a REPLACE * @return 0 one success - */ + */ int insert_replace(SqlDB *db, bool replace); /** diff --git a/include/HostTemplate.h b/include/HostTemplate.h index 0121ce889d..b478c08437 100644 --- a/include/HostTemplate.h +++ b/include/HostTemplate.h @@ -17,30 +17,22 @@ #ifndef HOST_TEMPLATE_H_ #define HOST_TEMPLATE_H_ -#include "TemplateSQL.h" +#include "Template.h" using namespace std; /** * Host Template class, it represents the attributes of a Host */ -class HostTemplate : public TemplateSQL +class HostTemplate : public Template { public: - HostTemplate(int tid = -1, - const char separator = '='): - TemplateSQL(table,tid,true,separator,"TEMPLATE"){}; + HostTemplate() : Template(true,'=',"TEMPLATE"){}; ~HostTemplate(){}; -private: - friend class Host; - - static const char * table; - - static const char * db_bootstrap; }; - + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/Image.h b/include/Image.h index 1fba0dafe5..b6f84cb7d7 100644 --- a/include/Image.h +++ b/include/Image.h @@ -109,6 +109,15 @@ public: return (public_img == 1); }; + /** + * Returns true if the image is persistent + * @return true if the image is persistent + */ + bool isPersistent() + { + return (persistent_img == 1); + }; + /** * Set enum type * @return 0 on success, -1 otherwise @@ -183,16 +192,51 @@ public: * @param pub true to publish the image * @return 0 on success */ - void publish(bool pub) + bool publish(bool pub) { + bool success = false; + if (pub == true) { - public_img = 1; + if (!isPersistent()) + { + public_img = 1; + success = true; + } } else { public_img = 0; + success = true; } + + return success; + } + + /** + * Set/Unset an image as persistent + * @param persistent true to make an image persistent + * @return 0 on success + */ + bool persistent(bool persis) + { + bool success = false; + + if (persis == true) + { + if (!isPublic() && running_vms == 0) + { + persistent_img = 1; + success = true; + } + } + else + { + persistent_img = 0; + success = true; + } + + return success; } /** @@ -273,9 +317,30 @@ public: * Removes an Image attribute * @param name of the attribute */ - int remove_template_attribute(SqlDB * db, const string& name) + int remove_template_attribute(const string& name) { - return image_template->remove_attribute(db, name); + return image_template->erase(name); + } + + /** + * Adds a new attribute to the template (replacing it if + * already defined), the image's mutex SHOULD be locked + * @param name of the new attribute + * @param value of the new attribute + * @return 0 on success + */ + int replace_template_attribute( + const string& name, + const string& value) + { + SingleAttribute * sattr; + + image_template->erase(name); + + sattr = new SingleAttribute(name,value); + image_template->set(sattr); + + return 0; } private: @@ -310,6 +375,11 @@ private: */ int public_img; + /** + * Persistency of the Image + */ + int persistent_img; + /** * Registration time */ @@ -367,10 +437,8 @@ private: static void bootstrap(SqlDB * db) { ostringstream oss_image(Image::db_bootstrap); - ostringstream oss_templ(ImageTemplate::db_bootstrap); db->exec(oss_image); - db->exec(oss_templ); }; @@ -402,12 +470,13 @@ protected: NAME = 2, /* Image name */ TYPE = 3, /* 0) OS 1) CDROM 2) DATABLOCK */ PUBLIC = 4, /* Public scope (YES OR NO) */ - REGTIME = 5, /* Time of registration */ - SOURCE = 6, /* Path to the image */ - STATE = 7, /* 0) INIT 1) ALLOCATED */ - /* 2) READY 3) USED */ - RUNNING_VMS = 8, /* Number of VMs using the img */ - LIMIT = 9 + PERSISTENT = 5, /* Peristency (YES OR NO) */ + REGTIME = 6, /* Time of registration */ + SOURCE = 7, /* Path to the image */ + STATE = 8, /* 0) INIT 1) ALLOCATED */ + RUNNING_VMS = 9, /* Number of VMs using the img */ + TEMPLATE = 10, /* Image template xml data */ + LIMIT = 11 }; static const char * db_names; @@ -428,7 +497,7 @@ protected: * @param db pointer to the db * @return 0 on success */ - virtual int insert(SqlDB *db); + virtual int insert(SqlDB *db, string& error_str); /** * Writes/updates the Images data fields in the database. diff --git a/include/ImagePool.h b/include/ImagePool.h index d7fd446ec0..6ba70ddc9e 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -57,7 +57,8 @@ public: int allocate ( int uid, ImageTemplate * img_template, - int * oid); + int * oid, + string& error_str); /** * Function to get a Image from the pool, if the object is not in memory @@ -120,34 +121,6 @@ public: return rc; }; - /** Modify an image attribute in the template (Image MUST be locked) - * @param image pointer to Image - * @param name of the attribute to be changed - * @param new value for the attribute - * @return 0 on success, -1 otherwise - */ - int replace_attribute( - Image * image, - const string& name, - const string& value) - { - SingleAttribute * sattr = new SingleAttribute(name,value); - - return image->image_template->replace_attribute(db,sattr); - } - - /** Delete an image attribute in the template (Image MUST be locked) - * @param image pointer to Image - * @param name of the attribute to be removed - * @return 0 on success, -1 otherwise - */ - int remove_attribute( - Image * image, - const string& name) - { - return image->image_template->remove_attribute(db, name); - } - /** * Bootstraps the database table(s) associated to the Image pool */ diff --git a/include/ImageTemplate.h b/include/ImageTemplate.h index 8a999aa9f4..17b8502dbd 100644 --- a/include/ImageTemplate.h +++ b/include/ImageTemplate.h @@ -17,29 +17,19 @@ #ifndef IMAGE_TEMPLATE_H_ #define IMAGE_TEMPLATE_H_ -#include "TemplateSQL.h" +#include "Template.h" using namespace std; /** * Image Template class, it represents the attributes of a Host */ -class ImageTemplate : public TemplateSQL +class ImageTemplate : public Template { public: - ImageTemplate(int tid = -1, - const char separator = '='): - TemplateSQL(table,tid,true,separator,"TEMPLATE"){}; + ImageTemplate() : Template(true,'=',"TEMPLATE"){}; ~ImageTemplate(){}; - -private: - friend class Image; - friend class ImagePool; - - static const char * table; - - static const char * db_bootstrap; }; /* -------------------------------------------------------------------------- */ diff --git a/include/InformationManager.h b/include/InformationManager.h index f7b12ff5db..8c2f065933 100644 --- a/include/InformationManager.h +++ b/include/InformationManager.h @@ -34,11 +34,13 @@ public: HostPool * _hpool, time_t _timer_period, time_t _monitor_period, + const string& _remotes_location, vector& _mads) :MadManager(_mads), hpool(_hpool), timer_period(_timer_period), - monitor_period(_monitor_period) + monitor_period(_monitor_period), + remotes_location(_remotes_location) { am.addListener(this); }; @@ -46,7 +48,7 @@ public: ~InformationManager(){}; /** - * This functions starts the associated listener thread, and creates a + * This functions starts the associated listener thread, and creates a * new thread for the Information Manager. This thread will wait in * an action loop till it receives ACTION_FINALIZE. * @return 0 on success. @@ -63,12 +65,12 @@ public: }; /** - * + * */ void load_mads(int uid=0); /** - * + * */ void finalize() { @@ -90,28 +92,33 @@ private: * Timer period for the Virtual Machine Manager. */ time_t timer_period; - + /** * Host monitoring interval */ time_t monitor_period; - + + /** + * Path for the remote action programs + */ + string remotes_location; + /** * Action engine for the Manager */ ActionManager am; /** - * Function to execute the Manager action loop method within a new pthread + * Function to execute the Manager action loop method within a new pthread * (requires C linkage) */ friend void * im_action_loop(void *arg); /** - * Returns a pointer to a Information Manager MAD. The driver is + * Returns a pointer to a Information Manager MAD. The driver is * searched by its name and owned by gwadmin with uid=0. * @param name of the driver - * @return the VM driver owned by uid 0, with attribute "NAME" equal to + * @return the VM driver owned by uid 0, with attribute "NAME" equal to * name or 0 in not found */ const InformationManagerDriver * get( diff --git a/include/InformationManagerDriver.h b/include/InformationManagerDriver.h index f725a21213..7b4bdf4a96 100644 --- a/include/InformationManagerDriver.h +++ b/include/InformationManagerDriver.h @@ -30,7 +30,7 @@ using namespace std; /** * InformationManagerDriver provides a base class to implement IM * Drivers. This class implements the protocol and recover functions - * from the Mad interface. This class may be used to further specialize + * from the Mad interface. This class may be used to further specialize * the IM driver. */ class InformationManagerDriver : public Mad @@ -42,35 +42,28 @@ public: const map& attrs, bool sudo, HostPool * pool): - Mad(userid,attrs,sudo),hpool(pool) - {} - ; + Mad(userid,attrs,sudo),hpool(pool){}; - virtual ~InformationManagerDriver() - {} - ; + virtual ~InformationManagerDriver(){}; /** * Implements the IM driver protocol. * @param message the string read from the driver */ - void protocol( - string& message); + void protocol(string& message); /** * TODO: What do we need here? just poll the Hosts to recover.. */ void recover(); - + /** * Sends a monitor request to the MAD: "MONITOR ID HOSTNAME -" * @param oid the virtual machine id. * @param host the hostname - * @param conf the filename of the deployment file + * @param update the remotes directory in host */ - void monitor ( - int oid, - const string& host) const; + void monitor(int oid, const string& host, bool update) const; private: /** @@ -78,8 +71,7 @@ private: */ HostPool * hpool; - friend class InformationManager; - + friend class InformationManager; }; /* -------------------------------------------------------------------------- */ diff --git a/include/Leases.h b/include/Leases.h index 2b5418b4e9..ab283b088c 100644 --- a/include/Leases.h +++ b/include/Leases.h @@ -284,7 +284,7 @@ private: * @param db pointer to the database. * @return 0 on success. */ - int insert(SqlDB * db); + int insert(SqlDB * db, string& error_str); /** * Leases are added/removed/updated through add/del interface diff --git a/include/Nebula.h b/include/Nebula.h index d3baf79f70..baf4b31159 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -203,7 +203,7 @@ public: static string version() { - return "OpenNebula 1.5.0"; + return "OpenNebula 1.9.80"; }; void start(); @@ -232,10 +232,12 @@ private: { nebula_location = "/"; - mad_location = "/usr/lib/one/mads/"; - etc_location = "/etc/one/"; - log_location = "/var/log/one/"; - var_location = "/var/lib/one/"; + mad_location = "/usr/lib/one/mads/"; + etc_location = "/etc/one/"; + log_location = "/var/log/one/"; + var_location = "/var/lib/one/"; + hook_location = "/usr/share/one/hooks/"; + remotes_location = "/usr/lib/one/remotes/"; } else { @@ -246,10 +248,12 @@ private: nebula_location += "/"; } - mad_location = nebula_location + "lib/mads/"; - etc_location = nebula_location + "etc/"; - log_location = nebula_location + "var/"; - var_location = nebula_location + "var/"; + mad_location = nebula_location + "lib/mads/"; + etc_location = nebula_location + "etc/"; + log_location = nebula_location + "var/"; + var_location = nebula_location + "var/"; + hook_location = nebula_location + "share/hooks/"; + remotes_location = nebula_location + "lib/remotes/"; } }; @@ -345,6 +349,9 @@ private: string etc_location; string log_location; string var_location; + string hook_location; + string remotes_location; + string hostname; // --------------------------------------------------------------- diff --git a/include/NebulaLog.h b/include/NebulaLog.h index 3cb3147259..dccb57fa8c 100644 --- a/include/NebulaLog.h +++ b/include/NebulaLog.h @@ -64,21 +64,29 @@ public: } static void log( - const char * module, - const Log::MessageType type, - const char * message) + const char * module, + const Log::MessageType type, + const char * message) { logger->log(module,type,message); }; static void log( - const char * module, - const Log::MessageType type, + const char * module, + const Log::MessageType type, const ostringstream& message) { logger->log(module,type,message.str().c_str()); }; + static void log( + const char * module, + const Log::MessageType type, + const string& message) + { + logger->log(module,type,message.c_str()); + }; + private: NebulaLog(){}; ~NebulaLog(){}; diff --git a/include/ObjectSQL.h b/include/ObjectSQL.h index 17e00f20d9..2043260f68 100644 --- a/include/ObjectSQL.h +++ b/include/ObjectSQL.h @@ -49,7 +49,8 @@ protected: * @return 0 on success */ virtual int insert( - SqlDB * db) = 0; + SqlDB * db, + string& error_str) = 0; /** * Updates the ObjectSQL in the database. diff --git a/include/PoolSQL.h b/include/PoolSQL.h index 74ffb85fe5..187fb066e2 100644 --- a/include/PoolSQL.h +++ b/include/PoolSQL.h @@ -46,7 +46,7 @@ public: * @param table the name of the table supporting the pool (to set the oid * counter). If null the OID counter is not updated. */ - PoolSQL(SqlDB * _db, const char * table=0); + PoolSQL(SqlDB * _db, const char * table); virtual ~PoolSQL(); @@ -57,7 +57,8 @@ public: * @return the oid assigned to the object or -1 in case of failure */ virtual int allocate( - PoolObjectSQL *objsql); + PoolObjectSQL *objsql, + string& error_str); /** * Gets an object from the pool (if needed the object is loaded from the diff --git a/include/RequestManager.h b/include/RequestManager.h index 5d9a135b84..e0d5a2cb39 100644 --- a/include/RequestManager.h +++ b/include/RequestManager.h @@ -57,7 +57,7 @@ public: ; /** - * This functions starts the associated listener thread (XML server), and + * This functions starts the associated listener thread (XML server), and * creates a new thread for the Request Manager. This thread will wait in * an action loop till it receives ACTION_FINALIZE. * @return 0 on success. @@ -74,7 +74,7 @@ public: }; /** - * + * */ void finalize() { @@ -110,17 +110,17 @@ private: * Pointer to the Host Pool, to access hosts */ HostPool * hpool; - + /** * Pointer to the VN Pool, to access Virtual Netowrks */ VirtualNetworkPool * vnpool; - + /** * Pointer to the User Pool, to access users */ UserPool * upool; - + /** * Pointer to the Image Pool, to access images */ @@ -130,10 +130,10 @@ private: * Port number where the connection will be open */ int port; - + /* * FD for the XML server socket - */ + */ int socket_fd; /** @@ -164,16 +164,16 @@ private: void do_action(const string & action, void * arg); void register_xml_methods(); - + int setup_socket(); - + // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // Error Messages // ---------------------------------------------------------------------- - // ---------------------------------------------------------------------- - - + // ---------------------------------------------------------------------- + + /** * Logs authorization errors * @param method name of the RM method where the error arose @@ -183,17 +183,17 @@ private: * @param id id of the object, -1 for Pool * @returns string for logging */ - static string authorization_error (const string& method, - const string &action, - const string &object, + static string authorization_error (const string& method, + const string &action, + const string &object, int uid, int id) { ostringstream oss; - oss << "[" << method << "]" << " User [" << uid << "] not authorized" - << " to perform " << action << " on " << object; - - + oss << "[" << method << "]" << " User [" << uid << "] not authorized" + << " to perform " << action << " on " << object; + + if ( id != -1 ) { oss << " [" << id << "]."; @@ -202,25 +202,25 @@ private: { oss << " Pool"; } - + return oss.str(); } - + /** * Logs authenticate errors * @param method name of the RM method where the error arose * @returns string for logging - */ + */ static string authenticate_error (const string& method) { ostringstream oss; - + oss << "[" << method << "]" << " User couldn't be authenticated," << " aborting call."; - + return oss.str(); } - + /** * Logs get object errors * @param method name of the RM method where the error arose @@ -228,52 +228,52 @@ private: * @param id of the object over which the get failed * @returns string for logging */ - static string get_error (const string& method, - const string &object, + static string get_error (const string& method, + const string &object, int id) { ostringstream oss; - - oss << "[" << method << "]" << " Error getting " << + + oss << "[" << method << "]" << " Error getting " << object; - + if ( id != -1 ) { oss << " [" << id << "]."; } else { - oss << " Pool."; + oss << " Pool."; } - + return oss.str(); } - + /** * Logs action errors * @param method name of the RM method where the error arose * @param action that triggered the error * @param object over which the action was applied - * @param id id of the object, -1 for Pool, -2 for no-id objects + * @param id id of the object, -1 for Pool, -2 for no-id objects * (allocate error, parse error) * @param rc returned error code (NULL to ignore) * @returns string for logging */ static string action_error (const string& method, - const string &action, - const string &object, + const string &action, + const string &object, int id, int rc) { ostringstream oss; - + oss << "[" << method << "]" << " Error trying to " << action << " " << object; - + switch(id) { case -2: - break; + break; case -1: oss << "Pool."; break; @@ -281,15 +281,15 @@ private: oss << " [" << id << "]."; break; } - + if ( rc != 0 ) { - oss << " Returned error code [" << rc << "]."; + oss << " Returned error code [" << rc << "]."; } - + return oss.str(); } - + // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // XML-RPC Methods @@ -297,7 +297,7 @@ private: // ---------------------------------------------------------------------- /* ---------------------------------------------------------------------- */ - /* Virtual Machine Interface */ + /* Virtual Machine Interface */ /* ---------------------------------------------------------------------- */ class VirtualMachineAllocate: public xmlrpc_c::method { @@ -327,9 +327,9 @@ private: ImagePool * ipool; UserPool * upool; }; - + /* ---------------------------------------------------------------------- */ - + class VirtualMachineDeploy: public xmlrpc_c::method { public: @@ -356,7 +356,7 @@ private: HostPool * hpool; UserPool * upool; }; - + /* ---------------------------------------------------------------------- */ class VirtualMachineAction: public xmlrpc_c::method @@ -384,7 +384,7 @@ private: }; /* ---------------------------------------------------------------------- */ - + class VirtualMachineMigrate: public xmlrpc_c::method { public: @@ -410,10 +410,10 @@ private: VirtualMachinePool * vmpool; HostPool * hpool; UserPool * upool; - }; - + }; + /* ---------------------------------------------------------------------- */ - + class VirtualMachineInfo: public xmlrpc_c::method { public: @@ -478,7 +478,7 @@ private: vmpool(_vmpool), upool(_upool) { - _signature="A:si"; + _signature="A:sibi"; _help="Returns the virtual machine pool"; }; @@ -491,10 +491,10 @@ private: private: VirtualMachinePool * vmpool; UserPool * upool; - }; - + }; + /* ---------------------------------------------------------------------- */ - /* Host Interface */ + /* Host Interface */ /* ---------------------------------------------------------------------- */ class HostAllocate: public xmlrpc_c::method @@ -522,7 +522,7 @@ private: }; /* ---------------------------------------------------------------------- */ - + class HostInfo: public xmlrpc_c::method { public: @@ -548,7 +548,7 @@ private: }; /* ---------------------------------------------------------------------- */ - + class HostPoolInfo: public xmlrpc_c::method { public: @@ -573,7 +573,7 @@ private: }; /* ---------------------------------------------------------------------- */ - + class HostDelete: public xmlrpc_c::method { public: @@ -597,9 +597,9 @@ private: HostPool * hpool; UserPool * upool; }; - + /* ---------------------------------------------------------------------- */ - + class HostEnable: public xmlrpc_c::method { public: @@ -622,7 +622,7 @@ private: private: HostPool * hpool; UserPool * upool; - }; + }; /* ---------------------------------------------------------------------- */ /* Cluster Interface */ @@ -784,10 +784,10 @@ private: /* ---------------------------------------------------------------------- */ - /* Virtual Network Interface */ + /* Virtual Network Interface */ /* ---------------------------------------------------------------------- */ - - + + class VirtualNetworkAllocate: public xmlrpc_c::method { public: @@ -810,10 +810,10 @@ private: private: VirtualNetworkPool * vnpool; UserPool * upool; - }; - + }; + /* ---------------------------------------------------------------------- */ - + class VirtualNetworkInfo: public xmlrpc_c::method { public: @@ -832,14 +832,14 @@ private: void execute( xmlrpc_c::paramList const& paramList, xmlrpc_c::value * const retvalP); - + private: VirtualNetworkPool * vnpool; UserPool * upool; }; - + /* ---------------------------------------------------------------------- */ - + class VirtualNetworkPoolInfo: public xmlrpc_c::method { public: @@ -862,7 +862,7 @@ private: VirtualNetworkPool * vnpool; UserPool * upool; }; - + /* ---------------------------------------------------------------------- */ class VirtualNetworkPublish: public xmlrpc_c::method @@ -916,10 +916,10 @@ private: }; /* ---------------------------------------------------------------------- */ - /* User Management Interface */ + /* User Management Interface */ /* ---------------------------------------------------------------------- */ - - + + class UserAllocate: public xmlrpc_c::method { public: @@ -1001,7 +1001,7 @@ private: private: UserPool * upool; }; - + /* ---------------------------------------------------------------------- */ /* Image Pool Interface */ /* ---------------------------------------------------------------------- */ @@ -1027,10 +1027,10 @@ private: private: ImagePool * ipool; UserPool * upool; - }; - + }; + /* ---------------------------------------------------------------------- */ - + class ImageDelete: public xmlrpc_c::method { public: @@ -1052,8 +1052,8 @@ private: private: ImagePool * ipool; UserPool * upool; - }; - + }; + /* ---------------------------------------------------------------------- */ class ImageInfo: public xmlrpc_c::method @@ -1077,8 +1077,8 @@ private: private: ImagePool * ipool; UserPool * upool; - }; - + }; + /* ---------------------------------------------------------------------- */ class ImageUpdate: public xmlrpc_c::method @@ -1103,7 +1103,7 @@ private: ImagePool * ipool; UserPool * upool; }; - + /* ---------------------------------------------------------------------- */ class ImageRemoveAttribute: public xmlrpc_c::method @@ -1128,7 +1128,7 @@ private: ImagePool * ipool; UserPool * upool; }; - + /* ---------------------------------------------------------------------- */ class ImagePublish: public xmlrpc_c::method @@ -1153,7 +1153,32 @@ private: ImagePool * ipool; UserPool * upool; }; - + + /* ---------------------------------------------------------------------- */ + + class ImagePersistent: public xmlrpc_c::method + { + public: + ImagePersistent(ImagePool * _ipool, + UserPool * _upool): + ipool(_ipool), + upool(_upool) + { + _signature="A:sib"; + _help="Make an Image (non)persistent"; + }; + + ~ImagePersistent(){}; + + void execute( + xmlrpc_c::paramList const& paramList, + xmlrpc_c::value * const retvalP); + + private: + ImagePool * ipool; + UserPool * upool; + }; + /* ---------------------------------------------------------------------- */ class ImageEnable: public xmlrpc_c::method @@ -1178,7 +1203,7 @@ private: ImagePool * ipool; UserPool * upool; }; - + /* ---------------------------------------------------------------------- */ class ImagePoolInfo: public xmlrpc_c::method @@ -1205,7 +1230,7 @@ private: }; }; - + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/Template.h b/include/Template.h index d4763a7370..4294f6efef 100644 --- a/include/Template.h +++ b/include/Template.h @@ -21,6 +21,9 @@ #include #include +#include +#include + #include "Attribute.h" using namespace std; @@ -165,12 +168,36 @@ public: friend ostream& operator<<(ostream& os, const Template& t); + /** + * Rebuilds the template from a xml formatted string + * @param xml_str The xml-formatted string + * + * @return 0 on success, -1 otherwise + */ + int from_xml(const string &xml_str); + protected: /** * The template attributes */ multimap attributes; + /** + * Builds a SingleAttribute from the given node + * @param node The xml element to build the attribute from. + * + * @return the attribute, or 0 if the node doesn't contain a single att. + */ + Attribute* single_xml_att(const xmlNode * node); + + /** + * Builds a VectorAttribute from the given node + * @param node The xml element to build the attribute from. + * + * @return the attribute, or 0 if the node doesn't contain a vector att. + */ + Attribute* vector_xml_att(const xmlNode * node); + private: bool replace_mode; diff --git a/include/TemplateSQL.h b/include/TemplateSQL.h deleted file mode 100644 index 3c219475ae..0000000000 --- a/include/TemplateSQL.h +++ /dev/null @@ -1,130 +0,0 @@ -/* ------------------------------------------------------------------------ */ -/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */ -/* */ -/* 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 TEMPLATE_SQL_H_ -#define TEMPLATE_SQL_H_ - -#include -#include -#include - -#include "Template.h" -#include "SqlDB.h" -#include "ObjectSQL.h" - -using namespace std; - -/** - * SQL Template class, it provides DB support for template objects - */ -class TemplateSQL : public Template, public ObjectSQL -{ -public: - TemplateSQL( - const char * _table, - int template_id = -1, - bool replace = false, - const char separator = '=', - const char * xml_root = "TEMPLATE"): - Template(replace,separator,xml_root),table(_table),id(template_id) - {}; - - virtual ~TemplateSQL(){}; - -protected: - - //Database implementation variables - - const char * table; - - static const char * db_names; - - //Template attributes - - /** - * Template unique identification. - */ - int id; - - /** - * Writes the template in the DB - * @param db pointer to the database. - * @return 0 on success. - */ - int insert(SqlDB * db); - - /** - * Updates the template in the DB - * @param db pointer to the database. - * @return 0 on success. - */ - int update(SqlDB *db); - - /** - * Reads the template (identified by its id) from the DB - * @param db pointer to the database. - * @return 0 on success. - */ - int select(SqlDB *db); - - /** - * Removes the template from the DB - * @param db pointer to the database. - */ - int drop(SqlDB *db); - - /** - * Execute an INSERT or REPLACE Sql query. - * @param db The SQL DB - * @param replace Execute an INSERT or a REPLACE - * @return 0 one success - */ - int insert_replace(SqlDB *db, bool replace); - - /** - * Removes a template attribute from the DB. If there are multiple - * attributes with the same name, only one will be replaced. The - * attribute MUST be allocated in the heap. - * @param db pointer to the database. - * @param attribute pointer to the new attribute. - */ - int replace_attribute(SqlDB * db, Attribute * attribute); - - /** - * Insert a given attribute (MUST be allocated in the heap) in the template - * and updates the DB. - * @param db pointer to the database. - * @param attribute pointer to the new attribute - */ - int insert_attribute(SqlDB * db, Attribute * attribute); - - /** - * Remove a given attribute from the template and the DB. - * @param db pointer to the database. - * @param name name of the attribute - */ - int remove_attribute(SqlDB * db, const string& name); - - /** - * Callback to recover template attributes (TemplateSQL::select) - */ - int select_cb(void *nil, int num, char **values, char **names); -}; - -/* ------------------------------------------------------------------------ */ -/* ------------------------------------------------------------------------ */ - -#endif /*TEMPLATE_SQL_H_*/ diff --git a/include/User.h b/include/User.h index b4dc75f597..473c5f29b8 100644 --- a/include/User.h +++ b/include/User.h @@ -235,7 +235,7 @@ protected: * @param db pointer to the db * @return 0 on success */ - virtual int insert(SqlDB *db); + virtual int insert(SqlDB *db, string& error_str); /** * Writes/updates the User data fields in the database. diff --git a/include/UserPool.h b/include/UserPool.h index 7a1aa2ae24..3c96cdf683 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -48,10 +48,11 @@ public: * @return the oid assigned to the object or -1 in case of failure */ int allocate ( - int * oid, - string hostname, - string password, - bool enabled); + int * oid, + string hostname, + string password, + bool enabled, + string& error_str); /** * Function to get a User from the pool, if the object is not in memory diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 8330967428..1f9d0da607 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -598,6 +598,28 @@ public: vm_template->get(str,value); } + /** + * Adds a new attribute to the template (replacing it if + * already defined), the vm's mutex SHOULD be locked + * @param name of the new attribute + * @param value of the new attribute + * @return 0 on success + */ + int replace_template_attribute( + string& name, + string& value) + { + SingleAttribute * sattr; + + vm_template->erase(name); + + sattr = new SingleAttribute(name,value); + vm_template->set(sattr); + + return 0; + } + + /** * Generates a XML string for the template of the VM * @param xml the string to store the XML description. @@ -713,7 +735,7 @@ public: * Get all disk images for this Virtual Machine * @return 0 if success */ - int get_disk_images(); + int get_disk_images(string &error_str); /** * Releases all disk images taken by this Virtual Machine @@ -869,11 +891,9 @@ private: static void bootstrap(SqlDB * db) { ostringstream oss_vm(VirtualMachine::db_bootstrap); - ostringstream oss_tmpl(VirtualMachineTemplate::db_bootstrap); ostringstream oss_hist(History::db_bootstrap); db->exec(oss_vm); - db->exec(oss_tmpl); db->exec(oss_hist); }; @@ -925,44 +945,6 @@ private: return -1; }; - /** - * Updates the template of a VM, adding a new attribute (replacing it if - * already defined), the vm's mutex SHOULD be locked - * @param db pointer to the database - * @param name of the new attribute - * @param value of the new attribute - * @return 0 on success - */ - int update_template_attribute( - SqlDB * db, - string& name, - string& value) - { - SingleAttribute * sattr; - int rc; - - sattr = new SingleAttribute(name,value); - rc = vm_template->replace_attribute(db,sattr); - - if (rc != 0) - { - delete sattr; - } - - return rc; - } - - /** - * Inserts a new attribute in the template of a VM, also the DB is - * updated. The vm's mutex SHOULD be locked - * @param db pointer to the database - * @param attribute the new attribute for the template - * @return 0 on success - */ - int insert_template_attribute(SqlDB * db, Attribute * attribute) - { - return vm_template->insert_attribute(db,attribute); - } // ------------------------------------------------------------------------- // Attribute Parser @@ -1023,7 +1005,8 @@ protected: NET_TX = 11, NET_RX = 12, LAST_SEQ = 13, - LIMIT = 14 + TEMPLATE = 14, + LIMIT = 15 }; static const char * table; @@ -1044,7 +1027,7 @@ protected: * @param db pointer to the db * @return 0 on success */ - virtual int insert(SqlDB * db); + virtual int insert(SqlDB * db, string& error_str); /** * Writes/updates the Virtual Machine data fields in the database. @@ -1074,6 +1057,18 @@ protected: * @return 0 on success */ static int dump(ostringstream& oss, int num, char ** values, char ** names); + + /** + * Dumps the contect of a set of VirtualMachine objects in the given stream + * using XML format + * @param oss the output stream + * @param num the number of columns read from the DB + * @param names the column names + * @param vaues the column values + * @return 0 on success + */ + static int dump_extended( ostringstream& oss, + int num, char ** values, char ** names); }; #endif /*VIRTUAL_MACHINE_H_*/ diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index fe8ca25bae..7d7f3a77fe 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -32,7 +32,9 @@ class VirtualMachinePool : public PoolSQL { public: - VirtualMachinePool(SqlDB * db, vector hook_mads); + VirtualMachinePool(SqlDB * db, + vector hook_mads, + const string& hook_location); ~VirtualMachinePool(){}; @@ -48,8 +50,9 @@ public: int allocate ( int uid, VirtualMachineTemplate *vm_template, - int * oid, - bool on_hold = false); + int * oid, + string& error_str, + bool on_hold = false); /** * Function to get a VM from the pool, if the object is not in memory @@ -90,22 +93,6 @@ public: // Virtual Machine DB access functions //-------------------------------------------------------------------------- - /** - * Updates the template of a VM, adding a new attribute (replacing it if - * already defined), the vm's mutex SHOULD be locked - * @param vm pointer to the virtual machine object - * @param name of the new attribute - * @param value of the new attribute - * @return 0 on success - */ - int update_template_attribute( - VirtualMachine * vm, - string& name, - string& value) - { - return vm->update_template_attribute(db,name,value); - } - /** * Updates the history record of a VM, the vm's mutex SHOULD be locked * @param vm pointer to the virtual machine object @@ -145,7 +132,24 @@ public: * * @return 0 on success */ - int dump(ostringstream& oss, const string& where); + int dump(ostringstream& oss, const string& where) + { + return dump(oss, true, -1, where); + } + + /** + * Dumps the VM pool in XML format. A filter can be also added to the query + * Also the hostname where the VirtualMachine is running is added to the + * pool + * @param oss the output stream to dump the pool contents + * @param where filter for the objects, defaults to all + * @param extended condition to include history and username data + * @param state include only VMs in this state. -1 means any state, + * except DONE + * + * @return 0 on success + */ + int dump(ostringstream& oss, bool extended, int state, const string& where); private: /** @@ -166,6 +170,17 @@ private: * @return 0 on success */ int dump_cb(void * _oss, int num, char **values, char **names); + + /** + * Callback function to get output the vm pool in XML format + * (VirtualMachinePool::dump) + * @param num the number of columns read from the DB + * @param names the column names + * @param vaues the column values + * @return 0 on success + */ + int dump_extended_cb(void * _oss, int num, char **values, char **names); + }; #endif /*VIRTUAL_MACHINE_POOL_H_*/ diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index c661663dd2..62053e61b4 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -17,29 +17,25 @@ #ifndef VIRTUAL_MACHINE_TEMPLATE_H_ #define VIRTUAL_MACHINE_TEMPLATE_H_ -#include "TemplateSQL.h" +#include "Template.h" using namespace std; /** * Virtual Machine Template class, it represents a VM configuration file. */ -class VirtualMachineTemplate : public TemplateSQL +class VirtualMachineTemplate : public Template { public: - VirtualMachineTemplate(int tid = -1): - TemplateSQL(table,tid,false,'=',"TEMPLATE"){}; + VirtualMachineTemplate(): + Template(false,'=',"TEMPLATE"){}; ~VirtualMachineTemplate(){}; - + private: friend class VirtualMachine; - - static const char * table; - - static const char * db_bootstrap; }; - + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index 509fb04db5..33172da74e 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -313,11 +313,9 @@ private: static void bootstrap(SqlDB * db) { ostringstream oss_vnet(VirtualNetwork::db_bootstrap); - ostringstream oss_templ(VirtualNetworkTemplate::db_bootstrap); ostringstream oss_lease(Leases::db_bootstrap); db->exec(oss_vnet); - db->exec(oss_templ); db->exec(oss_lease); }; @@ -337,34 +335,6 @@ private: int vn_drop(SqlDB * db); - - /** - * Updates the template of a VNW, adding a new attribute (replacing it if - * already defined), the VN's mutex SHOULD be locked - * @param db pointer to the DB - * @param name of the new attribute - * @param value of the new attribute - * @return 0 on success - */ - int update_template_attribute( - SqlDB * db, - string& name, - string& value) - { - SingleAttribute * sattr; - int rc; - - sattr = new SingleAttribute(name,value); - rc = vn_template->replace_attribute(db,sattr); - - if (rc != 0) - { - delete sattr; - } - - return rc; - } - protected: //************************************************************************** @@ -387,7 +357,8 @@ protected: TYPE = 3, BRIDGE = 4, PUBLIC = 5, - LIMIT = 6 + TEMPLATE = 6, + LIMIT = 7 }; static const char * table; @@ -408,7 +379,7 @@ protected: * @param db pointer to the db * @return 0 on success */ - int insert(SqlDB * db); + int insert(SqlDB * db, string& error_str); /** * Writes/updates the Virtual Network data fields in the database. @@ -428,9 +399,7 @@ protected: { int rc; - rc = vn_template->drop(db); - - rc += leases->drop(db); + rc = leases->drop(db); rc += vn_drop(db); diff --git a/include/VirtualNetworkPool.h b/include/VirtualNetworkPool.h index f57c53037b..7286c8d88b 100644 --- a/include/VirtualNetworkPool.h +++ b/include/VirtualNetworkPool.h @@ -49,7 +49,8 @@ public: int allocate ( int uid, VirtualNetworkTemplate * vn_template, - int * oid); + int * oid, + string& error_str); /** * Function to get a VN from the pool, if the object is not in memory @@ -96,22 +97,6 @@ public: */ void authorize_nic(VectorAttribute * nic, AuthRequest * ar); - /** - * Updates the template of a VN, adding a new attribute (replacing it if - * already defined), the VN's mutex SHOULD be locked - * @param vn pointer to the virtual network object - * @param name of the new attribute - * @param value of the new attribute - * @return 0 on success - */ - int update_template_attribute( - VirtualNetwork * vn, - string& name, - string& value) - { - return vn->update_template_attribute(db,name,value); - }; - /** * Bootstraps the database table(s) associated to the VirtualNetwork pool */ diff --git a/include/VirtualNetworkTemplate.h b/include/VirtualNetworkTemplate.h index 82cb99473d..c611345996 100644 --- a/include/VirtualNetworkTemplate.h +++ b/include/VirtualNetworkTemplate.h @@ -17,29 +17,22 @@ #ifndef VIRTUAL_NETWORK_TEMPLATE_H_ #define VIRTUAL_NETWORK_TEMPLATE_H_ -#include "TemplateSQL.h" +#include "Template.h" using namespace std; /** * Virtual Network Template class, it represents a VN configuration file. */ -class VirtualNetworkTemplate : public TemplateSQL +class VirtualNetworkTemplate : public Template { public: - VirtualNetworkTemplate(int tid = -1): - TemplateSQL(table,tid,false,'=',"TEMPLATE"){}; + VirtualNetworkTemplate(): + Template(false,'=',"TEMPLATE"){}; ~VirtualNetworkTemplate(){}; - -private: - friend class VirtualNetwork; - - static const char * table; - - static const char * db_bootstrap; }; - + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/vnm/VirtualNetworkTemplate.cc b/include/mem_collector.h similarity index 56% rename from src/vnm/VirtualNetworkTemplate.cc rename to include/mem_collector.h index 790de8eebf..95ef4bce95 100644 --- a/src/vnm/VirtualNetworkTemplate.cc +++ b/include/mem_collector.h @@ -14,10 +14,42 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ -#include "VirtualNetworkTemplate.h" +#ifndef MEM_COLLECTOR_H_ +#define MEM_COLLECTOR_H_ -const char * VirtualNetworkTemplate::table = "vn_template"; +#define MEM_COLLECTOR_CHUNK 100 -const char * VirtualNetworkTemplate::db_bootstrap = "CREATE TABLE IF NOT EXISTS" - " vn_template (id INTEGER, name TEXT, type INTEGER, value TEXT)"; +/** + * mem_collector. A simple struct to track strdup'ed strings in lex parsers. + * It prevents memory leaks in case of parse errors + */ +typedef struct mem_collector_ +{ + char** str_buffer; + int size; + int next; +} mem_collector; + +/** + * Initialize mem_collector internal memory buffers. MUST be called before + * using any relared function + * @param mc pointer to the mem_collector + */ +void mem_collector_init(mem_collector * mc); + +/** + * Frees mem_collector internal resources. + * @param mc pointer to the mem_collector + */ +void mem_collector_cleanup(mem_collector * mc); + +/** + * Strdup's a string + * @param mc pointer to the mem_collector + * @param str string to be copied + * @return pointer to the new string + */ +char * mem_collector_strdup(mem_collector *mc, const char * str); + +#endif /*MEM_COLLECTOR_H_*/ diff --git a/install.sh b/install.sh index a9172bdba4..782168eaff 100755 --- a/install.sh +++ b/install.sh @@ -99,7 +99,7 @@ if [ -z "$ROOT" ] ; then RUN_LOCATION="/var/run/one" LOCK_LOCATION="/var/lock/one" INCLUDE_LOCATION="/usr/include" - SHARE_LOCATION="/usr/share/doc/opennebula" + SHARE_LOCATION="/usr/share/one" if [ "$CLIENT" = "no" ]; then MAKE_DIRS="$BIN_LOCATION $LIB_LOCATION $ETC_LOCATION $VAR_LOCATION \ @@ -151,10 +151,9 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \ $ETC_LOCATION/im_xen \ $ETC_LOCATION/im_ec2 \ $ETC_LOCATION/im_eh \ - $ETC_LOCATION/vmm_kvm \ - $ETC_LOCATION/vmm_xen \ $ETC_LOCATION/vmm_ec2 \ $ETC_LOCATION/vmm_eh \ + $ETC_LOCATION/vmm_sh \ $ETC_LOCATION/tm_nfs \ $ETC_LOCATION/tm_ssh \ $ETC_LOCATION/tm_dummy \ @@ -164,7 +163,13 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \ $ETC_LOCATION/ec2query_templates \ $ETC_LOCATION/occi_templates" -LIB_DIRS="$LIB_LOCATION/im_probes \ +LIB_DIRS="$LIB_LOCATION/remotes \ + $LIB_LOCATION/remotes/im \ + $LIB_LOCATION/remotes/im/common.d \ + $LIB_LOCATION/remotes/im/kvm.d \ + $LIB_LOCATION/remotes/im/xen.d \ + $LIB_LOCATION/remotes/vmm/xen \ + $LIB_LOCATION/remotes/vmm/kvm \ $LIB_LOCATION/ruby \ $LIB_LOCATION/ruby/OpenNebula \ $LIB_LOCATION/ruby/cloud/ \ @@ -207,20 +212,25 @@ INSTALL_FILES[2]="LIB_FILES:$LIB_LOCATION" INSTALL_FILES[3]="RUBY_LIB_FILES:$LIB_LOCATION/ruby" INSTALL_FILES[4]="RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula" INSTALL_FILES[5]="MADS_LIB_FILES:$LIB_LOCATION/mads" -INSTALL_FILES[6]="IM_PROBES_LIB_FILES:$LIB_LOCATION/im_probes" -INSTALL_FILES[7]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs" -INSTALL_FILES[8]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh" -INSTALL_FILES[9]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy" -INSTALL_FILES[10]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm" -INSTALL_FILES[11]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples" -INSTALL_FILES[12]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm" -INSTALL_FILES[13]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks" -INSTALL_FILES[14]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud" -INSTALL_FILES[15]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe" -INSTALL_FILES[16]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views" -INSTALL_FILES[17]="ECO_BIN_FILES:$BIN_LOCATION" -INSTALL_FILES[18]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi" -INSTALL_FILES[19]="OCCI_BIN_FILES:$BIN_LOCATION" +INSTALL_FILES[6]="IM_PROBES_FILES:$LIB_LOCATION/remotes/im" +INSTALL_FILES[7]="IM_PROBES_COMMON_FILES:$LIB_LOCATION/remotes/im/common.d" +INSTALL_FILES[8]="IM_PROBES_KVM_FILES:$LIB_LOCATION/remotes/im/kvm.d" +INSTALL_FILES[9]="IM_PROBES_XEN_FILES:$LIB_LOCATION/remotes/im/xen.d" +INSTALL_FILES[10]="VMM_SH_KVM_SCRIPTS:$LIB_LOCATION/remotes/vmm/kvm" +INSTALL_FILES[11]="VMM_SH_XEN_SCRIPTS:$LIB_LOCATION/remotes/vmm/xen" +INSTALL_FILES[12]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs" +INSTALL_FILES[13]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh" +INSTALL_FILES[14]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy" +INSTALL_FILES[15]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm" +INSTALL_FILES[16]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples" +INSTALL_FILES[17]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm" +INSTALL_FILES[18]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks" +INSTALL_FILES[19]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud" +INSTALL_FILES[20]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe" +INSTALL_FILES[21]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views" +INSTALL_FILES[22]="ECO_BIN_FILES:$BIN_LOCATION" +INSTALL_FILES[23]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi" +INSTALL_FILES[24]="OCCI_BIN_FILES:$BIN_LOCATION" INSTALL_ECO_CLIENT_FILES[0]="COMMON_CLOUD_CLIENT_LIB_FILES:$LIB_LOCATION/ruby/cloud" INSTALL_ECO_CLIENT_FILES[1]="ECO_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/econe" @@ -231,24 +241,21 @@ INSTALL_OCCI_CLIENT_FILES[1]="OCCI_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/occ INSTALL_OCCI_CLIENT_FILES[2]="OCCI_BIN_CLIENT_FILES:$BIN_LOCATION" INSTALL_ETC_FILES[0]="ETC_FILES:$ETC_LOCATION" -INSTALL_ETC_FILES[1]="VMM_XEN_ETC_FILES:$ETC_LOCATION/vmm_xen" -INSTALL_ETC_FILES[2]="VMM_KVM_ETC_FILES:$ETC_LOCATION/vmm_kvm" -INSTALL_ETC_FILES[3]="VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2" -INSTALL_ETC_FILES[4]="VMM_EH_ETC_FILES:$ETC_LOCATION/vmm_eh" -INSTALL_ETC_FILES[5]="IM_XEN_ETC_FILES:$ETC_LOCATION/im_xen" -INSTALL_ETC_FILES[6]="IM_KVM_ETC_FILES:$ETC_LOCATION/im_kvm" -INSTALL_ETC_FILES[7]="IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2" -INSTALL_ETC_FILES[8]="IM_EH_ETC_FILES:$ETC_LOCATION/im_eh" -INSTALL_ETC_FILES[9]="TM_NFS_ETC_FILES:$ETC_LOCATION/tm_nfs" -INSTALL_ETC_FILES[10]="TM_SSH_ETC_FILES:$ETC_LOCATION/tm_ssh" -INSTALL_ETC_FILES[11]="TM_DUMMY_ETC_FILES:$ETC_LOCATION/tm_dummy" -INSTALL_ETC_FILES[12]="TM_LVM_ETC_FILES:$ETC_LOCATION/tm_lvm" -INSTALL_ETC_FILES[13]="HM_ETC_FILES:$ETC_LOCATION/hm" -INSTALL_ETC_FILES[14]="AUTH_ETC_FILES:$ETC_LOCATION/auth" -INSTALL_ETC_FILES[15]="ECO_ETC_FILES:$ETC_LOCATION" -INSTALL_ETC_FILES[16]="ECO_ETC_TEMPLATE_FILES:$ETC_LOCATION/ec2query_templates" -INSTALL_ETC_FILES[17]="OCCI_ETC_FILES:$ETC_LOCATION" -INSTALL_ETC_FILES[18]="OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates" +INSTALL_ETC_FILES[1]="VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2" +INSTALL_ETC_FILES[2]="VMM_EH_ETC_FILES:$ETC_LOCATION/vmm_eh" +INSTALL_ETC_FILES[3]="VMM_SH_ETC_FILES:$ETC_LOCATION/vmm_sh" +INSTALL_ETC_FILES[4]="IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2" +INSTALL_ETC_FILES[5]="IM_EH_ETC_FILES:$ETC_LOCATION/im_eh" +INSTALL_ETC_FILES[6]="TM_NFS_ETC_FILES:$ETC_LOCATION/tm_nfs" +INSTALL_ETC_FILES[7]="TM_SSH_ETC_FILES:$ETC_LOCATION/tm_ssh" +INSTALL_ETC_FILES[8]="TM_DUMMY_ETC_FILES:$ETC_LOCATION/tm_dummy" +INSTALL_ETC_FILES[9]="TM_LVM_ETC_FILES:$ETC_LOCATION/tm_lvm" +INSTALL_ETC_FILES[10]="HM_ETC_FILES:$ETC_LOCATION/hm" +INSTALL_ETC_FILES[11]="AUTH_ETC_FILES:$ETC_LOCATION/auth" +INSTALL_ETC_FILES[14]="ECO_ETC_FILES:$ETC_LOCATION" +INSTALL_ETC_FILES[15]="ECO_ETC_TEMPLATE_FILES:$ETC_LOCATION/ec2query_templates" +INSTALL_ETC_FILES[16]="OCCI_ETC_FILES:$ETC_LOCATION" +INSTALL_ETC_FILES[17]="OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates" #------------------------------------------------------------------------------- # Binary files, to be installed under $BIN_LOCATION @@ -278,10 +285,7 @@ LIB_FILES="" # Ruby library files, to be installed under $LIB_LOCATION/ruby #------------------------------------------------------------------------------- -RUBY_LIB_FILES="src/mad/ruby/one_mad.rb \ - src/mad/ruby/one_ssh.rb \ - src/mad/ruby/ThreadScheduler.rb \ - src/mad/ruby/ActionManager.rb \ +RUBY_LIB_FILES="src/mad/ruby/ActionManager.rb \ src/mad/ruby/CommandManager.rb \ src/mad/ruby/OpenNebulaDriver.rb \ src/mad/ruby/VirtualMachineDriver.rb \ @@ -306,29 +310,33 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \ src/oca/ruby/OpenNebula/VirtualNetworkPool.rb \ src/oca/ruby/OpenNebula/Image.rb \ src/oca/ruby/OpenNebula/ImagePool.rb \ + src/oca/ruby/OpenNebula/ImageRepository.rb \ src/oca/ruby/OpenNebula/Cluster.rb \ src/oca/ruby/OpenNebula/ClusterPool.rb \ src/oca/ruby/OpenNebula/XMLUtils.rb" + #------------------------------------------------------------------------------- # Driver executable files, to be installed under $LIB_LOCATION/mads #------------------------------------------------------------------------------- MADS_LIB_FILES="src/mad/sh/madcommon.sh \ src/tm_mad/tm_common.sh \ - src/vmm_mad/xen/one_vmm_xen.rb \ - src/vmm_mad/xen/one_vmm_xen \ - src/vmm_mad/kvm/one_vmm_kvm.rb \ - src/vmm_mad/kvm/one_vmm_kvm \ + src/vmm_mad/sh/one_vmm_sh.rb \ + src/vmm_mad/sh/one_vmm_sh \ src/vmm_mad/ec2/one_vmm_ec2.rb \ src/vmm_mad/ec2/one_vmm_ec2 \ src/vmm_mad/eh/one_vmm_eh.rb \ src/vmm_mad/eh/one_vmm_eh \ + src/vmm_mad/dummy/one_vmm_dummy.rb \ + src/vmm_mad/dummy/one_vmm_dummy \ src/im_mad/im_ssh/one_im_ssh.rb \ src/im_mad/im_ssh/one_im_ssh \ src/im_mad/ec2/one_im_ec2.rb \ src/im_mad/ec2/one_im_ec2 \ src/im_mad/eh/one_im_eh.rb \ src/im_mad/eh/one_im_eh \ + src/im_mad/dummy/one_im_dummy.rb \ + src/im_mad/dummy/one_im_dummy \ src/tm_mad/one_tm \ src/tm_mad/one_tm.rb \ src/hm_mad/one_hm.rb \ @@ -337,14 +345,45 @@ MADS_LIB_FILES="src/mad/sh/madcommon.sh \ src/authm_mad/one_auth_mad" #------------------------------------------------------------------------------- -# Information Manager Probes, to be installed under $LIB_LOCATION/im_probes +# VMM SH Driver KVM scripts, to be installed under $REMOTES_LOCATION/vmm/kvm #------------------------------------------------------------------------------- -IM_PROBES_LIB_FILES="src/im_mad/xen/xen.rb \ - src/im_mad/kvm/kvm.rb \ - src/im_mad/host_probes/architecture.sh \ - src/im_mad/host_probes/cpu.sh \ - src/im_mad/host_probes/name.sh" +VMM_SH_KVM_SCRIPTS="src/vmm_mad/remotes/kvm/cancel \ + src/vmm_mad/remotes/kvm/deploy \ + src/vmm_mad/remotes/kvm/kvmrc \ + src/vmm_mad/remotes/kvm/migrate \ + src/vmm_mad/remotes/kvm/poll \ + src/vmm_mad/remotes/kvm/restore \ + src/vmm_mad/remotes/kvm/save \ + src/vmm_mad/remotes/kvm/shutdown" + +#------------------------------------------------------------------------------- +# VMM SH Driver Xen scripts, to be installed under $REMOTES_LOCATION/vmm/xen +#------------------------------------------------------------------------------- + +VMM_SH_XEN_SCRIPTS="src/vmm_mad/remotes/xen/cancel \ + src/vmm_mad/remotes/xen/deploy \ + src/vmm_mad/remotes/xen/xenrc \ + src/vmm_mad/remotes/xen/migrate \ + src/vmm_mad/remotes/xen/poll \ + src/vmm_mad/remotes/xen/restore \ + src/vmm_mad/remotes/xen/save \ + src/vmm_mad/remotes/xen/shutdown" + +#------------------------------------------------------------------------------- +# Information Manager Probes, to be installed under $LIB_LOCATION/remotes +#------------------------------------------------------------------------------- + +IM_PROBES_FILES="src/im_mad/remotes/run_probes" + +IM_PROBES_COMMON_FILES="src/im_mad/remotes/common.d/architecture.sh \ + src/im_mad/remotes/common.d/cpu.sh \ + src/im_mad/remotes/common.d/name.sh" + +IM_PROBES_XEN_FILES="src/im_mad/remotes/xen.d/xen.rb" + +IM_PROBES_KVM_FILES="src/im_mad/remotes/kvm.d/kvm.rb" + #------------------------------------------------------------------------------- # Transfer Manager commands, to be installed under $LIB_LOCATION/tm_commands @@ -389,37 +428,27 @@ ETC_FILES="share/etc/oned.conf \ #------------------------------------------------------------------------------- # Virtualization drivers config. files, to be installed under $ETC_LOCATION -# - xen, $ETC_LOCATION/vmm_xen -# - kvm, $ETC_LOCATION/vmm_kvm # - ec2, $ETC_LOCATION/vmm_ec2 # - eh, $ETC_LOCATION/vmm_eh +# - sh, $ETC_LOCATION/vmm_sh #------------------------------------------------------------------------------- -VMM_XEN_ETC_FILES="src/vmm_mad/xen/vmm_xenrc \ - src/vmm_mad/xen/vmm_xen.conf" - -VMM_KVM_ETC_FILES="src/vmm_mad/kvm/vmm_kvmrc \ - src/vmm_mad/kvm/vmm_kvm.conf" - VMM_EC2_ETC_FILES="src/vmm_mad/ec2/vmm_ec2rc \ src/vmm_mad/ec2/vmm_ec2.conf" VMM_EH_ETC_FILES="src/vmm_mad/eh/vmm_ehrc \ src/vmm_mad/eh/vmm_eh.conf" +VMM_SH_ETC_FILES="src/vmm_mad/sh/vmm_shrc \ + src/vmm_mad/sh/vmm_sh_kvm.conf \ + src/vmm_mad/sh/vmm_sh_xen.conf" + + #------------------------------------------------------------------------------- # Information drivers config. files, to be installed under $ETC_LOCATION -# - xen, $ETC_LOCATION/im_xen -# - kvm, $ETC_LOCATION/im_kvm # - ec2, $ETC_LOCATION/im_ec2 #------------------------------------------------------------------------------- -IM_XEN_ETC_FILES="src/im_mad/xen/im_xenrc \ - src/im_mad/xen/im_xen.conf" - -IM_KVM_ETC_FILES="src/im_mad/kvm/im_kvmrc \ - src/im_mad/kvm/im_kvm.conf" - IM_EC2_ETC_FILES="src/im_mad/ec2/im_ec2rc \ src/im_mad/ec2/im_ec2.conf" @@ -579,19 +608,6 @@ if [ "$UNINSTALL" = "no" ] ; then done fi -# --- Prepare oned.conf --- - -if [ "$UNINSTALL" = "no" -a "$CLIENT" = "no" ]; then - TEMPLATE=share/etc/oned.conf.template - SOURCE=share/etc/oned.conf - cp $TEMPLATE $SOURCE - HOOKS_LOCATION=$SHARE_LOCATION/hooks - sed -i -e "s%\[HOOKS_LOCATION\]%$HOOKS_LOCATION%" \ - $SOURCE - sed -i -e "s%\[IMAGES_LOCATION\]%$IMAGES_LOCATION%" \ - $SOURCE -fi - # --- Install/Uninstall files --- do_file() { diff --git a/share/etc/oned.conf.template b/share/etc/oned.conf similarity index 83% rename from share/etc/oned.conf.template rename to share/etc/oned.conf index 439c01053c..4033353643 100644 --- a/share/etc/oned.conf.template +++ b/share/etc/oned.conf @@ -82,7 +82,7 @@ MAC_PREFIX = "02:00" # vd KVM virtual disk #******************************************************************************* -IMAGE_REPOSITORY_PATH = [IMAGES_LOCATION] +#IMAGE_REPOSITORY_PATH = /srv/cloud/var/images DEFAULT_IMAGE_TYPE = "OS" DEFAULT_DEVICE_PREFIX = "hd" @@ -103,22 +103,26 @@ DEFAULT_DEVICE_PREFIX = "hd" # /etc/one/ if OpenNebula was installed in /) #******************************************************************************* -#IM_MAD = [ -# name = "im_xen", -# executable = "one_im_ssh", -# arguments = "im_xen/im_xen.conf" ] - #------------------------------------------------------------------------------- -# KVM Information Driver Manager sample configuration +# KVM Information Driver Manager Configuration #------------------------------------------------------------------------------- IM_MAD = [ name = "im_kvm", executable = "one_im_ssh", - arguments = "im_kvm/im_kvm.conf" ] + arguments = "kvm" ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- -# EC2 Information Driver Manager sample configuration +# XEN Information Driver Manager Configuration +#------------------------------------------------------------------------------- +#IM_MAD = [ +# name = "im_xen", +# executable = "one_im_ssh", +# arguments = "xen" ] +#------------------------------------------------------------------------------- + +#------------------------------------------------------------------------------- +# EC2 Information Driver Manager Configuration #------------------------------------------------------------------------------- #IM_MAD = [ # name = "im_ec2", @@ -126,6 +130,12 @@ IM_MAD = [ # arguments = "im_ec2/im_ec2.conf" ] #------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- +# Dummy Information Driver Manager Configuration +#------------------------------------------------------------------------------- +#IM_MAD = [ name="im_dummy", executable="one_im_dummy"] +#------------------------------------------------------------------------------- + #******************************************************************************* # Virtualization Driver Configuration #******************************************************************************* @@ -147,24 +157,30 @@ IM_MAD = [ # type : driver type, supported drivers: xen, kvm, xml #******************************************************************************* -#VM_MAD = [ -# name = "vmm_xen", -# executable = "one_vmm_xen", -# default = "vmm_xen/vmm_xen.conf", -# type = "xen" ] - #------------------------------------------------------------------------------- -# KVM Virtualization Driver Manager sample configuration +# KVM Virtualization Driver Manager Configuration #------------------------------------------------------------------------------- VM_MAD = [ name = "vmm_kvm", - executable = "one_vmm_kvm", - default = "vmm_kvm/vmm_kvm.conf", + executable = "one_vmm_sh", + arguments = "kvm", + default = "vmm_sh/vmm_sh_kvm.conf", type = "kvm" ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- -# EC2 Virtualization Driver Manager sample configuration +# XEN Virtualization Driver Manager Configuration +#------------------------------------------------------------------------------- +#VM_MAD = [ +# name = "vmm_xen", +# executable = "one_vmm_sh", +# arguments = "xen", +# default = "vmm_sh/vmm_sh_xen.conf", +# type = "xen" ] +#------------------------------------------------------------------------------- + +#------------------------------------------------------------------------------- +# EC2 Virtualization Driver Manager Configuration # arguments: default values for the EC2 driver, can be an absolute path or # relative to $ONE_LOCATION/etc (or /etc/one/ if OpenNebula was # installed in /). @@ -176,6 +192,12 @@ VM_MAD = [ # type = "xml" ] #------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- +# Dummy Virtualization Driver Configuration +#------------------------------------------------------------------------------- +#VM_MAD = [ name="vmm_dummy", executable="one_vmm_dummy", type="xml" ] +#------------------------------------------------------------------------------- + #******************************************************************************* # Transfer Manager Driver Configuration #******************************************************************************* @@ -192,13 +214,8 @@ VM_MAD = [ # /etc/one/ if OpenNebula was installed in /) #******************************************************************************* -#TM_MAD = [ -# name = "tm_ssh", -# executable = "one_tm", -# arguments = "tm_ssh/tm_ssh.conf" ] - #------------------------------------------------------------------------------- -# NFS Transfer Manager Driver sample configuration +# NFS Transfer Manager Driver Configuration #------------------------------------------------------------------------------- TM_MAD = [ name = "tm_nfs", @@ -207,7 +224,16 @@ TM_MAD = [ #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- -# Dummy Transfer Manager Driver sample configuration +# SSH Transfer Manager Driver Configuration +#------------------------------------------------------------------------------- +#TM_MAD = [ +# name = "tm_ssh", +# executable = "one_tm", +# arguments = "tm_ssh/tm_ssh.conf" ] +#------------------------------------------------------------------------------- + +#------------------------------------------------------------------------------- +# Dummy Transfer Manager Driver Configuration #------------------------------------------------------------------------------- #TM_MAD = [ # name = "tm_dummy", @@ -216,7 +242,7 @@ TM_MAD = [ #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- -# LVM Transfer Manager Driver sample configuration +# LVM Transfer Manager Driver Configuration #------------------------------------------------------------------------------- #TM_MAD = [ # name = "tm_lvm", @@ -244,7 +270,9 @@ TM_MAD = [ # - SHUTDOWN, after the VM is shutdown # - STOP, after the VM is stopped (including VM image transfers) # - DONE, after the VM is deleted or shutdown -# command : use absolute path here +# command : path can be absolute or relative to $ONE_LOCATION/share/hooks +# case of self-contained installation or relative to +# /usr/share/one/hooks in case of system-wide installation # arguments : for the hook. You can access to VM template variables with $ # - $ATTR, the value of an attribute e.g. $NAME or $VMID # - $ATTR[VAR], the value of a vector e.g. $NIC[MAC] @@ -266,7 +294,7 @@ HM_MAD = [ VM_HOOK = [ name = "image", on = "DONE", - command = "[HOOKS_LOCATION]/image.rb", + command = "image.rb", arguments = "$VMID" ] #------------------------------------------------------------------------------- diff --git a/share/examples/vm.template b/share/examples/vm.template index 223064b2bb..2d6b97fd9e 100644 --- a/share/examples/vm.template +++ b/share/examples/vm.template @@ -26,6 +26,8 @@ DISK = [ target = "sda2", readonly = "no" ] +DISK = [ IMAGE ="Ubuntu Server" ] + # --- 1 NIC --- NIC = [ mac="00:ff:72:17:20:27"] diff --git a/share/hooks/image.rb b/share/hooks/image.rb index 2d42ea53ca..8709a7d65f 100755 --- a/share/hooks/image.rb +++ b/share/hooks/image.rb @@ -37,6 +37,7 @@ end client = Client.new() +img_repo = ImageRepository.new vm = VirtualMachine.new( VirtualMachine.build_xml(vm_id), @@ -52,17 +53,8 @@ vm.each('TEMPLATE/DISK') do |disk| Image.build_xml(image_id), client) - result = image.info - exit -1 if OpenNebula.is_error?(result) - - # Disable the Image for a safe overwriting - # image.disable - - # Save the image file - result = image.move(source_path, image['SOURCE']) + result = img_repo.update_source(image, source_path) exit -1 if OpenNebula.is_error?(result) - - # image.enable end end diff --git a/share/scripts/one b/share/scripts/one index 5514bd29dd..df90024a5a 100755 --- a/share/scripts/one +++ b/share/scripts/one @@ -16,11 +16,12 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -if [ -z "$ONE_LOCATION" ]; then +if [ -z "$ONE_LOCATION" ]; then ONE_PID=/var/run/one/oned.pid ONE_SCHEDPID=/var/run/one/sched.pid ONE_CONF=/etc/one/oned.conf ONE_DB=/var/lib/one/one.db + ONE_LOG=/var/log/one/oned.log ONED=/usr/bin/oned ONE_SCHEDULER=/usr/bin/mm_sched @@ -31,29 +32,31 @@ else ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid ONE_CONF=$ONE_LOCATION/etc/oned.conf ONE_DB=$ONE_LOCATION/var/one.db + ONE_LOG=$ONE_LOCATION/var/oned.log ONED=$ONE_LOCATION/bin/oned ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched - + LOCK_FILE=$ONE_LOCATION/var/.lock -fi +fi setup() { - PORT=`cat $ONE_CONF | grep ^PORT= | cut -d= -f2` + PORT=$(sed -n '/^[ \t]*PORT/s/^.*PORT\s*=\s*\([0-9]\+\)\s*.*$/\1/p' \ + $ONE_CONF) if [ $? -ne 0 ]; then echo "Can not find PORT in $ONE_CONF." exit 1 fi - + if [ -f $LOCK_FILE ]; then if [ -f $ONE_PID ]; then ONEPID=`cat $ONE_PID` ps $ONEPID > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first." - exit 1 + exit 1 fi fi if [ -f $ONE_SCHEDPID ]; then @@ -73,12 +76,12 @@ start() { if [ ! -x "$ONED" ]; then echo "Can not find $ONED." - exit 1 + exit 1 fi if [ ! -x "$ONE_SCHEDULER" ]; then echo "Can not find $ONE_SCHEDULER." - exit 1 + exit 1 fi if [ ! -f "$ONE_DB" ]; then @@ -91,28 +94,34 @@ start() fi fi fi - + + + # Backup oned.log + if [ "$BACKUP" = "true" ];then + [ -f "$ONE_LOG" ] && cp $ONE_LOG{,.$(date '+%Y%m%d%H%M')} + fi + # Start the one daemon - $ONED -f 2>&1 & - + $ONED -f 2>&1 & + LASTRC=$? LASTPID=$! if [ $LASTRC -ne 0 ]; then echo "Error executing $ONED" - exit 1 + exit 1 else echo $LASTPID > $ONE_PID fi - + sleep 1 ps $LASTPID > /dev/null 2>&1 - + if [ $? -ne 0 ]; then echo "Error executing $ONED." exit 1 fi - + # Start the scheduler # The following command line arguments are supported by mm_shed: # [-p port] to connect to oned - default: 2633 @@ -123,7 +132,7 @@ start() # - default: 30 # [-h host dispatch] max number of VMs dispatched to a given host in each # scheduling action - default: 1 - + $ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1& LASTRC=$? @@ -131,11 +140,11 @@ start() if [ $LASTRC -ne 0 ]; then echo "Error executing $ONE_SCHEDULER" - exit 1 + exit 1 else echo $LASTPID > $ONE_SCHEDPID fi - + echo "oned and scheduler started" } @@ -159,7 +168,7 @@ stop() kill `cat $ONE_PID` > /dev/null 2>&1 # Kill the scheduler - + kill `cat $ONE_SCHEDPID` > /dev/null 2>&1 # Remove pid files @@ -170,6 +179,10 @@ stop() echo "oned and scheduler stopped" } +if [ "$1" = "-b" ]; then + BACKUP=true + shift +fi case "$1" in start) @@ -180,7 +193,10 @@ case "$1" in stop ;; *) - echo "Usage: one {start|stop}" >&2 + echo "Usage: one [-b] {start|stop}" >&2 + echo "Options:" >&2 + echo " -b Backup log file." >&2 exit 3 ;; esac + diff --git a/share/test/do_tests.sh b/share/test/do_tests.sh index 8d5c766099..5d62e96cb8 100755 --- a/share/test/do_tests.sh +++ b/share/test/do_tests.sh @@ -85,7 +85,13 @@ TESTS=`find $TWD_DIR -name test -type d | grep -v ruby` for i in $TESTS ; do cd $BASE_DIR + echo ; echo + echo "#####################################################################" + echo "#####################################################################" echo "Doing $i ..." + echo "#####################################################################" + echo "#####################################################################" + echo ; echo cd $i if [ "$CLEAR" = "yes" ] ; then @@ -95,7 +101,13 @@ for i in $TESTS ; do scons $BUILD_ARGS else for j in `ls test*` ; do - $CALLER ./$j $TEST_ARGS + if [ -x $j ] ; then + echo ; echo "---------------------------------------------------------------------" + echo "Test Program: $j" + echo "---------------------------------------------------------------------" + $CALLER ./$j $TEST_ARGS + echo "---------------------------------------------------------------------" + fi done fi done diff --git a/src/authm/AuthManagerDriver.cc b/src/authm/AuthManagerDriver.cc index b45d42cda9..d37e07fd57 100644 --- a/src/authm/AuthManagerDriver.cc +++ b/src/authm/AuthManagerDriver.cc @@ -100,9 +100,10 @@ void AuthManagerDriver::protocol( else return; + getline(is,info); + if (action == "LOG") { - getline(is,info); NebulaLog::log("AuM",Log::INFO,info.c_str()); } else if (result == "SUCCESS") @@ -111,7 +112,6 @@ void AuthManagerDriver::protocol( } else { - getline(is,info); authm->notify_request(id,false,info); } diff --git a/src/authm/test/AuthManagerTest.cc b/src/authm/test/AuthManagerTest.cc index c2c13435fe..882d8b4a91 100644 --- a/src/authm/test/AuthManagerTest.cc +++ b/src/authm/test/AuthManagerTest.cc @@ -31,6 +31,9 @@ #include #include +#include +#include + using namespace std; @@ -54,7 +57,13 @@ class AuthManagerTest : public CppUnit::TestFixture public: AuthManagerTest(){}; - ~AuthManagerTest(){}; + ~AuthManagerTest(){ + /*OpenSSL internal tables are allocated when an application starts up. + Since such tables do not grow in size over time they are harmless. */ + + EVP_cleanup() ; + CRYPTO_cleanup_all_ex_data(); + }; /* ********************************************************************* */ diff --git a/src/authm/test/SConstruct b/src/authm/test/SConstruct index ff13ad409b..e1605f0142 100644 --- a/src/authm/test/SConstruct +++ b/src/authm/test/SConstruct @@ -74,6 +74,9 @@ main_env.Append(CPPFLAGS=[ main_env.Append(LIBPATH=["/usr/lib/mysql"]) main_env.Append(CPPPATH=["/usr/include/mysql"]) +# libxml2 +main_env.ParseConfig('xml2-config --libs --cflags') + sqlite=ARGUMENTS.get('sqlite', 'yes') if sqlite=='yes': main_env.Append(CPPFLAGS=["-DSQLITE_DB"]) diff --git a/src/authm_mad/ssh_auth.rb b/src/authm_mad/ssh_auth.rb index 1a16207637..9d089dee70 100644 --- a/src/authm_mad/ssh_auth.rb +++ b/src/authm_mad/ssh_auth.rb @@ -77,7 +77,7 @@ class SshAuth time=Time.now.to_i+expire proxy_text="#{user}:#{time}" proxy_crypted=encrypt(proxy_text) - proxy="#{user}:ssh:#{proxy_crypted}" + proxy="#{user}:plain:#{proxy_crypted}" file=get_proxy_file file.write(proxy) file.close diff --git a/src/cli/command_parse.rb b/src/cli/command_parse.rb index f3f55ee4cd..67bc4c1d91 100644 --- a/src/cli/command_parse.rb +++ b/src/cli/command_parse.rb @@ -31,7 +31,7 @@ Options: EOT ONE_VERSION=<<-EOT -OpenNebula 1.5.0 +OpenNebula 1.9.80 Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) EOT diff --git a/src/cli/onehost b/src/cli/onehost index 199a7f2a5b..c05c18fd32 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -189,6 +189,9 @@ Commands: * top (Lists hosts continuously) onehost top +* sync (synchronizes probes with remote hosts) + onehost sync + EOT def text_commands @@ -359,6 +362,14 @@ when "disable" end end +when "sync" + check_parameters("sync", 0) + if ONE_LOCATION + FileUtils.touch "#{ONE_LOCATION}/lib/remotes" + else + FileUtils.touch "/var/lib/one/remotes" + end + else onehost_opts.print_help exit -1 diff --git a/src/cli/oneimage b/src/cli/oneimage index 41a17186a4..878f3e4a3d 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -78,6 +78,13 @@ ShowTableImage={ :proc => lambda {|d,e| if d["PUBLIC"].to_i == 1 then "Yes" else "No" end} }, + :persistent => { + :name => "PERSISTENT", + :desc => "Whether the Image is persistent or not", + :size => 3, + :proc => lambda {|d,e| + if d["PERSISTENT"].to_i == 1 then "Yes" else "No" end} + }, :state => { :name => "STAT", :desc => "State of the Image", @@ -94,7 +101,7 @@ ShowTableImage={ }, :default => [:id, :user, :name, :type, :regtime, - :public, :state, :runningvms] + :public, :persistent, :state, :runningvms] } @@ -217,6 +224,12 @@ Commands: * unpublish (Unpublish an Image) oneimage unpublish +* persistent (Makes an Image persistent) + oneimage persistent + +* nonpersistent (Makes an Image non persistent) + oneimage nonpersistent + * list (Shows Images in the pool) oneimage list @@ -251,6 +264,11 @@ EOT table.print_help end + def special_options(opts, options) + opts.on_tail("-n", "--no-cp", "Do not copy the source") do |o| + options[:no_cp]=true + end + end end @@ -300,58 +318,18 @@ result=[false, "Unknown error"] command=ARGV.shift +img_repo = OpenNebula::ImageRepository.new + case command -when "register", "create", "add" - # ---------- Get the Template ------------ - +when "register", "create", "add" check_parameters("register", 1) template = get_template(ARGV[0]) - - # ---------- Allocate the Image file ------------ - image = OpenNebula::Image.new( - OpenNebula::Image.build_xml, - get_one_client) - - result = image.allocate(template) - - if !is_successful?(result) - puts result.message - exit -1 - end + image = OpenNebula::Image.new(OpenNebula::Image.build_xml, get_one_client) - # ---------- Copy the Image file ------------ - - image.info - - if image['TEMPLATE/PATH'] - file_path = image['TEMPLATE/PATH'] - - if !File.exists?(file_path) - error_msg = "Image file could not be found, aborting." - result = OpenNebula::Error.new(error_msg) - end - - result = image.copy(file_path, image['SOURCE']) - elsif image['TEMPLATE/SIZE'] and - image['TEMPLATE/FSTYPE'] and - image['TEMPLATE/TYPE'] == 'DATABLOCK' - result = image.mk_datablock( - image['TEMPLATE/SIZE'], - image['TEMPLATE/FSTYPE'], - image['SOURCE']) - else - error_msg = "Image not present, aborting." - result = OpenNebula::Error.new(error_msg) - end - - - if is_successful?(result) - image.enable + result = img_repo.create(image, template, !ops[:no_cp]) + if is_successful?(result) puts "ID: " + image.id.to_s if ops[:verbose] - exit 0 - else - image.delete end @@ -421,6 +399,28 @@ when "unpublish" puts "Image unpublished" if ops[:verbose] end +when "persistent" + check_parameters("publish", 1) + image_id=get_image_id(ARGV[0]) + + image=OpenNebula::Image.new_with_id(image_id, get_one_client) + + result=image.persistent + if is_successful?(result) + puts "Image made persistent" if ops[:verbose] + end + +when "nonpersistent" + check_parameters("nonpersistent", 1) + image_id=get_image_id(ARGV[0]) + + image=OpenNebula::Image.new_with_id(image_id, get_one_client) + + result=image.nonpersistent + if is_successful?(result) + puts "Image made nonpersistent" if ops[:verbose] + end + when "list" ops.merge!(get_user_flags) if !ops[:xml] @@ -494,22 +494,14 @@ when "delete" args=expand_args(ARGV) args.each do |param| - image_id=get_image_id(param) - - image=OpenNebula::Image.new_with_id(image_id, get_one_client) - - result = image.info + image_id = get_image_id(param) + image = OpenNebula::Image.new( + OpenNebula::Image.build_xml(image_id), + get_one_client) + result = img_repo.delete(image) if is_successful?(result) - - file_path = image['SOURCE'] - - result=image.delete - - if is_successful?(result) - FileUtils.rm(file_path) if File.exists?(file_path) - puts "Image correctly deleted" if ops[:verbose] - end + puts "Image correctly deleted" if ops[:verbose] end end diff --git a/src/cli/onevm b/src/cli/onevm index f9bc3fdaaa..955b3b6c43 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -344,7 +344,7 @@ Commands: * resume (Resumes the execution of a saved VM) onevm resume -* saveas (Set the specified vm's disk to be saved in a new image (image_name) +* saveas (Set the specified vms disk to be saved in a new image (image_name) when the vm shutdowns) onevm saveas @@ -785,6 +785,21 @@ true) puts + print_header(str_h1,"VIRTUAL MACHINE MONITORING",false) + + poll_attrs = { + "USED MEMORY" => "MEMORY", + "USED CPU" => "CPU", + "NET_TX" => "NET_TX", + "NET_RX" => "NET_RX" + } + + poll_attrs.each do |k,v| + puts str % [k,vm[v]] + end + + puts + print_header(str_h1,"VIRTUAL MACHINE TEMPLATE",false) puts vm.template_str diff --git a/src/cloud/common/CloudServer.rb b/src/cloud/common/CloudServer.rb index f15acad711..157da9366c 100755 --- a/src/cloud/common/CloudServer.rb +++ b/src/cloud/common/CloudServer.rb @@ -58,6 +58,7 @@ class CloudServer @one_client = Client.new() @user_pool = UserPool.new(@one_client) + @img_repo = OpenNebula::ImageRepository.new end # @@ -110,47 +111,23 @@ class CloudServer if file if file[:tempfile] file_path = file[:tempfile].path + template = image.to_one_template + template << "\nPATH = #{file_path}" else error_msg = "Image not present, aborting." error = OpenNebula::Error.new(error_msg) return error end - - if !File.exists?(file_path) - error_msg = "Image file could not be found, aborting." - error = OpenNebula::Error.new(error_msg) - return error - end end - # ---------- Allocate the Image file ------------ + rc = @img_repo.create(image, template) - rc = image.allocate(image.to_one_template) + file[:tempfile].unlink + if OpenNebula.is_error?(rc) return rc end - # ---------- Copy the Image file ------------ - - image.info - - if file_path - rc = image.copy(file_path, image['SOURCE']) - file[:tempfile].unlink - elsif image['TEMPLATE/SIZE'] and - image['TEMPLATE/FSTYPE'] and - image['TEMPLATE/TYPE'] == 'DATABLOCK' - rc = image.mk_datablock( - image['TEMPLATE/SIZE'], - image['TEMPLATE/FSTYPE'], - image['SOURCE']) - end - - if OpenNebula.is_error?(rc) - image.delete - return rc - end - return nil end diff --git a/src/cloud/ec2/lib/EC2QueryServer.rb b/src/cloud/ec2/lib/EC2QueryServer.rb index 8b6c46f3bc..625a67b52a 100644 --- a/src/cloud/ec2/lib/EC2QueryServer.rb +++ b/src/cloud/ec2/lib/EC2QueryServer.rb @@ -49,11 +49,11 @@ class EC2QueryServer < CloudServer 'susp' => :pending, 'done' => :terminated, 'fail' => :terminated, - 'prol' => :pend, + 'prol' => :pending, 'boot' => :running, 'runn' => :running, 'migr' => :running, - 'save' => :pend, + 'save' => :pending, 'epil' => :shutdown, 'shut' => :shutdown, 'fail' => :terminated, diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index a5b3abf2aa..6fd0a91290 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -311,10 +311,13 @@ class OCCIServer < CloudServer end # --- Create and Add the new Image --- + occixml = request.params['occixml'] + occixml = occixml[:tempfile].read if occixml.class == Hash + image = ImageOCCI.new( Image.build_xml, get_client(request.env), - request.params['occixml']) + occixml) rc = add_image(image, request.params['file']) return rc, 500 if OpenNebula.is_error?(rc) @@ -355,7 +358,7 @@ class OCCIServer < CloudServer get_client(request.env)) # --- Delete the Image --- - rc = image.delete + rc = @img_repo.delete(image) return rc, 500 if OpenNebula::is_error?(rc) return "", 204 diff --git a/src/cloud/occi/share/examples/compute b/src/cloud/occi/share/examples/compute new file mode 100644 index 0000000000..036efd45a5 --- /dev/null +++ b/src/cloud/occi/share/examples/compute @@ -0,0 +1,10 @@ + + MyCompute + large + + + + + + + diff --git a/src/common/SConstruct b/src/common/SConstruct index 7ca42d71df..f3837df491 100644 --- a/src/common/SConstruct +++ b/src/common/SConstruct @@ -23,7 +23,8 @@ lib_name='nebula_common' # Sources to generate the library source_files=[ 'ActionManager.cc', - 'Attribute.cc' + 'Attribute.cc', + 'mem_collector.c' ] # Build library diff --git a/src/common/mem_collector.c b/src/common/mem_collector.c new file mode 100644 index 0000000000..05698c582d --- /dev/null +++ b/src/common/mem_collector.c @@ -0,0 +1,90 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* 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 + +#include "mem_collector.h" + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void mem_collector_init(mem_collector * mc) +{ + int i; + + mc->str_buffer = (char **) malloc (sizeof(char*) * MEM_COLLECTOR_CHUNK); + mc->size = MEM_COLLECTOR_CHUNK; + mc->next = 0; + + for (i=0; i< mc->size ; i++) + { + mc->str_buffer[i] = 0; + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void mem_collector_cleanup(mem_collector * mc) +{ + int i; + + for (i=0; i< mc->size ; i++) + { + if ( mc->str_buffer[i] != 0 ) + { + free(mc->str_buffer[i]); + } + else /* No str's left in the pool */ + { + break; + } + } + + free(mc->str_buffer); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +char * mem_collector_strdup(mem_collector *mc, const char * str) +{ + int i, old_size; + char * new_str; + + if ( mc->next == mc->size ) + { + old_size = mc->size; + mc->size = mc->size + MEM_COLLECTOR_CHUNK; + + mc->str_buffer = (char **) realloc(mc->str_buffer, + sizeof(char*) * mc->size); + + for ( i = old_size ; i < mc->size ; i++) + { + mc->str_buffer[i] = 0; + } + } + + new_str = strdup(str); + mc->str_buffer[mc->next++] = new_str; + + return new_str; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ diff --git a/src/common/test/SConstruct b/src/common/test/SConstruct index 0fda9eeca8..b414b5ec6f 100644 --- a/src/common/test/SConstruct +++ b/src/common/test/SConstruct @@ -63,3 +63,4 @@ main_env.Append(LDFLAGS=["-g"]) main_env.Program('test_sa','single_attribute.cc') main_env.Program('test_va','vector_attribute.cc') main_env.Program('test_am','action_manager.cc') +main_env.Program('test_collector','mem_collector.cc') diff --git a/src/common/test/mem_collector.cc b/src/common/test/mem_collector.cc new file mode 100644 index 0000000000..19397c2031 --- /dev/null +++ b/src/common/test/mem_collector.cc @@ -0,0 +1,117 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* 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. */ +/* -------------------------------------------------------------------------- */ + +extern "C" +{ +#include "mem_collector.h" +} + +#include + +#include +#include +#include +#include +#include + +using namespace std; + +class MemCollectorTest : public CppUnit::TestFixture +{ +public: + void setUp() + { + } + + void tearDown() + { + } + + void test_all_free() + { + mem_collector mc; + + mem_collector_init(&mc); + + char * st1 = mem_collector_strdup(&mc,"HOLA"); + char * st2 = mem_collector_strdup(&mc,"ADIOS"); + char * st3 = mem_collector_strdup(&mc,"HELLO"); + char * st4 = mem_collector_strdup(&mc,"BYE"); + + CPPUNIT_ASSERT(strcmp(mc.str_buffer[0],"HOLA")==0); + CPPUNIT_ASSERT(strcmp(mc.str_buffer[1],"ADIOS")==0); + CPPUNIT_ASSERT(strcmp(mc.str_buffer[2],"HELLO")==0); + CPPUNIT_ASSERT(strcmp(mc.str_buffer[3],"BYE")==0); + + //Check the content of the strings + CPPUNIT_ASSERT(strcmp(st1,"HOLA")==0); + CPPUNIT_ASSERT(strcmp(st2,"ADIOS")==0); + CPPUNIT_ASSERT(strcmp(st3,"HELLO")==0); + CPPUNIT_ASSERT(strcmp(st4,"BYE")==0); + + mem_collector_cleanup(&mc); + + CPPUNIT_ASSERT(mc.size == MEM_COLLECTOR_CHUNK); + } + + void test_realloc() + { + mem_collector mc; + int max_size; + + max_size = (MEM_COLLECTOR_CHUNK * 3) + 5; + + mem_collector_init(&mc); + + for (int i=0; i < max_size ; i++) + { + mem_collector_strdup(&mc,"HOLA"); + } + + for (int i=0; i < max_size ; i++) + { + CPPUNIT_ASSERT(strcmp(mc.str_buffer[i],"HOLA")==0); + } + + mem_collector_cleanup(&mc); + + CPPUNIT_ASSERT(mc.size == MEM_COLLECTOR_CHUNK * 4); + } + + static CppUnit::TestSuite * suite() + { + CppUnit::TestSuite *ts=new CppUnit::TestSuite("mem_collector Tests"); + + ts->addTest(new CppUnit::TestCaller( + "test_all_free() Test", + &MemCollectorTest::test_all_free)); + + ts->addTest(new CppUnit::TestCaller( + "test_realloc() Test", + &MemCollectorTest::test_realloc)); + return ts; + } +}; + +int main(int argc, char ** argv) +{ + CppUnit::TextUi::TestRunner tr; + + tr.addTest(MemCollectorTest::suite()); + tr.run(); + + return 0; +} diff --git a/src/host/ClusterPool.cc b/src/host/ClusterPool.cc index ff91cc98e2..edf3c4e84a 100644 --- a/src/host/ClusterPool.cc +++ b/src/host/ClusterPool.cc @@ -30,7 +30,7 @@ const string ClusterPool::DEFAULT_CLUSTER_NAME = "default"; /* -------------------------------------------------------------------------- */ -int ClusterPool::allocate(int * clid, string name, SqlDB *db) +int ClusterPool::allocate(int * clid, string name, SqlDB *db, string& error_str) { int rc; map::iterator it; @@ -60,16 +60,16 @@ int ClusterPool::allocate(int * clid, string name, SqlDB *db) error_existing_name: - oss << "Could not allocate new cluster: Name \"" - << name << "\" already exists."; + oss << "Could not allocate new cluster: " + << name << ", already exists."; goto error_common; error_db: - oss << "Could not allocate new cluster \"" << name - << "\": Database returned error code " << rc << "."; + oss << "Could not allocate new cluster " << name << "."; goto error_common; error_common: + error_str = oss.str(); NebulaLog::log("CLUSTER", Log::ERROR, oss); *clid = -1; diff --git a/src/host/Host.cc b/src/host/Host.cc index 0edf917b43..bd44089dce 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -41,10 +41,9 @@ Host::Host( tm_mad_name(_tm_mad_name), last_monitored(0), cluster(ClusterPool::DEFAULT_CLUSTER_NAME), - host_template(id) + host_template() {} - Host::~Host(){} /* ************************************************************************ */ @@ -54,13 +53,13 @@ Host::~Host(){} const char * Host::table = "host_pool"; const char * Host::db_names = "(oid,host_name,state,im_mad,vm_mad," - "tm_mad,last_mon_time, cluster)"; + "tm_mad,last_mon_time, cluster, template)"; const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool (" - "oid INTEGER PRIMARY KEY,host_name VARCHAR(512), state INTEGER," + "oid INTEGER PRIMARY KEY,host_name VARCHAR(256), state INTEGER," "im_mad VARCHAR(128),vm_mad VARCHAR(128),tm_mad VARCHAR(128)," - "last_mon_time INTEGER, cluster VARCHAR(128), " - "UNIQUE(host_name, im_mad, vm_mad, tm_mad) )"; + "last_mon_time INTEGER, cluster VARCHAR(128), template TEXT, " + "UNIQUE(host_name))"; /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ @@ -75,6 +74,7 @@ int Host::select_cb(void * nil, int num, char **values, char ** names) (!values[TM_MAD]) || (!values[LAST_MON_TIME]) || (!values[CLUSTER]) || + (!values[TEMPLATE]) || (num != LIMIT )) { return -1; @@ -92,7 +92,8 @@ int Host::select_cb(void * nil, int num, char **values, char ** names) cluster = values[CLUSTER]; - host_template.id = oid; + host_template.from_xml(values[TEMPLATE]); + host_share.hsid = oid; return 0; @@ -122,9 +123,6 @@ int Host::select(SqlDB *db) return -1; } - // Get the template - rc = host_template.select(db); - if ( rc != 0 ) { return -1; @@ -144,37 +142,22 @@ int Host::select(SqlDB *db) /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ -int Host::insert(SqlDB *db) +int Host::insert(SqlDB *db, string& error_str) { int rc; map::iterator iter; - // Set up the template ID, to insert it - if ( host_template.id == -1 ) - { - host_template.id = oid; - } - // Set up the share ID, to insert it if ( host_share.hsid == -1 ) { host_share.hsid = oid; } - // Update the Template - rc = host_template.insert(db); - - if ( rc != 0 ) - { - return rc; - } - // Update the HostShare - rc = host_share.insert(db); + rc = host_share.insert(db, error_str); if ( rc != 0 ) { - host_template.drop(db); return rc; } @@ -183,7 +166,7 @@ int Host::insert(SqlDB *db) if ( rc != 0 ) { - host_template.drop(db); + error_str = "Error inserting Host in DB."; host_share.drop(db); return rc; @@ -199,14 +182,6 @@ int Host::update(SqlDB *db) { int rc; - // Update the Template needed by the monitoring action from IM - rc = host_template.update(db); - - if ( rc != 0 ) - { - return rc; - } - // Update the HostShare rc = host_share.update(db); @@ -235,12 +210,14 @@ int Host::insert_replace(SqlDB *db, bool replace) ostringstream oss; int rc; + string xml_template; char * sql_hostname; char * sql_im_mad_name; char * sql_tm_mad_name; char * sql_vmm_mad_name; char * sql_cluster; + char * sql_template; // Update the Host @@ -279,6 +256,14 @@ int Host::insert_replace(SqlDB *db, bool replace) goto error_cluster; } + host_template.to_xml(xml_template); + sql_template = db->escape_str(xml_template.c_str()); + + if ( sql_template == 0 ) + { + goto error_template; + } + if(replace) { oss << "REPLACE"; @@ -291,14 +276,15 @@ int Host::insert_replace(SqlDB *db, bool replace) // Construct the SQL statement to Insert or Replace oss <<" INTO "<< table <<" "<< db_names <<" VALUES (" - << oid << "," - << "'" << sql_hostname << "'," - << state << "," - << "'" << sql_im_mad_name << "'," - << "'" << sql_vmm_mad_name << "'," - << "'" << sql_tm_mad_name << "'," - << last_monitored << "," - << "'" << sql_cluster << "')"; + << oid << "," + << "'" << sql_hostname << "'," + << state << "," + << "'" << sql_im_mad_name << "'," + << "'" << sql_vmm_mad_name << "'," + << "'" << sql_tm_mad_name << "'," + << last_monitored << "," + << "'" << sql_cluster << "'," + << "'" << sql_template << "')"; rc = db->exec(oss); @@ -307,9 +293,12 @@ int Host::insert_replace(SqlDB *db, bool replace) db->free_str(sql_tm_mad_name); db->free_str(sql_vmm_mad_name); db->free_str(sql_cluster); + db->free_str(sql_template); return rc; +error_template: + db->free_str(sql_cluster); error_cluster: db->free_str(sql_vmm_mad_name); error_vmm: @@ -335,6 +324,7 @@ int Host::dump(ostringstream& oss, int num, char **values, char **names) (!values[TM_MAD]) || (!values[LAST_MON_TIME]) || (!values[CLUSTER]) || + (!values[TEMPLATE]) || (num != LIMIT + HostShare::LIMIT )) { return -1; @@ -349,7 +339,8 @@ int Host::dump(ostringstream& oss, int num, char **values, char **names) "" << values[VM_MAD] <<"" << "" << values[TM_MAD] <<"" << ""<< values[LAST_MON_TIME]<<""<< - "" << values[CLUSTER] <<""; + "" << values[CLUSTER] <<"" << + values[TEMPLATE]; HostShare::dump(oss,num - LIMIT, values + LIMIT, names + LIMIT); @@ -366,8 +357,6 @@ int Host::drop(SqlDB * db) ostringstream oss; int rc; - host_template.drop(db); - host_share.drop(db); oss << "DELETE FROM " << table << " WHERE oid=" << oid; diff --git a/src/host/HostPool.cc b/src/host/HostPool.cc index 7752d109da..96771cf2e1 100644 --- a/src/host/HostPool.cc +++ b/src/host/HostPool.cc @@ -70,10 +70,11 @@ HostPool::HostPool(SqlDB* db):PoolSQL(db,Host::table) int HostPool::allocate ( int * oid, - string hostname, - string im_mad_name, - string vmm_mad_name, - string tm_mad_name) + const string& hostname, + const string& im_mad_name, + const string& vmm_mad_name, + const string& tm_mad_name, + string& error_str) { Host * host; @@ -87,7 +88,7 @@ int HostPool::allocate ( // Insert the Object in the pool - *oid = PoolSQL::allocate(host); + *oid = PoolSQL::allocate(host, error_str); return *oid; } diff --git a/src/host/HostShare.cc b/src/host/HostShare.cc index 2a538e6ace..825536a652 100644 --- a/src/host/HostShare.cc +++ b/src/host/HostShare.cc @@ -197,12 +197,17 @@ int HostShare::select(SqlDB * db) /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ -int HostShare::insert(SqlDB * db) +int HostShare::insert(SqlDB * db, string& error_str) { int rc; rc = insert_replace(db, false); + if ( rc == -1 ) + { + error_str = "Error inserting Host Share in DB."; + } + return rc; } @@ -225,7 +230,7 @@ int HostShare::insert_replace(SqlDB *db, bool replace) { ostringstream oss; int rc; - + if(replace) { oss << "REPLACE"; @@ -234,7 +239,7 @@ int HostShare::insert_replace(SqlDB *db, bool replace) { oss << "INSERT"; } - + oss << " INTO " << table << " "<< db_names <<" VALUES (" << hsid << "," << disk_usage <<","<< mem_usage <<","<< cpu_usage<< "," @@ -242,7 +247,7 @@ int HostShare::insert_replace(SqlDB *db, bool replace) << free_disk <<","<< free_mem <<","<< free_cpu << "," << used_disk <<","<< used_mem <<","<< used_cpu << "," << running_vms<< ")"; - + rc = db->exec(oss); return rc; diff --git a/src/host/HostTemplate.cc b/src/host/HostTemplate.cc deleted file mode 100644 index 0f5c6ccfa1..0000000000 --- a/src/host/HostTemplate.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */ -/* */ -/* 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 "HostTemplate.h" - -const char * HostTemplate::table = "host_attributes"; - -const char * HostTemplate::db_bootstrap = "CREATE TABLE IF NOT EXISTS " - "host_attributes (id INTEGER, name VARCHAR(256), type INTEGER, value TEXT, " - "PRIMARY KEY(id,name))"; - diff --git a/src/host/SConstruct b/src/host/SConstruct index 4e0ef053f8..c87e054d76 100644 --- a/src/host/SConstruct +++ b/src/host/SConstruct @@ -25,7 +25,6 @@ source_files=[ 'Host.cc', 'HostShare.cc', 'HostPool.cc', - 'HostTemplate.cc', 'ClusterPool.cc', ] diff --git a/src/host/test/HostPoolTest.cc b/src/host/test/HostPoolTest.cc index 5d72de6f9b..e6e141ffdd 100644 --- a/src/host/test/HostPoolTest.cc +++ b/src/host/test/HostPoolTest.cc @@ -54,34 +54,34 @@ const string xmls[] = const string xml_dump = "0a0im_madvmm_madtm_mad0" - "default00default00000000000000" "1a name0im_madvmm_madtm_mad0default100default100000" "000000002a_name0im_madvmm_madtm_mad0defaulttm_mad0default200000000000003another " "name0im_madvmm_mad" - "tm_mad0defaulttm_mad0default300000000000004host0im_madvmm_madtm_mad" - "0default4" + "0default4" "000" "0000" "000vmm_madtm_mad0" - "default00default00000000000000" "1a name0im_madvmm_madtm_mad0default100default100000" "000000002a_name0im_madvmm_madtm_mad0defaulttm_mad0default200000000000003another " "name0im_madvmm_mad" - "tm_mad0defaulttm_mad0default30000000000000"; +const string host0_updated = + "0Host one0im_madvmm_madtm_mad0default00000000000000"; const string cluster_default = "0default"; @@ -149,6 +151,7 @@ class HostPoolTest : public PoolTest CPPUNIT_TEST (cluster_dump); CPPUNIT_TEST (set_cluster); CPPUNIT_TEST (remove_cluster); + CPPUNIT_TEST (update_info); CPPUNIT_TEST_SUITE_END (); @@ -166,9 +169,10 @@ protected: int allocate(int index) { - int oid; + int oid; + string err; return ((HostPool*)pool)->allocate(&oid, names[index], im_mad, - vmm_mad, tm_mad); + vmm_mad, tm_mad, err); }; void check(int index, PoolObjectSQL* obj) @@ -189,9 +193,9 @@ protected: public: - HostPoolTest(){}; + HostPoolTest(){xmlInitParser();}; - ~HostPoolTest(){}; + ~HostPoolTest(){xmlCleanupParser();}; /* ********************************************************************* */ @@ -232,33 +236,30 @@ public: int rc, oid_0, oid_1; HostPool * hp = static_cast(pool); Host * host; + string err; string tm_mad_2 = "another_tm_mad"; // If we try to allocate two hosts with the same name and drivers, // should fail - rc = hp->allocate(&oid_0, names[0], im_mad, vmm_mad, tm_mad); + rc = hp->allocate(&oid_0, names[0], im_mad, vmm_mad, tm_mad, err); CPPUNIT_ASSERT( oid_0 == 0 ); CPPUNIT_ASSERT( rc == oid_0 ); - rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad); + rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad, err); CPPUNIT_ASSERT( oid_1 == -1 ); CPPUNIT_ASSERT( rc == oid_1 ); - // But if the drivers change, the hostname can be repeated - rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad_2); - CPPUNIT_ASSERT( oid_1 == 1 ); + // the hostname can not be repeated if the drivers change + rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad_2, err); + CPPUNIT_ASSERT( oid_1 == -1 ); CPPUNIT_ASSERT( rc == oid_1 ); // Get the hosts and check them host = hp->get(oid_0, false); CPPUNIT_ASSERT( host != 0 ); CPPUNIT_ASSERT( host->get_tm_mad() == tm_mad ); - - host = hp->get(oid_1, false); - CPPUNIT_ASSERT( host != 0 ); - CPPUNIT_ASSERT( host->get_tm_mad() == tm_mad_2 ); } /* ********************************************************************* */ @@ -267,10 +268,12 @@ public: { string names[] = {"a", "a name", "a_name", "another name", "host"}; int rc, oid; + string err; for(int i=0; i<5; i++) { - ((HostPool*)pool)->allocate(&oid, names[i], im_mad, vmm_mad, tm_mad); + ((HostPool*)pool)->allocate(&oid, names[i], + im_mad, vmm_mad, tm_mad, err); } ostringstream oss; @@ -289,10 +292,12 @@ public: { string names[] = {"a", "a name", "a_name", "another name", "host"}; int rc, oid; + string err; for(int i=0; i<5; i++) { - ((HostPool*)pool)->allocate(&oid, names[i], im_mad, vmm_mad, tm_mad); + ((HostPool*)pool)->allocate(&oid, names[i], + im_mad, vmm_mad, tm_mad, err); } @@ -318,12 +323,13 @@ public: Host * host; HostPool * hp = static_cast(pool); ostringstream oss; + string err; for(i=0, oss.str(""); i<20; i++,oss.str("")) { oss << "host" << i; - hp->allocate(&oid, oss.str().c_str(), im_mad, vmm_mad, tm_mad); + hp->allocate(&oid, oss.str().c_str(), im_mad, vmm_mad, tm_mad, err); CPPUNIT_ASSERT(oid == i); if (i >=8 ) @@ -368,8 +374,9 @@ public: { HostPool * hp = static_cast(pool); int clid, rc; + string err; - rc = hp->allocate_cluster(&clid, "new_cluster"); + rc = hp->allocate_cluster(&clid, "new_cluster", err); CPPUNIT_ASSERT( rc == clid ); CPPUNIT_ASSERT( clid == 1 ); @@ -377,7 +384,7 @@ public: "1new_cluster"); // Try to allocate using the same name - rc = hp->allocate_cluster(&clid, "new_cluster"); + rc = hp->allocate_cluster(&clid, "new_cluster", err); CPPUNIT_ASSERT( rc == clid ); CPPUNIT_ASSERT( clid == -1 ); } @@ -388,13 +395,14 @@ public: { HostPool * hp = static_cast(pool); int clid, rc; + string err; // Drop a non-existing cluster rc = hp->drop_cluster(20); CPPUNIT_ASSERT( rc == -1 ); // Allocate a cluster and drop it - rc = hp->allocate_cluster(&clid, "new_cluster"); + rc = hp->allocate_cluster(&clid, "new_cluster", err); CPPUNIT_ASSERT( clid == 1); rc = hp->drop_cluster(clid); @@ -412,18 +420,19 @@ public: HostPool * hp = static_cast(pool); int clid, rc; ostringstream oss; + string err; // Allocate some clusters - rc = hp->allocate_cluster(&clid, "cluster_a"); + rc = hp->allocate_cluster(&clid, "cluster_a", err); CPPUNIT_ASSERT( rc == 1 ); - rc = hp->allocate_cluster(&clid, "cluster_b"); + rc = hp->allocate_cluster(&clid, "cluster_b", err); CPPUNIT_ASSERT( rc == 2 ); - rc = hp->allocate_cluster(&clid, "cluster_c"); + rc = hp->allocate_cluster(&clid, "cluster_c", err); CPPUNIT_ASSERT( rc == 3 ); - rc = hp->allocate_cluster(&clid, "cluster_d"); + rc = hp->allocate_cluster(&clid, "cluster_d", err); CPPUNIT_ASSERT( rc == 4 ); // Drop id 2 @@ -431,7 +440,7 @@ public: CPPUNIT_ASSERT( rc == 0 ); // Next one should use id 5, because the biggest id is 4 - rc = hp->allocate_cluster(&clid, "cluster_e"); + rc = hp->allocate_cluster(&clid, "cluster_e", err); CPPUNIT_ASSERT( rc == 5 ); // Drop id 5 @@ -439,7 +448,7 @@ public: CPPUNIT_ASSERT( rc == 0 ); // Next one should use id 5, because the biggest id is 4 again - rc = hp->allocate_cluster(&clid, "cluster_f"); + rc = hp->allocate_cluster(&clid, "cluster_f", err); CPPUNIT_ASSERT( rc == 5 ); } @@ -451,18 +460,19 @@ public: HostPool * hp = static_cast(pool); int clid, rc; ostringstream oss; + string err; // Allocate some clusters - rc = hp->allocate_cluster(&clid, "cluster_a"); + rc = hp->allocate_cluster(&clid, "cluster_a", err); CPPUNIT_ASSERT( rc == 1 ); - rc = hp->allocate_cluster(&clid, "cluster_b"); + rc = hp->allocate_cluster(&clid, "cluster_b", err); CPPUNIT_ASSERT( rc == 2 ); - rc = hp->allocate_cluster(&clid, "cluster_c"); + rc = hp->allocate_cluster(&clid, "cluster_c", err); CPPUNIT_ASSERT( rc == 3 ); - rc = hp->allocate_cluster(&clid, "cluster_d"); + rc = hp->allocate_cluster(&clid, "cluster_d", err); CPPUNIT_ASSERT( rc == 4 ); @@ -482,14 +492,16 @@ public: HostPool * hp = static_cast(pool); Host* host; int clid, rc, oid; - string xml_str; + string xml_str, err; // Allocate a host oid = allocate(0); + CPPUNIT_ASSERT(oid >= 0); host = hp->get(0, false); + CPPUNIT_ASSERT(host != 0); - rc = hp->allocate_cluster(&clid, "cluster_a"); + rc = hp->allocate_cluster(&clid, "cluster_a", err); CPPUNIT_ASSERT( rc == 1 ); rc = hp->set_cluster(host, clid); @@ -514,14 +526,16 @@ public: HostPool * hp = static_cast(pool); Host* host; int clid, rc, oid; - string xml_str; + string xml_str, err; // Allocate a host oid = allocate(0); + CPPUNIT_ASSERT(oid >= 0); host = hp->get(0, false); + CPPUNIT_ASSERT(host != 0); - rc = hp->allocate_cluster(&clid, "cluster_a"); + rc = hp->allocate_cluster(&clid, "cluster_a", err); CPPUNIT_ASSERT( rc == 1 ); // Set host 0 to cluster 1 @@ -540,6 +554,40 @@ public: host->to_xml(xml_str); check(0, host); } + + /* ********************************************************************* */ + + void update_info() + { + int rc; + int oid_1; + HostPool * hp = static_cast(pool); + Host* host; + string str; + + oid_1 = allocate(0); + + host = hp->get(oid_1, false); + CPPUNIT_ASSERT( host != 0 ); + + string info = "ATT_A=VALUE_A ATT_B=VALUE_B"; + rc = host->update_info(info); + + CPPUNIT_ASSERT(rc == 0); + + pool->update(host); + + host = hp->get(oid_1,false); + CPPUNIT_ASSERT( host != 0 ); + CPPUNIT_ASSERT( host->to_xml(str) == host0_updated ); + + //Now force access to DB + pool->clean(); + host = hp->get(oid_1,false); + + CPPUNIT_ASSERT( host != 0 ); + CPPUNIT_ASSERT( host->to_xml(str) == host0_updated ); + } }; diff --git a/src/host/test/SConstruct b/src/host/test/SConstruct index cefd0057e8..f3406c93d7 100644 --- a/src/host/test/SConstruct +++ b/src/host/test/SConstruct @@ -67,6 +67,10 @@ main_env.Append(LIBPATH=["/usr/lib/mysql"]) main_env.Append(CPPPATH=["/usr/include/mysql"]) +# libxml2 +main_env.ParseConfig('xml2-config --libs --cflags') + + sqlite=ARGUMENTS.get('sqlite', 'yes') if sqlite=='yes': main_env.Append(CPPFLAGS=["-DSQLITE_DB"]) diff --git a/src/im/InformationManager.cc b/src/im/InformationManager.cc index 5b374611cc..36f521dcd1 100644 --- a/src/im/InformationManager.cc +++ b/src/im/InformationManager.cc @@ -17,6 +17,9 @@ #include "InformationManager.h" #include "NebulaLog.h" +#include +#include + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -145,7 +148,7 @@ void InformationManager::timer_action() istringstream iss; // -------------- Max. number of hosts to monitor. --------------------- - int host_limit = 10; + int host_limit = 15; mark = mark + timer_period; @@ -164,6 +167,16 @@ void InformationManager::timer_action() thetime = time(0); + struct stat sb; + + if (stat(remotes_location.c_str(), &sb) == -1) + { + sb.st_mtime = 0; + + NebulaLog::log("InM",Log::ERROR,"Could not stat remotes directory, " + "will not update remotes."); + } + for(it=discovered_hosts.begin();it!=discovered_hosts.end();it++) { host = hpool->get(it->first,true); @@ -204,7 +217,15 @@ void InformationManager::timer_action() } else { - imd->monitor(it->first,host->get_hostname()); + bool update_remotes = false; + + if ((sb.st_mtime != 0) && + (sb.st_mtime > host->get_last_monitored())) + { + update_remotes = true; + } + + imd->monitor(it->first,host->get_hostname(),update_remotes); host->set_state(Host::MONITORING); } diff --git a/src/im/InformationManagerDriver.cc b/src/im/InformationManagerDriver.cc index 6b0cce0054..e67ee1a75a 100644 --- a/src/im/InformationManagerDriver.cc +++ b/src/im/InformationManagerDriver.cc @@ -23,13 +23,13 @@ /* Driver ASCII Protocol Implementation */ /* ************************************************************************** */ -void InformationManagerDriver::monitor ( - const int oid, - const string& host) const +void InformationManagerDriver::monitor(int oid, + const string& host, + bool update) const { ostringstream os; - os << "MONITOR " << oid << " " << host << endl; + os << "MONITOR " << oid << " " << host << " " << update << endl; write(os); } @@ -39,8 +39,8 @@ void InformationManagerDriver::monitor ( void InformationManagerDriver::protocol( string& message) -{ - istringstream is(message); +{ + istringstream is(message); //stores the action name string action; //stores the action result @@ -51,7 +51,7 @@ void InformationManagerDriver::protocol( ostringstream ess; string hinfo; Host * host; - + // Parse the driver message if ( is.good() ) @@ -84,61 +84,61 @@ void InformationManagerDriver::protocol( // ----------------------- // Protocol implementation // ----------------------- - + if ( action == "MONITOR" ) { host = hpool->get(id,true); - + if ( host == 0 ) { goto error_host; } - + if (result == "SUCCESS") - { - size_t pos; + { + size_t pos; int rc; - + ostringstream oss; - + getline (is,hinfo); - + for (pos=hinfo.find(',');pos!=string::npos;pos=hinfo.find(',')) { hinfo.replace(pos,1,"\n"); } hinfo += "\n"; - + oss << "Host " << id << " successfully monitored."; //, info: "<< hinfo; NebulaLog::log("InM",Log::DEBUG,oss); - + rc = host->update_info(hinfo); - + if (rc != 0) { goto error_parse_info; - } + } } else { - goto error_driver_info; + goto error_driver_info; } - + host->touch(true); - + hpool->update(host); - host->unlock(); + host->unlock(); } else if (action == "LOG") { string info; - + getline(is,info); NebulaLog::log("InM",Log::INFO,info.c_str()); } - + return; error_driver_info: @@ -146,27 +146,27 @@ error_driver_info: NebulaLog::log("InM", Log::ERROR, ess); goto error_common_info; - + error_parse_info: ess << "Error parsing host information: " << hinfo; NebulaLog::log("InM",Log::ERROR,ess); - + error_common_info: host->touch(false); - + hpool->update(host); - + host->unlock(); - + return; error_host: ess << "Could not get host " << id; NebulaLog::log("InM",Log::ERROR,ess); - + return; - + error_parse: ess << "Error while parsing driver message: " << message; diff --git a/src/im_mad/dummy/one_im_dummy b/src/im_mad/dummy/one_im_dummy new file mode 100755 index 0000000000..61d637dbbf --- /dev/null +++ b/src/im_mad/dummy/one_im_dummy @@ -0,0 +1,34 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad # +# Complutense de Madrid (dsa-research.org) # +# # +# 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. # +#--------------------------------------------------------------------------- # + +if [ -z "${ONE_LOCATION}" ]; then + MADCOMMON=/usr/lib/one/mads/madcommon.sh + VAR_LOCATION=/var/lib/one +else + MADCOMMON=$ONE_LOCATION/lib/mads/madcommon.sh + VAR_LOCATION=$ONE_LOCATION/var +fi + +. $MADCOMMON + +# Go to var directory ONE_LOCATION/var or /var/lib/one +cd $VAR_LOCATION + +# Execute the actual MAD +execute_mad $* diff --git a/src/im_mad/dummy/one_im_dummy.rb b/src/im_mad/dummy/one_im_dummy.rb new file mode 100755 index 0000000000..dcf7a8b8c5 --- /dev/null +++ b/src/im_mad/dummy/one_im_dummy.rb @@ -0,0 +1,78 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad # +# Complutense de Madrid (dsa-research.org) # +# # +# 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. # +#--------------------------------------------------------------------------- # + +ONE_LOCATION=ENV["ONE_LOCATION"] + +if !ONE_LOCATION + RUBY_LIB_LOCATION="/usr/lib/one/ruby" + ETC_LOCATION="/etc/one/" +else + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" + ETC_LOCATION=ONE_LOCATION+"/etc/" +end + +$: << RUBY_LIB_LOCATION + +require 'OpenNebulaDriver' +require 'CommandManager' + +#------------------------------------------------------------------------------- +# The SSH Information Manager Driver +#------------------------------------------------------------------------------- +class DummyInformationManager < OpenNebulaDriver + + #--------------------------------------------------------------------------- + # Init the driver + #--------------------------------------------------------------------------- + def initialize(num) + super(num, true) + + # register actions + register_action(:MONITOR, method("action_monitor")) + end + + #--------------------------------------------------------------------------- + # Execute the sensor array in the remote host + #--------------------------------------------------------------------------- + def action_monitor(number, host, not_used) + results = "HYPERVISOR=dummy," + results << "NAME=#{host}," + + results << "TOTALCPU=800," + results << "CPUSPEED=2.2GHz," + + results << "TOTALMEMORY=16777216," + results << "USEDMEMORY=0," + results << "FREEMEMORY=16777216," + + results << "FREECPU=800," + results << "USEDCPU=0" + + send_message("MONITOR", RESULT[:success], number, results) + end +end + +#------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- +# Information Manager main program +#------------------------------------------------------------------------------- +#------------------------------------------------------------------------------- + +im = DummyInformationManager.new(15) +im.start_driver diff --git a/src/im_mad/host_probes/architecture.sh b/src/im_mad/host_probes/architecture.sh deleted file mode 100755 index ef623381be..0000000000 --- a/src/im_mad/host_probes/architecture.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -echo ARCH=`uname -m` diff --git a/src/im_mad/host_probes/cpu.sh b/src/im_mad/host_probes/cpu.sh deleted file mode 100755 index 6fd555c0c5..0000000000 --- a/src/im_mad/host_probes/cpu.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -if [ -f /proc/cpuinfo ]; then - - echo -n "MODELNAME=\"" - grep -m 1 "model name" /proc/cpuinfo | cut -d: -f2 | sed -e 's/^ *//' | sed -e 's/$/"/' - -fi - diff --git a/src/im_mad/host_probes/name.sh b/src/im_mad/host_probes/name.sh deleted file mode 100755 index 7cf919ce80..0000000000 --- a/src/im_mad/host_probes/name.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -echo HOSTNAME=`uname -n` - - diff --git a/src/im_mad/im_ssh/one_im_ssh b/src/im_mad/im_ssh/one_im_ssh index 6bf146355f..af34f360a1 100755 --- a/src/im_mad/im_ssh/one_im_ssh +++ b/src/im_mad/im_ssh/one_im_ssh @@ -47,7 +47,7 @@ export_rc_vars $DRIVERRC # Go to var directory ONE_LOCATION/var or /var/lib/one cd $VAR_LOCATION -LOG_FILE=$DRIVER_NAME +LOG_FILE=one_im_ssh_$DRIVER_NAME # Execute the actual MAD execute_mad $* diff --git a/src/im_mad/im_ssh/one_im_ssh.rb b/src/im_mad/im_ssh/one_im_ssh.rb index 70340e11a1..243df86f1a 100755 --- a/src/im_mad/im_ssh/one_im_ssh.rb +++ b/src/im_mad/im_ssh/one_im_ssh.rb @@ -22,127 +22,19 @@ if !ONE_LOCATION RUBY_LIB_LOCATION="/usr/lib/one/ruby" ETC_LOCATION="/etc/one/" PROBE_LOCATION="/usr/lib/one/im_probes/" + REMOTES_LOCATION="/usr/lib/one/remotes" else RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" ETC_LOCATION=ONE_LOCATION+"/etc/" PROBE_LOCATION=ONE_LOCATION+"/lib/im_probes/" + REMOTES_LOCATION=ONE_LOCATION+"/lib/remotes/" end $: << RUBY_LIB_LOCATION - -require 'pp' -require 'digest/md5' -require 'fileutils' require 'OpenNebulaDriver' require 'CommandManager' -#------------------------------------------------------------------------------- -# This class holds the information of a IM probe and the methods to copy the -# script to the remote hosts and run it -#------------------------------------------------------------------------------- -class Sensor - - #--------------------------------------------------------------------------- - # Class constructor init the remote script name and working directory - #--------------------------------------------------------------------------- - def initialize(name, script, remote_dir) - id = Digest::MD5.hexdigest("#{name}#{script}") - - @script = script - @remote_script = "#{remote_dir}/one_im-#{id}" - @remote_dir = remote_dir - end - - #--------------------------------------------------------------------------- - # Sends the monitor probe script to the remote host and execute it - #--------------------------------------------------------------------------- - def execute(host, log_proc) - script_text = File.read @script - - src = "'mkdir -p #{@remote_dir}; cat > #{@remote_script};" \ - " if [ \"x$?\" != \"x0\" ]; then exit -1; fi;" \ - " chmod +x #{@remote_script}; #{@remote_script}'" - - cmd = SSHCommand.run(src, host, log_proc, script_text) - - case cmd.code - when 0 - # Splits the output by lines, strips each line and gets only - # lines that have something - value = cmd.stdout.split("\n").collect {|v| - v2 = v.strip - if v2 == "" - nil - else - v2 - end - }.compact.join(",") - else - nil - end - end -end - - -#------------------------------------------------------------------------------- -# This class is an array of sensor probes to be executed by the information -# driver. The class is built on top of the Sensor class -#------------------------------------------------------------------------------- -class SensorList < Array - #--------------------------------------------------------------------------- - # Initialize the class - #--------------------------------------------------------------------------- - def initialize(config_file, remote_dir) - super(0) - - @remote_dir = remote_dir - - load_sensors(config_file) - end - - #--------------------------------------------------------------------------- - # Execute all sensors in the list in the given host - #--------------------------------------------------------------------------- - def execute_sensors(host, log_proc) - results = Array.new - - self.each {|sensor| - results << sensor.execute(host, log_proc) - } - results - end - -private - #--------------------------------------------------------------------------- - # Load sensors from a configuration file - #--------------------------------------------------------------------------- - def load_sensors(file) - f = open(file, "r") - - f.each_line {|line| - l = line.strip.gsub(/#.*$/, "") - - case l - when "" - when /^[^=]+=[^=]+$/ - (name, script)=l.split("=") - - name.strip! - script.strip! - - script = "#{PROBE_LOCATION}#{script}" if script[0] != ?/ - - self << Sensor.new(name, script, @remote_dir) - else - STDERR.puts "Malformed line in configuration file: #{line}" - end - } - - f.close - end -end - #------------------------------------------------------------------------------- # The SSH Information Manager Driver #------------------------------------------------------------------------------- @@ -151,26 +43,35 @@ class InformationManager < OpenNebulaDriver #--------------------------------------------------------------------------- # Init the driver #--------------------------------------------------------------------------- - def initialize(config_file, remote_dir, num) + def initialize(remote_dir, hypervisor, num) super(num, true) - @sensor_list=SensorList.new(config_file, remote_dir) + @hypervisor = hypervisor + @remote_dir = remote_dir # register actions register_action(:MONITOR, method("action_monitor")) end #--------------------------------------------------------------------------- - # Execute the sensor array in the remote host + # Execute the run_probes in the remote host #--------------------------------------------------------------------------- - def action_monitor(number, host) + def action_monitor(number, host, do_update) + if do_update == "1" + # Use SCP to sync: + sync_cmd = "scp -r #{REMOTES_LOCATION}/. #{host}:#{@remote_dir}" + + # Use rsync to sync: + # sync_cmd = "rsync -Laz #{REMOTES_LOCATION} #{host}:#{@remote_dir}" + LocalCommand.run(sync_cmd) + else + end - results = @sensor_list.execute_sensors(host, log_method(number)) + cmd = SSHCommand.run("#{@remote_dir}/im/run_probes #{@hypervisor}", + host) - information=results.select{|res| res && !res.empty? }.join(",") - - if information and !information.empty? - send_message("MONITOR", RESULT[:success], number, information) + if cmd.code == 0 + send_message("MONITOR", RESULT[:success], number, cmd.stdout) else send_message("MONITOR", RESULT[:failure], number, "Could not monitor host #{host}.") @@ -184,22 +85,10 @@ end # Information Manager main program #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- -im_conf = ARGV.last - -if !im_conf || File.exists?(im_conf) - puts "You need to specify config file." - exit(-1) -end - -im_conf = "#{ETC_LOCATION}#{im_conf}" if im_conf[0] != ?/ - -if !File.exists?(im_conf) - puts "Configuration file #{im_conf} does not exists." - exit(-1) -end remote_dir = ENV["IM_REMOTE_DIR"] -remote_dir = "/tmp/one-im" if !remote_dir +remote_dir = "/tmp/one" if !remote_dir -im = InformationManager.new(im_conf, "#{remote_dir}/", 15) +hypervisor = ARGV[0]||'' +im = InformationManager.new(remote_dir, hypervisor, 15) im.start_driver diff --git a/src/im_mad/kvm/im_kvm.conf b/src/im_mad/kvm/im_kvm.conf deleted file mode 100644 index a891f402c6..0000000000 --- a/src/im_mad/kvm/im_kvm.conf +++ /dev/null @@ -1,8 +0,0 @@ -#------------------------------------------------------------------------------- -# Probes for KVM hosts add as many monitorization sensors as you need -#------------------------------------------------------------------------------- - -cpuarchitecture=architecture.sh -nodename=name.sh -cpu=cpu.sh -kvm=kvm.rb diff --git a/src/vmm_mad/kvm/vmm_kvmrc b/src/im_mad/remotes/common.d/architecture.sh old mode 100644 new mode 100755 similarity index 96% rename from src/vmm_mad/kvm/vmm_kvmrc rename to src/im_mad/remotes/common.d/architecture.sh index 5f10e4cabe..1565665945 --- a/src/vmm_mad/kvm/vmm_kvmrc +++ b/src/im_mad/remotes/common.d/architecture.sh @@ -1,3 +1,5 @@ +#!/bin/sh + # -------------------------------------------------------------------------- # # Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # # # @@ -13,5 +15,5 @@ # See the License for the specific language governing permissions and # # limitations under the License. # #--------------------------------------------------------------------------- # -LIBVIRT_DEFAULT_URI="qemu:///system" +echo ARCH=`uname -m` diff --git a/src/vmm_mad/xen/vmm_xenrc b/src/im_mad/remotes/common.d/cpu.sh old mode 100644 new mode 100755 similarity index 83% rename from src/vmm_mad/xen/vmm_xenrc rename to src/im_mad/remotes/common.d/cpu.sh index 258c5f9339..12bc9bea8e --- a/src/vmm_mad/xen/vmm_xenrc +++ b/src/im_mad/remotes/common.d/cpu.sh @@ -1,3 +1,5 @@ +#!/bin/sh + # -------------------------------------------------------------------------- # # Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # # # @@ -14,10 +16,10 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -#--------------------------------------------------------------------------- -# Path to Xen utilities -#--------------------------------------------------------------------------- +if [ -f /proc/cpuinfo ]; then -XENTOP_PATH="/usr/sbin/xentop" + echo -n "MODELNAME=\"" + grep -m 1 "model name" /proc/cpuinfo | cut -d: -f2 | sed -e 's/^ *//' | sed -e 's/$/"/' + +fi -XM_PATH="/usr/sbin/xm" diff --git a/src/im_mad/xen/im_xenrc b/src/im_mad/remotes/common.d/name.sh old mode 100644 new mode 100755 similarity index 88% rename from src/im_mad/xen/im_xenrc rename to src/im_mad/remotes/common.d/name.sh index 5950cc3036..90611577a8 --- a/src/im_mad/xen/im_xenrc +++ b/src/im_mad/remotes/common.d/name.sh @@ -1,3 +1,5 @@ +#!/bin/sh + # -------------------------------------------------------------------------- # # Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # # # @@ -14,9 +16,6 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -# To change the directory where the IM probes are copied on the remote node -# uncomment and change the path of IM_REMOTE_DIR -# -#IM_REMOTE_DIR=/tmp/ne_im_scripts +echo HOSTNAME=`uname -n` diff --git a/src/im_mad/kvm/kvm.rb b/src/im_mad/remotes/kvm.d/kvm.rb similarity index 100% rename from src/im_mad/kvm/kvm.rb rename to src/im_mad/remotes/kvm.d/kvm.rb diff --git a/src/im_mad/remotes/run_probes b/src/im_mad/remotes/run_probes new file mode 100755 index 0000000000..f92bcd6564 --- /dev/null +++ b/src/im_mad/remotes/run_probes @@ -0,0 +1,44 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# 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. # +#--------------------------------------------------------------------------- # + +HYPERVISOR_DIR=$1.d + +SCRIPTS_DIR=`dirname $0` +cd $SCRIPTS_DIR + + +function run_dir { + ( + DIR=$1 + cd $DIR + for i in `ls *`;do + if [ -x "$i" ]; then + ./$i + fi + done + ) +} + +data=$( + run_dir 'common.d' + if [ -d "$HYPERVISOR_DIR" ]; then + run_dir $HYPERVISOR_DIR + fi +) + +echo $data | tr '\n' ' ' diff --git a/src/im_mad/xen/xen.rb b/src/im_mad/remotes/xen.d/xen.rb similarity index 100% rename from src/im_mad/xen/xen.rb rename to src/im_mad/remotes/xen.d/xen.rb diff --git a/src/im_mad/xen/im_xen.conf b/src/im_mad/xen/im_xen.conf deleted file mode 100644 index b86c8630a8..0000000000 --- a/src/im_mad/xen/im_xen.conf +++ /dev/null @@ -1,8 +0,0 @@ -#------------------------------------------------------------------------------- -# Probes for Xen hosts add as many monitorization sensors as you need -#------------------------------------------------------------------------------- - -cpuarchitecture=architecture.sh -nodename=name.sh -cpu=cpu.sh -xen=xen.rb diff --git a/src/image/Image.cc b/src/image/Image.cc index 047551a8f7..5a19ed6b24 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -66,28 +66,30 @@ Image::~Image() const char * Image::table = "image_pool"; -const char * Image::db_names = "(oid, uid, name, type, public, regtime, " - "source, state, running_vms)"; +const char * Image::db_names = "(oid, uid, name, type, public, persistent, regtime, " + "source, state, running_vms, template)"; const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool (" "oid INTEGER PRIMARY KEY, uid INTEGER, name VARCHAR(128), " - "type INTEGER, public INTEGER, regtime INTEGER, source TEXT, state INTEGER, " - "running_vms INTEGER, UNIQUE(name) )"; + "type INTEGER, public INTEGER, persistent INTEGER, regtime INTEGER, source TEXT, state INTEGER, " + "running_vms INTEGER, template TEXT, UNIQUE(name) )"; /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ int Image::select_cb(void * nil, int num, char **values, char ** names) { - if ((!values[OID]) || - (!values[UID]) || - (!values[NAME]) || - (!values[TYPE]) || - (!values[PUBLIC]) || - (!values[REGTIME]) || - (!values[SOURCE]) || - (!values[STATE]) || - (!values[RUNNING_VMS]) || + if ((!values[OID]) || + (!values[UID]) || + (!values[NAME]) || + (!values[TYPE]) || + (!values[PUBLIC]) || + (!values[PERSISTENT]) || + (!values[REGTIME]) || + (!values[SOURCE]) || + (!values[STATE]) || + (!values[RUNNING_VMS]) || + (!values[TEMPLATE]) || (num != LIMIT )) { return -1; @@ -98,9 +100,10 @@ int Image::select_cb(void * nil, int num, char **values, char ** names) name = values[NAME]; - type = static_cast(atoi(values[TYPE])); - public_img = atoi(values[PUBLIC]); - regtime = static_cast(atoi(values[REGTIME])); + type = static_cast(atoi(values[TYPE])); + public_img = atoi(values[PUBLIC]); + persistent_img = atoi(values[PERSISTENT]); + regtime = static_cast(atoi(values[REGTIME])); source = values[SOURCE]; @@ -108,7 +111,7 @@ int Image::select_cb(void * nil, int num, char **values, char ** names) running_vms = atoi(values[RUNNING_VMS]); - image_template->id = oid; + image_template->from_xml(values[TEMPLATE]); return 0; } @@ -136,15 +139,6 @@ int Image::select(SqlDB *db) return -1; } - // Get the template - - rc = image_template->select(db); - - if ( rc != 0 ) - { - return -1; - } - return 0; } @@ -152,13 +146,14 @@ int Image::select(SqlDB *db) /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ -int Image::insert(SqlDB *db) +int Image::insert(SqlDB *db, string& error_str) { int rc; string source_att; string type_att; string public_attr; + string persistent_attr; string dev_prefix; ostringstream tmp_hashstream; @@ -204,6 +199,23 @@ int Image::insert(SqlDB *db) public_img = (public_attr == "YES"); + // ------------ PERSISTENT -------------------- + + get_template_attribute("PERSISTENT", persistent_attr); + image_template->erase("PERSISTENT"); + + transform (persistent_attr.begin(), persistent_attr.end(), persistent_attr.begin(), + (int(*)(int))toupper); + + persistent_img = (persistent_attr == "YES"); + + // An image cannot be public and persistent simultaneously + + if ( public_img && persistent_img ) + { + goto error_public_and_persistent; + } + // ------------ PREFIX -------------------- get_template_attribute("DEV_PREFIX", dev_prefix); @@ -225,46 +237,36 @@ int Image::insert(SqlDB *db) source = tmp_sourcestream.str(); - // ------------ INSERT THE TEMPLATE -------------------- - - if ( image_template->id == -1 ) - { - image_template->id = oid; - } state = DISABLED; - rc = image_template->insert(db); - - if ( rc != 0 ) - { - return rc; - } - //-------------------------------------------------------------------------- // Insert the Image //-------------------------------------------------------------------------- rc = insert_replace(db, false); - if ( rc != 0 ) + if ( rc == -1 ) { - image_template->drop(db); - - return rc; + error_str = "Error inserting Image in DB."; } - return 0; + return rc; error_name: - NebulaLog::log("IMG", Log::ERROR, "NAME not present in image template"); + error_str = "NAME not present in image template."; goto error_common; error_type: - NebulaLog::log("IMG", Log::ERROR, "Incorrect TYPE in image template"); + error_str = "Incorrect TYPE in image template."; + goto error_common; + +error_public_and_persistent: + error_str = "Image cannot be public and persistent."; goto error_common; error_common: + NebulaLog::log("IMG", Log::ERROR, error_str); return -1; } @@ -285,10 +287,13 @@ int Image::insert_replace(SqlDB *db, bool replace) int rc; + string xml_template; + char * sql_name; char * sql_source; + char * sql_template; - // Update the Image + // Update the Image sql_name = db->escape_str(name.c_str()); @@ -304,6 +309,14 @@ int Image::insert_replace(SqlDB *db, bool replace) goto error_source; } + image_template->to_xml(xml_template); + sql_template = db->escape_str(xml_template.c_str()); + + if ( sql_template == 0 ) + { + goto error_template; + } + if(replace) { oss << "REPLACE"; @@ -321,18 +334,23 @@ int Image::insert_replace(SqlDB *db, bool replace) << "'" << sql_name << "'," << type << "," << public_img << "," + << persistent_img << "," << regtime << "," << "'" << sql_source << "'," << state << "," - << running_vms << ")"; + << running_vms << "," + << "'" << sql_template << "')"; rc = db->exec(oss); db->free_str(sql_name); db->free_str(sql_source); + db->free_str(sql_template); return rc; +error_template: + db->free_str(sql_source); error_source: db->free_str(sql_name); error_name: @@ -344,15 +362,17 @@ error_name: int Image::dump(ostringstream& oss, int num, char **values, char **names) { - if ((!values[OID]) || - (!values[UID]) || - (!values[NAME]) || - (!values[TYPE]) || - (!values[PUBLIC]) || - (!values[REGTIME]) || - (!values[SOURCE]) || - (!values[STATE]) || - (!values[RUNNING_VMS]) || + if ((!values[OID]) || + (!values[UID]) || + (!values[NAME]) || + (!values[TYPE]) || + (!values[PUBLIC]) || + (!values[PERSISTENT]) || + (!values[REGTIME]) || + (!values[SOURCE]) || + (!values[STATE]) || + (!values[RUNNING_VMS]) || + (!values[TEMPLATE]) || (num != LIMIT + 1)) { return -1; @@ -366,10 +386,12 @@ int Image::dump(ostringstream& oss, int num, char **values, char **names) "" << values[NAME] << "" << "" << values[TYPE] << "" << "" << values[PUBLIC] << "" << + "" << values[PERSISTENT] << "" << "" << values[REGTIME] << "" << "" << values[SOURCE] << "" << "" << values[STATE] << "" << "" << values[RUNNING_VMS] << "" << + values[TEMPLATE] << ""; return 0; @@ -389,8 +411,6 @@ int Image::drop(SqlDB * db) return -1; } - image_template->drop(db); - oss << "DELETE FROM " << table << " WHERE oid=" << oid; rc = db->exec(oss); @@ -425,20 +445,19 @@ string& Image::to_xml(string& xml) const string template_xml; ostringstream oss; - - oss << "" << - "" << oid << "" << - "" << uid << "" << - "" << name << "" << - "" << type << "" << - "" << public_img << "" << - "" << regtime << "" << - "" << source << "" << - "" << state << "" << - "" << running_vms << "" << - image_template->to_xml(template_xml) << + "" << oid << "" << + "" << uid << "" << + "" << name << "" << + "" << type << "" << + "" << public_img << "" << + "" << persistent_img << "" << + "" << regtime << "" << + "" << source << "" << + "" << state << "" << + "" << running_vms << "" << + image_template->to_xml(template_xml) << ""; xml = oss.str(); @@ -456,15 +475,16 @@ string& Image::to_str(string& str) const ostringstream os; os << - "ID = " << oid << endl << - "UID = " << uid << endl << - "NAME = " << name << endl << - "TYPE = " << type << endl << - "PUBLIC = " << public_img << endl << - "REGTIME = " << regtime << endl << - "SOURCE = " << source << endl << - "STATE = " << state << endl << - "RUNNING_VMS = " << running_vms << endl << + "ID = " << oid << endl << + "UID = " << uid << endl << + "NAME = " << name << endl << + "TYPE = " << type << endl << + "PUBLIC = " << public_img << endl << + "PERSISTENT = " << persistent_img << endl << + "REGTIME = " << regtime << endl << + "SOURCE = " << source << endl << + "STATE = " << state << endl << + "RUNNING_VMS = " << running_vms << endl << "TEMPLATE" << endl << image_template->to_str(template_str) << endl; @@ -490,7 +510,14 @@ int Image::acquire_image() break; case USED: - running_vms++; + if (persistent_img) + { + rc = -1; + } + else + { + running_vms++; + } break; case DISABLED: @@ -539,17 +566,21 @@ int Image::disk_attribute( VectorAttribute * disk, ImageType* img_type) { string bus; + string target; ostringstream iid; *img_type = type; bus = disk->vector_value("BUS"); + target = disk->vector_value("TARGET"); iid << oid; string template_bus; + string template_target; string prefix; get_template_attribute("BUS", template_bus); + get_template_attribute("TARGET", template_target); get_template_attribute("DEV_PREFIX", prefix); //-------------------------------------------------------------------------- @@ -571,24 +602,31 @@ int Image::disk_attribute( VectorAttribute * disk, new_disk.insert(make_pair("IMAGE_ID", iid.str())); new_disk.insert(make_pair("SOURCE", source)); - if (bus.empty()) - { - if (!template_bus.empty()) - { - new_disk.insert(make_pair("BUS",template_bus)); - } - } - else + if (!bus.empty()) { new_disk.insert(make_pair("BUS",bus)); } + else if (!template_bus.empty()) + { + new_disk.insert(make_pair("BUS",template_bus)); + } //--------------------------------------------------------------------------- // TYPE, READONLY, CLONE, and SAVE attributes //--------------------------------------------------------------------------- - new_disk.insert(make_pair("CLONE","YES")); - new_disk.insert(make_pair("SAVE","NO")); + if ( persistent_img ) + { + new_disk.insert(make_pair("CLONE","NO")); + new_disk.insert(make_pair("SAVE","YES")); + + new_disk.insert(make_pair("SAVE_AS", iid.str())); // Tells the hook to overwrite + } + else + { + new_disk.insert(make_pair("CLONE","YES")); + new_disk.insert(make_pair("SAVE","NO")); + } switch(type) { @@ -608,23 +646,35 @@ int Image::disk_attribute( VectorAttribute * disk, // TARGET attribute //--------------------------------------------------------------------------- - switch(type) + if (!target.empty()) { - case OS: - prefix += "a"; - break; + new_disk.insert(make_pair("TARGET", target)); + } + else if (!template_target.empty()) + { + new_disk.insert(make_pair("TARGET", template_target)); + } + else + { + switch(type) + { + case OS: + prefix += "a"; + break; - case CDROM: - prefix += "c"; // b is for context - break; + case CDROM: + prefix += "c"; // b is for context + break; - case DATABLOCK: - prefix += static_cast(('e'+ *index)); - *index = *index + 1; - break; + case DATABLOCK: + prefix += static_cast(('e'+ *index)); + *index = *index + 1; + break; + } + + new_disk.insert(make_pair("TARGET", prefix)); } - new_disk.insert(make_pair("TARGET", prefix)); disk->replace(new_disk); diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 840096c879..e85a563e4b 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -90,7 +90,8 @@ ImagePool::ImagePool( SqlDB * db, int ImagePool::allocate ( int uid, ImageTemplate* img_template, - int * oid) + int * oid, + string& error_str) { Image * img; string name; @@ -105,7 +106,7 @@ int ImagePool::allocate ( // --------------------------------------------------------------------- // Insert the Object in the pool // --------------------------------------------------------------------- - *oid = PoolSQL::allocate(img); + *oid = PoolSQL::allocate(img, error_str); // --------------------------------------------------------------------- // Add the image name to the map of image_names diff --git a/src/image/ImageTemplate.cc b/src/image/ImageTemplate.cc deleted file mode 100644 index 2daa1d7bba..0000000000 --- a/src/image/ImageTemplate.cc +++ /dev/null @@ -1,22 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */ -/* */ -/* 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 "ImageTemplate.h" - -const char * ImageTemplate::table = "image_attributes"; - -const char * ImageTemplate::db_bootstrap = "CREATE TABLE IF NOT EXISTS" - " image_attributes (id INTEGER, name TEXT, type INTEGER, value TEXT)"; diff --git a/src/image/SConstruct b/src/image/SConstruct index 94de312801..f98729c3c0 100644 --- a/src/image/SConstruct +++ b/src/image/SConstruct @@ -22,7 +22,6 @@ lib_name='nebula_image' # Sources to generate the library source_files=[ - 'ImageTemplate.cc', 'Image.cc', 'ImagePool.cc' ] diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index 04300e573a..a9219ae6c0 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -31,6 +31,7 @@ const string templates[] = { "NAME = \"Image one\"\n" "ORIGINAL_PATH = /tmp/image_test\n" + "PERSISTENT = YES\n" "DESCRIPTION = \"This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.\"\n", "NAME = \"Second Image\"\n" @@ -48,20 +49,19 @@ const string templates[] = const string xmls[] = { - "00Image one000000000000source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa19840", + "00Image one0010000000000source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa19830", - "11Second Image010000000000source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f340", + "11Second Image0100000000000source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f330", - "02The third image000000000000source_prefix/e50b0c738be9d431475bf5859629e5580301a7d640" + "02The third image0000000000000source_prefix/e50b0c738be9d431475bf5859629e5580301a7d630" }; // This xml dump result has the STIMEs modified to 0000000000 const string xml_dump = -"00one_user_testImage one000000000000source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa1984011A userSecond Image010000000000source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f34022B userThe third image000000000000source_prefix/e50b0c738be9d431475bf5859629e5580301a7d640"; - +"00one_user_testImage one0010000000000source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa1983011A userSecond Image0100000000000source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f33022B userThe third image0000000000000source_prefix/e50b0c738be9d431475bf5859629e5580301a7d630"; const string xml_dump_where = -"00one_user_testImage one000000000000source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa1984011A userSecond Image010000000000source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f340"; +"00one_user_testImage one0010000000000source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa1983011A userSecond Image0100000000000source_prefix/c9d51800847467911c755e5e4c13dfe28c3a79f330"; const string replacement = "0000000000"; @@ -84,16 +84,23 @@ public: ImageTemplate * img_template; char * error_msg = 0; int rc; + string err; img_template = new ImageTemplate; rc = img_template->parse(stemplate,&error_msg); if( rc == 0 ) { - return ImagePool::allocate(uid, img_template, oid); + return ImagePool::allocate(uid, img_template, oid, err); } else { + if (error_msg != 0 ) + { + free(error_msg); + } + + delete img_template; return -2; } }; @@ -119,7 +126,7 @@ class ImagePoolTest : public PoolTest CPPUNIT_TEST ( target_generation ); CPPUNIT_TEST ( bus_source_assignment ); CPPUNIT_TEST ( public_attribute ); - CPPUNIT_TEST ( disk_overwrite ); + CPPUNIT_TEST ( persistence ); CPPUNIT_TEST ( imagepool_disk_attribute ); CPPUNIT_TEST ( dump ); CPPUNIT_TEST ( dump_where ); @@ -174,6 +181,7 @@ protected: // So the ONE_AUTH environment is forced to point to a test one_auth // file. ostringstream oss; + string err; oss << getenv("PWD") << "/one_auth"; setenv("ONE_AUTH", oss.str().c_str(), 1); @@ -188,17 +196,17 @@ protected: string pass_1 = "A pass"; string pass_2 = "B pass"; - user_pool->allocate(&uid_1, username_1, pass_1, true); - user_pool->allocate(&uid_2, username_2, pass_2, true); + user_pool->allocate(&uid_1, username_1, pass_1, true, err); + user_pool->allocate(&uid_2, username_2, pass_2, true, err); delete user_pool; }; public: - ImagePoolTest(){}; + ImagePoolTest(){xmlInitParser();}; - ~ImagePoolTest(){}; + ~ImagePoolTest(){xmlCleanupParser();}; /* ********************************************************************* */ @@ -255,9 +263,11 @@ public: CPPUNIT_ASSERT( img != 0 ); // Image object should be cached. Let's change some template attributes - ip->replace_attribute(img, description_name, new_description); - ip->replace_attribute(img, attr_name, new_attr_value); - ip->remove_attribute(img, "ORIGINAL_PATH"); + img->replace_template_attribute(description_name, new_description); + img->replace_template_attribute(attr_name, new_attr_value); + img->remove_template_attribute("ORIGINAL_PATH"); + + ip->update(img); img->unlock(); @@ -466,7 +476,7 @@ public: CPPUNIT_ASSERT( oid == 0 ); img->enable(true); - img->disk_attribute(disk, &index, img_type); + img->disk_attribute(disk, &index, &img_type); value = disk->vector_value("TARGET"); @@ -488,7 +498,7 @@ public: img = imp->get(oid, false); img->enable(true); - img->disk_attribute(disk, &index, img_type); + img->disk_attribute(disk, &index, &img_type); value = disk->vector_value("TARGET"); CPPUNIT_ASSERT(value == "hdc"); @@ -509,7 +519,7 @@ public: img = imp->get(oid, false); img->enable(true); - img->disk_attribute(disk, &index, img_type); + img->disk_attribute(disk, &index, &img_type); value = disk->vector_value("TARGET"); CPPUNIT_ASSERT(value == "hde"); @@ -530,7 +540,7 @@ public: img = imp->get(oid, false); img->enable(true); - img->disk_attribute(disk, &index, img_type); + img->disk_attribute(disk, &index, &img_type); value = disk->vector_value("TARGET"); CPPUNIT_ASSERT(value == "sdf"); @@ -548,7 +558,7 @@ public: Image * img; VectorAttribute * disk; - int oid; + int rc, oid; string value; int index = 0; Image::ImageType img_type; @@ -562,7 +572,8 @@ public: disk = new VectorAttribute("DISK"); img->enable(true); - img->disk_attribute(disk, &index, img_type); + rc = img->disk_attribute(disk, &index, &img_type); + CPPUNIT_ASSERT( rc == 0 ); value = ""; value = disk->vector_value("BUS"); @@ -574,6 +585,7 @@ public: "source_prefix/9ab4a4e021ee2883f57e3aeecc9e2aed7c3fa198" ); // clean up + img->release_image(); delete disk; // --------------------------------------------------------------------- @@ -582,7 +594,8 @@ public: disk->replace("BUS", "SCSI"); img->enable(true); - img->disk_attribute(disk, &index, img_type); + rc = img->disk_attribute(disk, &index, &img_type); + CPPUNIT_ASSERT( rc == 0 ); value = disk->vector_value("BUS"); CPPUNIT_ASSERT( value == "SCSI" ); @@ -596,137 +609,6 @@ public: delete disk; } -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - - void disk_overwrite() - { - ImagePool * imp = static_cast(pool); - Image * img; - - VectorAttribute * disk; - int oid, rc; - string value; - int index = 0; - Image::ImageType img_type; - - // --------------------------------------------------------------------- - // Allocate an OS type image - oid = allocate(0); - CPPUNIT_ASSERT( oid > -1 ); - img = imp->get(oid, false); - - // Disk with overwrite=yes, save_as empty - disk = new VectorAttribute("DISK"); - - disk->replace("OVERWRITE", "yes"); - - img->enable(true); - rc = img->disk_attribute(disk, &index, img_type); - CPPUNIT_ASSERT( rc == 0 ); - - - value = disk->vector_value("OVERWRITE"); - CPPUNIT_ASSERT( value == "YES" ); - - value = ""; - value = disk->vector_value("SAVE_AS"); - CPPUNIT_ASSERT( value == "" ); - - value = ""; - value = disk->vector_value("CLONE"); - CPPUNIT_ASSERT( value == "NO" ); - - value = ""; - value = disk->vector_value("SAVE"); - CPPUNIT_ASSERT( value == "YES" ); - - value = ""; - value = disk->vector_value("READONLY"); - CPPUNIT_ASSERT( value == "NO" ); - - // clean up - delete disk; - - - // --------------------------------------------------------------------- - // Allocate an OS type image - oid = allocate(1); - CPPUNIT_ASSERT( oid > -1 ); - img = imp->get(oid, false); - - // Disk with overwrite=no, save_as not empty - disk = new VectorAttribute("DISK"); - - disk->replace("OVERWRITE", "NO"); - disk->replace("SAVE_AS", "path_to_save"); - - img->enable(true); - rc = img->disk_attribute(disk, &index, img_type); - CPPUNIT_ASSERT( rc == 0 ); - - value = ""; - value = disk->vector_value("OVERWRITE"); - CPPUNIT_ASSERT( value == "NO" ); - - value = ""; - value = disk->vector_value("SAVE_AS"); - CPPUNIT_ASSERT( value == "path_to_save" ); - - value = ""; - value = disk->vector_value("CLONE"); - CPPUNIT_ASSERT( value == "YES" ); - - value = ""; - value = disk->vector_value("SAVE"); - CPPUNIT_ASSERT( value == "YES" ); - - value = ""; - value = disk->vector_value("READONLY"); - CPPUNIT_ASSERT( value == "NO" ); - - // clean up - delete disk; - - // --------------------------------------------------------------------- - // Allocate an OS type image - oid = allocate(2); - CPPUNIT_ASSERT( oid > -1 ); - img = imp->get(oid, false); - - // Disk with overwrite=no, save_as not present - disk = new VectorAttribute("DISK"); - - disk->replace("OVERWRITE", "NO"); - - img->enable(true); - rc = img->disk_attribute(disk, &index, img_type); - CPPUNIT_ASSERT( rc == 0 ); - - value = ""; - value = disk->vector_value("OVERWRITE"); - CPPUNIT_ASSERT( value == "NO" ); - - value = ""; - value = disk->vector_value("SAVE_AS"); - CPPUNIT_ASSERT( value == "" ); - - value = ""; - value = disk->vector_value("CLONE"); - CPPUNIT_ASSERT( value == "YES" ); - - value = ""; - value = disk->vector_value("SAVE"); - CPPUNIT_ASSERT( value == "NO" ); - - value = ""; - value = disk->vector_value("READONLY"); - CPPUNIT_ASSERT( value == "NO" ); - - // clean up - delete disk; - } - /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -736,7 +618,7 @@ public: Image * img; VectorAttribute * disk; - int oid_0, oid_1; + int oid_0, oid_1, index; string value; Image::ImageType img_type; @@ -770,7 +652,7 @@ public: disk = new VectorAttribute("DISK"); disk->replace("IMAGE", "Image 0"); - ((ImagePool*)imp)->disk_attribute(disk, 0, img_type); + ((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type); value = ""; value = disk->vector_value("TARGET"); @@ -787,7 +669,7 @@ public: disk = new VectorAttribute("DISK"); disk->replace("IMAGE_ID", "1"); - ((ImagePool*)imp)->disk_attribute(disk, 0, img_type); + ((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type); value = ""; value = disk->vector_value("TARGET"); @@ -877,6 +759,108 @@ public: i++; } + + bool success; + + // img 0 is not public. + img = imp->get( 0, false ); + CPPUNIT_ASSERT( img != 0 ); + + success = img->publish(false); + CPPUNIT_ASSERT( success == true ); + CPPUNIT_ASSERT( img->isPublic() == false ); + + success = img->publish(true); + CPPUNIT_ASSERT( success == true ); + CPPUNIT_ASSERT( img->isPublic() == true ); + } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + void persistence() + { + int oid; + bool success; + ImagePoolFriend * imp = static_cast(pool); + Image * img; + + string templates [] = + { + "NAME = \"Image 1\"\n" + "PERSISTENT = NO\n" + "PUBLIC = NO\n", + + "NAME = \"Image 2\"\n" + "PERSISTENT = NO\n" + "PUBLIC = YES\n", + + "NAME = \"Image 3\"\n" + "PERSISTENT = YES\n" + "PUBLIC = NO\n", + + "NAME = \"Image 4\"\n" + "PERSISTENT = YES\n" + "PUBLIC = YES\n", + + "END" + }; + + bool results[] = { true, true, true, false }; + bool persistent[] = { false, false, true }; + + int i = 0; + while( templates[i] != "END" ) + { + imp->allocate(0, templates[i], &oid); +//cout << endl << i << " : exp. " << results[i] << " got " << (oid >= 0); + CPPUNIT_ASSERT( (oid >= 0) == results[i] ); + + if( oid >= 0 ) + { + img = imp->get( oid, false ); + CPPUNIT_ASSERT( img != 0 ); + + CPPUNIT_ASSERT( img->isPersistent() == persistent[i] ); + } + + i++; + } + + // img 0 is not persistent + img = imp->get( 0, false ); + CPPUNIT_ASSERT( img != 0 ); + + // make it persistent + success = img->persistent(true); + CPPUNIT_ASSERT( success == true ); + CPPUNIT_ASSERT( img->isPersistent() == true ); + + // it isn't public, try to unpublish + success = img->publish(false); + CPPUNIT_ASSERT( success == true ); + CPPUNIT_ASSERT( img->isPublic() == false ); + + // try to publish, should fail because it is persistent + success = img->publish(true); + CPPUNIT_ASSERT( success == false ); + CPPUNIT_ASSERT( img->isPublic() == false ); + + + // make it non-persistent + success = img->persistent(false); + CPPUNIT_ASSERT( success == true ); + CPPUNIT_ASSERT( img->isPersistent() == false ); + + // it isn't public, try to unpublish + success = img->publish(false); + CPPUNIT_ASSERT( success == true ); + CPPUNIT_ASSERT( img->isPublic() == false ); + + // try to publish, now it should be possible + success = img->publish(true); + CPPUNIT_ASSERT( success == true ); + CPPUNIT_ASSERT( img->isPublic() == true ); } /* -------------------------------------------------------------------------- */ @@ -901,9 +885,9 @@ public: string result = oss.str(); - result.replace(138, 10, replacement); - result.replace(403, 10, replacement); - result.replace(671, 10, replacement); + result.replace(164, 10, replacement); + result.replace(1154, 10, replacement); + result.replace(1684, 10, replacement); CPPUNIT_ASSERT( result == xml_dump ); } @@ -931,9 +915,8 @@ public: CPPUNIT_ASSERT(rc == 0); string result = oss.str(); - - result.replace(138, 10, replacement); - result.replace(403, 10, replacement); + result.replace(164, 10, replacement); + result.replace(1154, 10, replacement); CPPUNIT_ASSERT( result == xml_dump_where ); } diff --git a/src/image/test/SConstruct b/src/image/test/SConstruct index a7be866ebb..19db958bbc 100644 --- a/src/image/test/SConstruct +++ b/src/image/test/SConstruct @@ -80,6 +80,9 @@ main_env.Append(LIBS=[ main_env.Append(LIBPATH=["/usr/lib/mysql"]) main_env.Append(CPPPATH=["/usr/include/mysql"]) +# libxml2 +main_env.ParseConfig('xml2-config --libs --cflags') + sqlite=ARGUMENTS.get('sqlite', 'yes') if sqlite=='yes': main_env.Append(CPPFLAGS=["-DSQLITE_DB"]) diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index c5b4bc4cd0..d643e617e0 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -612,6 +612,7 @@ void LifeCycleManager::cancel_success_action(int vid) return; } + vm->set_running_etime(the_time); vm->set_etime(the_time); vm->set_reason(History::CANCEL); diff --git a/src/mad/ruby/ActionManager.rb b/src/mad/ruby/ActionManager.rb index 19b9e7981a..5b26809802 100644 --- a/src/mad/ruby/ActionManager.rb +++ b/src/mad/ruby/ActionManager.rb @@ -112,7 +112,7 @@ class ActionManager return end - arity=@actions[aname][:method].arity + arity=@actions[aname][:method].arity if arity < 0 # Last parameter is an array @@ -140,13 +140,18 @@ class ActionManager def cancel_action(action_id) @threads_mutex.synchronize { - thread = @action_running[action_id] + action = @action_running[action_id] + if action + thread = action[:thread] + else + thread = nil + end if thread thread.kill @num_running -= 1 - @action_running.delete(action_id) + delete_running_action(action_id) @threads_cond.signal else @@ -159,8 +164,7 @@ class ActionManager def start_listener while true @threads_mutex.synchronize { - while ((@concurrency - @num_running)==0) || - @action_queue.size==0 + while ((@concurrency - @num_running)==0) || empty_queue @threads_cond.wait(@threads_mutex) return if (@finalize && @num_running == 0) @@ -170,11 +174,23 @@ class ActionManager } end end - + private + + def delete_running_action(action_id) + @action_running.delete(action_id) + end + + def get_runable_action + @action_queue.shift + end + + def empty_queue + @action_queue.size==0 + end def run_action - action = @action_queue.shift + action = get_runable_action if action @num_running += 1 @@ -185,13 +201,14 @@ private @threads_mutex.synchronize { @num_running -= 1 - @action_running.delete(action[:id]) + delete_running_action(action[:id]) @threads_cond.signal } } - @action_running[action[:id]] = thread + action[:thread] = thread + @action_running[action[:id]] = action else action[:method].call(*action[:args]) @@ -212,6 +229,17 @@ if __FILE__ == $0 @am.register_action(:SLEEP,method("sleep_action")) # @am.register_action(:SLEEP,Proc.new{|s,i| p s ; sleep(s)}) @am.register_action(:NOP,method("nop_action")) + + def @am.get_runable_action + action = super + puts "getting: #{action.inspect}" + action + end + + def @am.delete_running_action(action_id) + puts "deleting: #{action_id}" + super(action_id) + end end def sleep_action(secs, id) @@ -223,6 +251,7 @@ if __FILE__ == $0 def nop_action p " - Just an action" end + end s = Sample.new diff --git a/src/mad/ruby/ThreadScheduler.rb b/src/mad/ruby/ThreadScheduler.rb deleted file mode 100644 index 188c76f3db..0000000000 --- a/src/mad/ruby/ThreadScheduler.rb +++ /dev/null @@ -1,131 +0,0 @@ -# -------------------------------------------------------------------------- # -# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # -# # -# 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. # -#--------------------------------------------------------------------------- # - -require 'thread' - -=begin rdoc -Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) - -This class manages a pool of threads with a maximun number of concurrent running jobs. - -== Example - -Creates 1000 threads that sleep 1 second and executes them with a concurrency of 100. - - th=ThreadScheduler.new(100) - - 1000.times { - th.new_thread { - sleep 1 - } - } -=end - -class ThreadScheduler - # Creates a new thread pool - # - # +concurrent_number+ is the maximun number of threads that can run - # at the same time - def initialize(concurrent_number=10) - @concurrent_number=concurrent_number - @thread_queue=Array.new - @running_threads=0 - @threads_mutex=Mutex.new - @threads_cond=ConditionVariable.new - start_thread_runner - end - - # Creates a new job that will be placed on the queue. It will be scheduled - # when there is room at the selected concurrency level. Job is a block. - def new_thread(&block) - @threads_mutex.synchronize { - @thread_queue< 'd', :unknown => '-' } + + HOST_ARG = 1 # ------------------------------------------------------------------------- # Register default actions for the protocol # ------------------------------------------------------------------------- def initialize(concurrency=10, threaded=true) super(concurrency,threaded) + + @hosts = Array.new register_action(ACTION[:deploy].to_sym, method("deploy")) register_action(ACTION[:shutdown].to_sym, method("shutdown")) @@ -152,6 +156,54 @@ class VirtualMachineDriver < OpenNebulaDriver error = "Action not implemented by driver #{self.class}" send_message(ACTION[:poll],RESULT[:failure],id,error) end + +private + + def delete_running_action(action_id) + action=@action_running[action_id] + if action + @hosts.delete(action[:args][HOST_ARG]) + @action_running.delete(action_id) + end + end + + def get_first_runable + action_index=@action_queue.index do |action| + if action[:args][HOST_ARG] + !@hosts.include? action[:args][HOST_ARG] + else + true + end + end + + return action_index + end + + def get_runable_action + action_index=get_first_runable + + if action_index + action=@action_queue[action_index] + else + action=nil + end + + if action + @hosts << action[:args][HOST_ARG] if action[:args][HOST_ARG] + @action_queue.delete_at(action_index) + end + + STDERR.puts "action: #{action.inspect}" + STDERR.puts "queue: #{@action_queue.inspect}" + STDERR.puts "hosts: #{@hosts.inspect}" + STDERR.flush + + return action + end + + def empty_queue + get_first_runable==nil + end end if __FILE__ == $0 diff --git a/src/mad/ruby/one_mad.rb b/src/mad/ruby/one_mad.rb deleted file mode 100755 index d1c01eb76a..0000000000 --- a/src/mad/ruby/one_mad.rb +++ /dev/null @@ -1,179 +0,0 @@ -# -------------------------------------------------------------------------- -# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) -# -# 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. -# -------------------------------------------------------------------------- - -require "thread" - -# Author:: dsa-research.org -# Copyright:: (c) 2007 Universidad Computense de Madrid -# License:: Apache License - -# This class provides basic messaging and logging functionality. -# -# A MAD inherits this class and only has to provide methods -# for each action it wants to receive. This methods will be -# named action_. For example a method that -# handles INIT message should be like this: -# -# def action_init(args) -# call_some_function(args[2], args[3]) -# send_message("INIT", "SUCCESS") -# end - - -class ONEMad - - ## - # Debug constants - ## - ERROR, DEBUG=[0,1] - - - # * +num_params_in+: number of parameters that mensages will have - # * +num_params_out+: number of parameters that mensages sent back - # will have - def initialize(num_params_in, num_params_out=nil) - @num_params=num_params_in - if !num_params_out - @num_params_out=num_params_in - else - @num_params_out=num_params_out - end - @debug_level = -1 - @send_mutex=Mutex.new - end - - # Sends a message to the logger - def log(str, level) - - if level == ERROR - str = "------- ERROR ---------------\n" + - str + "\n-----------------------------" - end - - if @debug_level != -1 and level <= @debug_level - - str.split("\n").each{|line| - @logger.puts(Time.now.ctime + ": " + line.strip) - @logger.flush - } - - end - end - - # Sets the logger file, this can be an open file - def set_logger(logger, level) - @debug_level = level.to_i - @logger=logger - end - - # Main loop that will get messages from STDIN and call any - # action associated to the message. - def loop - while true - exit(-1) if STDIN.eof? - str=STDIN.gets - next if !str - - line=str.split(/\s+/) - - log(str,DEBUG) - - args=Array.new - args+=line[0..(@num_params-2)] - args<=@num_params - process args - end - end - - # Sends a message to ONE, this takes an array with the message and arguments. - # If the message is shorter than the number of parameters specified in the - # initialization more marameters will be added containing '-'. - def send_message(*args) - @send_mutex.synchronize { - to_send=args - if args.length<@num_params_out - (@num_params_out-args.length).times{ to_send<<'-' } - end - STDOUT.puts to_send.join(' ') - STDOUT.flush - log(to_send.join(' '),DEBUG) - } - end - - # Sends a log message to ONE. The +message+ can be multiline, it will - # be automatically splitted by lines. - def mad_log(command, number, message) - msg=message.strip - msg.each_line {|line| - send_message("LOG", "-", number, line.strip) - } - end - - # Proceses each message received, called by +loop+. - def process(args) - return nil if !args or !args[0] - action=args[0].downcase - if self.respond_to?("action_#{action}") - self.action_debug(args) - self.send("action_#{action}", args) - else - self.action_debug(args) - end - end - - # Action called when there is not a handler for a message. By default it - # logs the message, but can be redefined to do any other thing. - def action_debug(args) - #@logger.puts(args.join(';')) - end - - # Default FINALIZE action. Exists the program. - def action_finalize(args) - exit(0) - end - - # Functions for VM deployment - # TODO: Move elsewhere - def get_local_deployment_file(remote_deployment_file) - local_deployment_file=nil - - one_location=ENV["ONE_LOCATION"] - - if one_location == nil - var_location = "/var/lib/one/" - else - var_location = one_location + "/var/" - end - - m=remote_deployment_file.match(/.*?\/(\d+)\/images\/(deployment.\d+)$/) - local_deployment_file="#{var_location}#{m[1]}/#{m[2]}" if m - - return local_deployment_file - end - - def execute_local_command(cmd_string) - command=SSHCommand.new(cmd_string) - stdout, stderr=command.exec_local_command(cmd_string) - exit_code=command.get_exit_code(stderr) - if exit_code!=0 - return stderr - else - nil - end - end - - -end diff --git a/src/mad/ruby/one_ssh.rb b/src/mad/ruby/one_ssh.rb deleted file mode 100644 index 8f61bcefd8..0000000000 --- a/src/mad/ruby/one_ssh.rb +++ /dev/null @@ -1,199 +0,0 @@ -# -------------------------------------------------------------------------- # -# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # -# # -# 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. # -#--------------------------------------------------------------------------- # - -=begin rdoc - -Here will be a description of SSH library and an example on -how to use it. - -=end - -require 'pp' -require 'open3' -require 'thread' -require 'ThreadScheduler' - -# This class holds a command that will be executed on a remote host -# using ssh. Commands can have an associated callback that will be -# after they finish. -class SSHCommand - attr_accessor :value, :code, :stdout, :stderr, :command - attr_accessor :callback - - # Creates a new command - def initialize(command) - @command=command - @callback=nil - end - - # Runs the command on the specified host - def run(host) - (@stdout, @stderr)=execute(host, @command) - @code=get_exit_code(@stderr) - end - - # Executes callback associated to this command - def exec_callback(num) - if @callback - @callback.call(self, num) - end - end - - #private - - # Gets exit code from STDERR - def get_exit_code(str) - tmp=str.scan(/^ExitCode: (\d*)$/) - return nil if !tmp[0] - tmp[0][0].to_i - end - - # Executes a command in a remote machine - def execute(host, command) - std=exec_remote_command(host, command) - [std[1].read, std[2].read] - end - - # Low level local command execution - def exec_local_command(command) - std=Open3.popen3( - "#{command} ;"+ - " echo ExitCode: $? 1>&2") - [std[1].read, std[2].read] - end - - # Low level remote command execution - def exec_remote_command(host, command) - Open3.popen3( - "ssh -n #{host} #{command} ;"+ - " echo ExitCode: $? 1>&2") - end -end - -class SSHCommandList < Array -=begin - def clone_actions - new_array=Array.new - self.each {|s| - new_array << s.clone - } - new_array - end -=end -end - -# An action is composed by one or more SSHCommands that will be executed in an -# specific host. It holds a number that is the command identifier for a MAD. -class SSHAction - attr_accessor :callback - - def initialize(number, host, actions) - @number=number - @host=host - if actions.is_a?(SSHCommandList) || actions.is_a?(Array) - @actions=clone_actions(actions) - else - @actions=SSHCommandList.new - @actions< #include +#include #include #include @@ -63,6 +64,15 @@ void Nebula::start() throw runtime_error("Could not load nebula configuration file."); } + string config_fname = log_location + "config"; + ofstream config_file(config_fname.c_str(), ios_base::trunc & ios_base::out); + + if (config_file.fail() == false) + { + config_file << *nebula_configuration << endl; + config_file.close(); + } + // ----------------------------------------------------------- // Log system // ----------------------------------------------------------- @@ -108,13 +118,17 @@ void Nebula::start() NebulaLog::log("ONE",Log::INFO,"----------------------------------------"); os.str(""); - - os << "\n--------------------------------------------"; + os << "\n----------------------------------\n"; os << *nebula_configuration; - os << "\n--------------------------------------------"; + os << "----------------------------------"; NebulaLog::log("ONE",Log::INFO,os); + // ----------------------------------------------------------- + // Initialize the XML library + // ----------------------------------------------------------- + xmlInitParser(); + // ----------------------------------------------------------- // Pools // ----------------------------------------------------------- @@ -224,7 +238,7 @@ void Nebula::start() nebula_configuration->get("VM_HOOK", vm_hooks); - vmpool = new VirtualMachinePool(db, vm_hooks); + vmpool = new VirtualMachinePool(db, vm_hooks,hook_location); hpool = new HostPool(db); nebula_configuration->get("MAC_PREFIX", mac_prefix); @@ -235,12 +249,6 @@ void Nebula::start() upool = new UserPool(db); nebula_configuration->get("IMAGE_REPOSITORY_PATH", repository_path); - - if (repository_path.empty()) // Defaults to ONE_LOCATION/var - { - repository_path = var_location; - } - nebula_configuration->get("DEFAULT_IMAGE_TYPE", default_image_type); nebula_configuration->get("DEFAULT_DEVICE_PREFIX", default_device_prefix); @@ -345,7 +353,11 @@ void Nebula::start() nebula_configuration->get("IM_MAD", im_mads); - im = new InformationManager(hpool,timer_period,monitor_period,im_mads); + im = new InformationManager(hpool, + timer_period, + monitor_period, + remotes_location, + im_mads); } catch (bad_alloc&) { @@ -532,6 +544,9 @@ void Nebula::start() pthread_join(rm->get_thread_id(),0); pthread_join(hm->get_thread_id(),0); + //XML Library + xmlCleanupParser(); + NebulaLog::log("ONE", Log::INFO, "All modules finalized, exiting.\n"); } diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index 0e94046082..a38f592fd2 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -31,60 +31,114 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location) { ostringstream os; SingleAttribute * attribute; + VectorAttribute * vattribute; string value; conf_file = etc_location + conf_name; + // MANAGER_TIMER + value = "15"; + + attribute = new SingleAttribute("MANAGER_TIMER",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + +/* +#******************************************************************************* +# Daemon configuration attributes +#------------------------------------------------------------------------------- +# HOST_MONITORING_INTERVAL +# VM_POLLING_INTERVAL +# VM_DIR +# PORT +# DB +# VNC_BASE_PORT +#******************************************************************************* +*/ + // MONITOR_INTERVAL + value = "600"; + + attribute = new SingleAttribute("HOST_MONITORING_INTERVAL",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + // POLL_INTERVAL - value = "300"; - + value = "600"; + attribute = new SingleAttribute("VM_POLLING_INTERVAL",value); conf_default.insert(make_pair(attribute->name(),attribute)); - // MANAGER_TIMER - value = "30"; - - attribute = new SingleAttribute("MANAGER_TIMER",value); - conf_default.insert(make_pair(attribute->name(),attribute)); - - // MONITOR_INTERVAL - value = "300"; - - attribute = new SingleAttribute("HOST_MONITORING_INTERVAL",value); - conf_default.insert(make_pair(attribute->name(),attribute)); - - //XML-RPC Server PORT - value = "2633"; - - attribute = new SingleAttribute("PORT",value); - conf_default.insert(make_pair(attribute->name(),attribute)); - - //VM_DIR + //VM_DIR attribute = new SingleAttribute("VM_DIR",var_location); conf_default.insert(make_pair(attribute->name(),attribute)); - - //MAC_PREFIX - value = "00:01"; - - attribute = new SingleAttribute("MAC_PREFIX",value); + + //XML-RPC Server PORT + value = "2633"; + + attribute = new SingleAttribute("PORT",value); conf_default.insert(make_pair(attribute->name(),attribute)); - //NETWORK_SIZE - value = "254"; - - attribute = new SingleAttribute("NETWORK_SIZE",value); - conf_default.insert(make_pair(attribute->name(),attribute)); + //DB CONFIGURATION + map vvalue; + vvalue.insert(make_pair("BACKEND","sqlite")); - //NETWORK_SIZE + vattribute = new VectorAttribute("DB",vvalue); + conf_default.insert(make_pair(attribute->name(),vattribute)); + + //VNC_BASE_PORT value = "5900"; attribute = new SingleAttribute("VNC_BASE_PORT",value); - conf_default.insert(make_pair(attribute->name(),attribute)); - - //DEBUG_LEVEL - value = Log::WARNING; - - attribute = new SingleAttribute("DEBUG_LEVEL",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + + //XML-RPC Server PORT + value = "2633"; + + attribute = new SingleAttribute("PORT",value); + conf_default.insert(make_pair(attribute->name(),attribute)); +/* +#******************************************************************************* +# Physical Networks configuration +#******************************************************************************* +# NETWORK_SIZE +# MAC_PREFIX +#******************************************************************************* +*/ + //MAC_PREFIX + value = "02:00"; + + attribute = new SingleAttribute("MAC_PREFIX",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + + //NETWORK_SIZE + value = "254"; + + attribute = new SingleAttribute("NETWORK_SIZE",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + +/* +#******************************************************************************* +# Image Repository Configuration +#******************************************************************************* +# IMAGE_REPOSITORY_PATH +# DEFAULT_IMAGE_TYPE +# DEFAULT_DEVICE_PREFIX +#******************************************************************************* +*/ + //IMAGE_REPOSITORY_PATH + value = var_location + "/images"; + + attribute = new SingleAttribute("IMAGE_REPOSITORY_PATH",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + + //DEFAULT_IMAGE_TYPE + value = "OS"; + + attribute = new SingleAttribute("DEFAULT_IMAGE_TYPE",value); + conf_default.insert(make_pair(attribute->name(),attribute)); + + //DEFAULT_DEVICE_PREFIX + value = "hd"; + + attribute = new SingleAttribute("DEFAULT_DEVICE_PREFIX",value); conf_default.insert(make_pair(attribute->name(),attribute)); } @@ -95,31 +149,31 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location) int NebulaTemplate::load_configuration() { char * error = 0; - map::iterator iter, j; + map::iterator iter, j; int rc; - + string aname; Attribute * attr; - + rc = parse(conf_file.c_str(), &error); - + if ( rc != 0 && error != 0) { cout << "\nError while parsing configuration file:\n" << error << endl; free(error); - + return -1; } - + for(iter=conf_default.begin();iter!=conf_default.end();) { aname = iter->first; attr = iter->second; - + j = attributes.find(aname); - + if ( j == attributes.end() ) { attributes.insert(make_pair(aname,attr)); @@ -131,7 +185,7 @@ int NebulaTemplate::load_configuration() conf_default.erase(iter++); } } - + return 0; } diff --git a/src/oca/ruby/OpenNebula.rb b/src/oca/ruby/OpenNebula.rb index 1e8412b8be..93b82525a5 100644 --- a/src/oca/ruby/OpenNebula.rb +++ b/src/oca/ruby/OpenNebula.rb @@ -15,6 +15,7 @@ require 'OpenNebula/VirtualNetwork' require 'OpenNebula/VirtualNetworkPool' require 'OpenNebula/Image' require 'OpenNebula/ImagePool' +require 'OpenNebula/ImageRepository' require 'OpenNebula/User' require 'OpenNebula/UserPool' require 'OpenNebula/Host' @@ -32,7 +33,7 @@ module OpenNebula # ------------------------------------------------------------------------- class Error attr_reader :message - + # +message+ a description of the error def initialize(message=nil) @message=message @@ -50,21 +51,21 @@ module OpenNebula def self.is_error?(value) value.class==OpenNebula::Error end - + # ------------------------------------------------------------------------- # The client class, represents the connection with the core and handles the # xml-rpc calls. # ------------------------------------------------------------------------- class Client attr_accessor :one_auth - + begin require 'xmlparser' XMLPARSER=true rescue LoadError XMLPARSER=false end - + def initialize(secret=nil, endpoint=nil) if secret one_secret = secret @@ -86,8 +87,8 @@ module OpenNebula one_secret=~/^(.+?):(.+)$/ user=$1 password=$2 - - if password.match(/^ssh:/) + + if password.match(/^plain:/) @one_auth = "#{user}:#{password.split(':').last}" else @one_auth = "#{user}:#{Digest::SHA1.hexdigest(password)}" @@ -100,24 +101,26 @@ module OpenNebula else @one_endpoint="http://localhost:2633/RPC2" end + + @server=XMLRPC::Client.new2(@one_endpoint) end def call(action, *args) - server=XMLRPC::Client.new2(@one_endpoint) + if XMLPARSER - server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new) + @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new) end begin - response = server.call("one."+action, @one_auth, *args) - + response = @server.call_async("one."+action, @one_auth, *args) + if response[0] == false Error.new(response[1]) else - response[1] #response[1..-1] + response[1] #response[1..-1] end rescue Exception => e - Error.new(e.message) + Error.new(e.message) end end end diff --git a/src/oca/ruby/OpenNebula/Image.rb b/src/oca/ruby/OpenNebula/Image.rb index 74840da8ab..965f4d333f 100644 --- a/src/oca/ruby/OpenNebula/Image.rb +++ b/src/oca/ruby/OpenNebula/Image.rb @@ -7,13 +7,14 @@ module OpenNebula # Constants and Class Methods # --------------------------------------------------------------------- IMAGE_METHODS = { - :info => "image.info", - :allocate => "image.allocate", - :update => "image.update", - :rmattr => "image.rmattr", - :enable => "image.enable", - :publish => "image.publish", - :delete => "image.delete" + :info => "image.info", + :allocate => "image.allocate", + :update => "image.update", + :rmattr => "image.rmattr", + :enable => "image.enable", + :publish => "image.publish", + :persistent => "image.persistent", + :delete => "image.delete" } IMAGE_STATES=%w{INIT READY USED DISABLED} @@ -55,7 +56,6 @@ module OpenNebula super(xml,client) @client = client - @immanager = ImageManager.new end ####################################################################### @@ -109,27 +109,22 @@ module OpenNebula def unpublish set_publish(false) end + + # Makes the Image persistent + def persistent + set_persistent(true) + end + + # Makes the Image non persistent + def nonpersistent + set_persistent(false) + end # Deletes the Image def delete() super(IMAGE_METHODS[:delete]) end - - def copy(path, source) - @immanager.copy(path, source) - end - - def move(path, source) - @immanager.move(path, source) - end - - def mk_datablock(size, fstype, source) - rc = @immanager.dd(size, source) - - return rc if OpenNebula.is_error?(rc) - - @immanager.mkfs(fstype, source) - end + ####################################################################### # Helpers to get Image information @@ -184,6 +179,15 @@ module OpenNebula return rc end + + def set_persistent(persistence) + return Error.new('ID not defined') if !@pe_id + + rc = @client.call(IMAGE_METHODS[:persistent], @pe_id, persistence) + rc = nil if !OpenNebula.is_error?(rc) + + return rc + end def do_rm_attr(name) return Error.new('ID not defined') if !@pe_id @@ -195,81 +199,4 @@ module OpenNebula end end - - class ImageManager - # --------------------------------------------------------------------- - # Constants and Class Methods - # --------------------------------------------------------------------- - FS_UTILS = { - :dd => "env dd", - :mkfs => "env mkfs" - } - - def copy(path, source) - if source.nil? or path.nil? - return OpenNebula::Error.new("copy Image: missing parameters.") - end - - begin - FileUtils.copy(path, source) - FileUtils.chmod(0660, source) - rescue Exception => e - return OpenNebula::Error.new(e.message) - end - - return nil - end - - def move(path, source) - if source.nil? or path.nil? - return OpenNebula::Error.new("copy Image: missing parameters.") - end - - begin - FileUtils.move(path, source) - FileUtils.chmod(0660, source) - rescue Exception => e - return OpenNebula::Error.new(e.message) - end - - return nil - end - - def dd(size, source) - if source.nil? or size.nil? - return OpenNebula::Error.new("dd Image: missing parameters.") - end - - command = "" - command << FS_UTILS[:dd] - command << " if=/dev/zero of=#{source} ibs=1 count=1" - command << " obs=1048576 seek=#{size}" - - local_command=LocalCommand.run(command) - - if local_command.code!=0 - return OpenNebula::Error.new("dd Image: in dd command.") - end - - return nil - end - - def mkfs(fstype, source) - if source.nil? or fstype.nil? - return OpenNebula::Error.new("mkfs Image: missing parameters.") - end - - command = "" - command << FS_UTILS[:mkfs] - command << " -t #{fstype} -F #{source}" - - local_command=LocalCommand.run(command) - - if local_command.code!=0 - return OpenNebula::Error.new("mkfs Image: in mkfs command.") - end - - return nil - end - end end diff --git a/src/oca/ruby/OpenNebula/ImageRepository.rb b/src/oca/ruby/OpenNebula/ImageRepository.rb new file mode 100644 index 0000000000..f80638cc83 --- /dev/null +++ b/src/oca/ruby/OpenNebula/ImageRepository.rb @@ -0,0 +1,185 @@ +require 'OpenNebula/Image' +require 'fileutils' + +module OpenNebula + class ImageRepository + + def create(image, template, copy=true) + if image.nil? + error_msg = "Image could not be found, aborting." + result = OpenNebula::Error.new(error_msg) + end + + # ------ Allocate the Image ------ + result = image.allocate(template) + + if OpenNebula.is_error?(result) + puts result.message + exit -1 + end + + + # ------ Copy the Image file ------ + image.info + + if image['TEMPLATE/PATH'] + if copy + # --- CDROM, DATABLOCK or OS based on a PATH --- + file_path = image['TEMPLATE/PATH'] + + if !File.exists?(file_path) + error_msg = "Image file could not be found, aborting." + result = OpenNebula::Error.new(error_msg) + end + + result = copy(file_path, image['SOURCE']) + end + elsif image['TEMPLATE/SIZE'] and image['TEMPLATE/FSTYPE'] and \ + image['TEMPLATE/TYPE'] == 'DATABLOCK' + # --- Empty DATABLOCK --- + result = dd(image['TEMPLATE/SIZE'], image['SOURCE']) + + if !OpenNebula.is_error?(result) + result = mkfs(image['TEMPLATE/FSTYPE'], image['SOURCE']) + end + else + error_msg = "Image not present, aborting." + result = OpenNebula::Error.new(error_msg) + end + + + # ------ Enable the Image ------ + if !OpenNebula.is_error?(result) + image.enable + else + image.delete + end + + return result + end + + def delete(image) + if image.nil? + error_msg = "Image could not be found, aborting." + result = OpenNebula::Error.new(error_msg) + end + + result = image.info + + if !OpenNebula.is_error?(result) + file_path = image['SOURCE'] + + result = image.delete + + if !OpenNebula.is_error?(result) + result = remove(file_path) + end + end + + return result + end + + def update_source(image, source) + if image.nil? + error_msg = "Image could not be found, aborting." + result = OpenNebula::Error.new(error_msg) + end + + result = image.info + + if !OpenNebula.is_error?(result) + result = move(source, image['SOURCE']) + + image.enable + end + + return result + end + + private + + FS_UTILS = { + :dd => "env dd", + :mkfs => "env mkfs" + } + + def copy(path, source) + if source.nil? or path.nil? + return OpenNebula::Error.new("copy Image: missing parameters.") + end + + begin + FileUtils.copy(path, source) + FileUtils.chmod(0660, source) + rescue Exception => e + return OpenNebula::Error.new(e.message) + end + + return nil + end + + def move(path, source) + if source.nil? or path.nil? + return OpenNebula::Error.new("copy Image: missing parameters.") + end + + begin + FileUtils.move(path, source) + FileUtils.chmod(0660, source) + rescue Exception => e + return OpenNebula::Error.new(e.message) + end + + return nil + end + + def dd(size, source) + if source.nil? or size.nil? + return OpenNebula::Error.new("dd Image: missing parameters.") + end + + command = "" + command << FS_UTILS[:dd] + command << " if=/dev/zero of=#{source} ibs=1 count=1" + command << " obs=1048576 seek=#{size}" + + local_command=LocalCommand.run(command) + + if local_command.code!=0 + return OpenNebula::Error.new("dd Image: in dd command.") + end + + return nil + end + + def mkfs(fstype, source) + if source.nil? or fstype.nil? + return OpenNebula::Error.new("mkfs Image: missing parameters.") + end + + command = "" + command << FS_UTILS[:mkfs] + command << " -t #{fstype} -F #{source}" + + local_command=LocalCommand.run(command) + + if local_command.code!=0 + return OpenNebula::Error.new("mkfs Image: in mkfs command.") + end + + return nil + end + + def remove(source) + if File.exists?(source) + begin + FileUtils.rm(source) + rescue Exception => e + return OpenNebula::Error.new(e.message) + end + end + + return nil + end + end +end \ No newline at end of file diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index 45bff5a124..1565a652b8 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -94,7 +94,8 @@ PoolSQL::~PoolSQL() /* -------------------------------------------------------------------------- */ int PoolSQL::allocate( - PoolObjectSQL *objsql) + PoolObjectSQL *objsql, + string& error_str) { int rc; @@ -109,7 +110,7 @@ int PoolSQL::allocate( objsql->oid = ++lastOID; - rc = objsql->insert(db); + rc = objsql->insert(db,error_str); if ( rc != 0 ) { diff --git a/src/pool/test/TestPoolSQL.cc b/src/pool/test/TestPoolSQL.cc index dc0f63f410..3ec121d270 100644 --- a/src/pool/test/TestPoolSQL.cc +++ b/src/pool/test/TestPoolSQL.cc @@ -85,7 +85,7 @@ int TestObjectSQL::select(SqlDB *db) /* -------------------------------------------------------------------------- */ -int TestObjectSQL::insert(SqlDB *db) +int TestObjectSQL::insert(SqlDB *db, string& str) { ostringstream oss; diff --git a/src/pool/test/TestPoolSQL.h b/src/pool/test/TestPoolSQL.h index 77228ea580..36ef519a39 100644 --- a/src/pool/test/TestPoolSQL.h +++ b/src/pool/test/TestPoolSQL.h @@ -43,7 +43,7 @@ public: int select(SqlDB *db); - int insert(SqlDB *db); + int insert(SqlDB *db, string& err); int update(SqlDB *db); diff --git a/src/pool/test/pool.cc b/src/pool/test/pool.cc index f32f58da7d..5b2580ae8b 100644 --- a/src/pool/test/pool.cc +++ b/src/pool/test/pool.cc @@ -53,9 +53,10 @@ private: int create_allocate(int n, string st) { + string err; TestObjectSQL *obj = new TestObjectSQL(n,st); - return pool->allocate(obj); + return pool->allocate(obj, err); }; public: diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index eef1d2cf52..46685c20c2 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -312,6 +312,9 @@ void RequestManager::register_xml_methods() xmlrpc_c::methodPtr image_publish(new RequestManager::ImagePublish(ipool, upool)); + xmlrpc_c::methodPtr image_persistent(new + RequestManager::ImagePersistent(ipool, upool)); + xmlrpc_c::methodPtr image_enable(new RequestManager::ImageEnable(ipool, upool)); @@ -368,15 +371,16 @@ void RequestManager::register_xml_methods() /* Image related methods*/ - RequestManagerRegistry.addMethod("one.image.allocate",image_allocate); - RequestManagerRegistry.addMethod("one.image.delete", image_delete); - RequestManagerRegistry.addMethod("one.image.info", image_info); - RequestManagerRegistry.addMethod("one.image.update", image_update); - RequestManagerRegistry.addMethod("one.image.rmattr", image_rm_attribute); - RequestManagerRegistry.addMethod("one.image.publish", image_publish); - RequestManagerRegistry.addMethod("one.image.enable", image_enable); + RequestManagerRegistry.addMethod("one.image.allocate", image_allocate); + RequestManagerRegistry.addMethod("one.image.delete", image_delete); + RequestManagerRegistry.addMethod("one.image.info", image_info); + RequestManagerRegistry.addMethod("one.image.update", image_update); + RequestManagerRegistry.addMethod("one.image.rmattr", image_rm_attribute); + RequestManagerRegistry.addMethod("one.image.publish", image_publish); + RequestManagerRegistry.addMethod("one.image.persistent", image_persistent); + RequestManagerRegistry.addMethod("one.image.enable", image_enable); - RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info); + RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info); }; diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index f51d7c8470..5c10608144 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -28,6 +28,7 @@ void RequestManager::VirtualMachineAllocate::execute( { string session; string str_template; + string error_str; const string method_name = "VirtualMachineAllocate"; @@ -123,12 +124,14 @@ void RequestManager::VirtualMachineAllocate::execute( //-------------------------------------------------------------------------- // Allocate the VirtualMAchine //-------------------------------------------------------------------------- - rc = VirtualMachineAllocate::vmpool->allocate(uid,vm_template,&vid,false); - + rc = VirtualMachineAllocate::vmpool->allocate(uid, + vm_template, + &vid, + error_str, + false); if ( rc < 0 ) { goto error_allocate; - } arrayData.push_back(xmlrpc_c::value_boolean(true)); @@ -163,7 +166,8 @@ error_parse: goto error_common; error_allocate: - oss.str(action_error(method_name, "CREATE", "VM", -2, rc)); + oss << action_error(method_name, "CREATE", "VM", -2, 0); + oss << " " << error_str; goto error_common; error_common: diff --git a/src/rm/RequestManagerClusterAllocate.cc b/src/rm/RequestManagerClusterAllocate.cc index be09bdf110..e94dec9f4b 100644 --- a/src/rm/RequestManagerClusterAllocate.cc +++ b/src/rm/RequestManagerClusterAllocate.cc @@ -27,10 +27,11 @@ void RequestManager::ClusterAllocate::execute( xmlrpc_c::value * const retval) { string session; + string error_str; string clustername; int id; - + const string method_name = "ClusterAllocate"; int rc; @@ -68,7 +69,7 @@ void RequestManager::ClusterAllocate::execute( } // Perform the allocation in the hostpool - rc = ClusterAllocate::hpool->allocate_cluster(&id, clustername); + rc = ClusterAllocate::hpool->allocate_cluster(&id, clustername, error_str); if ( rc == -1 ) { @@ -95,7 +96,8 @@ error_authorize: goto error_common; error_cluster_allocate: - oss.str(action_error(method_name, "CREATE", "CLUSTER", -2, rc)); + oss << action_error(method_name, "CREATE", "CLUSTER", -2, 0); + oss << " " << error_str; goto error_common; error_common: diff --git a/src/rm/RequestManagerHostAllocate.cc b/src/rm/RequestManagerHostAllocate.cc index e94296624c..3c17a8bfd6 100644 --- a/src/rm/RequestManagerHostAllocate.cc +++ b/src/rm/RequestManagerHostAllocate.cc @@ -32,7 +32,9 @@ void RequestManager::HostAllocate::execute( string im_mad_name; string vmm_mad_name; string tm_mad_name; - + + string error_str; + const string method_name = "HostAllocate"; int hid; @@ -79,7 +81,8 @@ void RequestManager::HostAllocate::execute( hostname, im_mad_name, vmm_mad_name, - tm_mad_name); + tm_mad_name, + error_str); if ( rc == -1 ) { goto error_host_allocate; @@ -105,7 +108,8 @@ error_authorize: goto error_common; error_host_allocate: - oss.str(action_error(method_name, "CREATE", "HOST", -2, rc)); + oss << action_error(method_name, "CREATE", "HOST", -2, 0); + oss << " " << error_str; goto error_common; error_common: diff --git a/src/rm/RequestManagerImageAllocate.cc b/src/rm/RequestManagerImageAllocate.cc index 84e1fd287f..d6c1fbc70a 100644 --- a/src/rm/RequestManagerImageAllocate.cc +++ b/src/rm/RequestManagerImageAllocate.cc @@ -30,6 +30,7 @@ void RequestManager::ImageAllocate::execute( { string session; string str_template; + string error_str; ImageTemplate * img_template; @@ -98,7 +99,7 @@ void RequestManager::ImageAllocate::execute( //-------------------------------------------------------------------------- // Allocate the Image //-------------------------------------------------------------------------- - rc = ImageAllocate::ipool->allocate(uid,img_template,&iid); + rc = ImageAllocate::ipool->allocate(uid,img_template,&iid, error_str); if ( rc < 0 ) { @@ -138,7 +139,8 @@ error_parse: goto error_common; error_allocate: - oss.str(action_error(method_name, "CREATE", "IMAGE", -2, rc)); + oss << action_error(method_name, "CREATE", "IMAGE", -2, 0); + oss << " " << error_str; goto error_common; error_common: diff --git a/src/rm/RequestManagerImagePersistent.cc b/src/rm/RequestManagerImagePersistent.cc new file mode 100644 index 0000000000..1a52510d6c --- /dev/null +++ b/src/rm/RequestManagerImagePersistent.cc @@ -0,0 +1,158 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* 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 "RequestManager.h" + +#include "NebulaLog.h" +#include "Nebula.h" + +#include "AuthManager.h" + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void RequestManager::ImagePersistent::execute( + xmlrpc_c::paramList const& paramList, + xmlrpc_c::value * const retval) +{ + string session; + + int iid; + bool persistent_flag; + int uid; + + int image_owner; + bool is_public; + + Image * image; + + ostringstream oss; + + bool response; + + const string method_name = "ImagePersistent"; + + vector arrayData; + xmlrpc_c::value_array * arrayresult; + + + NebulaLog::log("ReM",Log::DEBUG,"ImagePersistent invoked"); + + session = xmlrpc_c::value_string (paramList.getString(0)); + iid = xmlrpc_c::value_int (paramList.getInt(1)); + persistent_flag = xmlrpc_c::value_boolean(paramList.getBoolean(2)); + + // First, we need to authenticate the user + uid = ImagePersistent::upool->authenticate(session); + + if ( uid == -1 ) + { + goto error_authenticate; + } + + // Get image from the ImagePool + image = ImagePersistent::ipool->get(iid,true); + + if ( image == 0 ) + { + goto error_image_get; + } + + image_owner = image->get_uid(); + is_public = image->isPublic(); + + image->unlock(); + + //Authorize the operation + if ( uid != 0 ) // uid == 0 means oneadmin + { + AuthRequest ar(uid); + + ar.add_auth(AuthRequest::IMAGE, + iid, + AuthRequest::MANAGE, + image_owner, + is_public); + + if (UserPool::authorize(ar) == -1) + { + goto error_authorize; + } + } + + // Get the image locked again + image = ImagePersistent::ipool->get(iid,true); + + if ( image == 0 ) + { + goto error_image_get; + } + + response = image->persistent(persistent_flag); + + if (!response) + { + goto error_persistent; + } + + ImagePersistent::ipool->update(image); + + image->unlock(); + + arrayData.push_back(xmlrpc_c::value_boolean(true)); + arrayData.push_back(xmlrpc_c::value_int(iid)); + + // Copy arrayresult into retval mem space + arrayresult = new xmlrpc_c::value_array(arrayData); + *retval = *arrayresult; + + delete arrayresult; // and get rid of the original + + return; + +error_authenticate: + oss.str(authenticate_error(method_name)); + goto error_common; + +error_image_get: + oss.str(get_error(method_name, "IMAGE", iid)); + goto error_common; + +error_authorize: + oss.str(authorization_error(method_name, "MANAGE", "IMAGE", uid, iid)); + goto error_common; + +error_persistent: + image->unlock(); + oss << action_error(method_name, "MANAGE", "IMAGE", iid, 0) + << " Is the image public? An Image cannot be public and persistent."; + goto error_common; + +error_common: + arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE + arrayData.push_back(xmlrpc_c::value_string(oss.str())); + + NebulaLog::log("ReM",Log::ERROR,oss); + + xmlrpc_c::value_array arrayresult_error(arrayData); + + *retval = arrayresult_error; + + return; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManagerImagePublish.cc b/src/rm/RequestManagerImagePublish.cc index 9137766983..8c48677097 100644 --- a/src/rm/RequestManagerImagePublish.cc +++ b/src/rm/RequestManagerImagePublish.cc @@ -31,16 +31,18 @@ void RequestManager::ImagePublish::execute( string session; int iid; - bool publish_flag; + bool publish_flag; int uid; - + int image_owner; bool is_public; - + Image * image; + bool response; + ostringstream oss; - + const string method_name = "ImagePublish"; vector arrayData; @@ -60,20 +62,20 @@ void RequestManager::ImagePublish::execute( { goto error_authenticate; } - + // Get image from the ImagePool - image = ImagePublish::ipool->get(iid,true); - - if ( image == 0 ) - { - goto error_image_get; + image = ImagePublish::ipool->get(iid,true); + + if ( image == 0 ) + { + goto error_image_get; } - + image_owner = image->get_uid(); is_public = image->isPublic(); - + image->unlock(); - + //Authorize the operation if ( uid != 0 ) // uid == 0 means oneadmin { @@ -90,17 +92,22 @@ void RequestManager::ImagePublish::execute( goto error_authorize; } } - + // Get the image locked again - image = ImagePublish::ipool->get(iid,true); - - if ( image == 0 ) - { - goto error_image_get; - } - - image->publish(publish_flag); - + image = ImagePublish::ipool->get(iid,true); + + if ( image == 0 ) + { + goto error_image_get; + } + + response = image->publish(publish_flag); + + if (!response) + { + goto error_publish; + } + ImagePublish::ipool->update(image); image->unlock(); @@ -117,17 +124,22 @@ void RequestManager::ImagePublish::execute( return; error_authenticate: - oss.str(authenticate_error(method_name)); + oss.str(authenticate_error(method_name)); goto error_common; - + error_image_get: - oss.str(get_error(method_name, "IMAGE", iid)); + oss.str(get_error(method_name, "IMAGE", iid)); goto error_common; - + error_authorize: oss.str(authorization_error(method_name, "MANAGE", "IMAGE", uid, iid)); goto error_common; +error_publish: + oss<< action_error(method_name, "MANAGE", "IMAGE", iid, 0) + <<". Is the image persistent? An Image cannot be public and persistent."; + goto error_common; + error_common: arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE arrayData.push_back(xmlrpc_c::value_string(oss.str())); diff --git a/src/rm/RequestManagerImageRemoveAttribute.cc b/src/rm/RequestManagerImageRemoveAttribute.cc index a86d05882b..75bd493dcf 100644 --- a/src/rm/RequestManagerImageRemoveAttribute.cc +++ b/src/rm/RequestManagerImageRemoveAttribute.cc @@ -100,7 +100,12 @@ void RequestManager::ImageRemoveAttribute::execute( goto error_image_get; } - rc = ImageRemoveAttribute::ipool->remove_attribute(image, name); + rc = image->remove_template_attribute(name); + + if(rc == 0) + { + rc = ImageRemoveAttribute::ipool->update(image); + } if ( rc < 0 ) { diff --git a/src/rm/RequestManagerImageUpdate.cc b/src/rm/RequestManagerImageUpdate.cc index acc6eef587..a4ff3843bb 100644 --- a/src/rm/RequestManagerImageUpdate.cc +++ b/src/rm/RequestManagerImageUpdate.cc @@ -101,9 +101,12 @@ void RequestManager::ImageUpdate::execute( goto error_image_get; } - // This will perform the update on the DB as well, - // so no need to do it manually - rc = ImageUpdate::ipool->replace_attribute(image, name, value); + rc = image->replace_template_attribute(name, value); + + if(rc == 0) + { + rc = ImageUpdate::ipool->update(image); + } if ( rc < 0 ) { diff --git a/src/rm/RequestManagerPoolInfo.cc b/src/rm/RequestManagerPoolInfo.cc index e3f16c1a94..c9e0e3acf2 100644 --- a/src/rm/RequestManagerPoolInfo.cc +++ b/src/rm/RequestManagerPoolInfo.cc @@ -30,6 +30,9 @@ void RequestManager::VirtualMachinePoolInfo::execute( int filter_flag; int rc; + int state; + + bool extended; ostringstream oss; ostringstream where_string; @@ -37,11 +40,25 @@ void RequestManager::VirtualMachinePoolInfo::execute( /* -- RPC specific vars -- */ vector arrayData; xmlrpc_c::value_array * arrayresult; - + const string method_name = "VirtualMachinePoolInfo"; NebulaLog::log("ReM",Log::DEBUG,"VirtualMachinePoolInfo method invoked"); + switch (paramList.size()) + { + case 2: + extended = true; + state = -1; + break; + case 4: + extended = xmlrpc_c::value_boolean(paramList.getBoolean(2)); + state = xmlrpc_c::value_int (paramList.getInt(3)); + break; + default: + paramList.verifyEnd(4); + } + // Get the parameters session = xmlrpc_c::value_string(paramList.getString(0)); filter_flag = xmlrpc_c::value_int (paramList.getInt(1)); @@ -68,7 +85,7 @@ void RequestManager::VirtualMachinePoolInfo::execute( where_string << "UID=" << filter_flag; } - rc = VirtualMachinePoolInfo::vmpool->dump(oss,where_string.str()); + rc = VirtualMachinePoolInfo::vmpool->dump(oss, extended, state, where_string.str()); if ( rc != 0 ) { diff --git a/src/rm/RequestManagerUserAllocate.cc b/src/rm/RequestManagerUserAllocate.cc index d3ada755d8..84caa38065 100644 --- a/src/rm/RequestManagerUserAllocate.cc +++ b/src/rm/RequestManagerUserAllocate.cc @@ -30,6 +30,7 @@ void RequestManager::UserAllocate::execute( string username; string password; + string error_str; int uid; @@ -85,7 +86,7 @@ void RequestManager::UserAllocate::execute( } // Now let's add the user - rc = UserAllocate::upool->allocate(&uid,username,password,true); + rc = UserAllocate::upool->allocate(&uid,username,password,true,error_str); if ( rc == -1 ) { @@ -118,7 +119,8 @@ error_duplicate: goto error_common; error_allocate: - oss.str(action_error(method_name, "CREATE", "USER", -2, rc)); + oss << action_error(method_name, "CREATE", "USER", -2, 0); + oss << " " << error_str; goto error_common; error_common: diff --git a/src/rm/RequestManagerVirtualNetworkAllocate.cc b/src/rm/RequestManagerVirtualNetworkAllocate.cc index 0856d29d81..75082ce8eb 100644 --- a/src/rm/RequestManagerVirtualNetworkAllocate.cc +++ b/src/rm/RequestManagerVirtualNetworkAllocate.cc @@ -29,6 +29,7 @@ void RequestManager::VirtualNetworkAllocate::execute( string session; string name; string str_template; + string error_str; VirtualNetworkTemplate * vn_template; @@ -98,7 +99,7 @@ void RequestManager::VirtualNetworkAllocate::execute( //-------------------------------------------------------------------------- // Allocate the Virtual Network //-------------------------------------------------------------------------- - rc = vnpool->allocate(uid,vn_template,&nid); + rc = vnpool->allocate(uid,vn_template,&nid,error_str); if ( rc < 0 ) { @@ -138,7 +139,8 @@ error_parse: goto error_common; error_vn_allocate: - oss.str(action_error(method_name, "CREATE", "NET", -2, rc)); + oss << action_error(method_name, "CREATE", "NET", -2, 0); + oss << " " << error_str; goto error_common; error_common: diff --git a/src/rm/SConstruct b/src/rm/SConstruct index 8bdf6dc050..42a9da1f83 100644 --- a/src/rm/SConstruct +++ b/src/rm/SConstruct @@ -41,6 +41,7 @@ source_files=[ 'RequestManagerImageUpdate.cc', 'RequestManagerImageRemoveAttribute.cc', 'RequestManagerImagePublish.cc', + 'RequestManagerImagePersistent.cc', 'RequestManagerImageEnable.cc', 'RequestManagerImagePoolInfo.cc', 'RequestManagerClusterAdd.cc', diff --git a/src/scheduler/include/HostXML.h b/src/scheduler/include/HostXML.h index a4c4c557d0..6c9800f6a7 100644 --- a/src/scheduler/include/HostXML.h +++ b/src/scheduler/include/HostXML.h @@ -25,12 +25,16 @@ using namespace std; class HostXML : public ObjectXML { public: - HostXML(const string &xml_doc):ObjectXML(xml_doc) { init_attributes(); }; + HostXML(const xmlNodePtr node):ObjectXML(node) + { + init_attributes(); + }; + int get_hid() const { return oid; diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index c135a0236a..b94f02f933 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -53,8 +53,7 @@ protected: int get_suitable_nodes(vector& content) { - // Return VMs in PENDING state (PENDING = 1) - return get_nodes("/VM_POOL/VM[STATE=1]", content); + return get_nodes("/VM_POOL/VM", content); }; virtual void add_object(xmlNodePtr node); diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index 96428fdab9..0b9fcf65ca 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -28,11 +28,19 @@ using namespace std; class VirtualMachineXML : public ObjectXML { public: - VirtualMachineXML(const string &xml_doc); + + VirtualMachineXML(const string &xml_doc):ObjectXML(xml_doc) + { + init_attributes(); + }; + + VirtualMachineXML(const xmlNodePtr node):ObjectXML(node) + { + init_attributes(); + } ~VirtualMachineXML(); - int get_oid() const { return oid; @@ -59,7 +67,7 @@ public: /** * */ - int get_host(int& hid, + int get_host(int& hid, HostPoolXML * hpool, map& host_vms, int max_vms); @@ -94,6 +102,11 @@ public: protected: + /** + * For constructors + */ + void init_attributes(); + //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- struct Host diff --git a/src/scheduler/src/pool/HostPoolXML.cc b/src/scheduler/src/pool/HostPoolXML.cc index ddaccb64ce..328e20fac5 100644 --- a/src/scheduler/src/pool/HostPoolXML.cc +++ b/src/scheduler/src/pool/HostPoolXML.cc @@ -52,47 +52,12 @@ void HostPoolXML::add_object(xmlNodePtr node) NebulaLog::log("HOST",Log::ERROR, "XML Node does not represent a valid Host"); - return; + return; } - xmlChar * str_ptr = xmlNodeGetContent(node->children); - istringstream iss(reinterpret_cast(str_ptr)); + HostXML* host = new HostXML( node ); - int hid; - xmlrpc_c::value result; - - iss >> hid; - xmlFree(str_ptr); - - client->call(client->get_endpoint(), // serverUrl - "one.host.info", // methodName - "si", // arguments format - &result, // resultP - client->get_oneauth().c_str(), // argument 0 - hid); // argument 1 - - vector values = - xmlrpc_c::value_array(result).vectorValueValue(); - - bool success = xmlrpc_c::value_boolean( values[0] ); - string message = xmlrpc_c::value_string( values[1] ); - - if( !success ) - { - ostringstream oss; - - oss << "ONE returned error while retrieving info for Host " << hid; - oss << ":" << endl; - oss << message; - - NebulaLog::log("HOST",Log::ERROR,oss); - } - else - { - HostXML* host = new HostXML( message ); - - objects.insert( pair(hid, host) ); - } + objects.insert( pair(host->get_hid(), host) ); } /* -------------------------------------------------------------------------- */ diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 93667fd186..046107a125 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -21,9 +21,7 @@ int VirtualMachinePoolXML::set_up() { ostringstream oss; int rc; - rc = PoolXML::set_up(); - if ( rc == 0 ) { oss.str(""); @@ -51,58 +49,12 @@ void VirtualMachinePoolXML::add_object(xmlNodePtr node) { NebulaLog::log("VM",Log::ERROR, "XML Node does not represent a valid Virtual Machine"); - - return; + return; } - xmlChar * str_ptr = xmlNodeGetContent(node->children); - istringstream iss(reinterpret_cast(str_ptr)); + VirtualMachineXML* vm = new VirtualMachineXML(node); - int vid; - xmlrpc_c::value result; - - iss >> vid; - xmlFree(str_ptr); - - client->call(client->get_endpoint(), // serverUrl - "one.vm.info", // methodName - "si", // arguments format - &result, // resultP - client->get_oneauth().c_str(), // argument 0 - vid); // argument 1 - - vector values = - xmlrpc_c::value_array(result).vectorValueValue(); - - bool success = xmlrpc_c::value_boolean( values[0] ); - string message = xmlrpc_c::value_string( values[1] ); - - if( !success ) - { - ostringstream oss; - - oss << "ONE returned error while retrieving info for VM " << vid; - oss << ":" << endl; - oss << message; - - NebulaLog::log("VM",Log::ERROR,oss); - } - else - { - try - { - VirtualMachineXML* vm = new VirtualMachineXML( message ); - - objects.insert( pair(vid, vm) ); - } - catch(runtime_error& re) - { - ostringstream oss_re; - - oss_re << re.what(); - NebulaLog::log("VM",Log::ERROR,oss_re); - } - } + objects.insert(pair(vm->get_oid(),vm)); } /* -------------------------------------------------------------------------- */ @@ -114,10 +66,12 @@ int VirtualMachinePoolXML::load_info(xmlrpc_c::value &result) { client->call(client->get_endpoint(), // serverUrl "one.vmpool.info", // methodName - "si", // arguments format + "sibi", // arguments format &result, // resultP - client->get_oneauth().c_str(), // argument 0 - -2); // argument 1 + client->get_oneauth().c_str(), // auth string + -2, // VM from all users + false, // not extended info + 1); // in pending state return 0; } catch (exception const& e) diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index cae51e9ea4..5bf1568c44 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -18,7 +18,7 @@ #include "VirtualMachineXML.h" -VirtualMachineXML::VirtualMachineXML(const string &xml_doc):ObjectXML(xml_doc) +void VirtualMachineXML::init_attributes() { vector result; @@ -130,9 +130,9 @@ void VirtualMachineXML::set_priorities(vector& total) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachineXML::get_host(int& hid, +int VirtualMachineXML::get_host(int& hid, HostPoolXML * hpool, - map& host_vms, + map& host_vms, int max_vms) { vector::reverse_iterator i; diff --git a/src/scheduler/src/pool/test/SConstruct b/src/scheduler/src/pool/test/SConstruct index ce1e6218d6..bca8de5178 100644 --- a/src/scheduler/src/pool/test/SConstruct +++ b/src/scheduler/src/pool/test/SConstruct @@ -37,7 +37,8 @@ main_env.Append(CPPPATH=[ main_env.Append(LIBPATH=[ cwd+'/..', cwd+'/../../xml', - cwd+'/../../../../log' + cwd+'/../../../../log', + cwd+'/../../../../common' ]) # Compile flags @@ -55,7 +56,8 @@ main_env.Append(LIBS=[ 'cppunit', 'scheduler_xml', 'scheduler_pool', - 'nebula_log' + 'nebula_log', + 'nebula_common' ]) main_env.Program('test_vm','VirtualMachineXMLTest.cc') diff --git a/src/scheduler/src/pool/test/VirtualMachineXMLTest.cc b/src/scheduler/src/pool/test/VirtualMachineXMLTest.cc index fed583f708..9b446e9eeb 100644 --- a/src/scheduler/src/pool/test/VirtualMachineXMLTest.cc +++ b/src/scheduler/src/pool/test/VirtualMachineXMLTest.cc @@ -339,7 +339,7 @@ const string FriendVirtualMachinePool::xmls[] = }; const string FriendVirtualMachinePool::vm_dump = -" 0 0 carlos vm-example 0 1 0 1274087556 1274087589 0 0 0 0 0 host16 15 1274087589 1274087589 1274087589 1274087589 0 0 0 0 1 1 0 carlos vm-example 0 1 0 1274087557 1274087590 0 0 0 0 0 host16 15 1274087589 1274087589 1274087589 1274087589 0 0 0 0 1 2 0 carlos vm-example 0 1 0 1274087557 1274087590 0 0 0 0 0 host16 15 1274087589 1274087590 1274087589 1274087590 0 0 0 0 1 3 0 carlos vm-example 0 7 0 1274087557 1274087590 0 0 0 0 0 host16 15 1274087589 1274087590 1274087589 1274087590 0 0 0 0 1 4 0 carlos vm-example 0 7 0 1274087558 1274087590 0 0 0 0 0 host16 15 1274087590 1274087590 1274087590 1274087590 0 0 0 0 1 5 0 carlos vm-example 0 7 0 1274087558 1274087590 0 0 0 0 0 host16 15 1274087590 1274087590 1274087590 1274087590 0 0 0 0 1 6 0 carlos vm-example 0 7 0 1274087559 1274087591 0 0 0 0 0 host16 15 1274087590 1274087590 1274087590 1274087590 0 0 0 0 1 "; +" 0 0 carlos vm-example 0 1 0 1274087556 1274087589 0 0 0 0 0 host16 15 1274087589 1274087589 1274087589 1274087589 0 0 0 0 1 1 0 carlos vm-example 0 1 0 1274087557 1274087590 0 0 0 0 0 host16 15 1274087589 1274087589 1274087589 1274087589 0 0 0 0 1 2 0 carlos vm-example 0 1 0 1274087557 1274087590 0 0 0 0 0 host16 15 1274087589 1274087590 1274087589 1274087590 0 0 0 0 1 "; const string FriendHostPool::xmls[] = { diff --git a/src/scheduler/src/sched/SConstruct b/src/scheduler/src/sched/SConstruct index ea848fa6f9..350fd93f10 100644 --- a/src/scheduler/src/sched/SConstruct +++ b/src/scheduler/src/sched/SConstruct @@ -28,11 +28,11 @@ env.StaticLibrary(lib_name, source_files) # Build daemon env.Append(LIBS=[ - 'nebula_common', 'scheduler_sched', 'scheduler_pool', 'nebula_log', 'scheduler_xml', + 'nebula_common', 'crypto', 'pthread' ]) diff --git a/src/scheduler/src/xml/expr_arith.cc b/src/scheduler/src/xml/expr_arith.cc index 37f1607267..88b2b04238 100644 --- a/src/scheduler/src/xml/expr_arith.cc +++ b/src/scheduler/src/xml/expr_arith.cc @@ -63,14 +63,14 @@ #define YYLSP_NEEDED 1 /* Substitute the variable and function names. */ -#define yyparse expr_arith_parse -#define yylex expr_arith_lex -#define yyerror expr_arith_error -#define yylval expr_arith_lval -#define yychar expr_arith_char -#define yydebug expr_arith_debug -#define yynerrs expr_arith_nerrs -#define yylloc expr_arith_lloc +#define yyparse expr_arith__parse +#define yylex expr_arith__lex +#define yyerror expr_arith__error +#define yylval expr_arith__lval +#define yychar expr_arith__char +#define yydebug expr_arith__debug +#define yynerrs expr_arith__nerrs +#define yylloc expr_arith__lloc /* Copy the first part of user declarations. */ @@ -82,6 +82,7 @@ #include #include #include +#include #include #include @@ -91,26 +92,46 @@ #include "ObjectXML.h" #define YYERROR_VERBOSE -#define expr_arith_lex expr_lex +#define expr_arith__lex expr_lex extern "C" { -void expr_arith_error( - YYLTYPE * llocp, - ObjectXML * oxml, - int& result, - char ** error_msg, - const char * str); + #include "mem_collector.h" -int expr_arith_lex (YYSTYPE *lvalp, YYLTYPE *llocp); + void expr_arith__error( + YYLTYPE * llocp, + mem_collector * mc, + ObjectXML * oxml, + int& result, + char ** error_msg, + const char * str); -int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg); + int expr_arith__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + + int expr_arith__parse(mem_collector * mc, + ObjectXML * oxml, + int& result, + char ** errmsg); + + int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg) + { + mem_collector mc; + int rc; + + mem_collector_init(&mc); + + rc = expr_arith__parse(&mc,oxml,result,errmsg); + + mem_collector_cleanup(&mc); + + return rc; + } } /* Line 189 of yacc.c */ -#line 114 "expr_arith.cc" +#line 135 "expr_arith.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -150,16 +171,16 @@ typedef union YYSTYPE { /* Line 214 of yacc.c */ -#line 54 "expr_arith.y" +#line 78 "expr_arith.y" - char * val_str; - int val_int; + char * val_str; + int val_int; float val_float; /* Line 214 of yacc.c */ -#line 163 "expr_arith.cc" +#line 184 "expr_arith.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -184,7 +205,7 @@ typedef struct YYLTYPE /* Line 264 of yacc.c */ -#line 188 "expr_arith.cc" +#line 209 "expr_arith.cc" #ifdef short # undef short @@ -472,8 +493,8 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 76, 76, 77, 80, 107, 108, 109, 110, 111, - 112, 113, 114 + 0, 100, 100, 101, 104, 129, 130, 131, 132, 133, + 134, 135, 136 }; #endif @@ -607,7 +628,7 @@ do \ } \ else \ { \ - yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error: cannot back up")); \ + yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) @@ -664,7 +685,7 @@ while (YYID (0)) #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) #else -# define YYLEX yylex (&yylval, &yylloc) +# define YYLEX yylex (&yylval, &yylloc, mc) #endif /* Enable debugging if requested. */ @@ -687,7 +708,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, Location, oxml, result, error_msg); \ + Type, Value, Location, mc, oxml, result, error_msg); \ YYFPRINTF (stderr, "\n"); \ } \ } while (YYID (0)) @@ -701,14 +722,15 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, ObjectXML * oxml, int& result, char ** error_msg) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg) #else static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg) +yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; YYLTYPE const * const yylocationp; + mem_collector * mc; ObjectXML * oxml; int& result; char ** error_msg; @@ -717,6 +739,7 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, er if (!yyvaluep) return; YYUSE (yylocationp); + YYUSE (mc); YYUSE (oxml); YYUSE (result); YYUSE (error_msg); @@ -741,14 +764,15 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, er #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, ObjectXML * oxml, int& result, char ** error_msg) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg) #else static void -yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg) +yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; YYLTYPE const * const yylocationp; + mem_collector * mc; ObjectXML * oxml; int& result; char ** error_msg; @@ -761,7 +785,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_ms YY_LOCATION_PRINT (yyoutput, *yylocationp); YYFPRINTF (yyoutput, ": "); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg); YYFPRINTF (yyoutput, ")"); } @@ -804,13 +828,14 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, ObjectXML * oxml, int& result, char ** error_msg) +yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg) #else static void -yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg) +yy_reduce_print (yyvsp, yylsp, yyrule, mc, oxml, result, error_msg) YYSTYPE *yyvsp; YYLTYPE *yylsp; int yyrule; + mem_collector * mc; ObjectXML * oxml; int& result; char ** error_msg; @@ -827,7 +852,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg) YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], &(yyvsp[(yyi + 1) - (yynrhs)]) - , &(yylsp[(yyi + 1) - (yynrhs)]) , oxml, result, error_msg); + , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, oxml, result, error_msg); YYFPRINTF (stderr, "\n"); } } @@ -835,7 +860,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg) # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyvsp, yylsp, Rule, oxml, result, error_msg); \ + yy_reduce_print (yyvsp, yylsp, Rule, mc, oxml, result, error_msg); \ } while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that @@ -1086,14 +1111,15 @@ yysyntax_error (char *yyresult, int yystate, int yychar) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, ObjectXML * oxml, int& result, char ** error_msg) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg) #else static void -yydestruct (yymsg, yytype, yyvaluep, yylocationp, oxml, result, error_msg) +yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg) const char *yymsg; int yytype; YYSTYPE *yyvaluep; YYLTYPE *yylocationp; + mem_collector * mc; ObjectXML * oxml; int& result; char ** error_msg; @@ -1101,6 +1127,7 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, oxml, result, error_msg) { YYUSE (yyvaluep); YYUSE (yylocationp); + YYUSE (mc); YYUSE (oxml); YYUSE (result); YYUSE (error_msg); @@ -1126,7 +1153,7 @@ int yyparse (); #endif #else /* ! YYPARSE_PARAM */ #if defined __STDC__ || defined __cplusplus -int yyparse (ObjectXML * oxml, int& result, char ** error_msg); +int yyparse (mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg); #else int yyparse (); #endif @@ -1154,10 +1181,11 @@ yyparse (YYPARSE_PARAM) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int -yyparse (ObjectXML * oxml, int& result, char ** error_msg) +yyparse (mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg) #else int -yyparse (oxml, result, error_msg) +yyparse (mc, oxml, result, error_msg) + mem_collector * mc; ObjectXML * oxml; int& result; char ** error_msg; @@ -1442,21 +1470,21 @@ yyreduce: case 2: /* Line 1464 of yacc.c */ -#line 76 "expr_arith.y" +#line 100 "expr_arith.y" { result = static_cast((yyvsp[(1) - (1)].val_float));;} break; case 3: /* Line 1464 of yacc.c */ -#line 77 "expr_arith.y" +#line 101 "expr_arith.y" { result = 0; ;} break; case 4: /* Line 1464 of yacc.c */ -#line 80 "expr_arith.y" +#line 104 "expr_arith.y" { float val = 0.0; ostringstream xpath_t; @@ -1481,71 +1509,69 @@ yyreduce: } (yyval.val_float) = val; - - free((yyvsp[(1) - (1)].val_str)); ;} break; case 5: /* Line 1464 of yacc.c */ -#line 107 "expr_arith.y" +#line 129 "expr_arith.y" { (yyval.val_float) = (yyvsp[(1) - (1)].val_float); ;} break; case 6: /* Line 1464 of yacc.c */ -#line 108 "expr_arith.y" +#line 130 "expr_arith.y" { (yyval.val_float) = static_cast((yyvsp[(1) - (1)].val_int)); ;} break; case 7: /* Line 1464 of yacc.c */ -#line 109 "expr_arith.y" +#line 131 "expr_arith.y" { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) + (yyvsp[(3) - (3)].val_float);;} break; case 8: /* Line 1464 of yacc.c */ -#line 110 "expr_arith.y" +#line 132 "expr_arith.y" { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) - (yyvsp[(3) - (3)].val_float);;} break; case 9: /* Line 1464 of yacc.c */ -#line 111 "expr_arith.y" +#line 133 "expr_arith.y" { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) * (yyvsp[(3) - (3)].val_float);;} break; case 10: /* Line 1464 of yacc.c */ -#line 112 "expr_arith.y" +#line 134 "expr_arith.y" { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) / (yyvsp[(3) - (3)].val_float);;} break; case 11: /* Line 1464 of yacc.c */ -#line 113 "expr_arith.y" +#line 135 "expr_arith.y" { (yyval.val_float) = - (yyvsp[(2) - (2)].val_float);;} break; case 12: /* Line 1464 of yacc.c */ -#line 114 "expr_arith.y" +#line 136 "expr_arith.y" { (yyval.val_float) = (yyvsp[(2) - (3)].val_float);;} break; /* Line 1464 of yacc.c */ -#line 1549 "expr_arith.cc" +#line 1575 "expr_arith.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -1581,7 +1607,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error")); + yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error")); #else { YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); @@ -1605,11 +1631,11 @@ yyerrlab: if (0 < yysize && yysize <= yymsg_alloc) { (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (&yylloc, oxml, result, error_msg, yymsg); + yyerror (&yylloc, mc, oxml, result, error_msg, yymsg); } else { - yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error")); + yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error")); if (yysize != 0) goto yyexhaustedlab; } @@ -1633,7 +1659,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval, &yylloc, oxml, result, error_msg); + yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); yychar = YYEMPTY; } } @@ -1690,7 +1716,7 @@ yyerrlab1: yyerror_range[0] = *yylsp; yydestruct ("Error: popping", - yystos[yystate], yyvsp, yylsp, oxml, result, error_msg); + yystos[yystate], yyvsp, yylsp, mc, oxml, result, error_msg); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1730,7 +1756,7 @@ yyabortlab: | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (&yylloc, oxml, result, error_msg, YY_("memory exhausted")); + yyerror (&yylloc, mc, oxml, result, error_msg, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif @@ -1738,7 +1764,7 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, oxml, result, error_msg); + yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -1746,7 +1772,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yylsp, oxml, result, error_msg); + yystos[*yyssp], yyvsp, yylsp, mc, oxml, result, error_msg); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1764,11 +1790,12 @@ yyreturn: /* Line 1684 of yacc.c */ -#line 117 "expr_arith.y" +#line 139 "expr_arith.y" -extern "C" void expr_arith_error( +extern "C" void expr_arith__error( YYLTYPE * llocp, + mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, diff --git a/src/scheduler/src/xml/expr_arith.h b/src/scheduler/src/xml/expr_arith.h index 7959e24cf1..c4371a5ad5 100644 --- a/src/scheduler/src/xml/expr_arith.h +++ b/src/scheduler/src/xml/expr_arith.h @@ -51,10 +51,10 @@ typedef union YYSTYPE { /* Line 1685 of yacc.c */ -#line 54 "expr_arith.y" +#line 78 "expr_arith.y" - char * val_str; - int val_int; + char * val_str; + int val_int; float val_float; diff --git a/src/scheduler/src/xml/expr_arith.y b/src/scheduler/src/xml/expr_arith.y index 83be574636..6bffd080f9 100644 --- a/src/scheduler/src/xml/expr_arith.y +++ b/src/scheduler/src/xml/expr_arith.y @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -29,38 +30,61 @@ #include "ObjectXML.h" #define YYERROR_VERBOSE -#define expr_arith_lex expr_lex +#define expr_arith__lex expr_lex extern "C" { -void expr_arith_error( - YYLTYPE * llocp, - ObjectXML * oxml, - int& result, - char ** error_msg, - const char * str); + #include "mem_collector.h" -int expr_arith_lex (YYSTYPE *lvalp, YYLTYPE *llocp); + void expr_arith__error( + YYLTYPE * llocp, + mem_collector * mc, + ObjectXML * oxml, + int& result, + char ** error_msg, + const char * str); -int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg); + int expr_arith__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + + int expr_arith__parse(mem_collector * mc, + ObjectXML * oxml, + int& result, + char ** errmsg); + + int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg) + { + mem_collector mc; + int rc; + + mem_collector_init(&mc); + + rc = expr_arith__parse(&mc,oxml,result,errmsg); + + mem_collector_cleanup(&mc); + + return rc; + } } %} +%parse-param {mem_collector * mc} %parse-param {ObjectXML * oxml} %parse-param {int& result} %parse-param {char ** error_msg} +%lex-param {mem_collector * mc} + %union { - char * val_str; - int val_int; + char * val_str; + int val_int; float val_float; }; %defines %locations %pure_parser -%name-prefix = "expr_arith_" +%name-prefix = "expr_arith__" %output = "expr_arith.cc" %left '+' '-' @@ -101,8 +125,6 @@ expr: STRING { float val = 0.0; } $$ = val; - - free($1); } | FLOAT { $$ = $1; } | INTEGER { $$ = static_cast($1); } @@ -116,8 +138,9 @@ expr: STRING { float val = 0.0; %% -extern "C" void expr_arith_error( +extern "C" void expr_arith__error( YYLTYPE * llocp, + mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, diff --git a/src/scheduler/src/xml/expr_bool.cc b/src/scheduler/src/xml/expr_bool.cc index 3d47c3e300..d1b86f1d85 100644 --- a/src/scheduler/src/xml/expr_bool.cc +++ b/src/scheduler/src/xml/expr_bool.cc @@ -63,14 +63,14 @@ #define YYLSP_NEEDED 1 /* Substitute the variable and function names. */ -#define yyparse expr_bool_parse -#define yylex expr_bool_lex -#define yyerror expr_bool_error -#define yylval expr_bool_lval -#define yychar expr_bool_char -#define yydebug expr_bool_debug -#define yynerrs expr_bool_nerrs -#define yylloc expr_bool_lloc +#define yyparse expr_bool__parse +#define yylex expr_bool__lex +#define yyerror expr_bool__error +#define yylval expr_bool__lval +#define yychar expr_bool__char +#define yydebug expr_bool__debug +#define yynerrs expr_bool__nerrs +#define yylloc expr_bool__lloc /* Copy the first part of user declarations. */ @@ -91,20 +91,40 @@ #include "ObjectXML.h" #define YYERROR_VERBOSE -#define expr_bool_lex expr_lex +#define expr_bool__lex expr_lex extern "C" { -void expr_bool_error( - YYLTYPE * llocp, - ObjectXML * oxml, - bool& result, - char ** error_msg, - const char * str); + #include "mem_collector.h" -int expr_bool_lex (YYSTYPE *lvalp, YYLTYPE *llocp); + void expr_bool__error( + YYLTYPE * llocp, + mem_collector * mc, + ObjectXML * oxml, + bool& result, + char ** error_msg, + const char * str); -int expr_bool_parse(ObjectXML * oxml, bool& result, char ** errmsg); + int expr_bool__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + + int expr_bool__parse(mem_collector * mc, + ObjectXML * oxml, + bool& result, + char ** errmsg); + + int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg) + { + mem_collector mc; + int rc; + + mem_collector_init(&mc); + + rc = expr_bool__parse(&mc,oxml,result,errmsg); + + mem_collector_cleanup(&mc); + + return rc; + } } void get_xml_attribute(ObjectXML * oxml, const char* attr, int& val); @@ -116,7 +136,7 @@ void get_xml_attribute(ObjectXML * oxml, const char* attr, string& val); /* Line 189 of yacc.c */ -#line 120 "expr_bool.cc" +#line 140 "expr_bool.cc" /* Enabling traces. */ #ifndef YYDEBUG @@ -156,7 +176,7 @@ typedef union YYSTYPE { /* Line 214 of yacc.c */ -#line 60 "expr_bool.y" +#line 83 "expr_bool.y" char * val_str; int val_int; @@ -165,7 +185,7 @@ typedef union YYSTYPE /* Line 214 of yacc.c */ -#line 169 "expr_bool.cc" +#line 189 "expr_bool.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -190,7 +210,7 @@ typedef struct YYLTYPE /* Line 264 of yacc.c */ -#line 194 "expr_bool.cc" +#line 214 "expr_bool.cc" #ifdef short # undef short @@ -481,8 +501,8 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 80, 80, 81, 84, 91, 98, 105, 112, 119, - 126, 133, 140, 148, 156, 157, 158, 159 + 0, 103, 103, 104, 107, 112, 117, 122, 127, 132, + 137, 142, 147, 152, 157, 158, 159, 160 }; #endif @@ -619,7 +639,7 @@ do \ } \ else \ { \ - yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error: cannot back up")); \ + yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) @@ -676,7 +696,7 @@ while (YYID (0)) #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) #else -# define YYLEX yylex (&yylval, &yylloc) +# define YYLEX yylex (&yylval, &yylloc, mc) #endif /* Enable debugging if requested. */ @@ -699,7 +719,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, Location, oxml, result, error_msg); \ + Type, Value, Location, mc, oxml, result, error_msg); \ YYFPRINTF (stderr, "\n"); \ } \ } while (YYID (0)) @@ -713,22 +733,24 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, ObjectXML * oxml, bool& result, char ** error_msg) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg) #else static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg) +yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; YYLTYPE const * const yylocationp; - ObjectXML * oxml; - bool& result; - char ** error_msg; + mem_collector * mc; + ObjectXML * oxml; + bool& result; + char ** error_msg; #endif { if (!yyvaluep) return; YYUSE (yylocationp); + YYUSE (mc); YYUSE (oxml); YYUSE (result); YYUSE (error_msg); @@ -753,17 +775,18 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, er #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, ObjectXML * oxml, bool& result, char ** error_msg) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg) #else static void -yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg) +yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; YYLTYPE const * const yylocationp; - ObjectXML * oxml; - bool& result; - char ** error_msg; + mem_collector * mc; + ObjectXML * oxml; + bool& result; + char ** error_msg; #endif { if (yytype < YYNTOKENS) @@ -773,7 +796,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_ms YY_LOCATION_PRINT (yyoutput, *yylocationp); YYFPRINTF (yyoutput, ": "); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, oxml, result, error_msg); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg); YYFPRINTF (yyoutput, ")"); } @@ -816,16 +839,17 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, ObjectXML * oxml, bool& result, char ** error_msg) +yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg) #else static void -yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg) +yy_reduce_print (yyvsp, yylsp, yyrule, mc, oxml, result, error_msg) YYSTYPE *yyvsp; YYLTYPE *yylsp; int yyrule; - ObjectXML * oxml; - bool& result; - char ** error_msg; + mem_collector * mc; + ObjectXML * oxml; + bool& result; + char ** error_msg; #endif { int yynrhs = yyr2[yyrule]; @@ -839,7 +863,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg) YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], &(yyvsp[(yyi + 1) - (yynrhs)]) - , &(yylsp[(yyi + 1) - (yynrhs)]) , oxml, result, error_msg); + , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, oxml, result, error_msg); YYFPRINTF (stderr, "\n"); } } @@ -847,7 +871,7 @@ yy_reduce_print (yyvsp, yylsp, yyrule, oxml, result, error_msg) # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyvsp, yylsp, Rule, oxml, result, error_msg); \ + yy_reduce_print (yyvsp, yylsp, Rule, mc, oxml, result, error_msg); \ } while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that @@ -1098,21 +1122,23 @@ yysyntax_error (char *yyresult, int yystate, int yychar) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, ObjectXML * oxml, bool& result, char ** error_msg) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg) #else static void -yydestruct (yymsg, yytype, yyvaluep, yylocationp, oxml, result, error_msg) +yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg) const char *yymsg; int yytype; YYSTYPE *yyvaluep; YYLTYPE *yylocationp; - ObjectXML * oxml; - bool& result; - char ** error_msg; + mem_collector * mc; + ObjectXML * oxml; + bool& result; + char ** error_msg; #endif { YYUSE (yyvaluep); YYUSE (yylocationp); + YYUSE (mc); YYUSE (oxml); YYUSE (result); YYUSE (error_msg); @@ -1138,7 +1164,7 @@ int yyparse (); #endif #else /* ! YYPARSE_PARAM */ #if defined __STDC__ || defined __cplusplus -int yyparse (ObjectXML * oxml, bool& result, char ** error_msg); +int yyparse (mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg); #else int yyparse (); #endif @@ -1166,13 +1192,14 @@ yyparse (YYPARSE_PARAM) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int -yyparse (ObjectXML * oxml, bool& result, char ** error_msg) +yyparse (mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg) #else int -yyparse (oxml, result, error_msg) - ObjectXML * oxml; - bool& result; - char ** error_msg; +yyparse (mc, oxml, result, error_msg) + mem_collector * mc; + ObjectXML * oxml; + bool& result; + char ** error_msg; #endif #endif { @@ -1454,171 +1481,149 @@ yyreduce: case 2: /* Line 1464 of yacc.c */ -#line 80 "expr_bool.y" +#line 103 "expr_bool.y" { result=(yyvsp[(1) - (1)].val_int); ;} break; case 3: /* Line 1464 of yacc.c */ -#line 81 "expr_bool.y" +#line 104 "expr_bool.y" { result=true; ;} break; case 4: /* Line 1464 of yacc.c */ -#line 84 "expr_bool.y" +#line 107 "expr_bool.y" { int val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val == (yyvsp[(3) - (3)].val_int); - - free((yyvsp[(1) - (3)].val_str));;} + (yyval.val_int) = val == (yyvsp[(3) - (3)].val_int);;} break; case 5: /* Line 1464 of yacc.c */ -#line 91 "expr_bool.y" +#line 112 "expr_bool.y" { int val; get_xml_attribute(oxml,(yyvsp[(1) - (4)].val_str),val); - (yyval.val_int) = val != (yyvsp[(4) - (4)].val_int); - - free((yyvsp[(1) - (4)].val_str));;} + (yyval.val_int) = val != (yyvsp[(4) - (4)].val_int);;} break; case 6: /* Line 1464 of yacc.c */ -#line 98 "expr_bool.y" +#line 117 "expr_bool.y" { int val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val > (yyvsp[(3) - (3)].val_int); - - free((yyvsp[(1) - (3)].val_str));;} + (yyval.val_int) = val > (yyvsp[(3) - (3)].val_int);;} break; case 7: /* Line 1464 of yacc.c */ -#line 105 "expr_bool.y" +#line 122 "expr_bool.y" { int val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val < (yyvsp[(3) - (3)].val_int); - - free((yyvsp[(1) - (3)].val_str));;} + (yyval.val_int) = val < (yyvsp[(3) - (3)].val_int);;} break; case 8: /* Line 1464 of yacc.c */ -#line 112 "expr_bool.y" +#line 127 "expr_bool.y" { float val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val == (yyvsp[(3) - (3)].val_float); - - free((yyvsp[(1) - (3)].val_str));;} + (yyval.val_int) = val == (yyvsp[(3) - (3)].val_float);;} break; case 9: /* Line 1464 of yacc.c */ -#line 119 "expr_bool.y" +#line 132 "expr_bool.y" { float val; get_xml_attribute(oxml,(yyvsp[(1) - (4)].val_str),val); - (yyval.val_int) = val != (yyvsp[(4) - (4)].val_float); - - free((yyvsp[(1) - (4)].val_str));;} + (yyval.val_int) = val != (yyvsp[(4) - (4)].val_float);;} break; case 10: /* Line 1464 of yacc.c */ -#line 126 "expr_bool.y" +#line 137 "expr_bool.y" {float val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val > (yyvsp[(3) - (3)].val_float); - - free((yyvsp[(1) - (3)].val_str));;} + (yyval.val_int) = val > (yyvsp[(3) - (3)].val_float);;} break; case 11: /* Line 1464 of yacc.c */ -#line 133 "expr_bool.y" +#line 142 "expr_bool.y" {float val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val < (yyvsp[(3) - (3)].val_float); - - free((yyvsp[(1) - (3)].val_str));;} + (yyval.val_int) = val < (yyvsp[(3) - (3)].val_float);;} break; case 12: /* Line 1464 of yacc.c */ -#line 140 "expr_bool.y" +#line 147 "expr_bool.y" { string val; get_xml_attribute(oxml,(yyvsp[(1) - (3)].val_str),val); - (yyval.val_int) = val.empty() ? false :fnmatch((yyvsp[(3) - (3)].val_str), val.c_str(), 0) == 0; - - free((yyvsp[(1) - (3)].val_str)); - free((yyvsp[(3) - (3)].val_str));;} + (yyval.val_int) = val.empty() ? false :fnmatch((yyvsp[(3) - (3)].val_str), val.c_str(), 0) == 0;;} break; case 13: /* Line 1464 of yacc.c */ -#line 148 "expr_bool.y" +#line 152 "expr_bool.y" { string val; get_xml_attribute(oxml,(yyvsp[(1) - (4)].val_str),val); - (yyval.val_int) = val.empty() ? false : fnmatch((yyvsp[(4) - (4)].val_str), val.c_str(), 0) != 0; - - free((yyvsp[(1) - (4)].val_str)); - free((yyvsp[(4) - (4)].val_str));;} + (yyval.val_int) = val.empty() ? false : fnmatch((yyvsp[(4) - (4)].val_str), val.c_str(), 0) != 0;;} break; case 14: /* Line 1464 of yacc.c */ -#line 156 "expr_bool.y" +#line 157 "expr_bool.y" { (yyval.val_int) = (yyvsp[(1) - (3)].val_int) && (yyvsp[(3) - (3)].val_int); ;} break; case 15: /* Line 1464 of yacc.c */ -#line 157 "expr_bool.y" +#line 158 "expr_bool.y" { (yyval.val_int) = (yyvsp[(1) - (3)].val_int) || (yyvsp[(3) - (3)].val_int); ;} break; case 16: /* Line 1464 of yacc.c */ -#line 158 "expr_bool.y" +#line 159 "expr_bool.y" { (yyval.val_int) = ! (yyvsp[(2) - (2)].val_int); ;} break; case 17: /* Line 1464 of yacc.c */ -#line 159 "expr_bool.y" +#line 160 "expr_bool.y" { (yyval.val_int) = (yyvsp[(2) - (3)].val_int); ;} break; /* Line 1464 of yacc.c */ -#line 1622 "expr_bool.cc" +#line 1627 "expr_bool.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -1654,7 +1659,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error")); + yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error")); #else { YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); @@ -1678,11 +1683,11 @@ yyerrlab: if (0 < yysize && yysize <= yymsg_alloc) { (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (&yylloc, oxml, result, error_msg, yymsg); + yyerror (&yylloc, mc, oxml, result, error_msg, yymsg); } else { - yyerror (&yylloc, oxml, result, error_msg, YY_("syntax error")); + yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error")); if (yysize != 0) goto yyexhaustedlab; } @@ -1706,7 +1711,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval, &yylloc, oxml, result, error_msg); + yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); yychar = YYEMPTY; } } @@ -1763,7 +1768,7 @@ yyerrlab1: yyerror_range[0] = *yylsp; yydestruct ("Error: popping", - yystos[yystate], yyvsp, yylsp, oxml, result, error_msg); + yystos[yystate], yyvsp, yylsp, mc, oxml, result, error_msg); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1803,7 +1808,7 @@ yyabortlab: | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (&yylloc, oxml, result, error_msg, YY_("memory exhausted")); + yyerror (&yylloc, mc, oxml, result, error_msg, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif @@ -1811,7 +1816,7 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, oxml, result, error_msg); + yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -1819,7 +1824,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yylsp, oxml, result, error_msg); + yystos[*yyssp], yyvsp, yylsp, mc, oxml, result, error_msg); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1837,11 +1842,12 @@ yyreturn: /* Line 1684 of yacc.c */ -#line 162 "expr_bool.y" +#line 163 "expr_bool.y" -extern "C" void expr_bool_error( +extern "C" void expr_bool__error( YYLTYPE * llocp, + mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, @@ -1863,6 +1869,8 @@ extern "C" void expr_bool_error( llocp->first_column, llocp->last_column); } + + result = false; } void get_xml_attribute(ObjectXML * oxml, const char* attr, int& val) diff --git a/src/scheduler/src/xml/expr_bool.h b/src/scheduler/src/xml/expr_bool.h index 74a5306442..41d20a621f 100644 --- a/src/scheduler/src/xml/expr_bool.h +++ b/src/scheduler/src/xml/expr_bool.h @@ -51,7 +51,7 @@ typedef union YYSTYPE { /* Line 1685 of yacc.c */ -#line 60 "expr_bool.y" +#line 83 "expr_bool.y" char * val_str; int val_int; diff --git a/src/scheduler/src/xml/expr_bool.y b/src/scheduler/src/xml/expr_bool.y index ba22fa034d..0a1bb7199c 100644 --- a/src/scheduler/src/xml/expr_bool.y +++ b/src/scheduler/src/xml/expr_bool.y @@ -29,20 +29,40 @@ #include "ObjectXML.h" #define YYERROR_VERBOSE -#define expr_bool_lex expr_lex +#define expr_bool__lex expr_lex extern "C" { -void expr_bool_error( - YYLTYPE * llocp, - ObjectXML * oxml, - bool& result, - char ** error_msg, - const char * str); + #include "mem_collector.h" -int expr_bool_lex (YYSTYPE *lvalp, YYLTYPE *llocp); + void expr_bool__error( + YYLTYPE * llocp, + mem_collector * mc, + ObjectXML * oxml, + bool& result, + char ** error_msg, + const char * str); -int expr_bool_parse(ObjectXML * oxml, bool& result, char ** errmsg); + int expr_bool__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + + int expr_bool__parse(mem_collector * mc, + ObjectXML * oxml, + bool& result, + char ** errmsg); + + int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg) + { + mem_collector mc; + int rc; + + mem_collector_init(&mc); + + rc = expr_bool__parse(&mc,oxml,result,errmsg); + + mem_collector_cleanup(&mc); + + return rc; + } } void get_xml_attribute(ObjectXML * oxml, const char* attr, int& val); @@ -53,9 +73,12 @@ void get_xml_attribute(ObjectXML * oxml, const char* attr, string& val); %} -%parse-param {ObjectXML * oxml} -%parse-param {bool& result} -%parse-param {char ** error_msg} +%parse-param {mem_collector * mc} +%parse-param {ObjectXML * oxml} +%parse-param {bool& result} +%parse-param {char ** error_msg} + +%lex-param {mem_collector * mc} %union { char * val_str; @@ -66,7 +89,7 @@ void get_xml_attribute(ObjectXML * oxml, const char* attr, string& val); %defines %locations %pure_parser -%name-prefix = "expr_bool_" +%name-prefix = "expr_bool__" %output = "expr_bool.cc" %left '!' '&' '|' @@ -84,74 +107,52 @@ stmt: expr { result=$1; } expr: STRING '=' INTEGER { int val; get_xml_attribute(oxml,$1,val); - $$ = val == $3; - - free($1);} + $$ = val == $3;} | STRING '!' '=' INTEGER { int val; get_xml_attribute(oxml,$1,val); - $$ = val != $4; - - free($1);} + $$ = val != $4;} | STRING '>' INTEGER { int val; get_xml_attribute(oxml,$1,val); - $$ = val > $3; - - free($1);} + $$ = val > $3;} | STRING '<' INTEGER { int val; get_xml_attribute(oxml,$1,val); - $$ = val < $3; - - free($1);} + $$ = val < $3;} | STRING '=' FLOAT { float val; get_xml_attribute(oxml,$1,val); - $$ = val == $3; - - free($1);} + $$ = val == $3;} | STRING '!' '=' FLOAT { float val; get_xml_attribute(oxml,$1,val); - $$ = val != $4; - - free($1);} + $$ = val != $4;} | STRING '>' FLOAT {float val; get_xml_attribute(oxml,$1,val); - $$ = val > $3; - - free($1);} + $$ = val > $3;} | STRING '<' FLOAT {float val; get_xml_attribute(oxml,$1,val); - $$ = val < $3; - - free($1);} + $$ = val < $3;} | STRING '=' STRING { string val; get_xml_attribute(oxml,$1,val); - $$ = val.empty() ? false :fnmatch($3, val.c_str(), 0) == 0; - - free($1); - free($3);} + $$ = val.empty() ? false :fnmatch($3, val.c_str(), 0) == 0;} | STRING '!''=' STRING { string val; get_xml_attribute(oxml,$1,val); - $$ = val.empty() ? false : fnmatch($4, val.c_str(), 0) != 0; - - free($1); - free($4);} + $$ = val.empty() ? false : fnmatch($4, val.c_str(), 0) != 0;} | expr '&' expr { $$ = $1 && $3; } | expr '|' expr { $$ = $1 || $3; } @@ -161,8 +162,9 @@ expr: STRING '=' INTEGER { int val; %% -extern "C" void expr_bool_error( +extern "C" void expr_bool__error( YYLTYPE * llocp, + mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, @@ -184,6 +186,8 @@ extern "C" void expr_bool_error( llocp->first_column, llocp->last_column); } + + result = false; } void get_xml_attribute(ObjectXML * oxml, const char* attr, int& val) diff --git a/src/scheduler/src/xml/expr_parser.c b/src/scheduler/src/xml/expr_parser.c index 648d37f6fd..33c05ed989 100644 --- a/src/scheduler/src/xml/expr_parser.c +++ b/src/scheduler/src/xml/expr_parser.c @@ -512,17 +512,19 @@ char *expr_text; #line 18 "expr_parser.l" #include #include -#include #include "expr_bool.h" #include "expr_arith.h" +#include "mem_collector.h" -#define YY_DECL int expr_lex (YYSTYPE *lvalp, YYLTYPE *llocp) +#define YY_NO_INPUT + +#define YY_DECL int expr_lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector *mc) #define YY_USER_ACTION llocp->first_line = expr_lineno; \ llocp->first_column = llocp->last_column; \ llocp->last_column += expr_leng; -#line 526 "expr_parser.c" +#line 528 "expr_parser.c" #define INITIAL 0 @@ -702,11 +704,11 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -#line 37 "expr_parser.l" +#line 39 "expr_parser.l" /* --- Tokens --- */ -#line 710 "expr_parser.c" +#line 712 "expr_parser.c" if ( !(yy_init) ) { @@ -801,55 +803,55 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 40 "expr_parser.l" +#line 42 "expr_parser.l" { return *expr_text;} YY_BREAK /* --- Strings, also quoted form --- */ case 2: YY_RULE_SETUP -#line 44 "expr_parser.l" -{ lvalp->val_str = strdup(expr_text); +#line 46 "expr_parser.l" +{ lvalp->val_str = mem_collector_strdup(mc,expr_text); return STRING;} YY_BREAK case 3: YY_RULE_SETUP -#line 47 "expr_parser.l" +#line 49 "expr_parser.l" { lvalp->val_str = NULL; return STRING;} YY_BREAK case 4: /* rule 4 can match eol */ YY_RULE_SETUP -#line 50 "expr_parser.l" -{ lvalp->val_str = strdup(expr_text+1); +#line 52 "expr_parser.l" +{ lvalp->val_str = mem_collector_strdup(mc,expr_text+1); lvalp->val_str[expr_leng-2] = '\0'; return STRING;} YY_BREAK /* --- Numbers --- */ case 5: YY_RULE_SETUP -#line 56 "expr_parser.l" +#line 58 "expr_parser.l" { lvalp->val_int = atoi(expr_text); return INTEGER;} YY_BREAK case 6: YY_RULE_SETUP -#line 59 "expr_parser.l" +#line 61 "expr_parser.l" { lvalp->val_float = atof(expr_text); return FLOAT;} YY_BREAK /* --- blanks --- */ case 7: YY_RULE_SETUP -#line 64 "expr_parser.l" +#line 66 "expr_parser.l" YY_BREAK case 8: YY_RULE_SETUP -#line 66 "expr_parser.l" +#line 68 "expr_parser.l" ECHO; YY_BREAK -#line 853 "expr_parser.c" +#line 855 "expr_parser.c" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -1818,7 +1820,7 @@ void expr_free (void * ptr ) #define YYTABLES_NAME "yytables" -#line 66 "expr_parser.l" +#line 68 "expr_parser.l" diff --git a/src/scheduler/src/xml/expr_parser.l b/src/scheduler/src/xml/expr_parser.l index 75a956303d..0d234ef353 100644 --- a/src/scheduler/src/xml/expr_parser.l +++ b/src/scheduler/src/xml/expr_parser.l @@ -17,12 +17,14 @@ %{ #include #include -#include #include "expr_bool.h" #include "expr_arith.h" +#include "mem_collector.h" -#define YY_DECL int expr_lex (YYSTYPE *lvalp, YYLTYPE *llocp) +#define YY_NO_INPUT + +#define YY_DECL int expr_lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector *mc) #define YY_USER_ACTION llocp->first_line = yylineno; \ llocp->first_column = llocp->last_column; \ @@ -41,13 +43,13 @@ /* --- Strings, also quoted form --- */ -[A-Za-z][0-9A-Za-z_]* { lvalp->val_str = strdup(yytext); +[A-Za-z][0-9A-Za-z_]* { lvalp->val_str = mem_collector_strdup(mc,yytext); return STRING;} \"\" { lvalp->val_str = NULL; return STRING;} -\"[^\"]*\" { lvalp->val_str = strdup(yytext+1); +\"[^\"]*\" { lvalp->val_str = mem_collector_strdup(mc,yytext+1); lvalp->val_str[yyleng-2] = '\0'; return STRING;} diff --git a/src/scheduler/src/xml/test/ObjectXMLTest.cc b/src/scheduler/src/xml/test/ObjectXMLTest.cc index e579aa19f4..8a3ef1b809 100644 --- a/src/scheduler/src/xml/test/ObjectXMLTest.cc +++ b/src/scheduler/src/xml/test/ObjectXMLTest.cc @@ -240,7 +240,7 @@ public: // is not set to false. rc = obj.eval_bool( "TOTALCPU ^ * - = abc", res, &err ); CPPUNIT_ASSERT( rc != 0 ); - // CPPUNIT_ASSERT( res == false ); + CPPUNIT_ASSERT( res == false ); if (err != 0) { diff --git a/src/scheduler/src/xml/test/SConstruct b/src/scheduler/src/xml/test/SConstruct index 7c498aeef6..f17f7e4cf6 100644 --- a/src/scheduler/src/xml/test/SConstruct +++ b/src/scheduler/src/xml/test/SConstruct @@ -34,6 +34,7 @@ main_env.Append(CPPPATH=[ # Library dirs main_env.Append(LIBPATH=[ + cwd+'/../../../../common', '../' ]) @@ -50,7 +51,8 @@ main_env.Append(LDFLAGS=["-g"]) # Libraries main_env.Append(LIBS=[ 'cppunit', - 'scheduler_xml' + 'scheduler_xml', + 'nebula_common' ]) main_env.Program('test_xml','ObjectXMLTest.cc') diff --git a/src/sql/SqliteDB.cc b/src/sql/SqliteDB.cc index 43a3e0668d..d23ff0664f 100644 --- a/src/sql/SqliteDB.cc +++ b/src/sql/SqliteDB.cc @@ -99,7 +99,7 @@ int SqliteDB::exec(ostringstream& cmd, Callbackable* obj) rc = sqlite3_exec(db, c_str, callback, arg, &err_msg); - if (rc == SQLITE_BUSY || rc == SQLITE_IOERR_BLOCKED) + if (rc == SQLITE_BUSY || rc == SQLITE_IOERR) { struct timeval timeout; fd_set zero; @@ -110,7 +110,7 @@ int SqliteDB::exec(ostringstream& cmd, Callbackable* obj) select(0, &zero, &zero, &zero, &timeout); } - }while( (rc == SQLITE_BUSY || rc == SQLITE_IOERR_BLOCKED) && + }while( (rc == SQLITE_BUSY || rc == SQLITE_IOERR) && (counter < 10)); unlock(); diff --git a/src/template/SConstruct b/src/template/SConstruct index aa0dfbfa5e..1352b341f3 100644 --- a/src/template/SConstruct +++ b/src/template/SConstruct @@ -37,7 +37,6 @@ if env['parsers']=='yes': # Sources to generate the library source_files=[ 'Template.cc', - 'TemplateSQL.cc', 'template_parser.c', 'template_syntax.cc' ] diff --git a/src/template/Template.cc b/src/template/Template.cc index 0ab226040f..8556237ed4 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -367,7 +367,7 @@ string& Template::to_str(string& str) const { s = it->second->marshall(","); - os << endl << "\t" << it->first << separator << *s; + os << it->first << separator << *s << endl; delete s; } @@ -388,6 +388,121 @@ ostream& operator << (ostream& os, const Template& t) return os; } +/* ------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------ */ + +Attribute * Template::single_xml_att(const xmlNode * node) +{ + Attribute * attr = 0; + xmlNode * child = node->children; + + if( child != 0 && (child->type == XML_TEXT_NODE || + child->type == XML_CDATA_SECTION_NODE)) + { + attr = new SingleAttribute( + reinterpret_cast(node->name), + reinterpret_cast(child->content) ); + } + + return attr; +} + +/* ------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------ */ + +Attribute * Template::vector_xml_att(const xmlNode * node) +{ + VectorAttribute * attr = 0; + + xmlNode * child = node->children; + xmlNode * grandchild = 0; + + if(child != 0 && child->type == XML_ELEMENT_NODE) + { + attr = new VectorAttribute( + reinterpret_cast(node->name)); + + for(child = child; child != 0; child = child->next) + { + grandchild = child->children; + + if( grandchild != 0 && (grandchild->type == XML_TEXT_NODE || + grandchild->type == XML_CDATA_SECTION_NODE)) + { + attr->replace( + reinterpret_cast(child->name), + reinterpret_cast(grandchild->content) ); + } + } + } + + return attr; +} + +/* ------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------ */ + +int Template::from_xml(const string &xml_str) +{ + xmlDocPtr xml_doc = 0; + + xmlNode * root_element; + xmlNode * cur_node = 0; + + Attribute * attr; + + + // Parse xml string as libxml document + xml_doc = xmlParseMemory (xml_str.c_str(),xml_str.length()); + + if (xml_doc == 0) // Error parsing XML Document + { + return -1; + } + + //Clear the template if not empty + if (!attributes.empty()) + { + multimap::iterator it; + + for ( it = attributes.begin(); it != attributes.end(); it++) + { + delete it->second; + } + + attributes.clear(); + } + + // Get the