From 3debc8a318f5a7a9c32cf4eb2b5cb9a431e94d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 14 May 2010 15:30:21 +0200 Subject: [PATCH] feature #212: Some pending tasks, mostly log errors. --- src/scheduler/include/Client.h | 2 + src/scheduler/include/PoolXML.h | 71 +++++++++++-------- src/scheduler/include/VirtualMachinePoolXML.h | 4 +- src/scheduler/include/VirtualMachineXML.h | 7 +- .../src/pool/VirtualMachinePoolXML.cc | 30 +++++--- src/scheduler/src/pool/VirtualMachineXML.cc | 11 ++- src/scheduler/src/xml/Client.cc | 8 +-- 7 files changed, 75 insertions(+), 58 deletions(-) diff --git a/src/scheduler/include/Client.h b/src/scheduler/include/Client.h index eac81447b0..4463180988 100644 --- a/src/scheduler/include/Client.h +++ b/src/scheduler/include/Client.h @@ -24,6 +24,8 @@ #include #include +#include "NebulaLog.h" + using namespace std; // ============================================================================= diff --git a/src/scheduler/include/PoolXML.h b/src/scheduler/include/PoolXML.h index f50950282e..6d3074b9a6 100644 --- a/src/scheduler/include/PoolXML.h +++ b/src/scheduler/include/PoolXML.h @@ -18,6 +18,7 @@ #ifndef POOL_XML_H_ #define POOL_XML_H_ +#include "NebulaLog.h" #include "ObjectXML.h" #include "Client.h" @@ -67,7 +68,8 @@ protected: if ( rc != 0 ) { - // TODO: log error + NebulaLog::log("POOL",Log::ERROR, + "Could not retrieve pool info from ONE"); return -1; } @@ -79,7 +81,12 @@ protected: if( !success ) { - // TODO log error, in message + ostringstream oss; + + oss << "ONE returned error while retrieving pool info:" << endl; + oss << message; + + NebulaLog::log("POOL", Log::ERROR, oss); return -1; } @@ -98,6 +105,28 @@ protected: return 0; }; + /** + * Gets an object from the pool + * @param oid the object unique identifier + * + * @return a pointer to the object, 0 in case of failure + */ + virtual ObjectXML * get(int oid) const + { + map::const_iterator it; + + it = objects.find(oid); + + if ( it == objects.end() ) + { + return 0; + } + else + { + return it->second; + } + }; + /** * * @@ -107,17 +136,6 @@ protected: return objects; }; -protected: - /** - * XML-RPC client - */ - Client * client; - - /** - * Hash map contains the suitable [id, object] pairs. - */ - map objects; - /** * Inserts a new ObjectXML into the objects map */ @@ -133,27 +151,20 @@ protected: */ virtual int load_info(xmlrpc_c::value &result) = 0; + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** - * Gets an object from the pool - * @param oid the object unique identifier - * - * @return a pointer to the object, 0 in case of failure + * XML-RPC client */ - virtual const ObjectXML * get(int oid) const - { - map::const_iterator it; + Client * client; - it = objects.find(oid); + /** + * Hash map contains the suitable [id, object] pairs. + */ + map objects; - if ( it == objects.end() ) - { - return 0; - } - else - { - return it->second; - } - }; private: /** diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index 5a61cd2121..1d5a201464 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -39,9 +39,9 @@ public: * * @return a pointer to the object, 0 in case of failure */ - const VirtualMachineXML * get(int oid) const + VirtualMachineXML * get(int oid) const { - return static_cast(PoolXML::get(oid)); + return static_cast(PoolXML::get(oid)); }; protected: diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index 11692b7662..01433fce58 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -18,13 +18,12 @@ #ifndef VM_XML_H_ #define VM_XML_H_ -#include "ObjectXML.h" #include -using namespace std; +#include "ObjectXML.h" +#include "HostPoolXML.h" -//TODO include the HostPool file... -class HostPoolXML; +using namespace std; class VirtualMachineXML : public ObjectXML { diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 2064352c64..b800e3542f 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -25,8 +25,6 @@ int VirtualMachinePoolXML::set_up() if ( rc == 0 ) { - // TODO FIX LOG - /* oss.str(""); oss << "Pending virtual machines :"; @@ -37,8 +35,7 @@ int VirtualMachinePoolXML::set_up() oss << " " << it->second; } - Scheduler::log("VM",Log::DEBUG,oss); - //*/ + NebulaLog::log("VM",Log::DEBUG,oss); } return rc; @@ -51,7 +48,10 @@ void VirtualMachinePoolXML::add_object(xmlNodePtr node) { if ( node == 0 || node->children == 0 || node->children->next==0 ) { - //TODO Log error + NebulaLog::log("VM",Log::ERROR, + "XML Node does not represent a valid Virtual Machine"); + // TODO: if the xml node isn't valid, do nothing? + return; } xmlChar * str_ptr = xmlNodeGetContent(node->children->next); @@ -78,7 +78,13 @@ void VirtualMachinePoolXML::add_object(xmlNodePtr node) if( !success ) { - // TODO log error + ostringstream oss; + + oss << "ONE returned error while retrieving info for VM " << vid; + oss << ":" << endl; + oss << message; + + NebulaLog::log("VM",Log::ERROR,oss); } else { @@ -94,18 +100,22 @@ void VirtualMachinePoolXML::add_object(xmlNodePtr node) int VirtualMachinePoolXML::load_info(xmlrpc_c::value &result) { try - {/*TODO make it compile + { client->call(client->get_endpoint(), // serverUrl "one.vmpool.info", // methodName "si", // arguments format - result, // resultP + &result, // resultP client->get_oneauth().c_str(), // argument 0 - -2); // argument 1*/ + -2); // argument 1 return 0; } catch (exception const& e) { - // TODO log error, in e.what() + ostringstream oss; + oss << "Exception raised: " << e.what(); + + NebulaLog::log("VM", Log::ERROR, oss); + return -1; } } diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index cf6bf5f3bf..e5943fee99 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -15,6 +15,7 @@ /* -------------------------------------------------------------------------- */ #include + #include "VirtualMachineXML.h" VirtualMachineXML::VirtualMachineXML(const string &xml_doc):ObjectXML(xml_doc) @@ -113,8 +114,7 @@ void VirtualMachineXML::set_priorities(vector& total) { if ( hosts.size() != total.size() ) { - // TODO log error - // Scheduler::log("VM",Log::ERROR,"Wrong size for priority vector"); + NebulaLog::log("VM",Log::ERROR,"Wrong size for priority vector"); return; } @@ -132,11 +132,10 @@ void VirtualMachineXML::set_priorities(vector& total) int VirtualMachineXML::get_host(int& hid, HostPoolXML * hpool) { -/*TODO Uncomment for HostPool vector::reverse_iterator i; vector::iterator j; - HostXML * host; + HostXML * host; int cpu; int mem; @@ -146,7 +145,7 @@ int VirtualMachineXML::get_host(int& hid, HostPoolXML * hpool) for (i=hosts.rbegin();i!=hosts.rend();i++) { - host = hpool->get( (*i)->hid ) ); + host = hpool->get( (*i)->hid ); if ( host == 0 ) { @@ -163,7 +162,7 @@ int VirtualMachineXML::get_host(int& hid, HostPoolXML * hpool) } hid = -1; -*/ + return -1; } diff --git a/src/scheduler/src/xml/Client.cc b/src/scheduler/src/xml/Client.cc index 195c082984..cc66accc0f 100644 --- a/src/scheduler/src/xml/Client.cc +++ b/src/scheduler/src/xml/Client.cc @@ -57,13 +57,10 @@ void Client::set_one_auth(string secret) } else { - // TODO NOTIFY ERROR -/* - NebulaLog::log("ONE",Log::ERROR, + NebulaLog::log("XMLRPC",Log::ERROR, "ONE_AUTH wrong format, must be :"); throw; -//*/ } } } @@ -128,8 +125,7 @@ int Client::read_oneauth(string &secret) if (rc != 0) { - // TODO NOTIFY ERROR -// NebulaLog::log("ONE",Log::ERROR,oss); + NebulaLog::log("XMLRPC",Log::ERROR,oss); } return rc;