mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-13 13:17:39 +03:00
Merge branch 'feature-206'
This commit is contained in:
commit
e86c0f07eb
27
SConstruct
27
SConstruct
@ -39,6 +39,8 @@ main_env.Append(CPPPATH=[
|
||||
# Library dirs
|
||||
main_env.Append(LIBPATH=[
|
||||
cwd+'/src/common',
|
||||
cwd+'/src/log',
|
||||
cwd+'/src/sql',
|
||||
cwd+'/src/host',
|
||||
cwd+'/src/mad',
|
||||
cwd+'/src/nebula',
|
||||
@ -70,11 +72,27 @@ main_env.Append(LDFLAGS=["-g"])
|
||||
#######################
|
||||
|
||||
# SQLITE
|
||||
sqlite_dir=ARGUMENTS.get('sqlite', 'none')
|
||||
sqlite_dir=ARGUMENTS.get('sqlite_dir', 'none')
|
||||
if sqlite_dir!='none':
|
||||
main_env.Append(LIBPATH=[sqlite_dir+"/lib"])
|
||||
main_env.Append(CPPPATH=[sqlite_dir+"/include"])
|
||||
|
||||
sqlite=ARGUMENTS.get('sqlite', 'yes')
|
||||
if sqlite=='yes':
|
||||
main_env.Append(sqlite='yes')
|
||||
main_env.Append(CPPFLAGS=["-DSQLITE_DB"])
|
||||
else:
|
||||
main_env.Append(sqlite='no')
|
||||
|
||||
# MySQL
|
||||
mysql=ARGUMENTS.get('mysql', 'no')
|
||||
if mysql=='yes':
|
||||
main_env.Append(mysql='yes')
|
||||
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
|
||||
else:
|
||||
main_env.Append(mysql='no')
|
||||
|
||||
|
||||
# xmlrpc
|
||||
xmlrpc_dir=ARGUMENTS.get('xmlrpc', 'none')
|
||||
if xmlrpc_dir!='none':
|
||||
@ -92,6 +110,10 @@ if not main_env.GetOption('clean'):
|
||||
try:
|
||||
main_env.ParseConfig('share/scons/get_xmlrpc_config server')
|
||||
main_env.ParseConfig('share/scons/get_xmlrpc_config client')
|
||||
|
||||
if mysql=='yes':
|
||||
main_env.ParseConfig('mysql_config --cflags --libs')
|
||||
|
||||
except Exception, e:
|
||||
print ""
|
||||
print "Error searching for xmlrpc-c libraries. Please check this"+\
|
||||
@ -118,7 +140,8 @@ else:
|
||||
|
||||
# SCONS scripts to build
|
||||
build_scripts=[
|
||||
'src/client/SConstruct',
|
||||
'src/sql/SConstruct',
|
||||
'src/log/SConstruct',
|
||||
'src/common/SConstruct',
|
||||
'src/template/SConstruct',
|
||||
'src/host/SConstruct',
|
||||
|
@ -143,8 +143,8 @@ public:
|
||||
{
|
||||
string * xml = new string;
|
||||
|
||||
*xml = "<" + name() + ">" + attribute_value
|
||||
+ "</"+ name() + ">";
|
||||
*xml = "<" + name() + "><![CDATA[" + attribute_value
|
||||
+ "]]></"+ name() + ">";
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
83
include/Callbackable.h
Normal file
83
include/Callbackable.h
Normal file
@ -0,0 +1,83 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 CALLBACKABLE_H_
|
||||
#define CALLBACKABLE_H_
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* ObjectSQL class. Provides a SQL backend interface, it should be implemented
|
||||
* by persistent objects.
|
||||
*/
|
||||
class Callbackable
|
||||
{
|
||||
public:
|
||||
|
||||
Callbackable():cb(0),arg(0){};
|
||||
|
||||
virtual ~Callbackable(){};
|
||||
|
||||
/**
|
||||
* Datatype for call back pointers
|
||||
*/
|
||||
typedef int (Callbackable::*Callback)(void *, int, char ** ,char **);
|
||||
|
||||
/**
|
||||
* Set the callback function and custom arguments to be executed by the
|
||||
* next SQL command
|
||||
* @param ptr to the callback function
|
||||
* @param arg custom arguments for the callback function
|
||||
*/
|
||||
void set_callback(Callback _cb, void * _arg = 0)
|
||||
{
|
||||
cb = _cb;
|
||||
arg = _arg;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if the CallBack is set for the object.
|
||||
* @return true if the callback is set
|
||||
*/
|
||||
bool isCallBackSet()
|
||||
{
|
||||
return (cb != 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the callback function and custom arguments to be executed by the
|
||||
* next SQL command
|
||||
* @param ptr to the callback function
|
||||
* @param arg custom arguments for the callback function
|
||||
*/
|
||||
int do_callback(int num, char **values, char **names)
|
||||
{
|
||||
return (this->*cb)(arg, num, values, names);
|
||||
};
|
||||
|
||||
private:
|
||||
/**
|
||||
* SQL callback to be executed for each row result of an SQL statement
|
||||
*/
|
||||
Callback cb;
|
||||
|
||||
/**
|
||||
* Custom arguments for the callback
|
||||
*/
|
||||
void * arg;
|
||||
};
|
||||
|
||||
#endif /*CALLBACKABLE_H_*/
|
@ -22,31 +22,31 @@
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* The FixedLeases class represents a pool of fixed IP-MAC leases. A lease can
|
||||
* The FixedLeases class represents a pool of fixed IP-MAC leases. A lease can
|
||||
* be either a IP (the MAC is then PREFIX:IP) or the IP and MAC addresses. The
|
||||
* pool is read from a template file, each lease is in the form:
|
||||
* LEASE = [ IP = "<the ip>", MAC = "<the mac>"]
|
||||
*/
|
||||
*/
|
||||
class FixedLeases : public Leases
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create a FixedLeases from template
|
||||
*/
|
||||
FixedLeases(SqliteDB * db,
|
||||
int _oid,
|
||||
unsigned int _mac_prefix,
|
||||
vector<const Attribute*>& vector_leases);
|
||||
/**
|
||||
* Create a plain FixedLeases, you can populate the lease pool using
|
||||
* select()
|
||||
*/
|
||||
FixedLeases(SqliteDB * db,
|
||||
int _oid,
|
||||
unsigned int _mac_prefix):
|
||||
Leases(db,_oid,0),
|
||||
mac_prefix(_mac_prefix),
|
||||
current(leases.begin()){};
|
||||
/**
|
||||
* Create a FixedLeases from template
|
||||
*/
|
||||
FixedLeases(SqlDB * db,
|
||||
int _oid,
|
||||
unsigned int _mac_prefix,
|
||||
vector<const Attribute*>& vector_leases);
|
||||
/**
|
||||
* Create a plain FixedLeases, you can populate the lease pool using
|
||||
* select()
|
||||
*/
|
||||
FixedLeases(SqlDB * db,
|
||||
int _oid,
|
||||
unsigned int _mac_prefix):
|
||||
Leases(db,_oid,0),
|
||||
mac_prefix(_mac_prefix),
|
||||
current(leases.begin()){};
|
||||
|
||||
~FixedLeases(){};
|
||||
|
||||
@ -58,7 +58,7 @@ public:
|
||||
* @return 0 if success
|
||||
*/
|
||||
int get(int vid, string& ip, string& mac);
|
||||
|
||||
|
||||
/**
|
||||
* Ask for a specific lease in the network
|
||||
* @param vid identifier of the VM getting this lease
|
||||
@ -76,32 +76,32 @@ public:
|
||||
{
|
||||
del(ip);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the leases from the DB.
|
||||
*/
|
||||
int select(SqliteDB * db)
|
||||
int select(SqlDB * db)
|
||||
{
|
||||
//Read the leases from the DB
|
||||
int rc = Leases::select(db);
|
||||
//Update the size
|
||||
size = leases.size();
|
||||
|
||||
return rc;
|
||||
//Read the leases from the DB
|
||||
int rc = Leases::select(db);
|
||||
//Update the size
|
||||
size = leases.size();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The default MAC prefix for the OpenNebula cluster
|
||||
*/
|
||||
unsigned int mac_prefix;
|
||||
|
||||
/**
|
||||
* Current lease pointer
|
||||
*/
|
||||
map<unsigned int, Lease *>::iterator current;
|
||||
|
||||
|
||||
/**
|
||||
* The default MAC prefix for the OpenNebula cluster
|
||||
*/
|
||||
unsigned int mac_prefix;
|
||||
|
||||
/**
|
||||
* Current lease pointer
|
||||
*/
|
||||
map<unsigned int, Lease *>::iterator current;
|
||||
|
||||
/**
|
||||
* Add a lease, from the Lease interface
|
||||
* @param ip ip of the lease
|
||||
@ -110,7 +110,7 @@ private:
|
||||
* @return 0 if success
|
||||
*/
|
||||
int add(const string& ip, const string& mac, int vid, bool used=true);
|
||||
|
||||
|
||||
/**
|
||||
* Remove a lease, from the Lease interface
|
||||
* @param db pointer to DB
|
||||
|
@ -17,17 +17,10 @@
|
||||
#ifndef HISTORY_H_
|
||||
#define HISTORY_H_
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include "ObjectSQL.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" int history_select_cb (
|
||||
void * _history,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
/**
|
||||
* The History class, it represents an execution record of a Virtual Machine.
|
||||
*/
|
||||
@ -37,23 +30,23 @@ class History:public ObjectSQL
|
||||
public:
|
||||
enum MigrationReason
|
||||
{
|
||||
NONE, /** < Normal termination in host */
|
||||
ERROR, /** < The VM was migrated because of an error */
|
||||
NONE, /** < Normal termination in host */
|
||||
ERROR, /** < The VM was migrated because of an error */
|
||||
STOP_RESUME,/** < The VM was migrated because of a stop/resume request*/
|
||||
USER, /** < The VM was migrated because of an explicit request */
|
||||
CANCEL /** < The VM was migrated because of an explicit cancel */
|
||||
USER, /** < The VM was migrated because of an explicit request */
|
||||
CANCEL /** < The VM was migrated because of an explicit cancel */
|
||||
};
|
||||
|
||||
History(int oid, int _seq = -1);
|
||||
|
||||
History(
|
||||
int oid,
|
||||
int seq,
|
||||
int hid,
|
||||
string& hostname,
|
||||
string& vm_dir,
|
||||
string& vmm,
|
||||
string& tm);
|
||||
int oid,
|
||||
int seq,
|
||||
int hid,
|
||||
string& hostname,
|
||||
string& vm_dir,
|
||||
string& vmm,
|
||||
string& tm);
|
||||
|
||||
~History(){};
|
||||
|
||||
@ -77,9 +70,10 @@ public:
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
|
||||
private:
|
||||
friend class VirtualMachine;
|
||||
friend class VirtualMachinePool;
|
||||
|
||||
// ----------------------------------------
|
||||
// DataBase implementation variables
|
||||
@ -166,52 +160,50 @@ private:
|
||||
string checkpoint_file;
|
||||
string rdeployment_file;
|
||||
|
||||
friend int history_select_cb (
|
||||
void * _history,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
/**
|
||||
* Writes the history record in the DB
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int insert(SqliteDB * db);
|
||||
int insert(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Reads the history record from the DB
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int select(SqliteDB * db);
|
||||
|
||||
/**
|
||||
* Removes the all history records from the DB
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
|
||||
*/
|
||||
int drop(SqliteDB * db);
|
||||
|
||||
int select(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Updates the history record
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int update(SqliteDB * db)
|
||||
{
|
||||
return insert(db);
|
||||
}
|
||||
int update(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Function to unmarshall a history object
|
||||
* Removes the all history records from the DB
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
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 on success
|
||||
*/
|
||||
int insert_replace(SqlDB *db, bool replace);
|
||||
|
||||
/**
|
||||
* Callback function to unmarshall a history object (History::select)
|
||||
* @param num the number of columns read from the DB
|
||||
* @para names the column names
|
||||
* @para vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
int unmarshall(int num, char **names, char ** values);
|
||||
int select_cb(void *nil, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Function to unmarshall a History object into an output stream with XML
|
||||
@ -222,10 +214,7 @@ private:
|
||||
* @param vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
static int unmarshall(ostringstream& oss,
|
||||
int num,
|
||||
char ** names,
|
||||
char ** values);
|
||||
static int dump(ostringstream& oss, int num, char **names, char **values);
|
||||
};
|
||||
|
||||
#endif /*HISTORY_H_*/
|
||||
#endif /*HISTORY_H_*/
|
282
include/Host.h
282
include/Host.h
@ -1,18 +1,18 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* 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 HOST_H_
|
||||
#define HOST_H_
|
||||
@ -23,32 +23,20 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" int host_select_cb (void * _host,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
extern "C" int host_dump_cb (void * _oss,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* The Host class. It represents a Host...
|
||||
* The Host class.
|
||||
*/
|
||||
class Host : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Host States
|
||||
// ------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
enum HostState
|
||||
{
|
||||
INIT = 0, /**< Initial state for enabled hosts. */
|
||||
INIT = 0, /**< Initial state for enabled hosts. */
|
||||
MONITORING = 1, /**< The host is being monitored. */
|
||||
MONITORED = 2, /**< The host has been successfully monitored. */
|
||||
ERROR = 3, /**< An error ocurrer while monitoring the host. */
|
||||
@ -63,14 +51,14 @@ public:
|
||||
/**
|
||||
* Function to print the Host object into a string in plain text
|
||||
* @param str the resulting string
|
||||
* @return a reference to the generated string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_str(string& str) const;
|
||||
|
||||
/**
|
||||
* Function to print the Host object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
@ -91,7 +79,7 @@ public:
|
||||
{
|
||||
return state != DISABLED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the Host's last_monitored time stamp.
|
||||
* @param success if the monitored action was successfully performed
|
||||
@ -99,7 +87,7 @@ public:
|
||||
void touch(bool success)
|
||||
{
|
||||
last_monitored = time(0);
|
||||
|
||||
|
||||
if ( state != DISABLED) //Don't change the state is host is disabled
|
||||
{
|
||||
if (success == true)
|
||||
@ -112,25 +100,25 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Disables the current host, it will not be monitored nor used by the
|
||||
* Disables the current host, it will not be monitored nor used by the
|
||||
* scheduler
|
||||
*/
|
||||
*/
|
||||
void disable()
|
||||
{
|
||||
state = DISABLED;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enables the current host, it will be monitored and could be used by
|
||||
* Enables the current host, it will be monitored and could be used by
|
||||
* the scheduler
|
||||
*/
|
||||
*/
|
||||
void enable()
|
||||
{
|
||||
state = INIT;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns host host_name
|
||||
* @return host_name Host's hostname
|
||||
@ -139,7 +127,7 @@ public:
|
||||
{
|
||||
return hostname;
|
||||
};
|
||||
|
||||
|
||||
/** Update host counters and update the whole host on the DB
|
||||
* @param parse_str string with values to be parsed
|
||||
* @return 0 on success
|
||||
@ -147,7 +135,8 @@ public:
|
||||
int update_info(string &parse_str);
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrives host state
|
||||
* @return HostState code number
|
||||
*/
|
||||
HostState get_state() const
|
||||
{
|
||||
@ -155,39 +144,44 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrives VMM mad name
|
||||
* @return string vmm mad name
|
||||
*/
|
||||
const string& get_vmm_mad() const
|
||||
{
|
||||
return vmm_mad_name;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrives TM mad name
|
||||
* @return string tm mad name
|
||||
*/
|
||||
const string& get_tm_mad() const
|
||||
{
|
||||
return tm_mad_name;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrives IM mad name
|
||||
* @return string im mad name
|
||||
*/
|
||||
const string& get_im_mad() const
|
||||
{
|
||||
return im_mad_name;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Sets host state
|
||||
* @param HostState state that applies to this host
|
||||
*/
|
||||
void set_state(HostState state)
|
||||
{
|
||||
this->state = state;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrives last time the host was monitored
|
||||
* @return time_t last monitored time
|
||||
*/
|
||||
time_t get_last_monitored() const
|
||||
{
|
||||
@ -196,7 +190,7 @@ public:
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Template
|
||||
// ------------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Gets the values of a template attribute
|
||||
@ -205,7 +199,7 @@ public:
|
||||
* @return the number of values
|
||||
*/
|
||||
int get_template_attribute(
|
||||
string& name,
|
||||
string& name,
|
||||
vector<const Attribute*>& values) const
|
||||
{
|
||||
return host_template.get(name,values);
|
||||
@ -224,61 +218,37 @@ public:
|
||||
string str=name;
|
||||
return host_template.get(str,values);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets a string based host attribute
|
||||
* @param name of the attribute
|
||||
* @param value of the attribute (a string), will be "" if not defined
|
||||
* @param value of the attribute (a string), will be "" if not defined
|
||||
*/
|
||||
void get_template_attribute(
|
||||
const char * name,
|
||||
const char * name,
|
||||
string& value) const
|
||||
{
|
||||
string str=name;
|
||||
host_template.get(str,value);
|
||||
}
|
||||
|
||||
host_template.get(str,value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string based host attribute
|
||||
* @param name of the attribute
|
||||
* @param value of the attribute (an int), will be 0 if not defined
|
||||
* @param value of the attribute (an int), will be 0 if not defined
|
||||
*/
|
||||
void get_template_attribute(
|
||||
const char * name,
|
||||
const char * name,
|
||||
int& value) const
|
||||
{
|
||||
string str=name;
|
||||
host_template.get(str,value);
|
||||
host_template.get(str,value);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Lex & bison parser for requirements and rank expressions
|
||||
// ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Evaluates a requirement expression on the given host.
|
||||
* @param requirements string
|
||||
* @param result true if the host matches the requirements
|
||||
* @param errmsg string describing the error, must be freed by the
|
||||
* calling function
|
||||
* @return 0 on success
|
||||
*/
|
||||
int match(const string& requirements, bool& result, char **errmsg);
|
||||
|
||||
/**
|
||||
* Evaluates a rank expression on the given host.
|
||||
* @param rank string
|
||||
* @param result of the rank evaluation
|
||||
* @param errmsg string describing the error, must be freed by the
|
||||
* calling function
|
||||
* @return 0 on success
|
||||
*/
|
||||
int rank(const string& rank, int& result, char **errmsg);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Share functions
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@ -349,7 +319,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new VM to the given share by icrementing the cpu,mem and disk
|
||||
* Adds a new VM to the given share by icrementing the cpu,mem and disk
|
||||
* counters
|
||||
* @param cpu needed by the VM (percentage)
|
||||
* @param mem needed by the VM (in Kb)
|
||||
@ -360,9 +330,9 @@ public:
|
||||
{
|
||||
host_share.add(cpu,mem,disk);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Deletes a new VM from the given share by decrementing the cpu,mem and
|
||||
* Deletes a new VM from the given share by decrementing the cpu,mem and
|
||||
* disk counters
|
||||
* @param cpu useded by the VM (percentage)
|
||||
* @param mem used by the VM (in Kb)
|
||||
@ -370,8 +340,8 @@ public:
|
||||
* @return 0 on success
|
||||
*/
|
||||
void del_capacity(int cpu, int mem, int disk)
|
||||
{
|
||||
host_share.del(cpu,mem,disk);
|
||||
{
|
||||
host_share.del(cpu,mem,disk);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -385,22 +355,15 @@ public:
|
||||
{
|
||||
return host_share.test(cpu,mem,disk);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Friends
|
||||
// -------------------------------------------------------------------------
|
||||
friend class HostPool;
|
||||
|
||||
friend int host_select_cb (void * _host,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
friend int host_dump_cb (void * _oss,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
friend class HostPool;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Host Description
|
||||
// -------------------------------------------------------------------------
|
||||
@ -411,32 +374,32 @@ private:
|
||||
* The state of the Host
|
||||
*/
|
||||
HostState state;
|
||||
|
||||
|
||||
/**
|
||||
* Name of the IM driver used to monitor this host
|
||||
*/
|
||||
*/
|
||||
string im_mad_name;
|
||||
|
||||
|
||||
/**
|
||||
* Name of the VM driver used to execute VMs in this host
|
||||
*/
|
||||
*/
|
||||
string vmm_mad_name;
|
||||
|
||||
|
||||
/**
|
||||
* Name of the TM driver used to transfer file to and from this host
|
||||
*/
|
||||
*/
|
||||
string tm_mad_name;
|
||||
|
||||
|
||||
/**
|
||||
* If Host State = MONITORED last time it got fully monitored or 1 Jan 1970
|
||||
* Host State = MONITORING last time it got a signal to be monitored
|
||||
*/
|
||||
*/
|
||||
time_t last_monitored;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Host Attributes
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* The Host template, holds the Host attributes.
|
||||
*/
|
||||
@ -447,54 +410,43 @@ private:
|
||||
*/
|
||||
HostShare host_share;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Lex & bison
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Mutex to perform just one flex-bison parsing at a time
|
||||
*/
|
||||
static pthread_mutex_t lex_mutex;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Function to unmarshall a Host object
|
||||
* @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 unmarshall(int num, char **names, char ** values);
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Function to unmarshall a Host object in to an output stream in XML
|
||||
* @param oss the output stream
|
||||
* Callback function to unmarshall a Host object (Host::select)
|
||||
* @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 unmarshall(ostringstream& oss,
|
||||
int num,
|
||||
char ** names,
|
||||
char ** values);
|
||||
int select_cb(void *nil, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Host
|
||||
*/
|
||||
static void bootstrap(SqliteDB * db)
|
||||
{
|
||||
db->exec(Host::db_bootstrap);
|
||||
|
||||
db->exec(HostShare::db_bootstrap);
|
||||
|
||||
db->exec(HostTemplate::db_bootstrap);
|
||||
static void bootstrap(SqlDB * db)
|
||||
{
|
||||
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:
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
@ -502,23 +454,23 @@ protected:
|
||||
Host(int id=-1,
|
||||
string _hostname="",
|
||||
string _im_mad_name="",
|
||||
string _vmm_mad_name="",
|
||||
string _vmm_mad_name="",
|
||||
string _tm_mad_name="");
|
||||
|
||||
virtual ~Host();
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
||||
|
||||
enum ColNames
|
||||
{
|
||||
OID = 0,
|
||||
HOST_NAME = 1,
|
||||
STATE = 2,
|
||||
IM_MAD = 3,
|
||||
VM_MAD = 4,
|
||||
TM_MAD = 5,
|
||||
OID = 0,
|
||||
HOST_NAME = 1,
|
||||
STATE = 2,
|
||||
IM_MAD = 3,
|
||||
VM_MAD = 4,
|
||||
TM_MAD = 5,
|
||||
LAST_MON_TIME = 6,
|
||||
LIMIT = 7
|
||||
};
|
||||
@ -526,7 +478,7 @@ protected:
|
||||
static const char * db_names;
|
||||
|
||||
static const char * db_bootstrap;
|
||||
|
||||
|
||||
static const char * table;
|
||||
|
||||
/**
|
||||
@ -534,38 +486,38 @@ protected:
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int select(SqliteDB *db);
|
||||
virtual int select(SqlDB *db);
|
||||
|
||||
/**
|
||||
* Writes the Host and its associated HostShares in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int insert(SqliteDB *db);
|
||||
virtual int insert(SqlDB *db);
|
||||
|
||||
/**
|
||||
* Writes/updates the Hosts data fields in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int update(SqliteDB *db);
|
||||
|
||||
virtual int update(SqlDB *db);
|
||||
|
||||
/**
|
||||
* Drops host from the database
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int drop(SqliteDB *db);
|
||||
virtual int drop(SqlDB *db);
|
||||
|
||||
/**
|
||||
* Dumps the contect of a set of Host objects in the given stream
|
||||
* using XML format
|
||||
* @param db pointer to the db
|
||||
* Function to output a Host object in to an stream in XML format
|
||||
* @param oss the output stream
|
||||
* @param where string to filter the VirtualMachine objects
|
||||
* @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(SqliteDB * db, ostringstream& oss, const string& where);
|
||||
static int dump(ostringstream& oss, int num, char **values, char **names);
|
||||
};
|
||||
|
||||
#endif /*HOST_H_*/
|
||||
|
@ -30,26 +30,26 @@
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* The Host Pool class. ...
|
||||
* The Host Pool class.
|
||||
*/
|
||||
class HostPool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
HostPool(SqliteDB * db):PoolSQL(db,Host::table){};
|
||||
HostPool(SqlDB * db):PoolSQL(db,Host::table){};
|
||||
|
||||
~HostPool(){};
|
||||
|
||||
/**
|
||||
* Function to allocate a new Host object
|
||||
* @param oid the id assigned to the Host
|
||||
* @return 0 on success
|
||||
* @return the oid assigned to the object or -1 in case of failure
|
||||
*/
|
||||
int allocate (
|
||||
int * oid,
|
||||
string hostname,
|
||||
string im_mad_name,
|
||||
string vmm_mad_name,
|
||||
string im_mad_name,
|
||||
string vmm_mad_name,
|
||||
string tm_mad_name);
|
||||
|
||||
/**
|
||||
@ -65,33 +65,24 @@ public:
|
||||
{
|
||||
return static_cast<Host *>(PoolSQL::get(oid,lock));
|
||||
};
|
||||
|
||||
/** Update a particular Host
|
||||
|
||||
/** Update a particular Host
|
||||
* @param host pointer to Host
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update(Host * host)
|
||||
{
|
||||
return host->update(db);
|
||||
};
|
||||
|
||||
|
||||
/** Drops a host from the DB, the host mutex MUST BE locked
|
||||
* @param host pointer to Host
|
||||
*/
|
||||
int drop(Host * host)
|
||||
{
|
||||
return host->drop(db);
|
||||
return host->update(db);
|
||||
};
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Host pool
|
||||
*/
|
||||
static void bootstrap(SqliteDB *_db)
|
||||
static void bootstrap(SqlDB *_db)
|
||||
{
|
||||
Host::bootstrap(_db);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the 10 least monitored hosts
|
||||
* @param discovered hosts, map to store the retrieved hosts hids and
|
||||
@ -109,36 +100,37 @@ public:
|
||||
*/
|
||||
void add_capacity(int oid,int cpu, int mem, int disk)
|
||||
{
|
||||
Host * host = get(oid, true);
|
||||
|
||||
if ( host != 0 )
|
||||
{
|
||||
host->add_capacity(cpu, mem, disk);
|
||||
|
||||
update(host);
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
Host * host = get(oid, true);
|
||||
|
||||
if ( host != 0 )
|
||||
{
|
||||
host->add_capacity(cpu, mem, disk);
|
||||
|
||||
update(host);
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* De-Allocates a given capacity to the host
|
||||
* @param oid the id of the host to allocate the capacity
|
||||
* @param cpu amount of CPU
|
||||
* @param mem amount of main memory
|
||||
* @param disk amount of disk
|
||||
*/
|
||||
*/
|
||||
void del_capacity(int oid,int cpu, int mem, int disk)
|
||||
{
|
||||
Host * host = get(oid, true);
|
||||
|
||||
if ( host != 0 )
|
||||
{
|
||||
host->del_capacity(cpu, mem, disk);
|
||||
|
||||
update(host);
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
Host * host = get(oid, true);
|
||||
|
||||
if ( host != 0 )
|
||||
{
|
||||
host->del_capacity(cpu, mem, disk);
|
||||
|
||||
update(host);
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -149,19 +141,8 @@ public:
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump(ostringstream& oss, const string& where)
|
||||
{
|
||||
int rc;
|
||||
int dump(ostringstream& oss, const string& where);
|
||||
|
||||
oss << "<HOST_POOL>";
|
||||
|
||||
rc = Host::dump(db,oss,where);
|
||||
|
||||
oss << "</HOST_POOL>";
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Factory method to produce Host objects
|
||||
@ -172,6 +153,25 @@ private:
|
||||
return new Host;
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback function to get the IDs of the hosts to be monitored
|
||||
* (Host::discover)
|
||||
* @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 discover_cb(void * _map, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Callback function to get output the host pool in XML format
|
||||
* (Host::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_cb(void * _oss, int num, char **values, char **names);
|
||||
};
|
||||
|
||||
#endif /*HOST_POOL_H_*/
|
||||
#endif /*HOST_POOL_H_*/
|
@ -1,40 +1,35 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* 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 HOST_SHARE_H_
|
||||
#define HOST_SHARE_H_
|
||||
|
||||
#include "SqliteDB.h"
|
||||
#include "SqlDB.h"
|
||||
#include "ObjectSQL.h"
|
||||
#include <time.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" int host_share_select_cb (void * _hs,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* The HostShare class. It represents a logical partition of a host...
|
||||
*/
|
||||
class HostShare : public ObjectSQL
|
||||
class HostShare : public ObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
@ -57,7 +52,7 @@ public:
|
||||
cpu_usage += cpu;
|
||||
mem_usage += mem;
|
||||
disk_usage += disk;
|
||||
|
||||
|
||||
running_vms++;
|
||||
}
|
||||
|
||||
@ -72,17 +67,17 @@ public:
|
||||
cpu_usage -= cpu;
|
||||
mem_usage -= mem;
|
||||
disk_usage -= disk;
|
||||
|
||||
running_vms--;
|
||||
|
||||
running_vms--;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if this share can host a VM.
|
||||
* Check if this share can host a VM.
|
||||
* @param cpu requested by the VM
|
||||
* @param mem requested by the VM
|
||||
* @param disk requested by the VM
|
||||
*
|
||||
* @return true if the share can host the VM or it is the only one
|
||||
*
|
||||
* @return true if the share can host the VM or it is the only one
|
||||
* configured
|
||||
*/
|
||||
bool test(int cpu, int mem, int disk) const
|
||||
@ -90,8 +85,8 @@ public:
|
||||
return (((max_cpu - cpu_usage ) >= cpu) &&
|
||||
((max_mem - mem_usage ) >= mem) &&
|
||||
((max_disk - disk_usage) >= disk));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to write a HostShare to an output stream
|
||||
*/
|
||||
@ -112,15 +107,15 @@ public:
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
int hsid; /**< HostShare identifier */
|
||||
|
||||
|
||||
int disk_usage; /**< Disk allocated to VMs (in Mb). */
|
||||
int mem_usage; /**< Memory allocated to VMs (in Mb) */
|
||||
int cpu_usage; /**< CPU allocated to VMs (in percentage) */
|
||||
|
||||
|
||||
int max_disk; /**< Total disk capacity (in Mb) */
|
||||
int max_mem; /**< Total memory capacity (in Mb) */
|
||||
int max_cpu; /**< Total cpu capacity (in percentage) */
|
||||
@ -134,19 +129,14 @@ private:
|
||||
int used_cpu; /**< Used cpu from the IM monitor */
|
||||
|
||||
int running_vms; /**< Number of running VMs in this Host */
|
||||
|
||||
|
||||
// ----------------------------------------
|
||||
// Friends
|
||||
// ----------------------------------------
|
||||
|
||||
friend class Host;
|
||||
|
||||
friend int host_share_select_cb (
|
||||
void * _hostshare,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
friend class HostPool;
|
||||
|
||||
// ----------------------------------------
|
||||
// DataBase implementation variables
|
||||
// ----------------------------------------
|
||||
@ -171,7 +161,7 @@ private:
|
||||
};
|
||||
|
||||
static const char * table;
|
||||
|
||||
|
||||
static const char * db_names;
|
||||
|
||||
static const char * db_bootstrap;
|
||||
@ -179,43 +169,51 @@ private:
|
||||
// ----------------------------------------
|
||||
// Database methods
|
||||
// ----------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Reads the HostShare (identified with its HSID) from the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select(SqliteDB * db);
|
||||
int select(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Writes the HostShare in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int insert(SqliteDB * db);
|
||||
int insert(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Writes/updates the HostShare data fields in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update(SqliteDB * db);
|
||||
|
||||
int update(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Drops hostshare from the database
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int drop(SqliteDB * db);
|
||||
|
||||
int drop(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Function to unmarshall a HostShare object
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Callback function to unmarshall a HostShare object (HostShare::select)
|
||||
* @param num the number of columns read from the DB
|
||||
* @para names the column names
|
||||
* @para vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
int unmarshall(int num, char **names, char ** values);
|
||||
int select_cb(void * nil, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Function to unmarshall a HostShare object in to an output stream in XML
|
||||
@ -225,10 +223,8 @@ private:
|
||||
* @param vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
static int unmarshall(ostringstream& oss,
|
||||
int num,
|
||||
char ** names,
|
||||
char ** values);
|
||||
static int dump(ostringstream& oss, int num, char **values, char **names);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
#ifndef LEASES_H_
|
||||
#define LEASES_H_
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include "ObjectSQL.h"
|
||||
#include "Attribute.h"
|
||||
|
||||
@ -27,12 +26,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" int leases_select_cb (
|
||||
void * _lease,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
/**
|
||||
* The Leases class represents all the IP and MAC addresses (lease) that can
|
||||
* be asigned (or are asigned) in a Virtual Network
|
||||
@ -46,13 +39,13 @@ public:
|
||||
* @param _oid the virtual network unique identifier
|
||||
* @param _size the max number of leases
|
||||
*/
|
||||
Leases(SqliteDB * _db, int _oid, unsigned long _size):
|
||||
Leases(SqlDB * _db, int _oid, unsigned long _size):
|
||||
oid(_oid), size(_size), db(_db){};
|
||||
|
||||
|
||||
virtual ~Leases()
|
||||
{
|
||||
map<unsigned int, Lease *>::iterator it;
|
||||
|
||||
|
||||
for(it=leases.begin();it!=leases.end();it++)
|
||||
{
|
||||
delete it->second;
|
||||
@ -78,7 +71,7 @@ public:
|
||||
* @return 0 if success
|
||||
*/
|
||||
virtual int set(int vid, const string& ip, string& mac) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Release an used lease, which becomes unused
|
||||
* @param ip of the lease in use
|
||||
@ -122,31 +115,31 @@ protected:
|
||||
};
|
||||
|
||||
~Lease(){};
|
||||
|
||||
|
||||
/**
|
||||
* Converts this lease's IP and MAC to string
|
||||
* @param ip ip of the lease in string
|
||||
* @param mac mac of the lease in string
|
||||
*/
|
||||
void to_string(string& _ip, string& _mac) const;
|
||||
|
||||
|
||||
/**
|
||||
* Conversion from string IP to unsigned int IP
|
||||
* @return 0 if success
|
||||
*/
|
||||
static int ip_to_number(const string& ip, unsigned int& i_ip);
|
||||
|
||||
|
||||
/**
|
||||
* Conversion from unsigned int IP to string IP
|
||||
*/
|
||||
static void ip_to_string(const unsigned int i_ip, string& ip);
|
||||
|
||||
|
||||
/**
|
||||
* Conversion from string MAC to unsigned int[] MAC
|
||||
* @return 0 if success
|
||||
*/
|
||||
static int mac_to_number(const string& mac, unsigned int i_mac[]);
|
||||
|
||||
|
||||
/**
|
||||
* Conversion from string IP to unsigned int IP
|
||||
*/
|
||||
@ -161,7 +154,7 @@ protected:
|
||||
* Function to print the Lease object into a string in
|
||||
* plain text
|
||||
* @param str the resulting string
|
||||
* @return a reference to the generated string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_str(string& str) const;
|
||||
|
||||
@ -169,10 +162,10 @@ protected:
|
||||
* Function to print the Lease object into a string in
|
||||
* XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
|
||||
/**
|
||||
* Constants to access the array storing the MAC address
|
||||
*/
|
||||
@ -181,19 +174,19 @@ protected:
|
||||
SUFFIX = 0,/**< Lower significant 4 bytes */
|
||||
PREFIX = 1 /**< Higher significant 2 bytes */
|
||||
};
|
||||
|
||||
|
||||
unsigned int ip;
|
||||
|
||||
|
||||
unsigned int mac [2];
|
||||
|
||||
|
||||
int vid;
|
||||
|
||||
|
||||
bool used;
|
||||
};
|
||||
|
||||
friend class VirtualNetwork;
|
||||
friend class VirtualNetworkPool;
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Leases fields
|
||||
// -------------------------------------------------------------------------
|
||||
@ -201,12 +194,12 @@ protected:
|
||||
* Leases indentifier. Connects it to a Virtual Network
|
||||
*/
|
||||
int oid;
|
||||
|
||||
|
||||
/**
|
||||
* Number of possible leases (free + asigned)
|
||||
*/
|
||||
unsigned int size;
|
||||
|
||||
|
||||
/**
|
||||
* Hash of leases, indexed by lease.ip
|
||||
*/
|
||||
@ -218,7 +211,7 @@ protected:
|
||||
/**
|
||||
* Pointer to the DataBase
|
||||
*/
|
||||
SqliteDB * db;
|
||||
SqlDB * db;
|
||||
|
||||
enum ColNames
|
||||
{
|
||||
@ -240,29 +233,30 @@ protected:
|
||||
// -------------------------------------------------------------------------
|
||||
// Leases methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Check if the passed ip corresponds with a given lease
|
||||
* @param ip of the lease to be checked
|
||||
* @return true if the ip was already assigned
|
||||
*/
|
||||
bool check(const string& ip);
|
||||
|
||||
bool check(unsigned int ip);
|
||||
bool check(const string& ip);
|
||||
|
||||
bool check(unsigned int ip);
|
||||
|
||||
/**
|
||||
* Reads the leases from the DB, and updates the lease hash table
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
virtual int select(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Reads the leases from the DB, and updates the lease hash table
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
virtual int select(SqliteDB * db);
|
||||
|
||||
friend ostream& operator<<(ostream& os, Lease& _lease);
|
||||
|
||||
/**
|
||||
* Function to print the Leases object into a string in
|
||||
* plain text
|
||||
* @param str the resulting string
|
||||
* @return a reference to the generated string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_str(string& str) const;
|
||||
|
||||
@ -270,34 +264,27 @@ protected:
|
||||
* Function to print the Leases object into a string in
|
||||
* XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
private:
|
||||
|
||||
friend int leases_select_cb (
|
||||
void * _leases,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
/**
|
||||
* Function to unmarshall a leases object
|
||||
* Callback function to unmarshall a Lease object (Lease::select)
|
||||
* @param num the number of columns read from the DB
|
||||
* @para names the column names
|
||||
* @para vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
int unmarshall(int num, char **names, char ** values);
|
||||
|
||||
int select_cb(void *nil, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* This method should not be called, leases are added/removed/updated
|
||||
* through add/del interface
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int insert(SqliteDB * db);
|
||||
int insert(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Leases are added/removed/updated through add/del interface
|
||||
@ -305,7 +292,7 @@ private:
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int drop(SqliteDB * db);
|
||||
int drop(SqlDB * db);
|
||||
|
||||
/**
|
||||
* This method should not be called, leases are added/removed/updated
|
||||
@ -313,7 +300,7 @@ private:
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int update(SqliteDB * db);
|
||||
int update(SqlDB * db);
|
||||
};
|
||||
|
||||
#endif /*LEASES_H_*/
|
||||
|
117
include/Log.h
117
include/Log.h
@ -22,6 +22,10 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* The Logger class is an interface used by OpenNebula components to log
|
||||
* messages
|
||||
*/
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
@ -29,39 +33,108 @@ public:
|
||||
ERROR = 0,
|
||||
WARNING = 1,
|
||||
INFO = 2,
|
||||
DEBUG = 3
|
||||
DEBUG = 3,
|
||||
DDEBUG = 4,
|
||||
DDDEBUG = 5
|
||||
};
|
||||
|
||||
typedef void (*LogFunction)(
|
||||
const char *,
|
||||
const MessageType,
|
||||
const ostringstream&,
|
||||
const char *,
|
||||
const MessageType);
|
||||
|
||||
Log(const string& file_name,
|
||||
const MessageType level = WARNING,
|
||||
ios_base::openmode mode = ios_base::app);
|
||||
static const char error_names[];
|
||||
|
||||
Log(const MessageType _level = WARNING):log_level(_level){};
|
||||
|
||||
virtual ~Log(){};
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Logger interface
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
virtual void log(
|
||||
const char * module,
|
||||
const MessageType type,
|
||||
const char * message) = 0;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Minimum log level for the messages
|
||||
*/
|
||||
MessageType log_level;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Log messages to a log file
|
||||
*/
|
||||
class FileLog : public Log
|
||||
{
|
||||
public:
|
||||
FileLog(const string& file_name,
|
||||
const MessageType level = WARNING,
|
||||
ios_base::openmode mode = ios_base::app);
|
||||
|
||||
virtual ~FileLog();
|
||||
|
||||
virtual void log(
|
||||
const char * module,
|
||||
const MessageType type,
|
||||
const char * message);
|
||||
|
||||
private:
|
||||
char * log_file;
|
||||
};
|
||||
|
||||
/**
|
||||
* Log messages to a log file
|
||||
*/
|
||||
class FileLogTS : public FileLog
|
||||
{
|
||||
public:
|
||||
FileLogTS(const string& file_name,
|
||||
const MessageType level = WARNING,
|
||||
ios_base::openmode mode = ios_base::app)
|
||||
:FileLog(file_name,level,mode)
|
||||
{
|
||||
pthread_mutex_init(&log_mutex,0);
|
||||
}
|
||||
|
||||
~FileLogTS()
|
||||
{
|
||||
pthread_mutex_destroy(&log_mutex);
|
||||
}
|
||||
|
||||
~Log();
|
||||
|
||||
void log(
|
||||
const char * module,
|
||||
const MessageType type,
|
||||
const ostringstream& message);
|
||||
const char * message)
|
||||
{
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
FileLog::log(module,type,message);
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
}
|
||||
|
||||
private:
|
||||
pthread_mutex_t log_mutex;
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class CerrLog : public Log
|
||||
{
|
||||
public:
|
||||
CerrLog(const MessageType level = WARNING):Log(level){};
|
||||
|
||||
~CerrLog(){};
|
||||
|
||||
void log(
|
||||
const char * module,
|
||||
const MessageType type,
|
||||
const char * message);
|
||||
|
||||
private:
|
||||
|
||||
static const char error_names[];
|
||||
|
||||
MessageType log_level;
|
||||
|
||||
char * log_file;
|
||||
};
|
||||
|
||||
#endif /* _LOG_H_ */
|
||||
|
129
include/MySqlDB.h
Normal file
129
include/MySqlDB.h
Normal file
@ -0,0 +1,129 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 MYSQL_DB_H_
|
||||
#define MYSQL_DB_H_
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "NebulaLog.h"
|
||||
#include "SqlDB.h"
|
||||
#include "ObjectSQL.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef MYSQL_DB
|
||||
|
||||
#include <mysql.h>
|
||||
|
||||
/**
|
||||
* SqliteDB class. Provides a wrapper to the mysql database interface.
|
||||
*/
|
||||
class MySqlDB : public SqlDB
|
||||
{
|
||||
public:
|
||||
|
||||
MySqlDB(const string& server,
|
||||
const string& user,
|
||||
const string& password,
|
||||
char * database);
|
||||
|
||||
~MySqlDB();
|
||||
|
||||
/**
|
||||
* Wraps the mysql_query function call
|
||||
* @param cmd the SQL command
|
||||
* @param obj Callbackable obj to call if the query succeeds
|
||||
* @return 0 on success
|
||||
*/
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0);
|
||||
|
||||
/**
|
||||
* This function returns a legal SQL string that can be used in an SQL
|
||||
* statement. The string is encoded to an escaped SQL string, taking into
|
||||
* account the current character set of the connection.
|
||||
* @param str the string to be escaped
|
||||
* @return a valid SQL string or NULL in case of failure
|
||||
*/
|
||||
char * escape_str(const string& str);
|
||||
|
||||
/**
|
||||
* Frees a previously scaped string
|
||||
* @param str pointer to the str
|
||||
*/
|
||||
void free_str(char * str);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The MySql connection handler
|
||||
*/
|
||||
MYSQL * db;
|
||||
|
||||
/**
|
||||
* Fine-grain mutex for DB access
|
||||
*/
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
/**
|
||||
* Function to lock the DB
|
||||
*/
|
||||
void lock()
|
||||
{
|
||||
pthread_mutex_lock(&mutex);
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to unlock the DB
|
||||
*/
|
||||
void unlock()
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
};
|
||||
};
|
||||
#else
|
||||
//CLass stub
|
||||
class MySqlDB : public SqlDB
|
||||
{
|
||||
public:
|
||||
|
||||
MySqlDB(
|
||||
string server,
|
||||
string user,
|
||||
string password,
|
||||
char * database)
|
||||
{
|
||||
throw runtime_error("Aborting oned, MySQL support not compiled!");
|
||||
};
|
||||
|
||||
~MySqlDB(){};
|
||||
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0){return -1;};
|
||||
|
||||
char * escape_str(const string& str){return 0;};
|
||||
|
||||
void free_str(char * str){};
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /*MYSQL_DB_H_*/
|
171
include/Nebula.h
171
include/Nebula.h
@ -17,9 +17,8 @@
|
||||
#ifndef NEBULA_H_
|
||||
#define NEBULA_H_
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include "SqlDB.h"
|
||||
|
||||
#include "Log.h"
|
||||
#include "NebulaTemplate.h"
|
||||
|
||||
#include "VirtualMachinePool.h"
|
||||
@ -38,63 +37,33 @@
|
||||
class Nebula
|
||||
{
|
||||
public:
|
||||
|
||||
static Nebula& instance()
|
||||
|
||||
static Nebula& instance()
|
||||
{
|
||||
static Nebula nebulad;
|
||||
|
||||
|
||||
return nebulad;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Logging
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
static void log(
|
||||
const char * module,
|
||||
const Log::MessageType type,
|
||||
const ostringstream& message,
|
||||
const char * filename = 0,
|
||||
Log::MessageType clevel = Log::ERROR)
|
||||
{
|
||||
static Log nebula_log(filename,clevel,ios_base::trunc);
|
||||
static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
nebula_log.log(module,type,message);
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
};
|
||||
|
||||
static void log(
|
||||
const char * module,
|
||||
const Log::MessageType type,
|
||||
const char * message,
|
||||
const char * filename = 0)
|
||||
{
|
||||
ostringstream os(message);
|
||||
|
||||
Nebula::log(module,type,os,filename);
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Pool Accessors
|
||||
// --------------------------------------------------------------
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
VirtualMachinePool * get_vmpool()
|
||||
{
|
||||
return vmpool;
|
||||
};
|
||||
};
|
||||
|
||||
HostPool * get_hpool()
|
||||
{
|
||||
return hpool;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
VirtualNetworkPool * get_vnpool()
|
||||
{
|
||||
return vnpool;
|
||||
};
|
||||
|
||||
|
||||
UserPool * get_upool()
|
||||
{
|
||||
return upool;
|
||||
@ -102,8 +71,8 @@ public:
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Manager Accessors
|
||||
// --------------------------------------------------------------
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
VirtualMachineManager * get_vmm()
|
||||
{
|
||||
return vmm;
|
||||
@ -113,7 +82,7 @@ public:
|
||||
{
|
||||
return lcm;
|
||||
};
|
||||
|
||||
|
||||
InformationManager * get_im()
|
||||
{
|
||||
return im;
|
||||
@ -128,29 +97,29 @@ public:
|
||||
{
|
||||
return dm;
|
||||
};
|
||||
|
||||
|
||||
HookManager * get_hm()
|
||||
{
|
||||
return hm;
|
||||
};
|
||||
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Environment & Configuration
|
||||
// --------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of ONE_LOCATION env variable. When this variable is
|
||||
* Returns the value of ONE_LOCATION env variable. When this variable is
|
||||
* not defined the nebula location is "/".
|
||||
* @return the nebula location.
|
||||
*/
|
||||
*/
|
||||
const string& get_nebula_location()
|
||||
{
|
||||
return nebula_location;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the path where mad executables are stored, if ONE_LOCATION is
|
||||
* defined this path points to $ONE_LOCATION/bin, otherwise it is
|
||||
* Returns the path where mad executables are stored, if ONE_LOCATION is
|
||||
* defined this path points to $ONE_LOCATION/bin, otherwise it is
|
||||
* /usr/lib/one/mads.
|
||||
* @return the mad execs location.
|
||||
*/
|
||||
@ -160,7 +129,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the path where defaults for mads are stored, if ONE_LOCATION is
|
||||
* Returns the path where defaults for mads are stored, if ONE_LOCATION is
|
||||
* defined this path points to $ONE_LOCATION/etc, otherwise it is /etc/one
|
||||
* @return the mad defaults location.
|
||||
*/
|
||||
@ -168,10 +137,10 @@ public:
|
||||
{
|
||||
return etc_location;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the path where logs (oned.log, schedd.log,...) are generated
|
||||
* if ONE_LOCATION is defined this path points to $ONE_LOCATION/var,
|
||||
* if ONE_LOCATION is defined this path points to $ONE_LOCATION/var,
|
||||
* otherwise it is /var/log/one.
|
||||
* @return the log location.
|
||||
*/
|
||||
@ -181,8 +150,8 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the path where the OpenNebula DB and the VM local directories
|
||||
* are stored. When ONE_LOCATION is defined this path points to
|
||||
* Returns the path where the OpenNebula DB and the VM local directories
|
||||
* are stored. When ONE_LOCATION is defined this path points to
|
||||
* $ONE_LOCATION/var, otherwise it is /var/lib/one.
|
||||
* @return the log location.
|
||||
*/
|
||||
@ -190,7 +159,7 @@ public:
|
||||
{
|
||||
return var_location;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the path of the log file for a VM, depending where OpenNebula is
|
||||
* installed,
|
||||
@ -202,46 +171,46 @@ public:
|
||||
string get_vm_log_filename(int oid)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
|
||||
if (nebula_location == "/")
|
||||
{
|
||||
oss << log_location << oid << ".log";
|
||||
oss << log_location << oid << ".log";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << nebula_location << "var/" << oid << "/vm.log";
|
||||
oss << nebula_location << "var/" << oid << "/vm.log";
|
||||
}
|
||||
|
||||
|
||||
return oss.str();
|
||||
};
|
||||
|
||||
|
||||
const string& get_nebula_hostname()
|
||||
{
|
||||
return hostname;
|
||||
};
|
||||
|
||||
|
||||
static string version()
|
||||
{
|
||||
return "OpenNebula 1.5.0";
|
||||
return "OpenNebula 1.5.0";
|
||||
};
|
||||
|
||||
|
||||
void start();
|
||||
|
||||
|
||||
void get_configuration_attribute(
|
||||
const char * name,
|
||||
const char * name,
|
||||
string& value) const
|
||||
{
|
||||
string _name(name);
|
||||
|
||||
nebula_configuration->Template::get(_name,value);
|
||||
|
||||
nebula_configuration->Template::get(_name,value);
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
//Constructors and = are private to only access the class through instance
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
|
||||
Nebula():nebula_configuration(0),db(0),vmpool(0),hpool(0),vnpool(0),upool(0),
|
||||
lcm(0),vmm(0),im(0),tm(0),dm(0),rm(0)
|
||||
{
|
||||
@ -250,7 +219,7 @@ private:
|
||||
if (nl == 0) //OpenNebula installed under root directory
|
||||
{
|
||||
nebula_location = "/";
|
||||
|
||||
|
||||
mad_location = "/usr/lib/one/mads/";
|
||||
etc_location = "/etc/one/";
|
||||
log_location = "/var/log/one/";
|
||||
@ -259,19 +228,19 @@ private:
|
||||
else
|
||||
{
|
||||
nebula_location = nl;
|
||||
|
||||
|
||||
if ( nebula_location.at(nebula_location.size()-1) != '/' )
|
||||
{
|
||||
nebula_location += "/";
|
||||
}
|
||||
|
||||
mad_location = nebula_location + "lib/mads/";
|
||||
etc_location = nebula_location + "etc/";
|
||||
|
||||
mad_location = nebula_location + "lib/mads/";
|
||||
etc_location = nebula_location + "etc/";
|
||||
log_location = nebula_location + "var/";
|
||||
var_location = nebula_location + "var/";
|
||||
}
|
||||
var_location = nebula_location + "var/";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
~Nebula()
|
||||
{
|
||||
if ( vmpool != 0)
|
||||
@ -303,7 +272,7 @@ private:
|
||||
{
|
||||
delete lcm;
|
||||
}
|
||||
|
||||
|
||||
if ( im != 0)
|
||||
{
|
||||
delete im;
|
||||
@ -313,69 +282,69 @@ private:
|
||||
{
|
||||
delete tm;
|
||||
}
|
||||
|
||||
|
||||
if ( dm != 0)
|
||||
{
|
||||
delete dm;
|
||||
}
|
||||
|
||||
|
||||
if ( rm != 0)
|
||||
{
|
||||
delete rm;
|
||||
}
|
||||
|
||||
|
||||
if ( hm != 0)
|
||||
{
|
||||
delete hm;
|
||||
}
|
||||
|
||||
|
||||
if ( nebula_configuration != 0)
|
||||
{
|
||||
delete nebula_configuration;
|
||||
}
|
||||
|
||||
|
||||
if ( db != 0 )
|
||||
{
|
||||
delete db;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Nebula(Nebula const&){};
|
||||
|
||||
Nebula& operator=(Nebula const&){return *this;};
|
||||
|
||||
|
||||
Nebula& operator=(Nebula const&){return *this;};
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Environment variables
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
|
||||
string nebula_location;
|
||||
|
||||
|
||||
string mad_location;
|
||||
string etc_location;
|
||||
string log_location;
|
||||
string var_location;
|
||||
string hostname;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Configuration
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
NebulaTemplate * nebula_configuration;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Nebula Pools
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
SqliteDB * db;
|
||||
|
||||
SqlDB * db;
|
||||
VirtualMachinePool * vmpool;
|
||||
HostPool * hpool;
|
||||
VirtualNetworkPool * vnpool;
|
||||
UserPool * upool;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Nebula Managers
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
|
||||
LifeCycleManager * lcm;
|
||||
VirtualMachineManager * vmm;
|
||||
InformationManager * im;
|
||||
@ -383,11 +352,11 @@ private:
|
||||
DispatchManager * dm;
|
||||
RequestManager * rm;
|
||||
HookManager * hm;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Implementation functions
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
|
||||
friend void nebula_signal_handler (int sig);
|
||||
};
|
||||
|
||||
|
92
include/NebulaLog.h
Normal file
92
include/NebulaLog.h
Normal file
@ -0,0 +1,92 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 _NEBULA_LOG_H_
|
||||
#define _NEBULA_LOG_H_
|
||||
|
||||
#include "Log.h"
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* The Logger class for the OpenNebula components
|
||||
*/
|
||||
class NebulaLog
|
||||
{
|
||||
public:
|
||||
enum LogType {
|
||||
FILE = 0,
|
||||
FILE_TS = 1,
|
||||
CERR = 2
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Logging
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
static void init_log_system(
|
||||
LogType ltype,
|
||||
Log::MessageType clevel,
|
||||
const char * filename = 0,
|
||||
ios_base::openmode mode = ios_base::trunc)
|
||||
{
|
||||
switch(ltype)
|
||||
{
|
||||
case FILE:
|
||||
NebulaLog::logger = new FileLog(filename,clevel,mode);
|
||||
break;
|
||||
case FILE_TS:
|
||||
NebulaLog::logger = new FileLogTS(filename,clevel,mode);
|
||||
break;
|
||||
default:
|
||||
NebulaLog::logger = new CerrLog(clevel);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
static void finalize_log_system()
|
||||
{
|
||||
delete logger;
|
||||
}
|
||||
|
||||
static void log(
|
||||
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 ostringstream& message)
|
||||
{
|
||||
logger->log(module,type,message.str().c_str());
|
||||
};
|
||||
|
||||
private:
|
||||
NebulaLog(){};
|
||||
~NebulaLog(){};
|
||||
|
||||
static Log * logger;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif /* _NEBULA_LOG_H_ */
|
@ -17,7 +17,8 @@
|
||||
#ifndef OBJECT_SQL_H_
|
||||
#define OBJECT_SQL_H_
|
||||
|
||||
#include "SqliteDB.h"
|
||||
#include "Callbackable.h"
|
||||
#include "SqlDB.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -25,8 +26,7 @@ using namespace std;
|
||||
* ObjectSQL class. Provides a SQL backend interface, it should be implemented
|
||||
* by persistent objects.
|
||||
*/
|
||||
|
||||
class ObjectSQL
|
||||
class ObjectSQL : public Callbackable
|
||||
{
|
||||
public:
|
||||
|
||||
@ -41,7 +41,7 @@ protected:
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int select(
|
||||
SqliteDB * db) = 0;
|
||||
SqlDB * db) = 0;
|
||||
|
||||
/**
|
||||
* Writes the ObjectSQL in the database.
|
||||
@ -49,7 +49,7 @@ protected:
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int insert(
|
||||
SqliteDB * db) = 0;
|
||||
SqlDB * db) = 0;
|
||||
|
||||
/**
|
||||
* Updates the ObjectSQL in the database.
|
||||
@ -57,7 +57,7 @@ protected:
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int update(
|
||||
SqliteDB * db) = 0;
|
||||
SqlDB * db) = 0;
|
||||
|
||||
/**
|
||||
* Removes the ObjectSQL from the database.
|
||||
@ -65,7 +65,7 @@ protected:
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int drop(
|
||||
SqliteDB * db) = 0;
|
||||
SqlDB * db) = 0;
|
||||
};
|
||||
|
||||
#endif /*OBJECT_SQL_H_*/
|
||||
#endif /*OBJECT_SQL_H_*/
|
@ -17,19 +17,18 @@
|
||||
#ifndef POOL_OBJECT_SQL_H_
|
||||
#define POOL_OBJECT_SQL_H_
|
||||
|
||||
#include "SqliteDB.h"
|
||||
#include "ObjectSQL.h"
|
||||
#include <pthread.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* PoolObject class. Provides a SQL backend interface for Pool components. Each
|
||||
* PoolObject class. Provides a SQL backend interface for Pool components. Each
|
||||
* object is identified with and unique OID
|
||||
*
|
||||
* Note: The PoolObject provides a synchronization mechanism (mutex). This
|
||||
*
|
||||
* Note: The PoolObject provides a synchronization mechanism (mutex). This
|
||||
* implementation assumes that the mutex IS LOCKED when the class destructor
|
||||
* is called.
|
||||
* is called.
|
||||
*/
|
||||
|
||||
class PoolObjectSQL : public ObjectSQL
|
||||
@ -44,10 +43,10 @@ public:
|
||||
virtual ~PoolObjectSQL()
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
|
||||
pthread_mutex_destroy(&mutex);
|
||||
};
|
||||
|
||||
|
||||
int get_oid() const
|
||||
{
|
||||
return oid;
|
||||
@ -63,7 +62,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the object valid flag
|
||||
* Set the object valid flag
|
||||
* @param _valid new valid flag
|
||||
*/
|
||||
void set_valid(const bool _valid)
|
||||
@ -86,8 +85,9 @@ public:
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* The object unique ID
|
||||
*/
|
||||
@ -96,7 +96,7 @@ protected:
|
||||
/**
|
||||
* The contents ob this object are valid
|
||||
*/
|
||||
bool valid;
|
||||
bool valid;
|
||||
|
||||
private:
|
||||
|
||||
@ -106,8 +106,8 @@ private:
|
||||
friend class PoolSQL;
|
||||
|
||||
/**
|
||||
* The mutex for the PoolObject. This implementation assumes that the mutex
|
||||
* IS LOCKED when the class destructor is called.
|
||||
* The mutex for the PoolObject. This implementation assumes that the mutex
|
||||
* IS LOCKED when the class destructor is called.
|
||||
*/
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <string>
|
||||
#include <queue>
|
||||
|
||||
#include "SqliteDB.h"
|
||||
#include "SqlDB.h"
|
||||
#include "PoolObjectSQL.h"
|
||||
#include "Log.h"
|
||||
#include "Hook.h"
|
||||
@ -30,11 +30,11 @@ using namespace std;
|
||||
|
||||
/**
|
||||
* PoolSQL class. Provides a base class to implement persistent generic pools.
|
||||
* The PoolSQL provides a synchronization mechanism (mutex) to operate in
|
||||
* multithreaded applications. Any modification or access function to the pool
|
||||
* The PoolSQL provides a synchronization mechanism (mutex) to operate in
|
||||
* multithreaded applications. Any modification or access function to the pool
|
||||
* SHOULD block the mutex.
|
||||
*/
|
||||
class PoolSQL: public Hookable
|
||||
class PoolSQL: public Callbackable, public Hookable
|
||||
{
|
||||
public:
|
||||
|
||||
@ -43,10 +43,10 @@ public:
|
||||
* the last used Object identifier by querying the corresponding database
|
||||
* table. This function SHOULD be called before any pool related function.
|
||||
* @param _db a pointer to the database
|
||||
* @param table the name of the table supporting the pool (to set the oid
|
||||
* @param table the name of the table supporting the pool (to set the oid
|
||||
* counter). If null the OID counter is not updated.
|
||||
*/
|
||||
PoolSQL(SqliteDB * _db, const char * table=0);
|
||||
PoolSQL(SqlDB * _db, const char * table=0);
|
||||
|
||||
virtual ~PoolSQL();
|
||||
|
||||
@ -60,11 +60,11 @@ public:
|
||||
PoolObjectSQL *objsql);
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param oid the object unique identifier
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
virtual PoolObjectSQL * get(
|
||||
@ -76,48 +76,70 @@ public:
|
||||
* @param oids a vector with the oids of the objects.
|
||||
* @param the name of the DB table.
|
||||
* @param where condition in SQL format.
|
||||
*
|
||||
* @return 0 on success
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int search(
|
||||
vector<int>& oids,
|
||||
const char * table,
|
||||
const string& where);
|
||||
|
||||
|
||||
/**
|
||||
* Updates the object's data in the data base. The object mutex SHOULD be
|
||||
* locked.
|
||||
* @param objsql a pointer to the object
|
||||
*
|
||||
*
|
||||
* @return 0 on success.
|
||||
*/
|
||||
virtual int update(
|
||||
PoolObjectSQL * objsql)
|
||||
{
|
||||
int rc;
|
||||
|
||||
|
||||
rc = objsql->update(db);
|
||||
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
do_hooks(objsql, Hook::UPDATE);
|
||||
}
|
||||
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Drops the object's data in the data base. The object mutex SHOULD be
|
||||
* locked.
|
||||
* @param objsql a pointer to the object
|
||||
* @return 0 on success.
|
||||
*/
|
||||
virtual int drop(
|
||||
PoolObjectSQL * objsql)
|
||||
{
|
||||
return objsql->drop(db);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes all the elements from the pool
|
||||
*/
|
||||
void clean();
|
||||
|
||||
|
||||
/**
|
||||
* Dumps the pool in XML format. A filter can be also added to the
|
||||
* query
|
||||
* @param oss the output stream to dump the pool contents
|
||||
* @param where filter for the objects, defaults to all
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int dump(ostringstream& oss, const string& where) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Pointer to the database.
|
||||
*/
|
||||
SqliteDB * db;
|
||||
|
||||
SqlDB * db;
|
||||
|
||||
/**
|
||||
* Function to lock the pool
|
||||
*/
|
||||
@ -133,13 +155,13 @@ protected:
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
/**
|
||||
* Max size for the pool, to control the memory footprint of the pool. This
|
||||
* Max size for the pool, to control the memory footprint of the pool. This
|
||||
* number MUST be greater than the max. number of objects that are
|
||||
* accessed simultaneously.
|
||||
*/
|
||||
@ -152,7 +174,7 @@ private:
|
||||
int lastOID;
|
||||
|
||||
/**
|
||||
* The pool is implemented with a Map of SQL object pointers, using the
|
||||
* The pool is implemented with a Map of SQL object pointers, using the
|
||||
* OID as key.
|
||||
*/
|
||||
map<int,PoolObjectSQL *> pool;
|
||||
@ -164,18 +186,28 @@ private:
|
||||
virtual PoolObjectSQL * create() = 0;
|
||||
|
||||
/**
|
||||
* OID queue to implement a FIFO-like replacement policy for the pool
|
||||
* cache.
|
||||
* OID queue to implement a FIFO-like replacement policy for the pool
|
||||
* cache.
|
||||
*/
|
||||
queue<int> oid_queue;
|
||||
|
||||
/**
|
||||
* FIFO-like replacement policy function. Before removing an object (pop)
|
||||
* from the cache its lock is checked. The object is removed only if
|
||||
* the associated mutex IS NOT blocked. Otherwise the oid is sent to the
|
||||
* back of the queue.
|
||||
* from the cache its lock is checked. The object is removed only if
|
||||
* the associated mutex IS NOT blocked. Otherwise the oid is sent to the
|
||||
* back of the queue.
|
||||
*/
|
||||
void replace();
|
||||
|
||||
/**
|
||||
* Callback to set the lastOID (PoolSQL::PoolSQL)
|
||||
*/
|
||||
int init_cb(void *nil, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Callback to store the IDs of pool objects (PoolSQL::search)
|
||||
*/
|
||||
int search_cb(void *_oids, int num, char **values, char **names);
|
||||
};
|
||||
|
||||
#endif /*POOL_SQL_H_*/
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
// *************************************************************************
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
RangedLeases(SqliteDB * db,
|
||||
RangedLeases(SqlDB * db,
|
||||
int _oid,
|
||||
unsigned long _size,
|
||||
unsigned int _mac_prefix,
|
||||
@ -53,40 +53,40 @@ public:
|
||||
* @return 0 if success
|
||||
*/
|
||||
int set(int vid, const string& ip, string& mac);
|
||||
|
||||
|
||||
/**
|
||||
* Release an used lease, which becomes unused
|
||||
* @param ip of the lease in use
|
||||
*/
|
||||
void release(const string& ip)
|
||||
{
|
||||
del(ip);
|
||||
del(ip);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the leases from the DB.
|
||||
*/
|
||||
int select(SqliteDB * db)
|
||||
int select(SqlDB * db)
|
||||
{
|
||||
//Read the leases from the DB
|
||||
int rc = Leases::select(db);
|
||||
|
||||
return rc;
|
||||
//Read the leases from the DB
|
||||
int rc = Leases::select(db);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* The default MAC prefix for the OpenNebula cluster
|
||||
*/
|
||||
unsigned int mac_prefix;
|
||||
|
||||
/**
|
||||
* The Network address to generate leases
|
||||
*/
|
||||
unsigned int network_address;
|
||||
|
||||
unsigned int current;
|
||||
|
||||
/**
|
||||
* The default MAC prefix for the OpenNebula cluster
|
||||
*/
|
||||
unsigned int mac_prefix;
|
||||
|
||||
/**
|
||||
* The Network address to generate leases
|
||||
*/
|
||||
unsigned int network_address;
|
||||
|
||||
unsigned int current;
|
||||
|
||||
/**
|
||||
* Add a lease, from the Lease interface
|
||||
* @param ip ip of the lease
|
||||
@ -95,7 +95,7 @@ private:
|
||||
* @return 0 if success
|
||||
*/
|
||||
int add(unsigned int ip, unsigned int mac[], int vid, bool used=true);
|
||||
|
||||
|
||||
/**
|
||||
* Remove a lease, from the Lease interface
|
||||
* @param db pointer to DB
|
||||
@ -103,7 +103,7 @@ private:
|
||||
* @return 0 if success
|
||||
*/
|
||||
int del(const string& ip);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /*RANGED_LEASES_H_*/
|
||||
#endif /*RANGED_LEASES_H_*/
|
@ -1,140 +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 SCHEDULER_HOST_H_
|
||||
#define SCHEDULER_HOST_H_
|
||||
|
||||
#include "Host.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* The SchedulerHost class. It represents the scheduler version of the host,
|
||||
* only read operations to the pool are allowed for the SchedulerHost class
|
||||
*/
|
||||
class SchedulerHost : public Host
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
SchedulerHost(){};
|
||||
|
||||
~SchedulerHost(){};
|
||||
|
||||
/**
|
||||
* Gets the current host capacity
|
||||
* @param cpu the host free cpu, scaled according to a given threshold
|
||||
* @param memory the host free memory
|
||||
* @param threshold to consider the host totally free
|
||||
*/
|
||||
void get_capacity(int& cpu, int& memory, int threshold);
|
||||
|
||||
private:
|
||||
|
||||
// ----------------------------------------
|
||||
// Friends
|
||||
// ----------------------------------------
|
||||
friend class SchedulerHostPool;
|
||||
|
||||
// ----------------------------------------
|
||||
// SQL functions do not modify the DB!
|
||||
// ----------------------------------------
|
||||
int insert(SqliteDB *db);
|
||||
|
||||
int update(SqliteDB *db);
|
||||
|
||||
int drop(SqliteDB *db);
|
||||
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* The SchedulerHost class. It represents the scheduler version of the host,
|
||||
* read only operation to the pool are allowed for the SchedulerHost class
|
||||
*/
|
||||
class SchedulerHostPool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
SchedulerHostPool(SqliteDB *db):PoolSQL(db){};
|
||||
|
||||
~SchedulerHostPool(){};
|
||||
|
||||
/**
|
||||
* Implements the Pool interface, just prints an error message. This
|
||||
* class DOES NOT modify the database.
|
||||
*/
|
||||
int allocate(
|
||||
PoolObjectSQL *objsql);
|
||||
|
||||
/**
|
||||
* Gets an ScheulerHost from the pool (if needed the object is loaded from
|
||||
* the database).
|
||||
* @param oid the object unique identifier
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
SchedulerHost * get(
|
||||
int oid,
|
||||
bool lock)
|
||||
{
|
||||
return static_cast<SchedulerHost *>(PoolSQL::get(oid,lock));
|
||||
};
|
||||
|
||||
/**
|
||||
* Set ups the host pool by performing the following actions:
|
||||
* - All the objects stored in the pool are flushed
|
||||
* - The ids of the hosts in the database are loaded
|
||||
* @return 0 on success
|
||||
*/
|
||||
int set_up();
|
||||
|
||||
private:
|
||||
friend class Scheduler;
|
||||
|
||||
/**
|
||||
* Hosts ids
|
||||
*/
|
||||
vector<int> hids;
|
||||
|
||||
/**
|
||||
* Factory method for the PoolSQL class
|
||||
* @return a pointer to a new SchedulerHost object
|
||||
*/
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new SchedulerHost;
|
||||
};
|
||||
|
||||
/**
|
||||
* Bootstrap method from the PoolSQL interface. It just prints
|
||||
* an error message as this class MUST not modify the DB.
|
||||
*/
|
||||
void bootstrap();
|
||||
};
|
||||
|
||||
#endif /*SCHEDULER_HOST_H_*/
|
@ -1,190 +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 SCHEDULER_VIRTUAL_MACHINE_H_
|
||||
#define SCHEDULER_VIRTUAL_MACHINE_H_
|
||||
|
||||
#include "VirtualMachine.h"
|
||||
#include "SchedulerHost.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* The SchedulerHost class. It represents the scheduler version of the host,
|
||||
* only read operations to the pool are allowed for the SchedulerHost class
|
||||
*/
|
||||
class SchedulerVirtualMachine : public VirtualMachine
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
SchedulerVirtualMachine(){};
|
||||
|
||||
~SchedulerVirtualMachine()
|
||||
{
|
||||
vector<SchedulerVirtualMachine::Host *>::iterator jt;
|
||||
|
||||
for (jt=hosts.begin();jt!=hosts.end();jt++)
|
||||
{
|
||||
delete *jt;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a new share to the map of suitable shares to start this VM
|
||||
* @param hid of the selected host
|
||||
* @param hsid of the selected host share
|
||||
*/
|
||||
void add_host(int hid)
|
||||
{
|
||||
SchedulerVirtualMachine::Host * ss;
|
||||
|
||||
ss = new SchedulerVirtualMachine::Host(hid);
|
||||
|
||||
hosts.push_back(ss);
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the matching hosts ids
|
||||
* @param mh vector with the hids of the matching hosts
|
||||
*/
|
||||
void get_matching_hosts(vector<int>& mh)
|
||||
{
|
||||
vector<SchedulerVirtualMachine::Host *>::iterator i;
|
||||
|
||||
for(i=hosts.begin();i!=hosts.end();i++)
|
||||
{
|
||||
mh.push_back((*i)->hid);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the priorities for each matching host
|
||||
*/
|
||||
void set_priorities(vector<float>& total);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
int get_host(int& hid, SchedulerHostPool * hpool);
|
||||
|
||||
/**
|
||||
* Function to write a Virtual Machine in an output stream
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, SchedulerVirtualMachine& vm);
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Friends
|
||||
// -------------------------------------------------------------------------
|
||||
friend class SchedulerVirtualMachinePool;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
struct Host
|
||||
{
|
||||
int hid;
|
||||
float priority;
|
||||
|
||||
Host(int _hid):
|
||||
hid(_hid),
|
||||
priority(0){};
|
||||
|
||||
~Host(){};
|
||||
|
||||
bool operator<(const Host& b) const { //Sort by priority
|
||||
return priority < b.priority;
|
||||
}
|
||||
};
|
||||
|
||||
static bool host_cmp (const Host * a, const Host * b )
|
||||
{
|
||||
return (*a < *b );
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Matching hosts
|
||||
*/
|
||||
vector<SchedulerVirtualMachine::Host *> hosts;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// SQL functions do not modify the DB!
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
int insert(SqliteDB *db);
|
||||
|
||||
int update(SqliteDB *db);
|
||||
|
||||
int drop(SqliteDB *db);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* The SchedulerHost class. It represents the scheduler version of the host,
|
||||
* read only operation to the pool are allowed for the SchedulerHost class
|
||||
*/
|
||||
class SchedulerVirtualMachinePool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
SchedulerVirtualMachinePool(SqliteDB * db):PoolSQL(db){};
|
||||
|
||||
~SchedulerVirtualMachinePool(){};
|
||||
|
||||
int allocate(
|
||||
PoolObjectSQL *objsql);
|
||||
|
||||
SchedulerVirtualMachine * get(
|
||||
int oid,
|
||||
bool lock)
|
||||
{
|
||||
return static_cast<SchedulerVirtualMachine *>(PoolSQL::get(oid,lock));
|
||||
};
|
||||
|
||||
/**
|
||||
* Set ups the VM pool by performing the following actions:
|
||||
* - All the objects stored in the pool are flushed
|
||||
* - The ids of the pendings VMs in the database are loaded
|
||||
* @return 0 on success
|
||||
*/
|
||||
int set_up();
|
||||
|
||||
private:
|
||||
friend class Scheduler;
|
||||
|
||||
/**
|
||||
* The ids of the pending VMs
|
||||
*/
|
||||
vector<int> pending_vms;
|
||||
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new SchedulerVirtualMachine;
|
||||
};
|
||||
|
||||
void bootstrap();
|
||||
};
|
||||
|
||||
#endif /*SCHEDULER_VIRTUAL_MACHINE_H_*/
|
60
include/SqlDB.h
Normal file
60
include/SqlDB.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 SQL_DB_H_
|
||||
#define SQL_DB_H_
|
||||
|
||||
#include <sstream>
|
||||
#include "Callbackable.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* SqlDB class.Provides an abstract interface to implement a SQL backend
|
||||
*/
|
||||
class SqlDB
|
||||
{
|
||||
public:
|
||||
|
||||
SqlDB(){};
|
||||
|
||||
virtual ~SqlDB(){};
|
||||
|
||||
/**
|
||||
* Performs a DB transaction
|
||||
* @param sql_cmd the SQL command
|
||||
* @param callbak function to execute on each data returned
|
||||
* @param arg to pass to the callback function
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int exec(ostringstream& cmd, Callbackable* obj=0) = 0;
|
||||
|
||||
/**
|
||||
* This function returns a legal SQL string that can be used in an SQL
|
||||
* statement.
|
||||
* @param str the string to be escaped
|
||||
* @return a valid SQL string or NULL in case of failure
|
||||
*/
|
||||
virtual char * escape_str(const string& str) = 0;
|
||||
|
||||
/**
|
||||
* Frees a previously scaped string
|
||||
* @param str pointer to the str
|
||||
*/
|
||||
virtual void free_str(char * str) = 0;
|
||||
};
|
||||
|
||||
#endif /*SQL_DB_H_*/
|
@ -20,49 +20,35 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "Log.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "SqlDB.h"
|
||||
#include "ObjectSQL.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef SQLITE_DB
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
/**
|
||||
* SqliteDB class. Provides a wrapper to the sqlite3 database interface. It also
|
||||
* provides "global" synchronization mechanism to use it in a multithread
|
||||
* provides "global" synchronization mechanism to use it in a multithread
|
||||
* environment.
|
||||
*/
|
||||
class SqliteDB
|
||||
class SqliteDB : public SqlDB
|
||||
{
|
||||
public:
|
||||
|
||||
SqliteDB(
|
||||
string& db_name,
|
||||
Log::LogFunction _log = 0
|
||||
):log(_log)
|
||||
{
|
||||
int rc;
|
||||
|
||||
pthread_mutex_init(&mutex,0);
|
||||
|
||||
rc = sqlite3_open(db_name.c_str(), &db);
|
||||
|
||||
if ( rc != SQLITE_OK )
|
||||
{
|
||||
throw runtime_error("Could not open database.");
|
||||
}
|
||||
};
|
||||
|
||||
~SqliteDB()
|
||||
{
|
||||
pthread_mutex_destroy(&mutex);
|
||||
|
||||
sqlite3_close(db);
|
||||
};
|
||||
|
||||
|
||||
SqliteDB(string& db_name);
|
||||
|
||||
~SqliteDB();
|
||||
|
||||
/**
|
||||
* Wraps the sqlite3_exec function call, and locks the DB mutex.
|
||||
* @param sql_cmd the SQL command
|
||||
@ -70,84 +56,23 @@ public:
|
||||
* mutex you block in the callback.
|
||||
* @param arg to pass to the callback function
|
||||
* @return 0 on success
|
||||
*/
|
||||
int exec(
|
||||
ostringstream& sql_cmd,
|
||||
int (*callback)(void*,int,char**,char**)=0,
|
||||
void * arg=0)
|
||||
{
|
||||
int rc;
|
||||
|
||||
const char * c_str;
|
||||
string str;
|
||||
|
||||
int counter = 0;
|
||||
|
||||
char * err_msg;
|
||||
char ** ptr = (log==0) ? 0 : &err_msg;
|
||||
|
||||
str = sql_cmd.str();
|
||||
c_str = str.c_str();
|
||||
|
||||
lock();
|
||||
|
||||
do
|
||||
{
|
||||
counter++;
|
||||
|
||||
rc = sqlite3_exec(db, c_str, callback, arg, ptr);
|
||||
|
||||
if (rc == SQLITE_BUSY || rc == SQLITE_IOERR_BLOCKED)
|
||||
{
|
||||
struct timeval timeout;
|
||||
fd_set zero;
|
||||
|
||||
FD_ZERO(&zero);
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 100000;
|
||||
|
||||
select(0, &zero, &zero, &zero, &timeout);
|
||||
}
|
||||
|
||||
}while( (rc == SQLITE_BUSY || rc == SQLITE_IOERR_BLOCKED) &&
|
||||
(counter < 10));
|
||||
|
||||
unlock();
|
||||
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
if ((log != 0) && (err_msg != 0))
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "SQL command was: " << c_str << ", error: " << err_msg;
|
||||
log("ONE",Log::ERROR,oss,0,Log::ERROR);
|
||||
|
||||
sqlite3_free(err_msg);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
int exec(
|
||||
const char * sql_c_str,
|
||||
int (*callback)(void*,int,char**,char**)=0,
|
||||
void * arg=0)
|
||||
{
|
||||
string sql_str = sql_c_str;
|
||||
ostringstream sql_cmd;
|
||||
|
||||
sql_cmd.str(sql_str);
|
||||
|
||||
return exec(sql_cmd,callback,arg);
|
||||
};
|
||||
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0);
|
||||
|
||||
/**
|
||||
* This function returns a legal SQL string that can be used in an SQL
|
||||
* statement.
|
||||
* @param str the string to be escaped
|
||||
* @return a valid SQL string or NULL in case of failure
|
||||
*/
|
||||
char * escape_str(const string& str);
|
||||
|
||||
/**
|
||||
* Frees a previously scaped string
|
||||
* @param str pointer to the str
|
||||
*/
|
||||
void free_str(char * str);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Fine-grain mutex for DB access
|
||||
@ -159,11 +84,6 @@ private:
|
||||
*/
|
||||
sqlite3 * db;
|
||||
|
||||
/**
|
||||
* Log facility
|
||||
*/
|
||||
Log::LogFunction log;
|
||||
|
||||
/**
|
||||
* Function to lock the DB
|
||||
*/
|
||||
@ -178,7 +98,27 @@ private:
|
||||
void unlock()
|
||||
{
|
||||
pthread_mutex_unlock(&mutex);
|
||||
};
|
||||
};
|
||||
};
|
||||
#else
|
||||
//CLass stub
|
||||
class SqliteDB : public SqlDB
|
||||
{
|
||||
public:
|
||||
|
||||
SqliteDB(string& db_name)
|
||||
{
|
||||
throw runtime_error("Aborting oned, Sqlite support not compiled!");
|
||||
};
|
||||
|
||||
~SqliteDB(){};
|
||||
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0){return -1;};
|
||||
|
||||
char * escape_str(const string& str){return 0;};
|
||||
|
||||
void free_str(char * str){};
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /*SQLITE_DB_H_*/
|
||||
|
@ -1,18 +1,18 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* 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_
|
||||
@ -22,7 +22,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "Template.h"
|
||||
#include "SqliteDB.h"
|
||||
#include "SqlDB.h"
|
||||
#include "ObjectSQL.h"
|
||||
|
||||
using namespace std;
|
||||
@ -39,7 +39,7 @@ public:
|
||||
bool replace = false,
|
||||
const char separator = '=',
|
||||
const char * xml_root = "TEMPLATE"):
|
||||
Template(replace,separator,xml_root),table(_table),id(template_id)
|
||||
Template(replace,separator,xml_root),table(_table),id(template_id)
|
||||
{};
|
||||
|
||||
virtual ~TemplateSQL(){};
|
||||
@ -48,7 +48,7 @@ protected:
|
||||
|
||||
//Database implementation variables
|
||||
|
||||
const char * table;
|
||||
const char * table;
|
||||
|
||||
static const char * db_names;
|
||||
|
||||
@ -64,36 +64,44 @@ protected:
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int insert(SqliteDB * db);
|
||||
int insert(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Updates the template in the DB
|
||||
* @param db pointer to the database.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int update(SqliteDB *db);
|
||||
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(SqliteDB *db);
|
||||
int select(SqlDB *db);
|
||||
|
||||
/**
|
||||
* Removes the template from the DB
|
||||
* @param db pointer to the database.
|
||||
*/
|
||||
int drop(SqliteDB *db);
|
||||
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.
|
||||
* 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(SqliteDB * db, Attribute * attribute);
|
||||
int replace_attribute(SqlDB * db, Attribute * attribute);
|
||||
|
||||
/**
|
||||
* Insert a given attribute (MUST be allocated in the heap) in the template
|
||||
@ -101,10 +109,20 @@ protected:
|
||||
* @param db pointer to the database.
|
||||
* @param attribute pointer to the new attribute
|
||||
*/
|
||||
int insert_attribute(SqliteDB * db, Attribute * attribute);
|
||||
int insert_attribute(SqlDB * db, Attribute * attribute);
|
||||
|
||||
/**
|
||||
* Callback to set the template id (TemplateSQL::insert)
|
||||
*/
|
||||
int insert_cb(void *nil, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Callback to recover template attributes (TemplateSQL::select)
|
||||
*/
|
||||
int select_cb(void *nil, int num, char **values, char **names);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
#endif /*TEMPLATE_SQL_H_*/
|
||||
#endif /*TEMPLATE_SQL_H_*/
|
182
include/User.h
182
include/User.h
@ -21,45 +21,35 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" int user_select_cb (void * _host,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
extern "C" int user_dump_cb (void * _oss,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* The User class. It represents a User...
|
||||
* The User class.
|
||||
*/
|
||||
class User : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Function to write a User on an output stream
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, User& u);
|
||||
|
||||
/**
|
||||
* Function to print the User object into a string in plain text
|
||||
* @param str the resulting string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_str(string& str) const;
|
||||
friend ostream& operator<<(ostream& os, User& u);
|
||||
|
||||
/**
|
||||
* Function to print the User object into a string in plain text
|
||||
* @param str the resulting string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_str(string& str) const;
|
||||
|
||||
/**
|
||||
* Function to print the User object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
/**
|
||||
* Function to print the User object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get the User unique identifier UID, that matches the OID of the object
|
||||
@ -69,9 +59,7 @@ public:
|
||||
{
|
||||
return oid;
|
||||
};
|
||||
|
||||
// ----- Getters ---------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Check if the user is enabled
|
||||
* @return true if the user is enabled
|
||||
@ -80,61 +68,59 @@ public:
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns user username
|
||||
* @return username User's hostname
|
||||
*/
|
||||
const string& get_username() const
|
||||
const string& get_username() const
|
||||
{
|
||||
return username;
|
||||
};
|
||||
|
||||
return username;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns user password
|
||||
* @return username User's hostname
|
||||
*/
|
||||
const string& get_password() const
|
||||
const string& get_password() const
|
||||
{
|
||||
return password;
|
||||
};
|
||||
|
||||
// ----- Setters ---------------------------------
|
||||
|
||||
/**
|
||||
return password;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enables the current user
|
||||
*/
|
||||
*/
|
||||
void enable()
|
||||
{
|
||||
enabled = true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Disables the current user
|
||||
*/
|
||||
*/
|
||||
void disable()
|
||||
{
|
||||
enabled = false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Sets user username
|
||||
*/
|
||||
void set_username(string _username)
|
||||
void set_username(string _username)
|
||||
{
|
||||
username = _username;
|
||||
};
|
||||
|
||||
/**
|
||||
username = _username;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets user password
|
||||
*/
|
||||
void set_password(string _password)
|
||||
void set_password(string _password)
|
||||
{
|
||||
password = _password;
|
||||
};
|
||||
|
||||
password = _password;
|
||||
};
|
||||
|
||||
/**
|
||||
* Looks for a match between _password and user password
|
||||
* Looks for a match between _password and user password
|
||||
* @return -1 if disabled or wrong password, uid otherwise
|
||||
**/
|
||||
int authenticate(string _password);
|
||||
@ -144,7 +130,7 @@ public:
|
||||
* @param secret, the authentication token
|
||||
* @param username
|
||||
* @param password
|
||||
* @return 0 on success
|
||||
* @return 0 on success
|
||||
**/
|
||||
static int split_secret(const string secret, string& user, string& pass);
|
||||
|
||||
@ -159,18 +145,8 @@ private:
|
||||
// -------------------------------------------------------------------------
|
||||
// Friends
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
friend class UserPool;
|
||||
|
||||
friend int user_select_cb (void * _host,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
friend int user_dump_cb (void * _oss,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
friend class UserPool;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// User Attributes
|
||||
@ -190,44 +166,40 @@ private:
|
||||
* Flag marking user enabled/disabled
|
||||
*/
|
||||
bool enabled;
|
||||
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Function to unmarshall a User object
|
||||
* @param num the number of columns read from the DB
|
||||
* @para names the column names
|
||||
* @para vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
int unmarshall(int num, char **names, char ** values);
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Function to unmarshall a User object in to an output stream in XML
|
||||
* @param oss the output stream
|
||||
* Callback function to unmarshall a User object (User::select)
|
||||
* @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 unmarshall(ostringstream& oss,
|
||||
int num,
|
||||
char ** names,
|
||||
char ** values);
|
||||
int select_cb(void *nil, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the User
|
||||
*/
|
||||
static void bootstrap(SqliteDB * db)
|
||||
{
|
||||
db->exec(User::db_bootstrap);
|
||||
static void bootstrap(SqlDB * db)
|
||||
{
|
||||
ostringstream oss_user(User::db_bootstrap);
|
||||
|
||||
db->exec(oss_user);
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
@ -238,16 +210,16 @@ protected:
|
||||
bool _enabled=true);
|
||||
|
||||
virtual ~User();
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
||||
|
||||
enum ColNames
|
||||
{
|
||||
OID = 0,
|
||||
USERNAME = 1,
|
||||
PASSWORD = 2,
|
||||
OID = 0,
|
||||
USERNAME = 1,
|
||||
PASSWORD = 2,
|
||||
ENABLED = 3, // 0 = false, 1 = true
|
||||
LIMIT = 4
|
||||
};
|
||||
@ -255,7 +227,7 @@ protected:
|
||||
static const char * db_names;
|
||||
|
||||
static const char * db_bootstrap;
|
||||
|
||||
|
||||
static const char * table;
|
||||
|
||||
/**
|
||||
@ -263,38 +235,38 @@ protected:
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int select(SqliteDB *db);
|
||||
virtual int select(SqlDB *db);
|
||||
|
||||
/**
|
||||
* Writes the User in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int insert(SqliteDB *db);
|
||||
virtual int insert(SqlDB *db);
|
||||
|
||||
/**
|
||||
* Writes/updates the User data fields in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int update(SqliteDB *db);
|
||||
|
||||
virtual int update(SqlDB *db);
|
||||
|
||||
/**
|
||||
* Drops USer from the database
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int drop(SqliteDB *db);
|
||||
|
||||
virtual int drop(SqlDB *db);
|
||||
|
||||
/**
|
||||
* Dumps the contect of a set of User objects in the given stream
|
||||
* using XML format
|
||||
* @param db pointer to the db
|
||||
* Function to output a User object in to an stream in XML format
|
||||
* @param oss the output stream
|
||||
* @param where string to filter the VirtualMachine objects
|
||||
* @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(SqliteDB * db, ostringstream& oss, const string& where);
|
||||
static int dump(ostringstream& oss, int num, char **values, char **names);
|
||||
};
|
||||
|
||||
#endif /*USER_H_*/
|
||||
|
@ -36,20 +36,20 @@ class UserPool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
UserPool(SqliteDB * db);
|
||||
UserPool(SqlDB * db);
|
||||
|
||||
~UserPool(){};
|
||||
|
||||
/**
|
||||
* Function to allocate a new User object
|
||||
* @param oid the id assigned to the User
|
||||
* @return 0 on success
|
||||
* @return the oid assigned to the object or -1 in case of failure
|
||||
*/
|
||||
int allocate (
|
||||
int * oid,
|
||||
string hostname,
|
||||
string password,
|
||||
bool enabled);
|
||||
bool enabled);
|
||||
|
||||
/**
|
||||
* Function to get a User from the pool, if the object is not in memory
|
||||
@ -63,10 +63,10 @@ public:
|
||||
bool lock)
|
||||
{
|
||||
User * user = static_cast<User *>(PoolSQL::get(oid,lock));
|
||||
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Function to get a User from the pool, if the object is not in memory
|
||||
@ -80,7 +80,7 @@ public:
|
||||
bool lock)
|
||||
{
|
||||
map<string, int>::iterator index;
|
||||
|
||||
|
||||
index = known_users.find(username);
|
||||
|
||||
if ( index != known_users.end() )
|
||||
@ -91,46 +91,46 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Update a particular User
|
||||
/** Update a particular User
|
||||
* @param user pointer to User
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update(User * user)
|
||||
{
|
||||
return user->update(db);
|
||||
return user->update(db);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/** Drops a user from the DB, the user mutex MUST BE locked
|
||||
* @param user pointer to User
|
||||
*/
|
||||
int drop(User * user)
|
||||
{
|
||||
int rc = user->drop(db);
|
||||
|
||||
if ( rc == 0)
|
||||
{
|
||||
int rc = PoolSQL::drop(user);
|
||||
|
||||
if ( rc == 0)
|
||||
{
|
||||
known_users.erase(user->get_username());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the User pool
|
||||
*/
|
||||
static void bootstrap(SqliteDB * _db)
|
||||
static void bootstrap(SqlDB * _db)
|
||||
{
|
||||
User::bootstrap(_db);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether there is a user with given username/password or not
|
||||
* @param session, colon separated username and password string
|
||||
* @return -1 if there is no such a user, uid of the user if it exists
|
||||
*/
|
||||
int authenticate(string& session);
|
||||
|
||||
|
||||
/**
|
||||
* Dumps the User pool in XML format. A filter can be also added to the
|
||||
* query
|
||||
@ -139,18 +139,7 @@ public:
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump(ostringstream& oss, const string& where)
|
||||
{
|
||||
int rc;
|
||||
|
||||
oss << "<USER_POOL>";
|
||||
|
||||
rc = User::dump(db,oss,where);
|
||||
|
||||
oss << "</USER_POOL>";
|
||||
|
||||
return rc;
|
||||
}
|
||||
int dump(ostringstream& oss, const string& where);
|
||||
|
||||
private:
|
||||
/**
|
||||
@ -161,12 +150,31 @@ private:
|
||||
{
|
||||
return new User;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This map stores the association between UIDs and Usernames
|
||||
*/
|
||||
map<string, int> known_users;
|
||||
|
||||
/**
|
||||
* Callback function to get output the user pool in XML format
|
||||
* (User::dump)
|
||||
* @param _oss pointer to 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
|
||||
*/
|
||||
int dump_cb(void * _oss, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Callback function to build the knwon_user map (User::User)
|
||||
* @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 init_cb(void *nil, int num, char **values, char **names);
|
||||
};
|
||||
|
||||
#endif /*USER_POOL_H_*/
|
||||
#endif /*USER_POOL_H_*/
|
@ -27,9 +27,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" int vm_select_cb (void * _vm, int num,char ** values, char ** names);
|
||||
extern "C" int vm_dump_cb (void * _oss, int num,char ** values, char ** names);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -97,7 +94,7 @@ public:
|
||||
{
|
||||
if (_log != 0)
|
||||
{
|
||||
_log->log(module,type,message);
|
||||
_log->log(module,type,message.str().c_str());
|
||||
}
|
||||
};
|
||||
|
||||
@ -121,22 +118,22 @@ public:
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, const VirtualMachine& vm);
|
||||
|
||||
/**
|
||||
* Function to print the VirtualMachine object into a string in
|
||||
* plain text
|
||||
* @param str the resulting string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_str(string& str) const;
|
||||
/**
|
||||
* Function to print the VirtualMachine object into a string in
|
||||
* plain text
|
||||
* @param str the resulting string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_str(string& str) const;
|
||||
|
||||
/**
|
||||
* Function to print the VirtualMachine object into a string in
|
||||
* XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
/**
|
||||
* Function to print the VirtualMachine object into a string in
|
||||
* XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Dynamic Info
|
||||
// ------------------------------------------------------------------------
|
||||
@ -291,7 +288,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the TM driver name for the previous host. The
|
||||
* Returns the TM driver name for the previous host. The
|
||||
* hasPreviousHistory() function MUST be called before this one.
|
||||
* @return the TM mad name
|
||||
*/
|
||||
@ -608,19 +605,19 @@ public:
|
||||
{
|
||||
vm_template.to_xml(xml);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse a string and substitute variables (e.g. $NAME) using the VM
|
||||
* Parse a string and substitute variables (e.g. $NAME) using the VM
|
||||
* template values:
|
||||
* @param attribute, the string to be parsed
|
||||
* @param parsed, the resulting parsed string
|
||||
* @return 0 on success.
|
||||
*/
|
||||
*/
|
||||
int parse_template_attribute(const string& attribute,
|
||||
string& parsed);
|
||||
|
||||
|
||||
/**
|
||||
* Parse a string and substitute variables (e.g. $NAME) using the VM
|
||||
* Parse a string and substitute variables (e.g. $NAME) using the VM
|
||||
* template values (blocking-free version for cross references):
|
||||
* @param vm_id ID of the VM used to substitute the variables
|
||||
* @param attribute, the string to be parsed
|
||||
@ -632,14 +629,14 @@ public:
|
||||
const string& attribute,
|
||||
string& parsed,
|
||||
char ** error_msg)
|
||||
{
|
||||
{
|
||||
return parse_attribute(0,vm_id,attribute,parsed,error_msg);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// States
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Returns the VM state (Dispatch Manager)
|
||||
* @return the VM state
|
||||
@ -747,18 +744,6 @@ private:
|
||||
// -------------------------------------------------------------------------
|
||||
friend class VirtualMachinePool;
|
||||
|
||||
friend int vm_select_cb (
|
||||
void * _vm,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
friend int vm_dump_cb (
|
||||
void * _vm,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
// *************************************************************************
|
||||
// Virtual Machine Attributes
|
||||
// *************************************************************************
|
||||
@ -857,11 +842,11 @@ private:
|
||||
|
||||
/**
|
||||
* Log class for the virtual machine, it writes log messages in
|
||||
* $ONE_LOCATION/var/$VID/vm.log
|
||||
* $ONE_LOCATION/var/$VID/vm.log
|
||||
* or, in case that OpenNebula is installed in root
|
||||
* /var/log/one/$VM_ID.log
|
||||
* /var/log/one/$VM_ID.log
|
||||
*/
|
||||
Log * _log;
|
||||
FileLog * _log;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
@ -870,48 +855,45 @@ private:
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the VirtualMachine
|
||||
*/
|
||||
static void bootstrap(SqliteDB * db)
|
||||
static void bootstrap(SqlDB * db)
|
||||
{
|
||||
db->exec(VirtualMachine::db_bootstrap);
|
||||
ostringstream oss_vm(VirtualMachine::db_bootstrap);
|
||||
ostringstream oss_tmpl(VirtualMachineTemplate::db_bootstrap);
|
||||
ostringstream oss_hist(History::db_bootstrap);
|
||||
|
||||
db->exec(VirtualMachineTemplate::db_bootstrap);
|
||||
|
||||
db->exec(History::db_bootstrap);
|
||||
db->exec(oss_vm);
|
||||
db->exec(oss_tmpl);
|
||||
db->exec(oss_hist);
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to unmarshall a VM object, an associated classes.
|
||||
* Callback function to unmarshall a VirtualMachine object
|
||||
* (VirtualMachine::select)
|
||||
* @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 unmarshall(int num, char **names, char ** values);
|
||||
|
||||
int select_cb(void *nil, int num, char **names, char ** values);
|
||||
|
||||
/**
|
||||
* Function to unmarshall a VM object into an output stream with 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 unmarshall(ostringstream& oss,
|
||||
int num,
|
||||
char ** names,
|
||||
char ** values);
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Updates the VM history record
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_history(SqliteDB * db)
|
||||
int update_history(SqlDB * db)
|
||||
{
|
||||
if ( history != 0 )
|
||||
{
|
||||
return history->insert(db);
|
||||
return history->update(db);
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
@ -922,11 +904,11 @@ private:
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_previous_history(SqliteDB * db)
|
||||
int update_previous_history(SqlDB * db)
|
||||
{
|
||||
if ( previous_history != 0 )
|
||||
{
|
||||
return previous_history->insert(db);
|
||||
return previous_history->update(db);
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
@ -941,9 +923,9 @@ private:
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_template_attribute(
|
||||
SqliteDB * db,
|
||||
string& name,
|
||||
string& value)
|
||||
SqlDB * db,
|
||||
string& name,
|
||||
string& value)
|
||||
{
|
||||
SingleAttribute * sattr;
|
||||
int rc;
|
||||
@ -966,7 +948,7 @@ private:
|
||||
* @param attribute the new attribute for the template
|
||||
* @return 0 on success
|
||||
*/
|
||||
int insert_template_attribute(SqliteDB * db, Attribute * attribute)
|
||||
int insert_template_attribute(SqlDB * db, Attribute * attribute)
|
||||
{
|
||||
return vm_template.insert_attribute(db,attribute);
|
||||
}
|
||||
@ -991,13 +973,13 @@ private:
|
||||
* @param parsed, the resulting parsed string
|
||||
* @param error_msg, string describing the syntax error
|
||||
* @return 0 on success.
|
||||
*/
|
||||
*/
|
||||
static int parse_attribute(VirtualMachine * vm,
|
||||
int vm_id,
|
||||
const string& attribute,
|
||||
string& parsed,
|
||||
char ** error_msg);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//**************************************************************************
|
||||
@ -1042,22 +1024,22 @@ protected:
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select(SqliteDB * db);
|
||||
int select(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Writes the Virtual Machine and its associated template in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int insert(SqliteDB * db);
|
||||
virtual int insert(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Writes/updates the Virtual Machine data fields in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int update(SqliteDB * db);
|
||||
|
||||
virtual int update(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Deletes a VM from the database and all its associated information:
|
||||
* - History records
|
||||
@ -1065,29 +1047,30 @@ protected:
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int drop(SqliteDB * db)
|
||||
virtual int drop(SqlDB * db)
|
||||
{
|
||||
int rc;
|
||||
int rc;
|
||||
|
||||
rc = vm_template.drop(db);
|
||||
rc = vm_template.drop(db);
|
||||
|
||||
if ( history != 0 )
|
||||
{
|
||||
rc += history->drop(db);
|
||||
}
|
||||
if ( history != 0 )
|
||||
{
|
||||
rc += history->drop(db);
|
||||
}
|
||||
|
||||
return rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the contect of a set of VirtualMachine objects in the given stream
|
||||
* using XML format
|
||||
* @param db pointer to the db
|
||||
* @param oss the output stream
|
||||
* @param where string to filter the VirtualMachine objects
|
||||
* @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(SqliteDB * db, ostringstream& oss, const string& where);
|
||||
static int dump(ostringstream& oss, int num, char ** values, char ** names);
|
||||
};
|
||||
|
||||
#endif /*VIRTUAL_MACHINE_H_*/
|
||||
|
@ -32,7 +32,7 @@ class VirtualMachinePool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
VirtualMachinePool(SqliteDB * db, vector<const Attribute *> hook_mads);
|
||||
VirtualMachinePool(SqlDB * db, vector<const Attribute *> hook_mads);
|
||||
|
||||
~VirtualMachinePool(){};
|
||||
|
||||
@ -42,7 +42,7 @@ public:
|
||||
* @param stemplate a string describing the VM
|
||||
* @param oid the id assigned to the VM (output)
|
||||
* @param on_hold flag to submit on hold
|
||||
* @return 0 on success, -1 error inserting in DB or -2 error parsing
|
||||
* @return oid on success, -1 error inserting in DB or -2 error parsing
|
||||
* the template
|
||||
*/
|
||||
int allocate (
|
||||
@ -126,11 +126,11 @@ public:
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the VirtualMachine pool
|
||||
*/
|
||||
static void bootstrap(SqliteDB * _db)
|
||||
static void bootstrap(SqlDB * _db)
|
||||
{
|
||||
VirtualMachine::bootstrap(_db);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -140,19 +140,8 @@ public:
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump(ostringstream& oss, const string& where)
|
||||
{
|
||||
int rc;
|
||||
int dump(ostringstream& oss, const string& where);
|
||||
|
||||
oss << "<VM_POOL>";
|
||||
|
||||
rc = VirtualMachine::dump(db,oss,where);
|
||||
|
||||
oss << "</VM_POOL>";
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Generate context file to be sourced upon VM booting
|
||||
@ -169,6 +158,16 @@ private:
|
||||
{
|
||||
return new VirtualMachine;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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_cb(void * _oss, int num, char **values, char **names);
|
||||
};
|
||||
|
||||
#endif /*VIRTUAL_MACHINE_POOL_H_*/
|
||||
|
@ -31,10 +31,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" int vn_select_cb (void * _vn, int num,char ** values, char ** names);
|
||||
|
||||
extern "C" int vn_dump_cb (void * _oss, int num, char ** values, char ** names);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -61,7 +57,6 @@ public:
|
||||
// *************************************************************************
|
||||
// Virtual Network Public Methods
|
||||
// *************************************************************************
|
||||
|
||||
|
||||
/**
|
||||
* Gets the uid of the owner of the Virtual Network
|
||||
@ -128,7 +123,7 @@ public:
|
||||
* Function to print the VirtualNetwork object into a string in
|
||||
* plain text
|
||||
* @param str the resulting string
|
||||
* @return a reference to the generated string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_str(string& str) const;
|
||||
|
||||
@ -136,10 +131,10 @@ public:
|
||||
* Function to print the VirtualNetwork object into a string in
|
||||
* XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -147,18 +142,6 @@ private:
|
||||
// -------------------------------------------------------------------------
|
||||
friend class VirtualNetworkPool;
|
||||
|
||||
friend int vn_select_cb (
|
||||
void * _vm,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
friend int vn_dump_cb (
|
||||
void * _oss,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names);
|
||||
|
||||
// *************************************************************************
|
||||
// Virtual Network Private Attributes
|
||||
// *************************************************************************
|
||||
@ -169,12 +152,12 @@ private:
|
||||
/**
|
||||
* Name of the Virtual Network
|
||||
*/
|
||||
string name;
|
||||
string name;
|
||||
|
||||
/**
|
||||
* Owner of the Virtual Network
|
||||
*/
|
||||
int uid;
|
||||
int uid;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Binded physical attributes
|
||||
@ -183,7 +166,7 @@ private:
|
||||
/**
|
||||
* Name of the bridge this VNW binds to
|
||||
*/
|
||||
string bridge;
|
||||
string bridge;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Virtual Network Description
|
||||
@ -191,13 +174,13 @@ private:
|
||||
/**
|
||||
* Holds the type of this network
|
||||
*/
|
||||
NetworkType type;
|
||||
NetworkType type;
|
||||
|
||||
/**
|
||||
* Pointer to leases class, can be fixed or ranged.
|
||||
* Holds information on given (and, optionally, possible) leases
|
||||
*/
|
||||
Leases * leases;
|
||||
Leases * leases;
|
||||
|
||||
/**
|
||||
* The Virtual Network template, holds the VNW attributes.
|
||||
@ -211,55 +194,53 @@ private:
|
||||
/**
|
||||
* MAC prefix for this OpenNebula site
|
||||
*/
|
||||
unsigned int mac_prefix;
|
||||
unsigned int mac_prefix;
|
||||
|
||||
/**
|
||||
* Default size for virtual networks
|
||||
*/
|
||||
int default_size;
|
||||
int default_size;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Execute an INSERT or REPLACE Sql query.
|
||||
* @param db The SQL DB
|
||||
* @param replace Execute an INSERT or a REPLACE
|
||||
* @return 0 on success
|
||||
*/
|
||||
int insert_replace(SqlDB *db, bool replace);
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Virtual Network
|
||||
*/
|
||||
static void bootstrap(SqliteDB * db)
|
||||
static void bootstrap(SqlDB * db)
|
||||
{
|
||||
db->exec(VirtualNetwork::db_bootstrap);
|
||||
ostringstream oss_vnet(VirtualNetwork::db_bootstrap);
|
||||
ostringstream oss_templ(VirtualNetworkTemplate::db_bootstrap);
|
||||
ostringstream oss_lease(Leases::db_bootstrap);
|
||||
|
||||
db->exec(VirtualNetworkTemplate::db_bootstrap);
|
||||
|
||||
db->exec(Leases::db_bootstrap);
|
||||
db->exec(oss_vnet);
|
||||
db->exec(oss_templ);
|
||||
db->exec(oss_lease);
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to unmarshall a VNW object, and associated classes.
|
||||
* Callback function to unmarshall a VNW object (VirtualNetwork::select)
|
||||
* @param num the number of columns read from the DB
|
||||
* @para names the column names
|
||||
* @para vaues the column values
|
||||
* @param names the column names
|
||||
* @param vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
int unmarshall(int num, char **names, char ** values);
|
||||
int select_cb(void * nil, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Function to unmarshall a VNW object into an stream in XML format.
|
||||
* @param oss the output stream
|
||||
* @param num the number of columns read from the DB
|
||||
* @para names the column names
|
||||
* @para vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
static int unmarshall(ostringstream& oss,
|
||||
int num,
|
||||
char ** names,
|
||||
char ** values);
|
||||
/**
|
||||
* Function to drop VN entry in vn_pool
|
||||
* @return 0 on success
|
||||
*/
|
||||
int vn_drop(SqliteDB * db);
|
||||
int vn_drop(SqlDB * db);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Template
|
||||
@ -321,15 +302,15 @@ private:
|
||||
/**
|
||||
* Updates the template of a VNW, adding a new attribute (replacing it if
|
||||
* already defined), the VN's mutex SHOULD be locked
|
||||
* @param vm pointer to the virtual network object
|
||||
* @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(
|
||||
SqliteDB * db,
|
||||
string& name,
|
||||
string& value)
|
||||
SqlDB * db,
|
||||
string& name,
|
||||
string& value)
|
||||
{
|
||||
SingleAttribute * sattr;
|
||||
int rc;
|
||||
@ -380,21 +361,21 @@ protected:
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select(SqliteDB * db);
|
||||
int select(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Writes the Virtual Network and its associated template and leases in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int insert(SqliteDB * db);
|
||||
int insert(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Writes/updates the Virtual Network data fields in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update(SqliteDB * db);
|
||||
int update(SqlDB * db);
|
||||
|
||||
/**
|
||||
* Deletes a VNW from the database and all its associated information:
|
||||
@ -403,28 +384,29 @@ protected:
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int drop(SqliteDB * db)
|
||||
int drop(SqlDB * db)
|
||||
{
|
||||
int rc;
|
||||
int rc;
|
||||
|
||||
rc = vn_template.drop(db);
|
||||
rc = vn_template.drop(db);
|
||||
|
||||
rc += leases->drop(db);
|
||||
|
||||
rc += vn_drop(db);
|
||||
|
||||
return rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the contect of a set of Host objects in the given stream
|
||||
* using XML format
|
||||
* @param db pointer to the db
|
||||
* Dumps the contect of a VirtualNetwork object in the given stream using
|
||||
* XML format
|
||||
* @param oss the output stream
|
||||
* @param where string to filter the VirtualMachine objects
|
||||
* @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(SqliteDB * db, ostringstream& oss, const string& where);
|
||||
static int dump(ostringstream& oss, int num, char **values, char **names);
|
||||
};
|
||||
|
||||
#endif /*VIRTUAL_NETWORK_H_*/
|
||||
|
@ -32,9 +32,9 @@ class VirtualNetworkPool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
VirtualNetworkPool(SqliteDB * db,
|
||||
const string& str_mac_prefix,
|
||||
int default_size);
|
||||
VirtualNetworkPool(SqlDB * db,
|
||||
const string& str_mac_prefix,
|
||||
int default_size);
|
||||
|
||||
~VirtualNetworkPool(){};
|
||||
|
||||
@ -43,7 +43,7 @@ public:
|
||||
* @param uid user identifier
|
||||
* @param stemplate a string describing the VN
|
||||
* @param oid the id assigned to the VM (output)
|
||||
* @return 0 on success, -1 error inserting in DB,-2 error parsing
|
||||
* @return oid on success, -1 error inserting in DB,-2 error parsing
|
||||
* the template, -3 wrong attributes in template
|
||||
*/
|
||||
int allocate (
|
||||
@ -64,7 +64,7 @@ public:
|
||||
{
|
||||
return static_cast<VirtualNetwork *>(PoolSQL::get(oid,lock));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Function to get a VN from the pool using the network name
|
||||
* If the object is not in memory it is loaded from the DB
|
||||
@ -74,14 +74,14 @@ public:
|
||||
*/
|
||||
VirtualNetwork * get(
|
||||
const string& name,
|
||||
bool lock);
|
||||
bool lock);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Virtual Network DB access functions
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Updates the template of a VN, adding a new attribute (replacing it if
|
||||
* 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
|
||||
@ -89,61 +89,42 @@ public:
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_template_attribute(
|
||||
VirtualNetwork * vn,
|
||||
string& name,
|
||||
string& value)
|
||||
VirtualNetwork * vn,
|
||||
string& name,
|
||||
string& value)
|
||||
{
|
||||
return vn->update_template_attribute(db,name,value);
|
||||
return vn->update_template_attribute(db,name,value);
|
||||
};
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the VirtualNetwork pool
|
||||
*/
|
||||
static void bootstrap(SqliteDB * _db)
|
||||
static void bootstrap(SqlDB * _db)
|
||||
{
|
||||
VirtualNetwork::bootstrap(_db);
|
||||
};
|
||||
|
||||
/** Drops a VN from the cache & DB, the VN mutex MUST BE locked
|
||||
* @param vn pointer to VN
|
||||
*/
|
||||
int drop(VirtualNetwork * vn)
|
||||
{
|
||||
return vn->drop(db);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Dumps the HOST pool in XML format. A filter can be also added to the
|
||||
* query
|
||||
* Dumps the Virtual Network pool in XML format. A filter can be also added
|
||||
* to the query
|
||||
* @param oss the output stream to dump the pool contents
|
||||
* @param where filter for the objects, defaults to all
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump(ostringstream& oss, const string& where)
|
||||
{
|
||||
int rc;
|
||||
|
||||
oss << "<VNET_POOL>";
|
||||
|
||||
rc = VirtualNetwork::dump(db,oss,where);
|
||||
|
||||
oss << "</VNET_POOL>";
|
||||
|
||||
return rc;
|
||||
}
|
||||
int dump(ostringstream& oss, const string& where);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Holds the system-wide MAC prefix
|
||||
*/
|
||||
unsigned int mac_prefix;
|
||||
|
||||
|
||||
/**
|
||||
* Default size for Virtual Networks
|
||||
*/
|
||||
unsigned int default_size;
|
||||
|
||||
unsigned int default_size;
|
||||
|
||||
/**
|
||||
* Factory method to produce VN objects
|
||||
* @return a pointer to the new VN
|
||||
@ -152,7 +133,26 @@ private:
|
||||
{
|
||||
return new VirtualNetwork(mac_prefix, default_size);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Callback function to get output the virtual network pool in XML format
|
||||
* (VirtualNetworkPool::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_cb(void * _oss, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Callback function to get the ID of a given virtual network
|
||||
* (VirtualNetworkPool::get)
|
||||
* @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 get_cb(void * _oss, int num, char **values, char **names);
|
||||
};
|
||||
|
||||
#endif /*VIRTUAL_NETWORK_POOL_H_*/
|
||||
|
||||
#endif /*VIRTUAL_NETWORK_POOL_H_*/
|
376
include/test/PoolTest.h
Normal file
376
include/test/PoolTest.h
Normal file
@ -0,0 +1,376 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 POOL_TEST_H_
|
||||
#define POOL_TEST_H_
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include <TestFixture.h>
|
||||
#include <TestAssert.h>
|
||||
#include <TestSuite.h>
|
||||
#include <TestCaller.h>
|
||||
#include <ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "SqlDB.h"
|
||||
#include "SqliteDB.h"
|
||||
#include "MySqlDB.h"
|
||||
#include "PoolSQL.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
// Use this macro in sub-classes to add all the tests defined here
|
||||
#define ALL_POOLTEST_CPPUNIT_TESTS() \
|
||||
CPPUNIT_TEST (oid_assignment); \
|
||||
CPPUNIT_TEST (get_from_cache); \
|
||||
CPPUNIT_TEST (get_from_db); \
|
||||
CPPUNIT_TEST (wrong_get); \
|
||||
CPPUNIT_TEST (drop_and_get); \
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
class PoolTest : public CppUnit::TestFixture
|
||||
{
|
||||
private:
|
||||
// Global flag to use either Sqlite or MySQL
|
||||
static bool mysql;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
PoolSQL * pool;
|
||||
SqlDB * db;
|
||||
|
||||
PoolObjectSQL* obj;
|
||||
|
||||
static string db_name;
|
||||
|
||||
/*
|
||||
* Bootstrap the DB with the neccessary tables for the test
|
||||
*/
|
||||
virtual void bootstrap(SqlDB* db) = 0;
|
||||
|
||||
/*
|
||||
* Create the appropiate pool
|
||||
*/
|
||||
virtual PoolSQL* create_pool(SqlDB* db) = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Allocate the indexth sample pool object
|
||||
*/
|
||||
virtual int allocate(int index) = 0;
|
||||
|
||||
/*
|
||||
* Check if the indexth sample object is equal to this one
|
||||
*/
|
||||
virtual void check(int index, PoolObjectSQL* obj) = 0;
|
||||
|
||||
PoolTest():pool(0),db(0){};
|
||||
virtual ~PoolTest(){};
|
||||
|
||||
public:
|
||||
|
||||
void setUp()
|
||||
{
|
||||
if (mysql)
|
||||
{
|
||||
db = new MySqlDB("localhost","oneadmin","onepass",NULL);
|
||||
|
||||
ostringstream oss1;
|
||||
oss1 << "DROP DATABASE IF EXISTS " << db_name;
|
||||
db->exec(oss1);
|
||||
|
||||
ostringstream oss;
|
||||
oss << "CREATE DATABASE " << db_name;
|
||||
db->exec(oss);
|
||||
|
||||
ostringstream oss2;
|
||||
oss2 << "use " << db_name;
|
||||
db->exec(oss2);
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink(db_name.c_str());
|
||||
|
||||
db = new SqliteDB(db_name);
|
||||
}
|
||||
|
||||
bootstrap(db);
|
||||
|
||||
pool = create_pool(db);
|
||||
};
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
|
||||
if (mysql)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "DROP DATABASE IF EXISTS " << db_name;
|
||||
db->exec(oss);
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink(db_name.c_str());
|
||||
}
|
||||
|
||||
if ( pool != 0 )
|
||||
{
|
||||
delete pool;
|
||||
}
|
||||
|
||||
if ( db != 0 )
|
||||
{
|
||||
delete db;
|
||||
}
|
||||
};
|
||||
|
||||
// *****************************************************************************
|
||||
|
||||
void oid_assignment()
|
||||
{
|
||||
int oid;
|
||||
|
||||
oid = allocate(0);
|
||||
// first element in the pool should have oid=0
|
||||
CPPUNIT_ASSERT(oid == 0);
|
||||
|
||||
oid = allocate(1);
|
||||
// second element in the pool should have oid=1
|
||||
CPPUNIT_ASSERT(oid == 1);
|
||||
}
|
||||
|
||||
// Try to allocate two objects, and retrieve them
|
||||
void get_from_cache()
|
||||
{
|
||||
int oid_0, oid_1;
|
||||
|
||||
// Allocate two objects
|
||||
oid_0 = allocate(0);
|
||||
oid_1 = allocate(1);
|
||||
|
||||
CPPUNIT_ASSERT(oid_0 != -1);
|
||||
CPPUNIT_ASSERT(oid_1 != -1);
|
||||
|
||||
// ---------------------------------
|
||||
|
||||
// Get first object and check its integrity
|
||||
obj = pool->get(oid_0, false);
|
||||
check(0, obj);
|
||||
|
||||
// Same for the second, but ask it to be locked
|
||||
obj = pool->get(oid_1, true);
|
||||
if(obj != 0)
|
||||
{
|
||||
obj->unlock();
|
||||
}
|
||||
|
||||
check(1, obj);
|
||||
};
|
||||
|
||||
// Try to allocate two objects, and retrieve them
|
||||
void get_from_db()
|
||||
{
|
||||
int oid_0, oid_1;
|
||||
|
||||
// Allocate two objects
|
||||
oid_0 = allocate(0);
|
||||
oid_1 = allocate(1);
|
||||
|
||||
CPPUNIT_ASSERT(oid_0 != -1);
|
||||
CPPUNIT_ASSERT(oid_1 != -1);
|
||||
|
||||
// Clean the cache, forcing the pool to read the objects from the DB
|
||||
pool->clean();
|
||||
|
||||
// ---------------------------------
|
||||
// Get first object and check its integrity
|
||||
obj = pool->get(oid_0, false);
|
||||
check(0, obj);
|
||||
|
||||
// Same for the second one, but ask it to be locked
|
||||
obj = pool->get(oid_1, true);
|
||||
if(obj != 0)
|
||||
{
|
||||
obj->unlock();
|
||||
}
|
||||
check(1, obj);
|
||||
|
||||
};
|
||||
|
||||
void wrong_get()
|
||||
{
|
||||
// The pool is empty
|
||||
// Non existing oid
|
||||
obj = pool->get(13, true);
|
||||
CPPUNIT_ASSERT( obj == 0 );
|
||||
|
||||
// Allocate an object
|
||||
allocate(0);
|
||||
|
||||
// Ask again for a non-existing oid
|
||||
obj = pool->get(213, true);
|
||||
CPPUNIT_ASSERT( obj == 0 );
|
||||
}
|
||||
|
||||
void drop_and_get()
|
||||
{
|
||||
int oid_0, oid_1;
|
||||
|
||||
// Allocate two objects
|
||||
oid_0 = allocate(0);
|
||||
oid_1 = allocate(1);
|
||||
|
||||
CPPUNIT_ASSERT(oid_0 != -1);
|
||||
CPPUNIT_ASSERT(oid_1 != -1);
|
||||
|
||||
// Get the first object
|
||||
obj = pool->get(oid_0, true);
|
||||
|
||||
if(obj != 0)
|
||||
{
|
||||
obj->unlock();
|
||||
}
|
||||
|
||||
CPPUNIT_ASSERT(obj != 0);
|
||||
|
||||
obj->lock();
|
||||
|
||||
// Delete it
|
||||
pool->drop(obj);
|
||||
|
||||
if(obj != 0)
|
||||
{
|
||||
obj->unlock();
|
||||
}
|
||||
|
||||
// It should be gone now
|
||||
obj = pool->get(oid_0, false);
|
||||
CPPUNIT_ASSERT(obj == 0);
|
||||
|
||||
// The cache is cleaned, the object should be also gone from the DB
|
||||
pool->clean();
|
||||
obj = pool->get(oid_0, true);
|
||||
CPPUNIT_ASSERT(obj == 0);
|
||||
|
||||
// But the other object must be accessible
|
||||
obj = pool->get(oid_1, false);
|
||||
check(1, obj);
|
||||
};
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
|
||||
|
||||
static void show_options ()
|
||||
{
|
||||
cout << "Options:\n";
|
||||
cout << " -h --help Show this help\n"
|
||||
" -s --sqlite Run Sqlite tests (default)\n"
|
||||
" -m --mysql Run MySQL tests\n"
|
||||
" -l --log Keep the log file, test.log\n";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Not a true main, but a static method that can be called from the
|
||||
* child classes' true main.
|
||||
* Options:
|
||||
* s: run sqlite tests
|
||||
* m: run mysql tests
|
||||
*/
|
||||
static int main(int argc, char ** argv, CPPUNIT_NS::TestSuite* suite)
|
||||
{
|
||||
|
||||
// Option flags
|
||||
bool sqlite_flag = true;
|
||||
bool log_flag = false;
|
||||
|
||||
// Long options
|
||||
const struct option long_opt[] =
|
||||
{
|
||||
{ "sqlite", 0, NULL, 's'},
|
||||
{ "mysql", 0, NULL, 'm'},
|
||||
{ "log", 0, NULL, 'l'},
|
||||
{ "help", 0, NULL, 'h'}
|
||||
};
|
||||
|
||||
int c;
|
||||
while ((c = getopt_long (argc, argv, "smlh", long_opt, NULL)) != -1)
|
||||
switch (c)
|
||||
{
|
||||
case 'm':
|
||||
sqlite_flag = false;
|
||||
break;
|
||||
case 'l':
|
||||
log_flag = true;
|
||||
break;
|
||||
case 'h':
|
||||
show_options();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// When a DB query fails, it tries to log the error.
|
||||
// We need to set the log file, otherwise it will end in a dead-lock
|
||||
NebulaLog::init_log_system(NebulaLog::FILE, Log::DEBUG, "test.log");
|
||||
NebulaLog::log("Test", Log::INFO, "Test started");
|
||||
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest( suite );
|
||||
|
||||
if (sqlite_flag)
|
||||
{
|
||||
PoolTest::mysql = false;
|
||||
NebulaLog::log("Test", Log::INFO, "Running Sqlite tests...");
|
||||
cout << "\nRunning Sqlite tests...\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
PoolTest::mysql = true;
|
||||
NebulaLog::log("Test", Log::INFO, "Running MySQL tests...");
|
||||
cout << "\nRunning MySQL tests...\n";
|
||||
}
|
||||
|
||||
runner.run();
|
||||
|
||||
if (!log_flag)
|
||||
remove("test.log");
|
||||
|
||||
NebulaLog::finalize_log_system();
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool PoolTest::mysql;
|
||||
|
||||
string PoolTest::db_name = "ONE_test_database";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#endif // POOL_TEST_H_
|
19
install.sh
19
install.sh
@ -250,11 +250,11 @@ INSTALL_ETC_FILES[17]="OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates"
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
BIN_FILES="src/nebula/oned \
|
||||
src/scheduler/mm_sched \
|
||||
src/client/ruby/onevm \
|
||||
src/client/ruby/onehost \
|
||||
src/client/ruby/onevnet \
|
||||
src/client/ruby/oneuser \
|
||||
src/scheduler/src/sched/mm_sched \
|
||||
src/cli/onevm \
|
||||
src/cli/onehost \
|
||||
src/cli/onevnet \
|
||||
src/cli/oneuser \
|
||||
share/scripts/one"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -263,9 +263,8 @@ BIN_FILES="src/nebula/oned \
|
||||
# Library files, to be installed under $LIB_LOCATION
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
INCLUDE_FILES="include/OneClient.h"
|
||||
LIB_FILES="src/client/liboneapi.a \
|
||||
src/client/liboneapi.so"
|
||||
INCLUDE_FILES=""
|
||||
LIB_FILES=""
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Ruby library files, to be installed under $LIB_LOCATION/ruby
|
||||
@ -278,8 +277,8 @@ RUBY_LIB_FILES="src/mad/ruby/one_mad.rb \
|
||||
src/mad/ruby/CommandManager.rb \
|
||||
src/mad/ruby/OpenNebulaDriver.rb \
|
||||
src/mad/ruby/VirtualMachineDriver.rb \
|
||||
src/client/ruby/client_utilities.rb \
|
||||
src/client/ruby/command_parse.rb \
|
||||
src/cli/client_utilities.rb \
|
||||
src/cli/command_parse.rb \
|
||||
src/oca/ruby/OpenNebula.rb \
|
||||
src/tm_mad/TMScript.rb"
|
||||
|
||||
|
@ -15,6 +15,13 @@
|
||||
#
|
||||
# PORT: Port where oned will listen for xmlrpc calls.
|
||||
#
|
||||
# DB: Configuration attributes for the database backend
|
||||
# backend : can be sqlite or mysql (default is sqlite)
|
||||
# server : (mysql) host name or an IP address for the MySQL server
|
||||
# user : (mysql) user's MySQL login ID
|
||||
# passwd : (mysql) the password for user
|
||||
# db_name : (mysql) the database name
|
||||
#
|
||||
# DEBUG_LEVEL: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG
|
||||
#*******************************************************************************
|
||||
|
||||
@ -26,6 +33,15 @@ VM_POLLING_INTERVAL = 60
|
||||
|
||||
PORT=2633
|
||||
|
||||
DB = [ backend = "sqlite" ]
|
||||
|
||||
# Sample configuration for MySQL
|
||||
# DB = [ backend = "mysql",
|
||||
# server = "localhost",
|
||||
# user = "oneadmin",
|
||||
# passwd = "oneadmin",
|
||||
# db_name = "opennebula" ]
|
||||
|
||||
DEBUG_LEVEL=3
|
||||
|
||||
#*******************************************************************************
|
||||
|
103
share/test/do_tests.sh
Executable file
103
share/test/do_tests.sh
Executable file
@ -0,0 +1,103 @@
|
||||
#!/bin/bash
|
||||
#-------------------------------------------------------------------------------
|
||||
# COMMAND LINE PARSING
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# COMMAND LINE PARSING
|
||||
#-------------------------------------------------------------------------------
|
||||
usage() {
|
||||
echo
|
||||
echo "Usage: do_test.sh [-smvgclh]"
|
||||
echo
|
||||
echo "-m: use MyQSL backend (defaults to Sqlite)"
|
||||
echo "-v: run tests using valgrind (memcheck) output will be memgrind.out"
|
||||
echo "-g: run tests using valgrind (callgrind) output will be callgrind.out"
|
||||
echo "-l: keep logs"
|
||||
echo "-c: clear everything"
|
||||
echo "-b: just build the tests and do not run them"
|
||||
echo
|
||||
echo "-h: prints this help"
|
||||
}
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
TEMP_OPT=`getopt -o mvgclbh -n 'install.sh' -- "$@"`
|
||||
|
||||
if [ $? != 0 ] ; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
eval set -- "$TEMP_OPT"
|
||||
|
||||
MYSQL="no"
|
||||
VAL_MEM="no"
|
||||
VAL_CALL="no"
|
||||
LOGS="no"
|
||||
CLEAR="no"
|
||||
BUILD="no"
|
||||
|
||||
TWD_DIR="../../src"
|
||||
BASE_DIR=$PWD
|
||||
|
||||
while true ; do
|
||||
case "$1" in
|
||||
-h) usage; exit 0;;
|
||||
-m) MYSQL="yes" ; shift ;;
|
||||
-v) VAL_MEM="yes" ; shift ;;
|
||||
-g) VAL_CALL="yes"; shift ;;
|
||||
-l) LOGS="yes" ; shift ;;
|
||||
-c) CLEAR="yes" ; shift ;;
|
||||
-b) BUILD="yes" ; shift ;;
|
||||
--) shift ; break ;;
|
||||
*) usage; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# SETUP ARGUMENTS
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if [ "$MYSQL" = "yes" ] ; then
|
||||
TEST_ARGS="-m"
|
||||
else
|
||||
TEST_ARGS="-s"
|
||||
fi
|
||||
|
||||
if [ "$LOGS" = "yes" ] ; then
|
||||
TEST_ARGS="$TEST_ARGS -l"
|
||||
fi
|
||||
|
||||
CALLER=""
|
||||
|
||||
if [ "$VAL_MEM" = "yes" ] ; then
|
||||
CALLER="valgrind --show-reachable=yes --leak-check=full"
|
||||
elif [ "$VAL_CALL" = "yes" ] ; then
|
||||
CALLER="valgrind --tool=callgrind"
|
||||
fi
|
||||
|
||||
TESTS=`find $TWD_DIR -name test -type d`
|
||||
|
||||
for i in $TESTS ; do
|
||||
cd $BASE_DIR
|
||||
|
||||
echo "Doing $i ..."
|
||||
cd $i
|
||||
|
||||
if [ "$CLEAR" = "yes" ] ; then
|
||||
scons -c
|
||||
rm -f callgrind.out* test.db* test.log* memgrid.out*
|
||||
elif [ "$BUILD" = "yes" ] ; then
|
||||
scons
|
||||
else
|
||||
for j in `ls test*` ; do
|
||||
$CALLER ./$j $TEST_ARGS
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
cd $BASE_DIR
|
||||
|
||||
exit 0
|
@ -1,487 +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 "OneClient.h"
|
||||
#include <fstream>
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int OneClient::allocate(string template_file, int& vmid, string& error)
|
||||
{
|
||||
|
||||
try{
|
||||
|
||||
string str_template="";
|
||||
ifstream file;
|
||||
char c;
|
||||
|
||||
file.open(template_file.c_str());
|
||||
|
||||
if ( file.good() == false )
|
||||
{
|
||||
error = "Could not open file\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
file.get(c);
|
||||
|
||||
while (file.good())
|
||||
{
|
||||
str_template+=c;
|
||||
file.get(c);
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
xmlrpc_c::value result;
|
||||
|
||||
this->call(url,
|
||||
"one.vmallocate",
|
||||
"ss",
|
||||
&result,
|
||||
session.c_str(),
|
||||
str_template.c_str());
|
||||
|
||||
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(result);
|
||||
vector<xmlrpc_c::value> const
|
||||
paramArrayValue(resultArray.vectorValueValue());
|
||||
|
||||
//check posible errors
|
||||
xmlrpc_c::value_boolean const status(paramArrayValue[0]);
|
||||
|
||||
if(static_cast<bool>(status) == true)
|
||||
{
|
||||
xmlrpc_c::value_int const _vmid (paramArrayValue[1]);
|
||||
|
||||
vmid = static_cast<int>(_vmid);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlrpc_c::value_string const valueS(paramArrayValue[1]);
|
||||
|
||||
error=static_cast<string>(valueS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "XML-RPC Error: " << e.what() << endl;
|
||||
|
||||
error=oss.str();
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int OneClient::allocate_template(const string& str_template,
|
||||
int& vmid,
|
||||
string& error)
|
||||
{
|
||||
try{
|
||||
xmlrpc_c::value result;
|
||||
|
||||
this->call(url,
|
||||
"one.vmallocate",
|
||||
"ss",
|
||||
&result,
|
||||
session.c_str(),
|
||||
str_template.c_str());
|
||||
|
||||
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(result);
|
||||
vector<xmlrpc_c::value> const
|
||||
paramArrayValue(resultArray.vectorValueValue());
|
||||
|
||||
//check posible errors
|
||||
xmlrpc_c::value_boolean const status(paramArrayValue[0]);
|
||||
|
||||
if(static_cast<bool>(status) == true)
|
||||
{
|
||||
xmlrpc_c::value_int const _vmid (paramArrayValue[1]);
|
||||
|
||||
vmid = static_cast<int>(_vmid);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlrpc_c::value_string const valueS(paramArrayValue[1]);
|
||||
|
||||
error=static_cast<string>(valueS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "XML-RPC Error: " << e.what() << endl;
|
||||
|
||||
error=oss.str();
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int OneClient::deploy(int vmid, int hid, string& error)
|
||||
{
|
||||
try {
|
||||
xmlrpc_c::value result;
|
||||
|
||||
this->call(url,"one.vmdeploy","sii", &result,session.c_str(),vmid,hid);
|
||||
|
||||
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(result);
|
||||
|
||||
vector<xmlrpc_c::value> const
|
||||
paramArrayValue(resultArray.vectorValueValue());
|
||||
|
||||
//check posible errors
|
||||
xmlrpc_c::value_boolean const status(paramArrayValue[0]);
|
||||
|
||||
if(static_cast<bool>(status) == true)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlrpc_c::value_string const valueS(paramArrayValue[1]);
|
||||
|
||||
error=static_cast<string>(valueS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "XML-RPC Error: " << e.what() << endl;
|
||||
|
||||
error=oss.str();
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int OneClient::migrate(int vmid, int hid, bool live, string& error)
|
||||
{
|
||||
try {
|
||||
xmlrpc_c::value result;
|
||||
|
||||
this->call(url,
|
||||
"one.vmmigrate",
|
||||
"siib",
|
||||
&result,
|
||||
session.c_str(),
|
||||
vmid,hid,live);
|
||||
|
||||
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(result);
|
||||
vector<xmlrpc_c::value> const
|
||||
paramArrayValue(resultArray.vectorValueValue());
|
||||
|
||||
//check posible errors
|
||||
xmlrpc_c::value_boolean const status(paramArrayValue[0]);
|
||||
|
||||
if(static_cast<bool>(status) == true)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlrpc_c::value_string const valueS(paramArrayValue[1]);
|
||||
|
||||
error=static_cast<string>(valueS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "XML-RPC Error: " << e.what() << endl;
|
||||
|
||||
error=oss.str();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int OneClient::action(int vmid, const char * action, string& error)
|
||||
{
|
||||
try {
|
||||
xmlrpc_c::value result;
|
||||
|
||||
this->call(url,
|
||||
"one.vmaction",
|
||||
"ssi",
|
||||
&result,
|
||||
session.c_str(),
|
||||
action,
|
||||
vmid);
|
||||
|
||||
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(result);
|
||||
vector<xmlrpc_c::value> const
|
||||
paramArrayValue(resultArray.vectorValueValue());
|
||||
|
||||
//check posible errors
|
||||
xmlrpc_c::value_boolean const status(paramArrayValue[0]);
|
||||
|
||||
if(static_cast<bool>(status) == true)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlrpc_c::value_string const valueS(paramArrayValue[1]);
|
||||
|
||||
error=static_cast<string>(valueS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "XML-RPC Error: " << e.what() << endl;
|
||||
|
||||
error=oss.str();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int OneClient::info(int vmid, string& info, string& error)
|
||||
{
|
||||
try{
|
||||
xmlrpc_c::value result;
|
||||
this->call(url,"one.vmget_info","si",&result,session.c_str(),vmid);
|
||||
|
||||
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(result);
|
||||
vector<xmlrpc_c::value> const
|
||||
paramArrayValue(resultArray.vectorValueValue());
|
||||
|
||||
//check posible errors
|
||||
xmlrpc_c::value_boolean const status(paramArrayValue[0]);
|
||||
|
||||
xmlrpc_c::value_string const valueS(paramArrayValue[1]);
|
||||
|
||||
if(static_cast<bool>(status) == true)
|
||||
{
|
||||
info = static_cast<string>(valueS);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
error = static_cast<string>(valueS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "XML-RPC Error: " << e.what() << endl;
|
||||
|
||||
error=oss.str();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int OneClient::host_info(int hid, string& info, string& error)
|
||||
{
|
||||
try{
|
||||
xmlrpc_c::value result;
|
||||
this->call(url,"one.hostinfo","si",&result,session.c_str(),hid);
|
||||
|
||||
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(result);
|
||||
vector<xmlrpc_c::value> const
|
||||
paramArrayValue(resultArray.vectorValueValue());
|
||||
|
||||
//check posible Errors:
|
||||
xmlrpc_c::value_boolean const status(paramArrayValue[0]);
|
||||
|
||||
xmlrpc_c::value_string const valueS (paramArrayValue[1]);
|
||||
|
||||
if(static_cast<bool>(status) == true)
|
||||
{
|
||||
info = static_cast<string>(valueS);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
error = static_cast<string>(valueS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "XML-RPC Error: " << e.what() << endl;
|
||||
|
||||
error=oss.str();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int OneClient::host_delete(int hid, string& error)
|
||||
{
|
||||
try {
|
||||
xmlrpc_c::value result;
|
||||
this->call(url, "one.hostdelete", "si", &result,session.c_str(), hid);
|
||||
|
||||
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(result);
|
||||
vector<xmlrpc_c::value> const
|
||||
paramArrayValue(resultArray.vectorValueValue());
|
||||
|
||||
//check posible errors
|
||||
xmlrpc_c::value_boolean const status(paramArrayValue[0]);
|
||||
|
||||
if(static_cast<bool>(status) == true)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlrpc_c::value_string const valueS(paramArrayValue[1]);
|
||||
|
||||
error=static_cast<string>(valueS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "XML-RPC Error: " << e.what() << endl;
|
||||
|
||||
error=oss.str();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int OneClient::host_available(int hid, bool enable, string& error)
|
||||
{
|
||||
|
||||
try{
|
||||
xmlrpc_c::value result;
|
||||
this->call(url,
|
||||
"one.hostenable",
|
||||
"sib",
|
||||
&result,
|
||||
session.c_str(),
|
||||
hid,
|
||||
enable);
|
||||
|
||||
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(result);
|
||||
vector<xmlrpc_c::value> const
|
||||
paramArrayValue(resultArray.vectorValueValue());
|
||||
|
||||
//check posible errors
|
||||
xmlrpc_c::value_boolean const status(paramArrayValue[0]);
|
||||
|
||||
if(static_cast<bool>(status) == true)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlrpc_c::value_string const valueS(paramArrayValue[1]);
|
||||
|
||||
error=static_cast<string>(valueS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "XML-RPC Error: " << e.what() << endl;
|
||||
|
||||
error=oss.str();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int OneClient::host_allocate(string& name,
|
||||
string& im_mad,
|
||||
string& vmm_mad,
|
||||
int& hid,
|
||||
string& error)
|
||||
{
|
||||
|
||||
try{
|
||||
xmlrpc_c::value result;
|
||||
this->call(url,
|
||||
"one.hostallocate",
|
||||
"sssssb",
|
||||
&result,
|
||||
session.c_str(),
|
||||
name.c_str(),
|
||||
im_mad.c_str(),
|
||||
vmm_mad.c_str(),
|
||||
"tm_mad",
|
||||
true);
|
||||
|
||||
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(result);
|
||||
vector<xmlrpc_c::value> const
|
||||
paramArrayValue(resultArray.vectorValueValue());
|
||||
|
||||
//check posible errors:
|
||||
xmlrpc_c::value_boolean const status(paramArrayValue[0]);
|
||||
|
||||
if (static_cast<bool>(status) == true)
|
||||
{
|
||||
xmlrpc_c::value_int const valueI (paramArrayValue[1]);
|
||||
|
||||
hid = static_cast<int>(valueI);
|
||||
return 0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlrpc_c::value_string const valueS = (paramArrayValue[1]);
|
||||
|
||||
error=static_cast<string>(valueS);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "XML-RPC Error: " << e.what() << endl;
|
||||
|
||||
error=oss.str();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -1,263 +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 "OneClient.h"
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
using namespace std;
|
||||
|
||||
/* ************************************************************************** */
|
||||
#define ONED_PORT 60222
|
||||
OneClient* client=0;
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
void c_oneStart()
|
||||
{
|
||||
#ifdef ONED_PORT
|
||||
client=new OneClient("localhost",ONED_PORT);
|
||||
#else
|
||||
client=new OneClient("localhost");
|
||||
#endif
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void c_oneFree()
|
||||
{
|
||||
if(client)
|
||||
delete client;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneDeploy(int vmid, int hid)
|
||||
{
|
||||
string info;
|
||||
|
||||
if(!client)
|
||||
return -1;
|
||||
|
||||
if(client->deploy(vmid,hid,info) <0)
|
||||
{
|
||||
cerr<<info<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneMigrate(int vmid, int hid, int flag)
|
||||
{
|
||||
string info;
|
||||
|
||||
if (!client)
|
||||
return -1;
|
||||
|
||||
if(client->migrate(vmid,hid,(bool)flag,info) <0)
|
||||
{
|
||||
cerr<<info<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneAllocate(char* vm_template)
|
||||
{
|
||||
string info;
|
||||
string template_file(vm_template);
|
||||
|
||||
int vmid;
|
||||
|
||||
if (!client)
|
||||
return -1;
|
||||
|
||||
if( (client->allocate(template_file,vmid, info)) <0)
|
||||
{
|
||||
cerr<<info<<endl;
|
||||
return -1;
|
||||
}
|
||||
return vmid;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneAllocateTemplate(char* vm_template)
|
||||
{
|
||||
string info;
|
||||
string template_str(vm_template);
|
||||
|
||||
int vmid;
|
||||
|
||||
if (!client)
|
||||
return -1;
|
||||
|
||||
if( (client->allocate_template(template_str,vmid, info)) <0)
|
||||
{
|
||||
cerr<<info<<endl;
|
||||
return -1;
|
||||
}
|
||||
return vmid;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneShutdown(int vmid)
|
||||
{
|
||||
string info;
|
||||
|
||||
if (!client)
|
||||
return -1;
|
||||
|
||||
if(client->shutdown(vmid,info) <0)
|
||||
{
|
||||
cerr<<info<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneSuspend(int vmid)
|
||||
{
|
||||
string info;
|
||||
|
||||
if (!client)
|
||||
return -1;
|
||||
|
||||
if (client->suspend(vmid,info) <0)
|
||||
{
|
||||
cerr<<info<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneStop(int vmid)
|
||||
{
|
||||
string info;
|
||||
|
||||
if (!client)
|
||||
return -1;
|
||||
|
||||
if (client->stop(vmid,info) <0)
|
||||
{
|
||||
cerr<<info<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneResume(int vmid)
|
||||
{
|
||||
string info;
|
||||
|
||||
if (!client)
|
||||
return -1;
|
||||
|
||||
if( client->resume(vmid,info) <0)
|
||||
{
|
||||
cerr<<info<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneCancel(int vmid)
|
||||
{
|
||||
string info;
|
||||
|
||||
if (!client)
|
||||
return -1;
|
||||
|
||||
if( client->cancel(vmid,info) <0)
|
||||
{
|
||||
cerr<<info<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneFinalize(int vmid)
|
||||
{
|
||||
string info;
|
||||
|
||||
if (!client)
|
||||
return -1;
|
||||
|
||||
if( client->finalize(vmid,info) <0)
|
||||
{
|
||||
cerr<<info<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int c_oneVmInfo(int vmid, char* ret_info,int leng)
|
||||
{
|
||||
string info;
|
||||
string error;
|
||||
|
||||
if (!client || !ret_info)
|
||||
return -1;
|
||||
|
||||
if(client->info(vmid,info,error) <0)
|
||||
{
|
||||
cerr<<error<<endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(ret_info,info.c_str(),leng-1);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
@ -75,8 +75,8 @@ string * VectorAttribute::to_xml() const
|
||||
|
||||
for (it=attribute_value.begin();it!=attribute_value.end();it++)
|
||||
{
|
||||
oss << "<" << it->first << ">" << it->second
|
||||
<< "</"<< it->first << ">";
|
||||
oss << "<" << it->first << "><![CDATA[" << it->second
|
||||
<< "]]></"<< it->first << ">";
|
||||
}
|
||||
|
||||
oss << "</"<< name() << ">";
|
||||
|
64
src/common/test/SConstruct
Normal file
64
src/common/test/SConstruct
Normal file
@ -0,0 +1,64 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
sys.path.append("../../../share/scons")
|
||||
from lex_bison import *
|
||||
|
||||
# This is the absolute path where the project is located
|
||||
cwd="../../../"
|
||||
|
||||
# Environment that will be applied to each scons child
|
||||
main_env=Environment()
|
||||
main_env['ENV']['PATH']=os.environ['PATH']
|
||||
|
||||
# Add builders for flex and bison
|
||||
add_lex(main_env)
|
||||
add_bison(main_env)
|
||||
|
||||
# Include dirs
|
||||
main_env.Append(CPPPATH=[
|
||||
cwd + '/include',
|
||||
'/usr/include/cppunit/'
|
||||
])
|
||||
|
||||
# Library dirs
|
||||
main_env.Append(LIBPATH=[
|
||||
cwd + '/src/common',
|
||||
])
|
||||
|
||||
main_env.Append(LIBS=[
|
||||
'nebula_common',
|
||||
'cppunit',
|
||||
'dl',
|
||||
'pthread'
|
||||
])
|
||||
|
||||
# Compile flags
|
||||
main_env.Append(CPPFLAGS=[
|
||||
"-g",
|
||||
"-Wall"
|
||||
])
|
||||
|
||||
# Linking flags
|
||||
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')
|
183
src/common/test/action_manager.cc
Normal file
183
src/common/test/action_manager.cc
Normal file
@ -0,0 +1,183 @@
|
||||
#include "ActionManager.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include <TestFixture.h>
|
||||
#include <TestAssert.h>
|
||||
#include <TestSuite.h>
|
||||
#include <TestCaller.h>
|
||||
#include <ui/text/TestRunner.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" void * addsub_loop(void *arg);
|
||||
|
||||
class AddSub : public ActionListener
|
||||
{
|
||||
public:
|
||||
AddSub(int i):am(),counter(i)
|
||||
{
|
||||
am.addListener(this);
|
||||
};
|
||||
|
||||
~AddSub(){};
|
||||
|
||||
void add(int i)
|
||||
{
|
||||
int * p;
|
||||
|
||||
p = new int(i);
|
||||
|
||||
am.trigger("ADD",(void *) p);
|
||||
}
|
||||
|
||||
void sub(int i)
|
||||
{
|
||||
int * p;
|
||||
|
||||
p = new int(i);
|
||||
|
||||
am.trigger("SUB",(void *) p);
|
||||
}
|
||||
|
||||
int value()
|
||||
{
|
||||
return counter;
|
||||
}
|
||||
|
||||
pthread_t id()
|
||||
{
|
||||
return pid;
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
pthread_attr_t pattr;
|
||||
|
||||
pthread_attr_init (&pattr);
|
||||
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
pthread_create(&pid,&pattr,addsub_loop,(void *) this);
|
||||
}
|
||||
|
||||
void end()
|
||||
{
|
||||
am.trigger(ActionListener::ACTION_FINALIZE,0);
|
||||
}
|
||||
|
||||
private:
|
||||
ActionManager am;
|
||||
|
||||
int counter;
|
||||
pthread_t pid;
|
||||
|
||||
friend void * addsub_loop(void *arg);
|
||||
|
||||
void do_action(const string &action, void * arg)
|
||||
{
|
||||
int * i = static_cast<int *>(arg);
|
||||
|
||||
if ( i == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if ( action == "ADD" )
|
||||
{
|
||||
counter = counter + *i;
|
||||
}
|
||||
else if ( action == "SUB" )
|
||||
{
|
||||
counter = counter - *i;
|
||||
}
|
||||
|
||||
delete i;
|
||||
}
|
||||
};
|
||||
|
||||
extern "C" void * addsub_loop(void *arg)
|
||||
{
|
||||
AddSub *as;
|
||||
|
||||
as = static_cast<AddSub *>(arg);
|
||||
|
||||
as->am.loop(0,0);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
class ActionManagerTest : public CppUnit::TestFixture
|
||||
{
|
||||
private:
|
||||
AddSub *as;
|
||||
|
||||
public:
|
||||
void setUp()
|
||||
{
|
||||
as = new AddSub(10);
|
||||
as->start();
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
delete as;
|
||||
}
|
||||
|
||||
void test_add()
|
||||
{
|
||||
as->add(23);
|
||||
as->add(5);
|
||||
|
||||
sleep(1);
|
||||
|
||||
CPPUNIT_ASSERT(as->value() == 38);
|
||||
|
||||
as->end();
|
||||
|
||||
pthread_join(as->id(),0);
|
||||
|
||||
CPPUNIT_ASSERT(as->value() == 38);
|
||||
}
|
||||
|
||||
void test_sub()
|
||||
{
|
||||
as->sub(3);
|
||||
as->sub(15);
|
||||
|
||||
sleep(1);
|
||||
|
||||
CPPUNIT_ASSERT(as->value() == -8);
|
||||
|
||||
as->end();
|
||||
|
||||
pthread_join(as->id(),0);
|
||||
|
||||
CPPUNIT_ASSERT(as->value() == -8);
|
||||
}
|
||||
|
||||
static CppUnit::TestSuite * suite()
|
||||
{
|
||||
CppUnit::TestSuite *ts=new CppUnit::TestSuite("ActionManager Tests");
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<ActionManagerTest>(
|
||||
"add() Test",
|
||||
&ActionManagerTest::test_add));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<ActionManagerTest>(
|
||||
"sub() Test",
|
||||
&ActionManagerTest::test_sub));
|
||||
return ts;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
|
||||
CppUnit::TextUi::TestRunner tr;
|
||||
|
||||
tr.addTest(ActionManagerTest::suite());
|
||||
tr.run();
|
||||
|
||||
return 0;
|
||||
}
|
131
src/common/test/single_attribute.cc
Normal file
131
src/common/test/single_attribute.cc
Normal file
@ -0,0 +1,131 @@
|
||||
#include "Attribute.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <TestFixture.h>
|
||||
#include <TestAssert.h>
|
||||
#include <TestSuite.h>
|
||||
#include <TestCaller.h>
|
||||
#include <ui/text/TestRunner.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class SingleAttributeTest : public CppUnit::TestFixture
|
||||
{
|
||||
private:
|
||||
SingleAttribute *a, *b;
|
||||
|
||||
public:
|
||||
void setUp()
|
||||
{
|
||||
string a_name = "single_a";
|
||||
|
||||
string b_name = "single_b";
|
||||
string b_value= "value_b";
|
||||
|
||||
a = new SingleAttribute(a_name);
|
||||
b = new SingleAttribute(b_name, b_value);
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
delete a;
|
||||
delete b;
|
||||
}
|
||||
|
||||
void test_type()
|
||||
{
|
||||
CPPUNIT_ASSERT(a->type() == Attribute::SIMPLE);
|
||||
CPPUNIT_ASSERT(b->type() == Attribute::SIMPLE);
|
||||
}
|
||||
|
||||
void test_name()
|
||||
{
|
||||
CPPUNIT_ASSERT(a->name() == "SINGLE_A");
|
||||
CPPUNIT_ASSERT(b->name() == "SINGLE_B");
|
||||
}
|
||||
|
||||
void test_value()
|
||||
{
|
||||
CPPUNIT_ASSERT(a->value().empty() == true);
|
||||
CPPUNIT_ASSERT(b->value() == "value_b");
|
||||
}
|
||||
|
||||
void test_marshall()
|
||||
{
|
||||
string *am, *bm;
|
||||
|
||||
am = a->marshall();
|
||||
bm = b->marshall();
|
||||
|
||||
CPPUNIT_ASSERT(am->empty() == true);
|
||||
CPPUNIT_ASSERT(*bm == "value_b");
|
||||
|
||||
delete am;
|
||||
delete bm;
|
||||
}
|
||||
|
||||
void test_xml()
|
||||
{
|
||||
string *am, *bm;
|
||||
|
||||
am = a->to_xml();
|
||||
bm = b->to_xml();
|
||||
|
||||
CPPUNIT_ASSERT(*am == "<SINGLE_A><![CDATA[]]></SINGLE_A>");
|
||||
CPPUNIT_ASSERT(*bm == "<SINGLE_B><![CDATA[value_b]]></SINGLE_B>");
|
||||
|
||||
delete am;
|
||||
delete bm;
|
||||
}
|
||||
|
||||
void test_replace()
|
||||
{
|
||||
string nv = "new_value_b";
|
||||
|
||||
b->replace(nv);
|
||||
|
||||
CPPUNIT_ASSERT(b->value() == "new_value_b");
|
||||
}
|
||||
|
||||
static CppUnit::TestSuite * suite()
|
||||
{
|
||||
CppUnit::TestSuite *ts=new CppUnit::TestSuite("SingleAttribute Tests");
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
|
||||
"type() Test",
|
||||
&SingleAttributeTest::test_type));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
|
||||
"name() Test",
|
||||
&SingleAttributeTest::test_name));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
|
||||
"value() Test",
|
||||
&SingleAttributeTest::test_value));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
|
||||
"marshall() Test",
|
||||
&SingleAttributeTest::test_marshall));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
|
||||
"to_xml() Test",
|
||||
&SingleAttributeTest::test_xml));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<SingleAttributeTest>(
|
||||
"replace() Test",
|
||||
&SingleAttributeTest::test_replace));
|
||||
return ts;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
CppUnit::TextUi::TestRunner tr;
|
||||
|
||||
tr.addTest(SingleAttributeTest::suite());
|
||||
tr.run();
|
||||
|
||||
return 0;
|
||||
}
|
164
src/common/test/vector_attribute.cc
Normal file
164
src/common/test/vector_attribute.cc
Normal file
@ -0,0 +1,164 @@
|
||||
#include "Attribute.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include <TestFixture.h>
|
||||
#include <TestAssert.h>
|
||||
#include <TestSuite.h>
|
||||
#include <TestCaller.h>
|
||||
#include <ui/text/TestRunner.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class VectorAttributeTest : public CppUnit::TestFixture
|
||||
{
|
||||
private:
|
||||
VectorAttribute *a, *b;
|
||||
map<string,string> b_value;
|
||||
|
||||
public:
|
||||
void setUp()
|
||||
{
|
||||
string a_name = "vector_a";
|
||||
string b_name = "vector_b";
|
||||
|
||||
b_value.insert(make_pair("attr1","val1"));
|
||||
b_value.insert(make_pair("attr2","val2"));
|
||||
b_value.insert(make_pair("attr3","val3"));
|
||||
|
||||
a = new VectorAttribute(a_name);
|
||||
b = new VectorAttribute(b_name, b_value);
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
delete a;
|
||||
delete b;
|
||||
}
|
||||
|
||||
void test_type()
|
||||
{
|
||||
CPPUNIT_ASSERT(a->type() == Attribute::VECTOR);
|
||||
CPPUNIT_ASSERT(b->type() == Attribute::VECTOR);
|
||||
}
|
||||
|
||||
void test_name()
|
||||
{
|
||||
CPPUNIT_ASSERT(a->name() == "VECTOR_A");
|
||||
CPPUNIT_ASSERT(b->name() == "VECTOR_B");
|
||||
}
|
||||
|
||||
void test_value()
|
||||
{
|
||||
CPPUNIT_ASSERT(a->value().empty() == true);
|
||||
CPPUNIT_ASSERT(b->value() == b_value);
|
||||
|
||||
CPPUNIT_ASSERT(a->vector_value("NAME").empty() == true);
|
||||
CPPUNIT_ASSERT(b->vector_value("NAME").empty() == true);
|
||||
|
||||
CPPUNIT_ASSERT(b->vector_value("attr1") == "val1");
|
||||
CPPUNIT_ASSERT(b->vector_value("attr2") == "val2");
|
||||
CPPUNIT_ASSERT(b->vector_value("attr3") == "val3");
|
||||
}
|
||||
|
||||
void test_marshall()
|
||||
{
|
||||
string *am, *bm;
|
||||
|
||||
am = a->marshall();
|
||||
bm = b->marshall();
|
||||
|
||||
CPPUNIT_ASSERT(am == 0);
|
||||
CPPUNIT_ASSERT(*bm == "attr1=val1@^_^@attr2=val2@^_^@attr3=val3");
|
||||
|
||||
VectorAttribute c("vector_c");
|
||||
c.unmarshall(*bm);
|
||||
|
||||
CPPUNIT_ASSERT(c.vector_value("attr1") == "val1");
|
||||
CPPUNIT_ASSERT(c.vector_value("attr2") == "val2");
|
||||
CPPUNIT_ASSERT(c.vector_value("attr3") == "val3");
|
||||
|
||||
delete am;
|
||||
delete bm;
|
||||
}
|
||||
|
||||
void test_xml()
|
||||
{
|
||||
string *am, *bm;
|
||||
|
||||
am = a->to_xml();
|
||||
bm = b->to_xml();
|
||||
|
||||
CPPUNIT_ASSERT(*am == "<VECTOR_A></VECTOR_A>");
|
||||
CPPUNIT_ASSERT(*bm == "<VECTOR_B><attr1><![CDATA[val1]]></attr1><attr2>"
|
||||
"<![CDATA[val2]]></attr2><attr3><![CDATA[val3]]>"
|
||||
"</attr3></VECTOR_B>");
|
||||
delete am;
|
||||
delete bm;
|
||||
}
|
||||
|
||||
void test_replace()
|
||||
{
|
||||
map<string,string> nm;
|
||||
string nv = "new_val1";
|
||||
|
||||
b->replace("attr1",nv);
|
||||
|
||||
CPPUNIT_ASSERT(b->vector_value("attr1") == "new_val1");
|
||||
|
||||
nm.insert(make_pair("other_attr1","other_val1"));
|
||||
nm.insert(make_pair("other_attr2","other_val2"));
|
||||
|
||||
b->replace(nm);
|
||||
|
||||
CPPUNIT_ASSERT(b->vector_value("other_attr1") == "other_val1");
|
||||
CPPUNIT_ASSERT(b->vector_value("other_attr2") == "other_val2");
|
||||
CPPUNIT_ASSERT(b->vector_value("attr3").empty() == true);
|
||||
CPPUNIT_ASSERT(b->value() == nm);
|
||||
}
|
||||
|
||||
static CppUnit::TestSuite * suite()
|
||||
{
|
||||
CppUnit::TestSuite *ts=new CppUnit::TestSuite("VectorAttribute Tests");
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
|
||||
"type() Test",
|
||||
&VectorAttributeTest::test_type));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
|
||||
"name() Test",
|
||||
&VectorAttributeTest::test_name));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
|
||||
"value() Test",
|
||||
&VectorAttributeTest::test_value));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
|
||||
"marshall() Test",
|
||||
&VectorAttributeTest::test_marshall));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
|
||||
"to_xml() Test",
|
||||
&VectorAttributeTest::test_xml));
|
||||
|
||||
ts->addTest(new CppUnit::TestCaller<VectorAttributeTest>(
|
||||
"replace() Test",
|
||||
&VectorAttributeTest::test_replace));
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
|
||||
CppUnit::TextUi::TestRunner tr;
|
||||
|
||||
tr.addTest(VectorAttributeTest::suite());
|
||||
tr.run();
|
||||
|
||||
return 0;
|
||||
}
|
@ -15,7 +15,8 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "DispatchManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -27,15 +28,15 @@ extern "C" void * dm_action_loop(void *arg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
dm = static_cast<DispatchManager *>(arg);
|
||||
|
||||
Nebula::log("DiM",Log::INFO,"Dispatch Manager started.");
|
||||
|
||||
NebulaLog::log("DiM",Log::INFO,"Dispatch Manager started.");
|
||||
|
||||
dm->am.loop(0,0);
|
||||
|
||||
Nebula::log("DiM",Log::INFO,"Dispatch Manager stopped.");
|
||||
|
||||
NebulaLog::log("DiM",Log::INFO,"Dispatch Manager stopped.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -49,7 +50,7 @@ int DispatchManager::start()
|
||||
pthread_attr_init (&pattr);
|
||||
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
Nebula::log("DiM",Log::INFO,"Starting Dispatch Manager...");
|
||||
NebulaLog::log("DiM",Log::INFO,"Starting Dispatch Manager...");
|
||||
|
||||
rc = pthread_create(&dm_thread,&pattr,dm_action_loop,(void *) this);
|
||||
|
||||
@ -83,14 +84,14 @@ void DispatchManager::trigger(Actions action, int _vid)
|
||||
case FAILED:
|
||||
aname = "FAILED";
|
||||
break;
|
||||
|
||||
|
||||
case FINALIZE:
|
||||
aname = ACTION_FINALIZE;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
delete vid;
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
am.trigger(aname,vid);
|
||||
@ -103,7 +104,7 @@ void DispatchManager::do_action(const string &action, void * arg)
|
||||
{
|
||||
int vid;
|
||||
ostringstream oss;
|
||||
|
||||
|
||||
if (arg == 0)
|
||||
{
|
||||
return;
|
||||
@ -112,7 +113,7 @@ void DispatchManager::do_action(const string &action, void * arg)
|
||||
vid = *(static_cast<int *>(arg));
|
||||
|
||||
delete static_cast<int *>(arg);
|
||||
|
||||
|
||||
if (action == "SUSPEND_SUCCESS")
|
||||
{
|
||||
suspend_success_action(vid);
|
||||
@ -128,16 +129,16 @@ void DispatchManager::do_action(const string &action, void * arg)
|
||||
else if (action == "FAILED")
|
||||
{
|
||||
failed_action(vid);
|
||||
}
|
||||
}
|
||||
else if (action == ACTION_FINALIZE)
|
||||
{
|
||||
Nebula::log("DiM",Log::INFO,"Stopping Dispatch Manager...");
|
||||
NebulaLog::log("DiM",Log::INFO,"Stopping Dispatch Manager...");
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Unknown action name: " << action;
|
||||
|
||||
Nebula::log("DiM", Log::ERROR, oss);
|
||||
|
||||
NebulaLog::log("DiM", Log::ERROR, oss);
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,9 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "DispatchManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -25,7 +26,7 @@ int DispatchManager::allocate (
|
||||
const string& stemplate,
|
||||
int * oid)
|
||||
{
|
||||
Nebula::log("DiM",Log::DEBUG,"Allocating a new VM");
|
||||
NebulaLog::log("DiM",Log::DEBUG,"Allocating a new VM");
|
||||
|
||||
return vmpool->allocate(uid,stemplate,oid);
|
||||
};
|
||||
@ -47,7 +48,7 @@ int DispatchManager::deploy (
|
||||
vid = vm->get_oid();
|
||||
|
||||
oss << "Deploying VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if ( vm->get_state() == VirtualMachine::PENDING )
|
||||
{
|
||||
@ -75,7 +76,7 @@ error:
|
||||
|
||||
oss.str("");
|
||||
oss << "Could not deploy VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -1;
|
||||
@ -98,7 +99,7 @@ int DispatchManager::migrate(
|
||||
vid = vm->get_oid();
|
||||
|
||||
oss << "Migrating VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING )
|
||||
@ -120,7 +121,7 @@ int DispatchManager::migrate(
|
||||
error:
|
||||
oss.str("");
|
||||
oss << "Could not migrate VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -1;
|
||||
@ -143,7 +144,7 @@ int DispatchManager::live_migrate(
|
||||
vid = vm->get_oid();
|
||||
|
||||
oss << "Live-migrating VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING )
|
||||
@ -165,7 +166,7 @@ int DispatchManager::live_migrate(
|
||||
error:
|
||||
oss.str("");
|
||||
oss << "Could not live-migrate VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -1;
|
||||
@ -188,7 +189,7 @@ int DispatchManager::shutdown (
|
||||
}
|
||||
|
||||
oss << "Shutting down VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING )
|
||||
@ -211,7 +212,7 @@ error:
|
||||
|
||||
oss.str("");
|
||||
oss << "Could not shutdown VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -2;
|
||||
@ -234,7 +235,7 @@ int DispatchManager::hold(
|
||||
}
|
||||
|
||||
oss << "Holding VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::PENDING)
|
||||
{
|
||||
@ -257,7 +258,7 @@ error:
|
||||
|
||||
oss.str("");
|
||||
oss << "Could not hold VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -2;
|
||||
@ -280,7 +281,7 @@ int DispatchManager::release(
|
||||
}
|
||||
|
||||
oss << "Releasing VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::HOLD)
|
||||
{
|
||||
@ -302,7 +303,7 @@ int DispatchManager::release(
|
||||
error:
|
||||
oss.str("");
|
||||
oss << "Could not release VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -2;
|
||||
@ -325,7 +326,7 @@ int DispatchManager::stop(
|
||||
}
|
||||
|
||||
oss << "Stopping VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING )
|
||||
@ -347,7 +348,7 @@ int DispatchManager::stop(
|
||||
error:
|
||||
oss.str("");
|
||||
oss << "Could not stop VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -2;
|
||||
@ -370,7 +371,7 @@ int DispatchManager::cancel(
|
||||
}
|
||||
|
||||
oss << "Cancelling VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING )
|
||||
@ -392,7 +393,7 @@ int DispatchManager::cancel(
|
||||
error:
|
||||
oss.str("");
|
||||
oss << "Could not cancel VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -2;
|
||||
@ -415,7 +416,7 @@ int DispatchManager::suspend(
|
||||
}
|
||||
|
||||
oss << "Suspending VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
vm->get_lcm_state() == VirtualMachine::RUNNING )
|
||||
@ -437,7 +438,7 @@ int DispatchManager::suspend(
|
||||
error:
|
||||
oss.str("");
|
||||
oss << "Could not suspend VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -2;
|
||||
@ -460,7 +461,7 @@ int DispatchManager::resume(
|
||||
}
|
||||
|
||||
oss << "Resuming VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::STOPPED )
|
||||
{
|
||||
@ -495,7 +496,7 @@ int DispatchManager::resume(
|
||||
error:
|
||||
oss.str("");
|
||||
oss << "Could not resume VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return -2;
|
||||
@ -517,9 +518,9 @@ int DispatchManager::restart(int vid)
|
||||
}
|
||||
|
||||
oss << "Restarting VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
if (vm->get_state() == VirtualMachine::ACTIVE &&
|
||||
(vm->get_lcm_state() == VirtualMachine::UNKNOWN ||
|
||||
vm->get_lcm_state() == VirtualMachine::BOOT))
|
||||
{
|
||||
@ -540,7 +541,7 @@ int DispatchManager::restart(int vid)
|
||||
error:
|
||||
oss.str("");
|
||||
oss << "Could not restart VM " << vid << ", wrong state.";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
@ -567,7 +568,7 @@ int DispatchManager::finalize(
|
||||
state = vm->get_state();
|
||||
|
||||
oss << "Finalizing VM " << vid;
|
||||
Nebula::log("DiM",Log::DEBUG,oss);
|
||||
NebulaLog::log("DiM",Log::DEBUG,oss);
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
TransferManager * tm = nd.get_tm();
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "DispatchManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
void DispatchManager::suspend_success_action(int vid)
|
||||
{
|
||||
@ -44,7 +44,7 @@ void DispatchManager::suspend_success_action(int vid)
|
||||
|
||||
oss << "suspend_success action received but VM " << vid
|
||||
<< " not in ACTIVE state";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
@ -82,7 +82,7 @@ void DispatchManager::stop_success_action(int vid)
|
||||
|
||||
oss << "stop_success action received but VM " << vid
|
||||
<< " not in ACTIVE state";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
@ -123,7 +123,7 @@ void DispatchManager::done_action(int vid)
|
||||
ostringstream oss;
|
||||
|
||||
oss << "done action received but VM " << vid << " not in ACTIVE state";
|
||||
Nebula::log("DiM",Log::ERROR,oss);
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "HookManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
const char * HookManager::hook_driver_name = "hook_exe";
|
||||
|
||||
@ -31,13 +31,13 @@ extern "C" void * hm_action_loop(void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
Nebula::log("HKM",Log::INFO,"Hook Manager started.");
|
||||
NebulaLog::log("HKM",Log::INFO,"Hook Manager started.");
|
||||
|
||||
hm = static_cast<HookManager *>(arg);
|
||||
|
||||
hm->am.loop(0,0);
|
||||
|
||||
Nebula::log("HKM",Log::INFO,"Hook Manager stopped.");
|
||||
NebulaLog::log("HKM",Log::INFO,"Hook Manager stopped.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -52,13 +52,13 @@ void HookManager::load_mads(int uid)
|
||||
const VectorAttribute * vattr;
|
||||
int rc;
|
||||
|
||||
Nebula::log("HKM",Log::INFO,"Loading Hook Manager driver.");
|
||||
NebulaLog::log("HKM",Log::INFO,"Loading Hook Manager driver.");
|
||||
|
||||
vattr = static_cast<const VectorAttribute *>(mad_conf[0]);
|
||||
|
||||
if ( vattr == 0 )
|
||||
{
|
||||
Nebula::log("HKM",Log::INFO,"Failed to load Hook Manager driver.");
|
||||
NebulaLog::log("HKM",Log::INFO,"Failed to load Hook Manager driver.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ void HookManager::load_mads(int uid)
|
||||
oss.str("");
|
||||
oss << "\tHook Manager loaded";
|
||||
|
||||
Nebula::log("HKM",Log::INFO,oss);
|
||||
NebulaLog::log("HKM",Log::INFO,oss);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ int HookManager::start()
|
||||
return -1;
|
||||
}
|
||||
|
||||
Nebula::log("HKM",Log::INFO,"Starting Hook Manager...");
|
||||
NebulaLog::log("HKM",Log::INFO,"Starting Hook Manager...");
|
||||
|
||||
pthread_attr_init (&pattr);
|
||||
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
|
||||
@ -111,7 +111,7 @@ void HookManager::do_action(const string &action, void * arg)
|
||||
{
|
||||
if (action == ACTION_FINALIZE)
|
||||
{
|
||||
Nebula::log("HKM",Log::INFO,"Stopping Hook Manager...");
|
||||
NebulaLog::log("HKM",Log::INFO,"Stopping Hook Manager...");
|
||||
|
||||
MadManager::stop();
|
||||
}
|
||||
@ -120,7 +120,7 @@ void HookManager::do_action(const string &action, void * arg)
|
||||
ostringstream oss;
|
||||
oss << "Unknown action name: " << action;
|
||||
|
||||
Nebula::log("HKM", Log::ERROR, oss);
|
||||
NebulaLog::log("HKM", Log::ERROR, oss);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "HookManagerDriver.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
#include <sstream>
|
||||
|
||||
/* ************************************************************************** */
|
||||
@ -92,7 +92,7 @@ void HookManagerDriver::protocol(
|
||||
// Parse the driver message
|
||||
|
||||
os << "Message received: " << message;
|
||||
Nebula::log("HKM", Log::DEBUG, os);
|
||||
NebulaLog::log("HKM", Log::DEBUG, os);
|
||||
|
||||
// Parse the driver message
|
||||
if ( is.good() )
|
||||
@ -125,7 +125,7 @@ void HookManagerDriver::protocol(
|
||||
|
||||
is.clear();
|
||||
getline(is,info);
|
||||
Nebula::log("HKM",Log::INFO, info.c_str());
|
||||
NebulaLog::log("HKM",Log::INFO, info.c_str());
|
||||
}
|
||||
|
||||
return;
|
||||
@ -190,6 +190,6 @@ void HookManagerDriver::protocol(
|
||||
|
||||
void HookManagerDriver::recover()
|
||||
{
|
||||
Nebula::log("HKM", Log::ERROR, "Hook driver crashed, recovering...");
|
||||
NebulaLog::log("HKM", Log::ERROR, "Hook driver crashed, recovering...");
|
||||
|
||||
}
|
||||
|
||||
|
457
src/host/Host.cc
457
src/host/Host.cc
@ -1,18 +1,18 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* 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 <limits.h>
|
||||
#include <string.h>
|
||||
@ -21,10 +21,11 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "Host.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Host :: Constructor/Destructor */
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************ */
|
||||
/* Host :: Constructor/Destructor */
|
||||
/* ************************************************************************ */
|
||||
|
||||
Host::Host(
|
||||
int id,
|
||||
@ -45,23 +46,24 @@ Host::Host(
|
||||
|
||||
Host::~Host(){};
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Host :: Database Access Functions */
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************ */
|
||||
/* Host :: Database Access Functions */
|
||||
/* ************************************************************************ */
|
||||
|
||||
const char * Host::table = "host_pool";
|
||||
|
||||
const char * Host::db_names = "(oid,host_name,state,im_mad,vm_mad,"
|
||||
"tm_mad,last_mon_time)";
|
||||
|
||||
const char * Host::db_bootstrap = "CREATE TABLE host_pool ("
|
||||
"oid INTEGER PRIMARY KEY,host_name TEXT,state INTEGER,"
|
||||
"im_mad TEXT,vm_mad TEXT,tm_mad TEXT,last_mon_time INTEGER)";
|
||||
const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool ("
|
||||
"oid INTEGER PRIMARY KEY,host_name VARCHAR(512), state INTEGER,"
|
||||
"im_mad VARCHAR(128),vm_mad VARCHAR(128),tm_mad VARCHAR(128),"
|
||||
"last_mon_time INTEGER, UNIQUE(host_name, im_mad, vm_mad, tm_mad) )";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Host::unmarshall(int num, char **names, char ** values)
|
||||
int Host::select_cb(void * nil, int num, char **values, char ** names)
|
||||
{
|
||||
if ((!values[OID]) ||
|
||||
(!values[HOST_NAME]) ||
|
||||
@ -78,11 +80,11 @@ int Host::unmarshall(int num, char **names, char ** values)
|
||||
oid = atoi(values[OID]);
|
||||
hostname = values[HOST_NAME];
|
||||
state = static_cast<HostState>(atoi(values[STATE]));
|
||||
|
||||
|
||||
im_mad_name = values[IM_MAD];
|
||||
vmm_mad_name = values[VM_MAD];
|
||||
tm_mad_name = values[TM_MAD];
|
||||
|
||||
|
||||
last_monitored = static_cast<time_t>(atoi(values[LAST_MON_TIME]));
|
||||
|
||||
host_template.id = oid;
|
||||
@ -91,41 +93,22 @@ int Host::unmarshall(int num, char **names, char ** values)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
extern "C" int host_select_cb (
|
||||
void * _host,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names)
|
||||
{
|
||||
Host * host;
|
||||
|
||||
host = static_cast<Host *>(_host);
|
||||
|
||||
if (host == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return host->unmarshall(num,names,values);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Host::select(SqliteDB *db)
|
||||
int Host::select(SqlDB *db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
int boid;
|
||||
|
||||
|
||||
set_callback(static_cast<Callbackable::Callback>(&Host::select_cb));
|
||||
|
||||
oss << "SELECT * FROM " << table << " WHERE oid = " << oid;
|
||||
|
||||
boid = oid;
|
||||
oid = -1;
|
||||
|
||||
rc = db->exec(oss, host_select_cb, (void *) this);
|
||||
rc = db->exec(oss, this);
|
||||
|
||||
if ((rc != 0) || (oid != boid ))
|
||||
{
|
||||
@ -153,55 +136,66 @@ int Host::select(SqliteDB *db)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Host::insert(SqliteDB *db)
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Host::insert(SqlDB *db)
|
||||
{
|
||||
int rc;
|
||||
map<int,HostShare *>::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;
|
||||
host_share.hsid = oid;
|
||||
}
|
||||
|
||||
//Insert the Host and its template
|
||||
rc = update(db);
|
||||
|
||||
// Update the Template
|
||||
rc = host_template.insert(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Update the HostShare
|
||||
rc = host_share.insert(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
host_template.drop(db);
|
||||
return rc;
|
||||
}
|
||||
|
||||
//Insert the Host
|
||||
rc = insert_replace(db, false);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
host_template.drop(db);
|
||||
host_share.drop(db);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Host::update(SqliteDB *db)
|
||||
int Host::update(SqlDB *db)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int rc;
|
||||
|
||||
char * sql_hostname;
|
||||
char * sql_im_mad_name;
|
||||
char * sql_tm_mad_name;
|
||||
char * sql_vmm_mad_name;
|
||||
|
||||
// Update the Template
|
||||
|
||||
rc = host_template.update(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
@ -210,7 +204,6 @@ int Host::update(SqliteDB *db)
|
||||
}
|
||||
|
||||
// Update the HostShare
|
||||
|
||||
rc = host_share.update(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
@ -218,39 +211,74 @@ int Host::update(SqliteDB *db)
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Update the Host
|
||||
|
||||
sql_hostname = sqlite3_mprintf("%q",hostname.c_str());
|
||||
rc = insert_replace(db, true);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Host::insert_replace(SqlDB *db, bool replace)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int rc;
|
||||
|
||||
char * sql_hostname;
|
||||
char * sql_im_mad_name;
|
||||
char * sql_tm_mad_name;
|
||||
char * sql_vmm_mad_name;
|
||||
|
||||
// Update the Host
|
||||
|
||||
sql_hostname = db->escape_str(hostname.c_str());
|
||||
|
||||
if ( sql_hostname == 0 )
|
||||
{
|
||||
goto error_hostname;
|
||||
}
|
||||
|
||||
sql_im_mad_name = sqlite3_mprintf("%q",im_mad_name.c_str());
|
||||
|
||||
sql_im_mad_name = db->escape_str(im_mad_name.c_str());
|
||||
|
||||
if ( sql_im_mad_name == 0 )
|
||||
{
|
||||
goto error_im;
|
||||
}
|
||||
|
||||
sql_tm_mad_name = sqlite3_mprintf("%q",tm_mad_name.c_str());
|
||||
|
||||
sql_tm_mad_name = db->escape_str(tm_mad_name.c_str());
|
||||
|
||||
if ( sql_tm_mad_name == 0 )
|
||||
{
|
||||
goto error_tm;
|
||||
}
|
||||
|
||||
sql_vmm_mad_name = sqlite3_mprintf("%q",vmm_mad_name.c_str());
|
||||
sql_vmm_mad_name = db->escape_str(vmm_mad_name.c_str());
|
||||
|
||||
if ( sql_vmm_mad_name == 0 )
|
||||
{
|
||||
goto error_vmm;
|
||||
}
|
||||
|
||||
// Construct the SQL statement to Insert or Replace (effectively, update)
|
||||
|
||||
oss << "INSERT OR REPLACE INTO " << table << " "<< db_names <<" VALUES ("
|
||||
if(replace)
|
||||
{
|
||||
oss << "REPLACE";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "INSERT";
|
||||
}
|
||||
|
||||
// Construct the SQL statement to Insert or Replace
|
||||
|
||||
oss <<" INTO "<< table <<" "<< db_names <<" VALUES ("
|
||||
<< oid << ","
|
||||
<< "'" << sql_hostname << "',"
|
||||
<< state << ","
|
||||
@ -261,30 +289,27 @@ int Host::update(SqliteDB *db)
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
sqlite3_free(sql_hostname);
|
||||
sqlite3_free(sql_im_mad_name);
|
||||
sqlite3_free(sql_tm_mad_name);
|
||||
sqlite3_free(sql_vmm_mad_name);
|
||||
db->free_str(sql_hostname);
|
||||
db->free_str(sql_im_mad_name);
|
||||
db->free_str(sql_tm_mad_name);
|
||||
db->free_str(sql_vmm_mad_name);
|
||||
|
||||
return rc;
|
||||
|
||||
|
||||
error_vmm:
|
||||
sqlite3_free(sql_tm_mad_name);
|
||||
db->free_str(sql_tm_mad_name);
|
||||
error_tm:
|
||||
sqlite3_free(sql_im_mad_name);
|
||||
db->free_str(sql_im_mad_name);
|
||||
error_im:
|
||||
sqlite3_free(sql_hostname);
|
||||
db->free_str(sql_hostname);
|
||||
error_hostname:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Host::unmarshall(ostringstream& oss,
|
||||
int num,
|
||||
char ** names,
|
||||
char ** values)
|
||||
int Host::dump(ostringstream& oss, int num, char **values, char **names)
|
||||
{
|
||||
if ((!values[OID]) ||
|
||||
(!values[HOST_NAME]) ||
|
||||
@ -301,65 +326,24 @@ int Host::unmarshall(ostringstream& oss,
|
||||
oss <<
|
||||
"<HOST>" <<
|
||||
"<ID>" << values[OID] <<"</ID>" <<
|
||||
"<NAME>" << values[HOST_NAME] <<"</NAME>" <<
|
||||
"<STATE>" << values[STATE] <<"</STATE>" <<
|
||||
"<IM_MAD>" << values[IM_MAD] <<"</IM_MAD>" <<
|
||||
"<VM_MAD>" << values[VM_MAD] <<"</VM_MAD>" <<
|
||||
"<TM_MAD>" << values[TM_MAD] <<"</TM_MAD>" <<
|
||||
"<LAST_MON_TIME>"<< values[LAST_MON_TIME]<<"</LAST_MON_TIME>";
|
||||
|
||||
HostShare::unmarshall(oss,num - LIMIT, names + LIMIT, values + LIMIT);
|
||||
|
||||
"<NAME>" << values[HOST_NAME] <<"</NAME>" <<
|
||||
"<STATE>" << values[STATE] <<"</STATE>" <<
|
||||
"<IM_MAD>" << values[IM_MAD] <<"</IM_MAD>" <<
|
||||
"<VM_MAD>" << values[VM_MAD] <<"</VM_MAD>" <<
|
||||
"<TM_MAD>" << values[TM_MAD] <<"</TM_MAD>" <<
|
||||
"<LAST_MON_TIME>"<< values[LAST_MON_TIME]<<"</LAST_MON_TIME>";
|
||||
|
||||
HostShare::dump(oss,num - LIMIT, values + LIMIT, names + LIMIT);
|
||||
|
||||
oss << "</HOST>";
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
extern "C" int host_dump_cb (
|
||||
void * _oss,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names)
|
||||
{
|
||||
ostringstream * oss;
|
||||
|
||||
oss = static_cast<ostringstream *>(_oss);
|
||||
|
||||
if (oss == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return Host::unmarshall(*oss,num,names,values);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Host::dump(SqliteDB * db, ostringstream& oss, const string& where)
|
||||
{
|
||||
int rc;
|
||||
ostringstream cmd;
|
||||
|
||||
cmd << "SELECT * FROM " << Host::table << "," << HostShare::table
|
||||
<< " ON " << Host::table << ".oid = " << HostShare::table << ".hid";
|
||||
|
||||
if ( !where.empty() )
|
||||
{
|
||||
cmd << " WHERE " << where;
|
||||
}
|
||||
|
||||
rc = db->exec(cmd,host_dump_cb,(void *) &oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Host::drop(SqliteDB * db)
|
||||
int Host::drop(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
@ -380,8 +364,8 @@ int Host::drop(SqliteDB * db)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Host::update_info(string &parse_str)
|
||||
{
|
||||
@ -389,15 +373,15 @@ int Host::update_info(string &parse_str)
|
||||
int rc;
|
||||
|
||||
rc = host_template.parse(parse_str, &error_msg);
|
||||
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
//Nebula::log("ONE", Log::ERROR, error_msg);
|
||||
|
||||
NebulaLog::log("ONE", Log::ERROR, error_msg);
|
||||
|
||||
free(error_msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
get_template_attribute("TOTALCPU",host_share.max_cpu);
|
||||
get_template_attribute("TOTALMEMORY",host_share.max_mem);
|
||||
|
||||
@ -410,40 +394,40 @@ int Host::update_info(string &parse_str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Host :: Misc */
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************ */
|
||||
/* Host :: Misc */
|
||||
/* ************************************************************************ */
|
||||
|
||||
ostream& operator<<(ostream& os, Host& host)
|
||||
{
|
||||
string host_str;
|
||||
|
||||
|
||||
os << host.to_xml(host_str);
|
||||
|
||||
|
||||
return os;
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
string& Host::to_xml(string& xml) const
|
||||
{
|
||||
string template_xml;
|
||||
string share_xml;
|
||||
ostringstream oss;
|
||||
|
||||
oss <<
|
||||
"<HOST>"
|
||||
"<ID>" << oid << "</ID>" <<
|
||||
"<NAME>" << hostname << "</NAME>" <<
|
||||
"<STATE>" << state << "</STATE>" <<
|
||||
"<IM_MAD>" << im_mad_name << "</IM_MAD>" <<
|
||||
"<VM_MAD>" << vmm_mad_name << "</VM_MAD>" <<
|
||||
"<TM_MAD>" << tm_mad_name << "</TM_MAD>" <<
|
||||
"<LAST_MON_TIME>" << last_monitored << "</LAST_MON_TIME>" <<
|
||||
host_share.to_xml(share_xml) <<
|
||||
host_template.to_xml(template_xml) <<
|
||||
|
||||
oss <<
|
||||
"<HOST>"
|
||||
"<ID>" << oid << "</ID>" <<
|
||||
"<NAME>" << hostname << "</NAME>" <<
|
||||
"<STATE>" << state << "</STATE>" <<
|
||||
"<IM_MAD>" << im_mad_name << "</IM_MAD>" <<
|
||||
"<VM_MAD>" << vmm_mad_name << "</VM_MAD>" <<
|
||||
"<TM_MAD>" << tm_mad_name << "</TM_MAD>" <<
|
||||
"<LAST_MON_TIME>" << last_monitored << "</LAST_MON_TIME>" <<
|
||||
host_share.to_xml(share_xml) <<
|
||||
host_template.to_xml(template_xml) <<
|
||||
"</HOST>";
|
||||
|
||||
xml = oss.str();
|
||||
@ -451,17 +435,17 @@ string& Host::to_xml(string& xml) const
|
||||
return xml;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
string& Host::to_str(string& str) const
|
||||
{
|
||||
string template_str;
|
||||
string share_str;
|
||||
|
||||
|
||||
ostringstream os;
|
||||
|
||||
os <<
|
||||
os <<
|
||||
"ID = " << oid << endl <<
|
||||
"NAME = " << hostname << endl <<
|
||||
"STATE = " << state << endl <<
|
||||
@ -473,113 +457,6 @@ string& Host::to_str(string& str) const
|
||||
"HOST SHARES" << endl << host_share.to_str(share_str) <<endl;
|
||||
|
||||
str = os.str();
|
||||
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Host :: Parse functions to compute rank and evaluate requirements */
|
||||
/* ************************************************************************** */
|
||||
|
||||
pthread_mutex_t Host::lex_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef struct yy_buffer_state * YY_BUFFER_STATE;
|
||||
|
||||
int host_requirements_parse(Host * host, bool& result, char ** errmsg);
|
||||
|
||||
int host_rank_parse(Host * host, int& result, char ** errmsg);
|
||||
|
||||
int host_lex_destroy();
|
||||
|
||||
YY_BUFFER_STATE host__scan_string(const char * str);
|
||||
|
||||
void host__delete_buffer(YY_BUFFER_STATE);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Host::match(const string& requirements, bool& result, char **errmsg)
|
||||
{
|
||||
YY_BUFFER_STATE str_buffer = 0;
|
||||
const char * str;
|
||||
int rc;
|
||||
|
||||
pthread_mutex_lock(&lex_mutex);
|
||||
|
||||
*errmsg = 0;
|
||||
|
||||
str = requirements.c_str();
|
||||
|
||||
str_buffer = host__scan_string(str);
|
||||
|
||||
if (str_buffer == 0)
|
||||
{
|
||||
goto error_yy;
|
||||
}
|
||||
|
||||
rc = host_requirements_parse(this,result,errmsg);
|
||||
|
||||
host__delete_buffer(str_buffer);
|
||||
|
||||
host_lex_destroy();
|
||||
|
||||
pthread_mutex_unlock(&lex_mutex);
|
||||
|
||||
return rc;
|
||||
|
||||
error_yy:
|
||||
|
||||
*errmsg=strdup("Error setting scan buffer");
|
||||
|
||||
pthread_mutex_unlock(&lex_mutex);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Host::rank(const string& rank, int& result, char **errmsg)
|
||||
{
|
||||
YY_BUFFER_STATE str_buffer = 0;
|
||||
const char * str;
|
||||
int rc;
|
||||
|
||||
pthread_mutex_lock(&lex_mutex);
|
||||
|
||||
*errmsg = 0;
|
||||
|
||||
str = rank.c_str();
|
||||
|
||||
str_buffer = host__scan_string(str);
|
||||
|
||||
if (str_buffer == 0)
|
||||
{
|
||||
goto error_yy;
|
||||
}
|
||||
|
||||
rc = host_rank_parse(this,result,errmsg);
|
||||
|
||||
host__delete_buffer(str_buffer);
|
||||
|
||||
host_lex_destroy();
|
||||
|
||||
pthread_mutex_unlock(&lex_mutex);
|
||||
|
||||
return rc;
|
||||
|
||||
error_yy:
|
||||
|
||||
*errmsg=strdup("Error setting scan buffer");
|
||||
|
||||
pthread_mutex_unlock(&lex_mutex);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -19,7 +19,6 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "HostPool.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
int HostPool::allocate (
|
||||
int * oid,
|
||||
@ -42,55 +41,50 @@ int HostPool::allocate (
|
||||
|
||||
*oid = PoolSQL::allocate(host);
|
||||
|
||||
return 0;
|
||||
return *oid;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
extern "C"
|
||||
int HostPool::discover_cb(void * _map, int num, char **values, char **names)
|
||||
{
|
||||
static int discover_cb (
|
||||
void * _discovered_hosts,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names)
|
||||
map<int, string> * discovered_hosts;
|
||||
string im_mad(values[1]);
|
||||
int hid;
|
||||
|
||||
discovered_hosts = static_cast<map<int, string> *>(_map);
|
||||
|
||||
if ( (num<=0) || (values[0] == 0) )
|
||||
{
|
||||
map<int, string> * discovered_hosts;
|
||||
string im_mad(values[1]);
|
||||
int hid;
|
||||
return -1;
|
||||
}
|
||||
|
||||
discovered_hosts = static_cast<map<int, string> *>(_discovered_hosts);
|
||||
hid = atoi(values[0]);
|
||||
im_mad = values[1];
|
||||
|
||||
if ( (discovered_hosts == 0) || (num<=0) || (values[0] == 0) )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
discovered_hosts->insert(make_pair(hid,im_mad));
|
||||
|
||||
hid = atoi(values[0]);
|
||||
im_mad = values[1];
|
||||
|
||||
discovered_hosts->insert(make_pair(hid,im_mad));
|
||||
|
||||
return 0;
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::discover(map<int, string> * discovered_hosts)
|
||||
{
|
||||
|
||||
ostringstream sql;
|
||||
int rc;
|
||||
|
||||
lock();
|
||||
|
||||
set_callback(static_cast<Callbackable::Callback>(&HostPool::discover_cb),
|
||||
static_cast<void *>(discovered_hosts));
|
||||
|
||||
sql << "SELECT oid, im_mad FROM "
|
||||
<< Host::table << " WHERE state != "
|
||||
<< Host::DISABLED << " ORDER BY last_mon_time LIMIT 10";
|
||||
|
||||
rc = db->exec(sql,discover_cb,(void *) discovered_hosts);
|
||||
rc = db->exec(sql,this);
|
||||
|
||||
unlock();
|
||||
|
||||
@ -99,3 +93,39 @@ int HostPool::discover(map<int, string> * discovered_hosts)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::dump_cb(void * _oss, int num, char **values, char **names)
|
||||
{
|
||||
ostringstream * oss;
|
||||
|
||||
oss = static_cast<ostringstream *>(_oss);
|
||||
|
||||
return Host::dump(*oss, num, values, names);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::dump(ostringstream& oss, const string& where)
|
||||
{
|
||||
int rc;
|
||||
ostringstream cmd;
|
||||
|
||||
oss << "<HOST_POOL>";
|
||||
|
||||
set_callback(static_cast<Callbackable::Callback>(&HostPool::dump_cb),
|
||||
static_cast<void *>(&oss));
|
||||
|
||||
cmd << "SELECT * FROM " << Host::table << " JOIN " << HostShare::table
|
||||
<< " ON " << Host::table << ".oid = " << HostShare::table << ".hid";
|
||||
|
||||
if ( !where.empty() )
|
||||
{
|
||||
cmd << " WHERE " << where;
|
||||
}
|
||||
|
||||
rc = db->exec(cmd, this);
|
||||
|
||||
oss << "</HOST_POOL>";
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -1,30 +1,31 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------*/
|
||||
/* 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 <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <algorithm>
|
||||
|
||||
#include "HostShare.h"
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* HostShare :: Constructor/Destructor */
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************ */
|
||||
/* HostShare :: Constructor/Destructor */
|
||||
/* ************************************************************************ */
|
||||
|
||||
HostShare::HostShare(
|
||||
int _hsid,
|
||||
@ -49,9 +50,9 @@ HostShare::HostShare(
|
||||
{
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* HostShare :: Database Access Functions */
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************ */
|
||||
/* HostShare :: Database Access Functions */
|
||||
/* ************************************************************************ */
|
||||
|
||||
const char * HostShare::table = "host_shares";
|
||||
|
||||
@ -62,18 +63,18 @@ const char * HostShare::db_names = "(hid,"
|
||||
"used_disk, used_mem, used_cpu,"
|
||||
"running_vms)";
|
||||
|
||||
const char * HostShare::db_bootstrap = "CREATE TABLE host_shares ("
|
||||
"hid INTEGER PRIMARY KEY,"
|
||||
const char * HostShare::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_shares("
|
||||
"hid INTEGER PRIMARY KEY,"
|
||||
"disk_usage INTEGER, mem_usage INTEGER, cpu_usage INTEGER,"
|
||||
"max_disk INTEGER, max_mem INTEGER, max_cpu INTEGER,"
|
||||
"free_disk INTEGER, free_mem INTEGER, free_cpu INTEGER,"
|
||||
"used_disk INTEGER, used_mem INTEGER, used_cpu INTEGER,"
|
||||
"running_vms INTEGER)";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int HostShare::unmarshall(int num, char **names, char ** values)
|
||||
int HostShare::select_cb(void * nil, int num, char **values, char **names)
|
||||
{
|
||||
if ((!values[HID]) ||
|
||||
(!values[DISK_USAGE]) ||
|
||||
@ -99,7 +100,7 @@ int HostShare::unmarshall(int num, char **names, char ** values)
|
||||
disk_usage = atoi(values[DISK_USAGE]);
|
||||
mem_usage = atoi(values[MEM_USAGE]);
|
||||
cpu_usage = atoi(values[CPU_USAGE]);
|
||||
|
||||
|
||||
max_disk = atoi(values[MAX_DISK]);
|
||||
max_mem = atoi(values[MAX_MEMORY]);
|
||||
max_cpu = atoi(values[MAX_CPU]);
|
||||
@ -113,93 +114,75 @@ int HostShare::unmarshall(int num, char **names, char ** values)
|
||||
used_cpu = atoi(values[USED_CPU]);
|
||||
|
||||
running_vms = atoi(values[RUNNING_VMS]);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int HostShare::unmarshall(ostringstream& oss,
|
||||
int num,
|
||||
char ** names,
|
||||
char ** values)
|
||||
int HostShare::dump(ostringstream& oss,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names)
|
||||
{
|
||||
if ((!values[HID]) ||
|
||||
if ((!values[HID]) ||
|
||||
(!values[DISK_USAGE]) ||
|
||||
(!values[MEM_USAGE]) ||
|
||||
(!values[CPU_USAGE]) ||
|
||||
(!values[MAX_DISK]) ||
|
||||
(!values[MAX_MEMORY]) ||
|
||||
(!values[MAX_CPU]) ||
|
||||
(!values[FREE_DISK]) ||
|
||||
(!values[FREE_MEMORY]) ||
|
||||
(!values[FREE_CPU]) ||
|
||||
(!values[USED_DISK]) ||
|
||||
(!values[USED_MEMORY]) ||
|
||||
(!values[USED_CPU]) ||
|
||||
(!values[RUNNING_VMS]) ||
|
||||
(num != LIMIT))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
oss <<
|
||||
"<HOST_SHARE>" <<
|
||||
"<HID>" << values[HID] << "</HID>" <<
|
||||
"<DISK_USAGE>"<< values[DISK_USAGE] << "</DISK_USAGE>"<<
|
||||
"<MEM_USAGE>" << values[MEM_USAGE] << "</MEM_USAGE>" <<
|
||||
"<CPU_USAGE>" << values[CPU_USAGE] << "</CPU_USAGE>" <<
|
||||
"<MAX_DISK>" << values[MAX_DISK] << "</MAX_DISK>" <<
|
||||
"<MAX_MEM>" << values[MAX_MEMORY] << "</MAX_MEM>" <<
|
||||
"<MAX_CPU>" << values[MAX_CPU] << "</MAX_CPU>" <<
|
||||
"<FREE_DISK>" << values[FREE_DISK] << "</FREE_DISK>" <<
|
||||
"<FREE_MEM>" << values[FREE_MEMORY] << "</FREE_MEM>" <<
|
||||
"<FREE_CPU>" << values[FREE_CPU] << "</FREE_CPU>" <<
|
||||
"<USED_DISK>" << values[USED_DISK] << "</USED_DISK>" <<
|
||||
"<USED_MEM>" << values[USED_MEMORY] << "</USED_MEM>" <<
|
||||
"<USED_CPU>" << values[USED_CPU] << "</USED_CPU>" <<
|
||||
"<RUNNING_VMS>"<<values[RUNNING_VMS] << "</RUNNING_VMS>"<<
|
||||
"</HOST_SHARE>";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
extern "C" int host_share_select_cb (
|
||||
void * _hs,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names)
|
||||
{
|
||||
HostShare * hs;
|
||||
|
||||
hs = static_cast<HostShare *>(_hs);
|
||||
|
||||
if (hs == 0)
|
||||
(!values[MEM_USAGE]) ||
|
||||
(!values[CPU_USAGE]) ||
|
||||
(!values[MAX_DISK]) ||
|
||||
(!values[MAX_MEMORY]) ||
|
||||
(!values[MAX_CPU]) ||
|
||||
(!values[FREE_DISK]) ||
|
||||
(!values[FREE_MEMORY]) ||
|
||||
(!values[FREE_CPU]) ||
|
||||
(!values[USED_DISK]) ||
|
||||
(!values[USED_MEMORY]) ||
|
||||
(!values[USED_CPU]) ||
|
||||
(!values[RUNNING_VMS]) ||
|
||||
(num != LIMIT))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return hs->unmarshall(num,names,values);
|
||||
};
|
||||
oss <<
|
||||
"<HOST_SHARE>" <<
|
||||
"<HID>" << values[HID] << "</HID>" <<
|
||||
"<DISK_USAGE>"<< values[DISK_USAGE] << "</DISK_USAGE>"<<
|
||||
"<MEM_USAGE>" << values[MEM_USAGE] << "</MEM_USAGE>" <<
|
||||
"<CPU_USAGE>" << values[CPU_USAGE] << "</CPU_USAGE>" <<
|
||||
"<MAX_DISK>" << values[MAX_DISK] << "</MAX_DISK>" <<
|
||||
"<MAX_MEM>" << values[MAX_MEMORY] << "</MAX_MEM>" <<
|
||||
"<MAX_CPU>" << values[MAX_CPU] << "</MAX_CPU>" <<
|
||||
"<FREE_DISK>" << values[FREE_DISK] << "</FREE_DISK>" <<
|
||||
"<FREE_MEM>" << values[FREE_MEMORY] << "</FREE_MEM>" <<
|
||||
"<FREE_CPU>" << values[FREE_CPU] << "</FREE_CPU>" <<
|
||||
"<USED_DISK>" << values[USED_DISK] << "</USED_DISK>" <<
|
||||
"<USED_MEM>" << values[USED_MEMORY] << "</USED_MEM>" <<
|
||||
"<USED_CPU>" << values[USED_CPU] << "</USED_CPU>" <<
|
||||
"<RUNNING_VMS>"<<values[RUNNING_VMS] << "</RUNNING_VMS>"<<
|
||||
"</HOST_SHARE>";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HostShare::select(SqliteDB * db)
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int HostShare::select(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
int bhsid;
|
||||
|
||||
set_callback(static_cast<Callbackable::Callback>(&HostShare::select_cb));
|
||||
|
||||
oss << "SELECT * FROM " << table << " WHERE hid = " << hsid;
|
||||
|
||||
bhsid = hsid;
|
||||
hsid = -1;
|
||||
|
||||
rc = db->exec(oss,host_share_select_cb,(void *) this);
|
||||
rc = db->exec(oss,this);
|
||||
|
||||
if (hsid != bhsid )
|
||||
{
|
||||
@ -209,48 +192,64 @@ int HostShare::select(SqliteDB * db)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int HostShare::insert(SqliteDB * db)
|
||||
int HostShare::insert(SqlDB * db)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = update(db);
|
||||
rc = insert_replace(db, false);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int HostShare::update(SqliteDB * db)
|
||||
int HostShare::update(SqlDB * db)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = insert_replace(db, true);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int HostShare::insert_replace(SqlDB *db, bool replace)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
oss << "INSERT OR REPLACE INTO " << table << " "<< db_names <<" VALUES ("
|
||||
|
||||
if(replace)
|
||||
{
|
||||
oss << "REPLACE";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "INSERT";
|
||||
}
|
||||
|
||||
oss << " INTO " << table << " "<< db_names <<" VALUES ("
|
||||
<< hsid << ","
|
||||
<< disk_usage <<","<< mem_usage <<","<< cpu_usage<< ","
|
||||
<< max_disk <<","<< max_mem <<","<< max_cpu << ","
|
||||
<< free_disk <<","<< free_mem <<","<< free_cpu << ","
|
||||
<< used_disk <<","<< used_mem <<","<< used_cpu << ","
|
||||
<< running_vms<< ")";
|
||||
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int HostShare::drop(SqliteDB * db)
|
||||
int HostShare::drop(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
@ -259,21 +258,21 @@ int HostShare::drop(SqliteDB * db)
|
||||
return db->exec(oss);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* HostShare :: Misc */
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************ */
|
||||
/* HostShare :: Misc */
|
||||
/* ************************************************************************ */
|
||||
|
||||
ostream& operator<<(ostream& os, HostShare& hs)
|
||||
{
|
||||
string str;
|
||||
|
||||
os << hs.to_xml(str);
|
||||
|
||||
|
||||
return os;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
string& HostShare::to_xml(string& xml) const
|
||||
{
|
||||
@ -281,19 +280,19 @@ string& HostShare::to_xml(string& xml) const
|
||||
ostringstream oss;
|
||||
|
||||
oss << "<HOST_SHARE>"
|
||||
<< "<HID>" << hsid << "</HID>"
|
||||
<< "<HID>" << hsid << "</HID>"
|
||||
<< "<DISK_USAGE>" << disk_usage << "</DISK_USAGE>"
|
||||
<< "<MEM_USAGE>" << mem_usage << "</MEM_USAGE>"
|
||||
<< "<CPU_USAGE>" << cpu_usage << "</CPU_USAGE>"
|
||||
<< "<CPU_USAGE>" << cpu_usage << "</CPU_USAGE>"
|
||||
<< "<MAX_DISK>" << max_disk << "</MAX_DISK>"
|
||||
<< "<MAX_MEM>" << max_mem << "</MAX_MEM>"
|
||||
<< "<MAX_CPU>" << max_cpu << "</MAX_CPU>"
|
||||
<< "<MAX_CPU>" << max_cpu << "</MAX_CPU>"
|
||||
<< "<FREE_DISK>" << free_disk << "</FREE_DISK>"
|
||||
<< "<FREE_MEM>" << free_mem << "</FREE_MEM>"
|
||||
<< "<FREE_CPU>" << free_cpu << "</FREE_CPU>"
|
||||
<< "<FREE_CPU>" << free_cpu << "</FREE_CPU>"
|
||||
<< "<USED_DISK>" << used_disk << "</USED_DISK>"
|
||||
<< "<USED_MEM>" << used_mem << "</USED_MEM>"
|
||||
<< "<USED_CPU>" << used_cpu << "</USED_CPU>"
|
||||
<< "<USED_CPU>" << used_cpu << "</USED_CPU>"
|
||||
<< "<RUNNING_VMS>"<<running_vms <<"</RUNNING_VMS>"
|
||||
<< "</HOST_SHARE>";
|
||||
|
||||
@ -302,18 +301,18 @@ string& HostShare::to_xml(string& xml) const
|
||||
return xml;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
string& HostShare::to_str(string& str) const
|
||||
{
|
||||
string template_xml;
|
||||
ostringstream oss;
|
||||
|
||||
oss<< "\tHID = " << hsid
|
||||
oss<< "\tHID = " << hsid
|
||||
<< "\tCPU_USAGE = " << cpu_usage << endl
|
||||
<< "\tMEMORY_USAGE = " << mem_usage << endl
|
||||
<< "\tDISK_USAGE = " << disk_usage<< endl
|
||||
<< "\tDISK_USAGE = " << disk_usage<< endl
|
||||
<< "\tMAX_CPU = " << max_cpu << endl
|
||||
<< "\tMAX_MEMORY = " << max_mem << endl
|
||||
<< "\tMAX_DISK = " << max_disk<< endl
|
||||
@ -330,5 +329,5 @@ string& HostShare::to_str(string& str) const
|
||||
return str;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
@ -17,7 +17,8 @@
|
||||
#include "HostTemplate.h"
|
||||
|
||||
const char * HostTemplate::table = "host_attributes";
|
||||
|
||||
const char * HostTemplate::db_bootstrap = "CREATE TABLE host_attributes"
|
||||
" (id INTEGER, name TEXT, type INTEGER, value TEXT, PRIMARY KEY(id,name))";
|
||||
|
||||
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))";
|
||||
|
||||
|
@ -44,9 +44,6 @@ source_files=[
|
||||
'HostShare.cc',
|
||||
'HostPool.cc',
|
||||
'HostTemplate.cc',
|
||||
'host_parser.c',
|
||||
'host_requirements.cc',
|
||||
'host_rank.cc',
|
||||
]
|
||||
|
||||
# Build library
|
||||
|
@ -1,192 +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 <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include "host_rank.h"
|
||||
#include "Host.h"
|
||||
|
||||
#define YYERROR_VERBOSE
|
||||
#define host_rank_lex host_lex
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void host_rank_error(
|
||||
YYLTYPE * llocp,
|
||||
Host * host,
|
||||
int& result,
|
||||
char ** error_msg,
|
||||
const char * str);
|
||||
|
||||
int host_rank_lex (YYSTYPE *lvalp, YYLTYPE *llocp);
|
||||
|
||||
int host_rank_parse(Host * host, int& result, char ** errmsg);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%parse-param {Host * host}
|
||||
%parse-param {int& result}
|
||||
%parse-param {char ** error_msg}
|
||||
|
||||
%union {
|
||||
char * val_str;
|
||||
int val_int;
|
||||
float val_float;
|
||||
};
|
||||
|
||||
%defines
|
||||
%locations
|
||||
%pure_parser
|
||||
%name-prefix = "host_rank_"
|
||||
%output = "host_rank.cc"
|
||||
|
||||
%left '+' '-'
|
||||
%left '*' '/'
|
||||
%token <val_int> INTEGER
|
||||
%token <val_str> STRING
|
||||
%token <val_float> FLOAT
|
||||
%type <val_int> stmt
|
||||
%type <val_float> expr
|
||||
|
||||
%%
|
||||
|
||||
stmt: expr { result = static_cast<int>($1);}
|
||||
| { result = 0; }
|
||||
;
|
||||
|
||||
expr: STRING { string val;
|
||||
string attr($1);
|
||||
|
||||
if (attr == "RUNNING_VMS")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_running_vms());
|
||||
}
|
||||
else if (attr == "ALLOCATED_MEMORY")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_mem_usage());
|
||||
}
|
||||
else if (attr == "ALLOCATED_CPU")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_cpu_usage());
|
||||
}
|
||||
else if (attr == "ALLOCATED_DISK")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_disk_usage());
|
||||
}
|
||||
else if (attr == "USED_MEMORY")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_used_mem());
|
||||
}
|
||||
else if (attr == "USED_CPU")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_used_cpu());
|
||||
}
|
||||
else if (attr == "USED_DISK")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_used_disk());
|
||||
}
|
||||
else if (attr == "FREE_MEMORY")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_free_mem());
|
||||
}
|
||||
else if (attr == "FREE_CPU")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_free_cpu());
|
||||
}
|
||||
else if (attr == "FREE_DISK")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_free_disk());
|
||||
}
|
||||
else if (attr == "MAX_MEMORY")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_max_mem());
|
||||
}
|
||||
else if (attr == "MAX_CPU")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_max_cpu());
|
||||
}
|
||||
else if (attr == "MAX_DISK")
|
||||
{
|
||||
$$ = static_cast<float>
|
||||
(host->get_share_max_disk());
|
||||
}
|
||||
else
|
||||
{
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val.empty() ? 0.0 : atof(val.c_str());
|
||||
}
|
||||
|
||||
free($1);
|
||||
}
|
||||
| FLOAT { $$ = $1; }
|
||||
| INTEGER { $$ = static_cast<float>($1); }
|
||||
| expr '+' expr { $$ = $1 + $3;}
|
||||
| expr '-' expr { $$ = $1 - $3;}
|
||||
| expr '*' expr { $$ = $1 * $3;}
|
||||
| expr '/' expr { $$ = $1 / $3;}
|
||||
| '-' expr { $$ = - $2;}
|
||||
| '(' expr ')' { $$ = $2;}
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
extern "C" void host_rank_error(
|
||||
YYLTYPE * llocp,
|
||||
Host * host,
|
||||
int& result,
|
||||
char ** error_msg,
|
||||
const char * str)
|
||||
{
|
||||
int length;
|
||||
|
||||
length = strlen(str)+ 64;
|
||||
|
||||
*error_msg = (char *) malloc(sizeof(char)*length);
|
||||
|
||||
if (*error_msg != 0)
|
||||
{
|
||||
snprintf(*error_msg,
|
||||
length,
|
||||
"%s at line %i, columns %i:%i",
|
||||
str,
|
||||
llocp->first_line,
|
||||
llocp->first_column,
|
||||
llocp->last_column);
|
||||
}
|
||||
}
|
||||
|
@ -1,181 +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 <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include "host_requirements.h"
|
||||
#include "Host.h"
|
||||
|
||||
#define YYERROR_VERBOSE
|
||||
#define host_requirements_lex host_lex
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void host_requirements_error(
|
||||
YYLTYPE * llocp,
|
||||
Host * host,
|
||||
bool& result,
|
||||
char ** error_msg,
|
||||
const char * str);
|
||||
|
||||
int host_requirements_lex (YYSTYPE *lvalp, YYLTYPE *llocp);
|
||||
|
||||
int host_requirements_parse(Host * host, bool& result, char ** errmsg);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%parse-param {Host * host}
|
||||
%parse-param {bool& result}
|
||||
%parse-param {char ** error_msg}
|
||||
|
||||
%union {
|
||||
char * val_str;
|
||||
int val_int;
|
||||
float val_float;
|
||||
};
|
||||
|
||||
%defines
|
||||
%locations
|
||||
%pure_parser
|
||||
%name-prefix = "host_requirements_"
|
||||
%output = "host_requirements.cc"
|
||||
|
||||
%left '!' '&' '|'
|
||||
%token <val_int> INTEGER
|
||||
%token <val_str> STRING
|
||||
%token <val_float> FLOAT
|
||||
%type <val_int> stmt expr
|
||||
|
||||
%%
|
||||
|
||||
stmt: expr { result=$1; }
|
||||
| { result=true; } /* TRUE BY DEFAULT, ON EMPTY STRINGS */
|
||||
;
|
||||
|
||||
expr: STRING '=' INTEGER { int val;
|
||||
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val == $3;
|
||||
|
||||
free($1);}
|
||||
|
||||
| STRING '!' '=' INTEGER { int val;
|
||||
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val != $4;
|
||||
|
||||
free($1);}
|
||||
|
||||
| STRING '>' INTEGER { int val;
|
||||
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val > $3;
|
||||
|
||||
free($1);}
|
||||
|
||||
| STRING '<' INTEGER { int val;
|
||||
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val < $3;
|
||||
|
||||
free($1);}
|
||||
|
||||
| STRING '=' FLOAT { string val;
|
||||
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val.empty() ? false : atof(val.c_str()) == $3;
|
||||
|
||||
free($1);}
|
||||
|
||||
| STRING '!' '=' FLOAT { string val;
|
||||
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val.empty() ? false : atof(val.c_str()) != $4;
|
||||
|
||||
free($1);}
|
||||
|
||||
| STRING '>' FLOAT { string val;
|
||||
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val.empty() ? false : atof(val.c_str()) > $3;
|
||||
|
||||
free($1);}
|
||||
|
||||
| STRING '<' FLOAT { string val;
|
||||
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val.empty() ? false : atof(val.c_str()) < $3;
|
||||
|
||||
free($1);}
|
||||
|
||||
| STRING '=' STRING { string val;
|
||||
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val.empty() ? false :fnmatch($3, val.c_str(), 0) == 0;
|
||||
|
||||
free($1);
|
||||
free($3);}
|
||||
|
||||
| STRING '!''=' STRING { string val;
|
||||
|
||||
host->get_template_attribute($1,val);
|
||||
$$ = val.empty() ? false : fnmatch($4, val.c_str(), 0) != 0;
|
||||
|
||||
free($1);
|
||||
free($4);}
|
||||
|
||||
| expr '&' expr { $$ = $1 && $3; }
|
||||
| expr '|' expr { $$ = $1 || $3; }
|
||||
| '!' expr { $$ = ! $2; }
|
||||
| '(' expr ')' { $$ = $2; }
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
extern "C" void host_requirements_error(
|
||||
YYLTYPE * llocp,
|
||||
Host * host,
|
||||
bool& result,
|
||||
char ** error_msg,
|
||||
const char * str)
|
||||
{
|
||||
int length;
|
||||
|
||||
length = strlen(str)+ 64;
|
||||
|
||||
*error_msg = (char *) malloc(sizeof(char)*length);
|
||||
|
||||
if (*error_msg != 0)
|
||||
{
|
||||
snprintf(*error_msg,
|
||||
length,
|
||||
"%s at line %i, columns %i:%i",
|
||||
str,
|
||||
llocp->first_line,
|
||||
llocp->first_column,
|
||||
llocp->last_column);
|
||||
}
|
||||
}
|
358
src/host/test/HostPoolTest.cc
Normal file
358
src/host/test/HostPoolTest.cc
Normal file
@ -0,0 +1,358 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 <string>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "HostPool.h"
|
||||
#include "PoolTest.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const string im_mad = "im_mad";
|
||||
const string vmm_mad = "vmm_mad";
|
||||
const string tm_mad = "tm_mad";
|
||||
|
||||
const string names[] = {"Host one", "Second host"};
|
||||
|
||||
const string xmls[] =
|
||||
{
|
||||
"<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE>"
|
||||
"<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
|
||||
"<LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHARE><HID>0</HID>"
|
||||
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
|
||||
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
|
||||
"<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
|
||||
"<USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU>"
|
||||
"<RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>",
|
||||
|
||||
"<HOST><ID>1</ID><NAME>Second host</NAME><STATE>0</STATE>"
|
||||
"<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
|
||||
"<LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHARE><HID>1</HID>"
|
||||
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
|
||||
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
|
||||
"<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
|
||||
"<USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU>"
|
||||
"<RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>"
|
||||
};
|
||||
|
||||
// This xml dump result has the LAST_MON_TIMEs modified to 0000000000
|
||||
const string xml_dump =
|
||||
"<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
|
||||
"M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>000000"
|
||||
"0000</LAST_MON_TIME><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
|
||||
"_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
|
||||
">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
|
||||
"MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
|
||||
"SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST>"
|
||||
"<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
|
||||
"D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_M"
|
||||
"ON_TIME><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
|
||||
"M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
|
||||
"<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
|
||||
"U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
|
||||
"SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>2</ID><N"
|
||||
"AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
|
||||
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_MON_TIME><HOS"
|
||||
"T_SHARE><HID>2</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
|
||||
"_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
|
||||
"MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
|
||||
"U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
|
||||
"NING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>3</ID><NAME>another "
|
||||
"name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
|
||||
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHAR"
|
||||
"E><HID>3</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
|
||||
">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
|
||||
"U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
|
||||
"D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
|
||||
"MS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>4</ID><NAME>host</NAME><ST"
|
||||
"ATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad"
|
||||
"</TM_MAD><LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHARE><HID>4</HID>"
|
||||
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
|
||||
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0"
|
||||
"</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED"
|
||||
"_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_"
|
||||
"VMS></HOST_SHARE></HOST></HOST_POOL>";
|
||||
|
||||
const string xml_dump_like_a =
|
||||
"<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
|
||||
"M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>000000"
|
||||
"0000</LAST_MON_TIME><HOST_SHARE><HID>0</HID><DISK_USAGE>0</DISK_USAGE><MEM"
|
||||
"_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
|
||||
">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
|
||||
"MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
|
||||
"SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST>"
|
||||
"<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
|
||||
"D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_M"
|
||||
"ON_TIME><HOST_SHARE><HID>1</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
|
||||
"M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
|
||||
"<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
|
||||
"U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
|
||||
"SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>2</ID><N"
|
||||
"AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
|
||||
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_MON_TIME><HOS"
|
||||
"T_SHARE><HID>2</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
|
||||
"_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
|
||||
"MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
|
||||
"U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
|
||||
"NING_VMS>0</RUNNING_VMS></HOST_SHARE></HOST><HOST><ID>3</ID><NAME>another "
|
||||
"name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
|
||||
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0000000000</LAST_MON_TIME><HOST_SHAR"
|
||||
"E><HID>3</HID><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
|
||||
">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
|
||||
"U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
|
||||
"D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
|
||||
"MS>0</RUNNING_VMS></HOST_SHARE></HOST></HOST_POOL>";
|
||||
|
||||
const string replacement = "0000000000";
|
||||
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
class HostPoolTest : public PoolTest
|
||||
{
|
||||
CPPUNIT_TEST_SUITE (HostPoolTest);
|
||||
|
||||
ALL_POOLTEST_CPPUNIT_TESTS();
|
||||
|
||||
CPPUNIT_TEST (update);
|
||||
CPPUNIT_TEST (dump);
|
||||
CPPUNIT_TEST (dump_where);
|
||||
CPPUNIT_TEST (discover);
|
||||
CPPUNIT_TEST (duplicates);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END ();
|
||||
|
||||
protected:
|
||||
|
||||
void bootstrap(SqlDB* db)
|
||||
{
|
||||
HostPool::bootstrap(db);
|
||||
};
|
||||
|
||||
PoolSQL* create_pool(SqlDB* db)
|
||||
{
|
||||
return new HostPool(db);
|
||||
};
|
||||
|
||||
int allocate(int index)
|
||||
{
|
||||
int oid;
|
||||
return ((HostPool*)pool)->allocate(&oid, names[index], im_mad,
|
||||
vmm_mad, tm_mad);
|
||||
};
|
||||
|
||||
void check(int index, PoolObjectSQL* obj)
|
||||
{
|
||||
Host * host = static_cast<Host *>(obj);
|
||||
|
||||
CPPUNIT_ASSERT( obj != 0 );
|
||||
|
||||
string xml_str = "";
|
||||
string name = host->get_hostname();
|
||||
|
||||
CPPUNIT_ASSERT( name == names[index] );
|
||||
|
||||
// Get the xml and replace the LAST_MON_TIME to 0, so we can compare
|
||||
// it with a prepared string.
|
||||
host->to_xml(xml_str);
|
||||
xml_str.replace( xml_str.find("<LAST_MON_TIME>")+15, 10, "0000000000");
|
||||
|
||||
CPPUNIT_ASSERT( xml_str == xmls[index]);
|
||||
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
HostPoolTest(){};
|
||||
|
||||
~HostPoolTest(){};
|
||||
|
||||
|
||||
/* ********************************************************************* */
|
||||
/* ********************************************************************* */
|
||||
|
||||
|
||||
void update()
|
||||
{
|
||||
HostPool * hp = static_cast<HostPool *>(pool);
|
||||
int oid_1 = allocate(0);
|
||||
|
||||
Host* host = hp->get(oid_1, true);
|
||||
CPPUNIT_ASSERT( host != 0 );
|
||||
|
||||
// Host object should be cached. Let's update its status
|
||||
host->set_state(Host::DISABLED);
|
||||
pool->update(host);
|
||||
|
||||
host->unlock();
|
||||
|
||||
host = hp->get(oid_1,false);
|
||||
CPPUNIT_ASSERT( host != 0 );
|
||||
CPPUNIT_ASSERT( host->get_state() == Host::DISABLED );
|
||||
|
||||
//Now force access to DB
|
||||
|
||||
pool->clean();
|
||||
host = hp->get(oid_1,false);
|
||||
|
||||
CPPUNIT_ASSERT( host != 0 );
|
||||
CPPUNIT_ASSERT( host->get_state() == Host::DISABLED );
|
||||
};
|
||||
|
||||
void duplicates()
|
||||
{
|
||||
int rc, oid_0, oid_1;
|
||||
HostPool * hp = static_cast<HostPool *>(pool);
|
||||
Host * host;
|
||||
|
||||
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);
|
||||
CPPUNIT_ASSERT( oid_0 == 0 );
|
||||
CPPUNIT_ASSERT( rc == oid_0 );
|
||||
|
||||
rc = hp->allocate(&oid_1, names[0], im_mad, vmm_mad, tm_mad);
|
||||
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 );
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
void dump()
|
||||
{
|
||||
string names[] = {"a", "a name", "a_name", "another name", "host"};
|
||||
int rc, oid;
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
((HostPool*)pool)->allocate(&oid, names[i], im_mad, vmm_mad, tm_mad);
|
||||
}
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
rc = ((HostPool*)pool)->dump(oss, "");
|
||||
CPPUNIT_ASSERT(rc == 0);
|
||||
|
||||
// To be able to compare one string to another, the monitoring times
|
||||
// have to be changed
|
||||
string result = oss.str();
|
||||
result.replace( 142, 10, replacement);
|
||||
result.replace( 648, 10, replacement);
|
||||
result.replace(1154, 10, replacement);
|
||||
result.replace(1666, 10, replacement);
|
||||
result.replace(2170, 10, replacement);
|
||||
|
||||
CPPUNIT_ASSERT( result == xml_dump );
|
||||
}
|
||||
|
||||
void dump_where()
|
||||
{
|
||||
string names[] = {"a", "a name", "a_name", "another name", "host"};
|
||||
int rc, oid;
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
((HostPool*)pool)->allocate(&oid, names[i], im_mad, vmm_mad, tm_mad);
|
||||
}
|
||||
|
||||
|
||||
ostringstream oss;
|
||||
rc = ((HostPool*)pool)->dump(oss, "host_name LIKE 'a%'");
|
||||
CPPUNIT_ASSERT(rc == 0);
|
||||
|
||||
// To be able to compare one string to another, the monitoring times
|
||||
// have to be changed
|
||||
string result = oss.str();
|
||||
result.replace( 142, 10, replacement);
|
||||
result.replace( 648, 10, replacement);
|
||||
result.replace(1154, 10, replacement);
|
||||
result.replace(1666, 10, replacement);
|
||||
|
||||
|
||||
CPPUNIT_ASSERT( result == xml_dump_like_a );
|
||||
}
|
||||
|
||||
void discover()
|
||||
{
|
||||
int rc, oid, i;
|
||||
|
||||
map<int, string> dh;
|
||||
map<int, string>::iterator it;
|
||||
|
||||
Host * host;
|
||||
HostPool * hp = static_cast<HostPool *>(pool);
|
||||
ostringstream oss;
|
||||
|
||||
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);
|
||||
CPPUNIT_ASSERT(oid == i);
|
||||
|
||||
if (i >=8 )
|
||||
{
|
||||
host = hp->get(oid, false);
|
||||
CPPUNIT_ASSERT(host!=0);
|
||||
host->disable();
|
||||
hp->update(host);
|
||||
}
|
||||
}
|
||||
|
||||
// Discover the enabled hosts
|
||||
rc = hp->discover(&dh);
|
||||
CPPUNIT_ASSERT(rc == 0);
|
||||
CPPUNIT_ASSERT(dh.size() == 8);
|
||||
|
||||
for(i=0,it=dh.begin(),oss.str("");it!=dh.end();it++,i++,oss.str(""))
|
||||
{
|
||||
CPPUNIT_ASSERT(it->first == i);
|
||||
CPPUNIT_ASSERT(it->second == im_mad);
|
||||
|
||||
host = hp->get(i, false);
|
||||
CPPUNIT_ASSERT(host!=0);
|
||||
CPPUNIT_ASSERT(host->isEnabled());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
return PoolTest::main(argc, argv, HostPoolTest::suite());
|
||||
}
|
91
src/host/test/SConstruct
Normal file
91
src/host/test/SConstruct
Normal file
@ -0,0 +1,91 @@
|
||||
# --------------------------------------------------------------------------
|
||||
# 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.
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
sys.path.append("../../../share/scons")
|
||||
from lex_bison import *
|
||||
|
||||
# This is the absolute path where the project is located
|
||||
cwd="../../../"
|
||||
|
||||
# Environment that will be applied to each scons child
|
||||
main_env=Environment()
|
||||
main_env['ENV']['PATH']=os.environ['PATH']
|
||||
|
||||
# Add builders for flex and bison
|
||||
add_lex(main_env)
|
||||
add_bison(main_env)
|
||||
|
||||
# Include dirs
|
||||
main_env.Append(CPPPATH=[
|
||||
cwd + '/include',
|
||||
cwd + '/include/test',
|
||||
'/usr/include/cppunit/',
|
||||
])
|
||||
|
||||
# Library dirs
|
||||
main_env.Append(LIBPATH=[
|
||||
cwd + '/src/common',
|
||||
cwd + '/src/log',
|
||||
cwd + '/src/nebula',
|
||||
cwd + '/src/sql',
|
||||
cwd + '/src/pool',
|
||||
cwd + '/src/template',
|
||||
cwd + '/src/host',
|
||||
])
|
||||
|
||||
main_env.Append(LIBS=[
|
||||
'nebula_log',
|
||||
'nebula_host',
|
||||
'nebula_template',
|
||||
'nebula_pool',
|
||||
'nebula_common',
|
||||
'nebula_core',
|
||||
'nebula_sql',
|
||||
'cppunit',
|
||||
'dl',
|
||||
'pthread',
|
||||
])
|
||||
|
||||
# MYSQL
|
||||
main_env.Append(LIBPATH=["/usr/lib/mysql"])
|
||||
main_env.Append(CPPPATH=["/usr/include/mysql"])
|
||||
|
||||
|
||||
sqlite=ARGUMENTS.get('sqlite', 'yes')
|
||||
if sqlite=='yes':
|
||||
main_env.Append(CPPFLAGS=["-DSQLITE_DB"])
|
||||
main_env.Append(LIBS=[ 'sqlite3', ])
|
||||
|
||||
# MySQL
|
||||
mysql=ARGUMENTS.get('mysql', 'no')
|
||||
if mysql=='yes':
|
||||
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
|
||||
main_env.Append(LIBS=[ 'mysqlclient', ])
|
||||
|
||||
# Compile flags
|
||||
main_env.Append(CPPFLAGS=[
|
||||
"-g",
|
||||
"-Wall"
|
||||
])
|
||||
|
||||
# Linking flags
|
||||
main_env.Append(LDFLAGS=["-g "])
|
||||
|
||||
main_env.Program('test','HostPoolTest.cc')
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "InformationManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -29,13 +29,13 @@ extern "C" void * im_action_loop(void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
Nebula::log("InM",Log::INFO,"Information Manager started.");
|
||||
NebulaLog::log("InM",Log::INFO,"Information Manager started.");
|
||||
|
||||
im = static_cast<InformationManager *>(arg);
|
||||
|
||||
im->am.loop(im->timer_period,0);
|
||||
|
||||
Nebula::log("InM",Log::INFO,"Information Manager stopped.");
|
||||
NebulaLog::log("InM",Log::INFO,"Information Manager stopped.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -51,7 +51,7 @@ void InformationManager::load_mads(int uid)
|
||||
const VectorAttribute * vattr;
|
||||
int rc;
|
||||
|
||||
Nebula::log("InM",Log::INFO,"Loading Information Manager drivers.");
|
||||
NebulaLog::log("InM",Log::INFO,"Loading Information Manager drivers.");
|
||||
|
||||
for(i=0;i<mad_conf.size();i++)
|
||||
{
|
||||
@ -60,7 +60,7 @@ void InformationManager::load_mads(int uid)
|
||||
oss.str("");
|
||||
oss << "\tLoading driver: " << vattr->vector_value("NAME");
|
||||
|
||||
Nebula::log("InM",Log::INFO,oss);
|
||||
NebulaLog::log("InM",Log::INFO,oss);
|
||||
|
||||
im_mad = new InformationManagerDriver(0,vattr->value(),false,hpool);
|
||||
|
||||
@ -71,7 +71,7 @@ void InformationManager::load_mads(int uid)
|
||||
oss.str("");
|
||||
oss << "\tDriver " << vattr->vector_value("NAME") << " loaded";
|
||||
|
||||
Nebula::log("InM",Log::INFO,oss);
|
||||
NebulaLog::log("InM",Log::INFO,oss);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,7 +91,7 @@ int InformationManager::start()
|
||||
return -1;
|
||||
}
|
||||
|
||||
Nebula::log("InM",Log::INFO,"Starting Information Manager...");
|
||||
NebulaLog::log("InM",Log::INFO,"Starting Information Manager...");
|
||||
|
||||
pthread_attr_init (&pattr);
|
||||
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
|
||||
@ -112,7 +112,7 @@ void InformationManager::do_action(const string &action, void * arg)
|
||||
}
|
||||
else if (action == ACTION_FINALIZE)
|
||||
{
|
||||
Nebula::log("InM",Log::INFO,"Stopping Information Manager...");
|
||||
NebulaLog::log("InM",Log::INFO,"Stopping Information Manager...");
|
||||
|
||||
MadManager::stop();
|
||||
}
|
||||
@ -121,7 +121,7 @@ void InformationManager::do_action(const string &action, void * arg)
|
||||
ostringstream oss;
|
||||
oss << "Unknown action name: " << action;
|
||||
|
||||
Nebula::log("InM", Log::ERROR, oss);
|
||||
NebulaLog::log("InM", Log::ERROR, oss);
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ void InformationManager::timer_action()
|
||||
|
||||
if ( mark >= 600 )
|
||||
{
|
||||
Nebula::log("InM",Log::INFO,"--Mark--");
|
||||
NebulaLog::log("InM",Log::INFO,"--Mark--");
|
||||
mark = 0;
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ void InformationManager::timer_action()
|
||||
oss.str("");
|
||||
oss << "Monitoring host " << host->get_hostname()
|
||||
<< " (" << it->first << ")";
|
||||
Nebula::log("InM",Log::INFO,oss);
|
||||
NebulaLog::log("InM",Log::INFO,oss);
|
||||
|
||||
imd = get(it->second);
|
||||
|
||||
@ -195,7 +195,7 @@ void InformationManager::timer_action()
|
||||
{
|
||||
oss.str("");
|
||||
oss << "Could not find information driver " << it->second;
|
||||
Nebula::log("InM",Log::ERROR,oss);
|
||||
NebulaLog::log("InM",Log::ERROR,oss);
|
||||
|
||||
host->set_state(Host::ERROR);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "InformationManagerDriver.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ void InformationManagerDriver::protocol(
|
||||
hinfo += "\n";
|
||||
|
||||
oss << "Host " << id << " successfully monitored."; //, info: "<< hinfo;
|
||||
Nebula::log("InM",Log::DEBUG,oss);
|
||||
NebulaLog::log("InM",Log::DEBUG,oss);
|
||||
|
||||
rc = host->update_info(hinfo);
|
||||
|
||||
@ -136,20 +136,20 @@ void InformationManagerDriver::protocol(
|
||||
string info;
|
||||
|
||||
getline(is,info);
|
||||
Nebula::log("InM",Log::INFO,info.c_str());
|
||||
NebulaLog::log("InM",Log::INFO,info.c_str());
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
error_driver_info:
|
||||
ess << "Error monitoring host " << id << " : " << is.str();
|
||||
Nebula::log("InM", Log::ERROR, ess);
|
||||
NebulaLog::log("InM", Log::ERROR, ess);
|
||||
|
||||
goto error_common_info;
|
||||
|
||||
error_parse_info:
|
||||
ess << "Error parsing host information: " << hinfo;
|
||||
Nebula::log("InM",Log::ERROR,ess);
|
||||
NebulaLog::log("InM",Log::ERROR,ess);
|
||||
|
||||
error_common_info:
|
||||
|
||||
@ -163,14 +163,14 @@ error_common_info:
|
||||
|
||||
error_host:
|
||||
ess << "Could not get host " << id;
|
||||
Nebula::log("InM",Log::ERROR,ess);
|
||||
NebulaLog::log("InM",Log::ERROR,ess);
|
||||
|
||||
return;
|
||||
|
||||
error_parse:
|
||||
|
||||
ess << "Error while parsing driver message: " << message;
|
||||
Nebula::log("InM",Log::ERROR,ess);
|
||||
NebulaLog::log("InM",Log::ERROR,ess);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -180,6 +180,6 @@ error_parse:
|
||||
|
||||
void InformationManagerDriver::recover()
|
||||
{
|
||||
Nebula::log("InM", Log::ERROR, "Information driver crashed, recovering...");
|
||||
NebulaLog::log("InM", Log::ERROR,
|
||||
"Information driver crashed, recovering...");
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "LifeCycleManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -31,11 +31,11 @@ extern "C" void * lcm_action_loop(void *arg)
|
||||
|
||||
lcm = static_cast<LifeCycleManager *>(arg);
|
||||
|
||||
Nebula::log("LCM",Log::INFO,"Life-cycle Manager started.");
|
||||
NebulaLog::log("LCM",Log::INFO,"Life-cycle Manager started.");
|
||||
|
||||
lcm->am.loop(0,0);
|
||||
|
||||
Nebula::log("LCM",Log::INFO,"Life-cycle Manager stopped.");
|
||||
NebulaLog::log("LCM",Log::INFO,"Life-cycle Manager stopped.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -50,7 +50,7 @@ int LifeCycleManager::start()
|
||||
pthread_attr_init (&pattr);
|
||||
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
Nebula::log("LCM",Log::INFO,"Starting Life-cycle Manager...");
|
||||
NebulaLog::log("LCM",Log::INFO,"Starting Life-cycle Manager...");
|
||||
|
||||
rc = pthread_create(&lcm_thread,&pattr,lcm_action_loop,(void *) this);
|
||||
|
||||
@ -300,14 +300,14 @@ void LifeCycleManager::do_action(const string &action, void * arg)
|
||||
}
|
||||
else if (action == ACTION_FINALIZE)
|
||||
{
|
||||
Nebula::log("LCM",Log::INFO,"Stopping Life-cycle Manager...");
|
||||
NebulaLog::log("LCM",Log::INFO,"Stopping Life-cycle Manager...");
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Unknown action name: " << action;
|
||||
|
||||
Nebula::log("LCM", Log::ERROR, oss);
|
||||
NebulaLog::log("LCM", Log::ERROR, oss);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,12 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "Log.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -28,14 +30,13 @@ const char Log::error_names[] ={ 'E', 'W', 'I', 'D' };
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Log::Log(const string& file_name,
|
||||
const MessageType level,
|
||||
ios_base::openmode mode):
|
||||
log_level(level),
|
||||
log_file(0)
|
||||
FileLog::FileLog(const string& file_name,
|
||||
const MessageType level,
|
||||
ios_base::openmode mode)
|
||||
:Log(level), log_file(0)
|
||||
{
|
||||
ofstream file;
|
||||
|
||||
|
||||
log_file = strdup(file_name.c_str());
|
||||
|
||||
file.open(log_file, mode);
|
||||
@ -44,7 +45,7 @@ Log::Log(const string& file_name,
|
||||
{
|
||||
throw runtime_error("Could not open log file");
|
||||
}
|
||||
|
||||
|
||||
if ( file.is_open() == true )
|
||||
{
|
||||
file.close();
|
||||
@ -54,62 +55,18 @@ Log::Log(const string& file_name,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Log::~Log()
|
||||
FileLog::~FileLog()
|
||||
{
|
||||
if ( log_file != 0 )
|
||||
{
|
||||
free(log_file);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void Log::log(
|
||||
const char * module,
|
||||
const MessageType type,
|
||||
const ostringstream& message)
|
||||
{
|
||||
char str[26];
|
||||
time_t the_time;
|
||||
ofstream file;
|
||||
|
||||
if( type <= log_level)
|
||||
if ( log_file != 0 )
|
||||
{
|
||||
|
||||
file.open(log_file, ios_base::app);
|
||||
|
||||
if (file.fail() == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
the_time = time(NULL);
|
||||
|
||||
#ifdef SOLARIS
|
||||
ctime_r(&(the_time),str,sizeof(char)*26);
|
||||
#else
|
||||
ctime_r(&(the_time),str);
|
||||
#endif
|
||||
// Get rid of final enter character
|
||||
str[24] = '\0';
|
||||
|
||||
file << str << " ";
|
||||
file << "[" << module << "]";
|
||||
file << "[" << error_names[type] << "]: ";
|
||||
file << message.str();
|
||||
file << endl;
|
||||
|
||||
file.flush();
|
||||
|
||||
file.close();
|
||||
free(log_file);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void Log::log(
|
||||
void FileLog::log(
|
||||
const char * module,
|
||||
const MessageType type,
|
||||
const char * message)
|
||||
@ -126,9 +83,9 @@ void Log::log(
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
the_time = time(NULL);
|
||||
|
||||
|
||||
#ifdef SOLARIS
|
||||
ctime_r(&(the_time),str,sizeof(char)*26);
|
||||
#else
|
||||
@ -142,9 +99,9 @@ void Log::log(
|
||||
file << "[" << error_names[type] << "]: ";
|
||||
file << message;
|
||||
file << endl;
|
||||
|
||||
|
||||
file.flush();
|
||||
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
@ -152,3 +109,33 @@ void Log::log(
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void CerrLog::log(
|
||||
const char * module,
|
||||
const MessageType type,
|
||||
const char * message)
|
||||
{
|
||||
char str[26];
|
||||
time_t the_time;
|
||||
ofstream file;
|
||||
|
||||
if( type <= log_level)
|
||||
{
|
||||
the_time = time(NULL);
|
||||
|
||||
#ifdef SOLARIS
|
||||
ctime_r(&(the_time),str,sizeof(char)*26);
|
||||
#else
|
||||
ctime_r(&(the_time),str);
|
||||
#endif
|
||||
// Get rid of final enter character
|
||||
str[24] = '\0';
|
||||
|
||||
cerr << str << " ";
|
||||
cerr << "[" << module << "]";
|
||||
cerr << "[" << error_names[type] << "]: ";
|
||||
cerr << message;
|
||||
cerr << endl;
|
||||
|
||||
cerr.flush();
|
||||
}
|
||||
}
|
26
src/log/NebulaLog.cc
Normal file
26
src/log/NebulaLog.cc
Normal file
@ -0,0 +1,26 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Log * NebulaLog::logger;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
@ -1,4 +1,4 @@
|
||||
# SConstruct for src/mad
|
||||
# SConstruct for src/log
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
|
||||
@ -18,18 +18,13 @@
|
||||
|
||||
Import('env')
|
||||
|
||||
lib_name='oneapi'
|
||||
lib_name='nebula_log'
|
||||
|
||||
# Sources to generate the library
|
||||
source_files=[
|
||||
'OneClient.cc',
|
||||
'OneClient_C_Wrapper.cc'
|
||||
'NebulaLog.cc',
|
||||
'Log.cc'
|
||||
]
|
||||
|
||||
# Compiling flags
|
||||
env.Append(CPPFLAGS=["-fPIC"])
|
||||
|
||||
# Build library
|
||||
env.StaticLibrary(lib_name, source_files)
|
||||
env.SharedLibrary(lib_name, source_files)
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "Mad.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
#include <cerrno>
|
||||
@ -237,43 +239,43 @@ int Mad::start()
|
||||
error_exec:
|
||||
oss.str("");
|
||||
oss << "Can not load driver " << executable << ", " << strerror(errno);
|
||||
Nebula::log("MAD", Log::ERROR, oss);
|
||||
NebulaLog::log("MAD", Log::ERROR, oss);
|
||||
exit(-1);
|
||||
|
||||
error_dup2:
|
||||
oss.str("");
|
||||
oss << "Can not duplicate descriptors, " << strerror(errno);
|
||||
Nebula::log("MAD", Log::ERROR, oss);
|
||||
NebulaLog::log("MAD", Log::ERROR, oss);
|
||||
exit(-1);
|
||||
|
||||
error_mad_result:
|
||||
oss.str("");
|
||||
oss << "MAD initialization failed, " << info;
|
||||
Nebula::log("MAD", Log::ERROR, oss);
|
||||
NebulaLog::log("MAD", Log::ERROR, oss);
|
||||
return -1;
|
||||
|
||||
error_mad_action:
|
||||
Nebula::log("MAD", Log::ERROR,"Wrong action in MAD response");
|
||||
NebulaLog::log("MAD", Log::ERROR,"Wrong action in MAD response");
|
||||
return -1;
|
||||
|
||||
error_mad_init:
|
||||
Nebula::log("MAD", Log::ERROR, "MAD did not answer INIT command");
|
||||
NebulaLog::log("MAD", Log::ERROR, "MAD did not answer INIT command");
|
||||
return -1;
|
||||
|
||||
error_fork:
|
||||
oss.str("");
|
||||
oss << "Error forking to start MAD, " << strerror(errno);
|
||||
Nebula::log("MAD", Log::ERROR, oss);
|
||||
NebulaLog::log("MAD", Log::ERROR, oss);
|
||||
return -1;
|
||||
|
||||
error_attributes:
|
||||
Nebula::log("MAD", Log::ERROR, "Wrong attributes for the driver");
|
||||
NebulaLog::log("MAD", Log::ERROR, "Wrong attributes for the driver");
|
||||
return -1;
|
||||
|
||||
error_pipes:
|
||||
oss.str("");
|
||||
oss << "Can not create driver pipes, " << strerror(errno);
|
||||
Nebula::log("MAD", Log::ERROR, oss);
|
||||
NebulaLog::log("MAD", Log::ERROR, oss);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,10 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "VirtualMachine.h"
|
||||
#include "SqliteDB.h"
|
||||
#include "MySqlDB.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdexcept>
|
||||
@ -39,31 +42,31 @@ void Nebula::start()
|
||||
sigset_t mask;
|
||||
int signal;
|
||||
char hn[80];
|
||||
|
||||
|
||||
if ( gethostname(hn,79) != 0 )
|
||||
{
|
||||
throw runtime_error("Error getting hostname");
|
||||
}
|
||||
|
||||
|
||||
hostname = hn;
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Configuration
|
||||
// -----------------------------------------------------------
|
||||
// -----------------------------------------------------------
|
||||
// Configuration
|
||||
// -----------------------------------------------------------
|
||||
|
||||
nebula_configuration = new NebulaTemplate(etc_location, var_location);
|
||||
|
||||
|
||||
rc = nebula_configuration->load_configuration();
|
||||
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not load nebula configuration file.");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Log system
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Log system
|
||||
// -----------------------------------------------------------
|
||||
|
||||
ostringstream os;
|
||||
|
||||
try
|
||||
@ -71,149 +74,211 @@ void Nebula::start()
|
||||
string log_fname;
|
||||
int log_level_int;
|
||||
Log::MessageType clevel = Log::ERROR;
|
||||
|
||||
|
||||
log_fname = log_location + "oned.log";
|
||||
|
||||
|
||||
nebula_configuration->get("DEBUG_LEVEL", log_level_int);
|
||||
|
||||
|
||||
if (0 <= log_level_int && log_level_int <= 3 )
|
||||
{
|
||||
clevel = static_cast<Log::MessageType>(log_level_int);
|
||||
}
|
||||
|
||||
os << "Init OpenNebula Log system";
|
||||
|
||||
// Initializing ONE Daemon log system
|
||||
|
||||
Nebula::log("ONE",
|
||||
Log::INFO,
|
||||
os,
|
||||
log_fname.c_str(),
|
||||
clevel);
|
||||
|
||||
os.str("");
|
||||
|
||||
NebulaLog::init_log_system(NebulaLog::FILE_TS,
|
||||
clevel,
|
||||
log_fname.c_str(),
|
||||
ios_base::trunc);
|
||||
|
||||
NebulaLog::log("ONE",Log::INFO,"Init OpenNebula Log system");
|
||||
|
||||
os << "Log Level: " << clevel << " [0=ERROR,1=WARNING,2=INFO,3=DEBUG]";
|
||||
|
||||
// Initializing ONE Daemon log system
|
||||
|
||||
Nebula::log("ONE",
|
||||
Log::INFO,
|
||||
os,
|
||||
log_fname.c_str(),
|
||||
clevel);
|
||||
NebulaLog::log("ONE",Log::INFO,os);
|
||||
}
|
||||
catch(runtime_error&)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
Nebula::log("ONE",Log::INFO,"----------------------------------------------");
|
||||
Nebula::log("ONE",Log::INFO," OpenNebula Configuration File ");
|
||||
Nebula::log("ONE",Log::INFO,"----------------------------------------------");
|
||||
|
||||
|
||||
NebulaLog::log("ONE",Log::INFO,"----------------------------------------");
|
||||
NebulaLog::log("ONE",Log::INFO," OpenNebula Configuration File ");
|
||||
NebulaLog::log("ONE",Log::INFO,"----------------------------------------");
|
||||
|
||||
os.str("");
|
||||
|
||||
|
||||
os << "\n--------------------------------------------";
|
||||
os << *nebula_configuration;
|
||||
os << "\n--------------------------------------------";
|
||||
|
||||
Nebula::log("ONE",Log::INFO,os);
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
NebulaLog::log("ONE",Log::INFO,os);
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Pools
|
||||
// -----------------------------------------------------------
|
||||
// -----------------------------------------------------------
|
||||
|
||||
try
|
||||
{
|
||||
string db_name = var_location + "one.db";
|
||||
struct stat db_stat;
|
||||
bool db_bootstrap = stat(db_name.c_str(), &db_stat) != 0;
|
||||
|
||||
db = new SqliteDB(db_name,Nebula::log);
|
||||
vector<const Attribute *> dbs;
|
||||
int rc;
|
||||
|
||||
if (db_bootstrap)
|
||||
{
|
||||
Nebula::log("ONE",Log::INFO,"Bootstraping OpenNebula database.");
|
||||
|
||||
VirtualMachinePool::bootstrap(db);
|
||||
HostPool::bootstrap(db);
|
||||
VirtualNetworkPool::bootstrap(db);
|
||||
UserPool::bootstrap(db);
|
||||
}
|
||||
bool db_is_sqlite = true;
|
||||
|
||||
string server = "localhost";
|
||||
string user = "oneadmin";
|
||||
string passwd = "oneadmin";
|
||||
string db_name = "opennebula";
|
||||
|
||||
rc = nebula_configuration->get("DB", dbs);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
string value;
|
||||
const VectorAttribute * db = static_cast<const VectorAttribute *>
|
||||
(dbs[0]);
|
||||
value = db->vector_value("BACKEND");
|
||||
|
||||
if (value == "mysql")
|
||||
{
|
||||
db_is_sqlite = false;
|
||||
|
||||
value = db->vector_value("SERVER");
|
||||
if (!value.empty())
|
||||
{
|
||||
server = value;
|
||||
}
|
||||
|
||||
value = db->vector_value("USER");
|
||||
if (!value.empty())
|
||||
{
|
||||
user = value;
|
||||
}
|
||||
|
||||
value = db->vector_value("PASSWD");
|
||||
if (!value.empty())
|
||||
{
|
||||
passwd = value;
|
||||
}
|
||||
|
||||
value = db->vector_value("DB_NAME");
|
||||
if (!value.empty())
|
||||
{
|
||||
db_name = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( db_is_sqlite )
|
||||
{
|
||||
string db_name = var_location + "one.db";
|
||||
|
||||
db = new SqliteDB(db_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
db = new MySqlDB(server,user,passwd,0);
|
||||
|
||||
oss << "CREATE DATABASE IF NOT EXISTS " << db_name;
|
||||
rc = db->exec(oss);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not create database.");
|
||||
}
|
||||
|
||||
oss.str("");
|
||||
oss << "USE " << db_name;
|
||||
rc = db->exec(oss);
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not open database.");
|
||||
}
|
||||
}
|
||||
|
||||
NebulaLog::log("ONE",Log::INFO,"Bootstraping OpenNebula database.");
|
||||
|
||||
VirtualMachinePool::bootstrap(db);
|
||||
HostPool::bootstrap(db);
|
||||
VirtualNetworkPool::bootstrap(db);
|
||||
UserPool::bootstrap(db);
|
||||
}
|
||||
catch (exception&)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
string mac_prefix;
|
||||
int size;
|
||||
|
||||
|
||||
vector<const Attribute *> vm_hooks;
|
||||
|
||||
|
||||
nebula_configuration->get("VM_HOOK", vm_hooks);
|
||||
|
||||
|
||||
vmpool = new VirtualMachinePool(db, vm_hooks);
|
||||
hpool = new HostPool(db);
|
||||
|
||||
|
||||
nebula_configuration->get("MAC_PREFIX", mac_prefix);
|
||||
nebula_configuration->get("NETWORK_SIZE", size);
|
||||
|
||||
|
||||
vnpool = new VirtualNetworkPool(db,mac_prefix,size);
|
||||
|
||||
|
||||
upool = new UserPool(db);
|
||||
}
|
||||
catch (exception&)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Close stds, we no longer need them
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Close stds, we no longer need them
|
||||
// -----------------------------------------------------------
|
||||
|
||||
fd = open("/dev/null", O_RDWR|O_CREAT);
|
||||
|
||||
|
||||
dup2(fd,0);
|
||||
dup2(fd,1);
|
||||
dup2(fd,1);
|
||||
dup2(fd,2);
|
||||
|
||||
close(fd);
|
||||
|
||||
|
||||
close(fd);
|
||||
|
||||
fcntl(0,F_SETFD,0); // Keep them open across exec funcs
|
||||
fcntl(1,F_SETFD,0);
|
||||
fcntl(2,F_SETFD,0);
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Block all signals before creating any Nebula thread
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Block all signals before creating any Nebula thread
|
||||
// -----------------------------------------------------------
|
||||
|
||||
sigfillset(&mask);
|
||||
|
||||
pthread_sigmask(SIG_BLOCK, &mask, NULL);
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
pthread_sigmask(SIG_BLOCK, &mask, NULL);
|
||||
|
||||
// -----------------------------------------------------------
|
||||
//Managers
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
MadManager::mad_manager_system_init();
|
||||
|
||||
time_t timer_period;
|
||||
|
||||
|
||||
nebula_configuration->get("MANAGER_TIMER", timer_period);
|
||||
|
||||
// ---- Virtual Machine Manager ----
|
||||
|
||||
// ---- Virtual Machine Manager ----
|
||||
try
|
||||
{
|
||||
time_t poll_period;
|
||||
vector<const Attribute *> vmm_mads;
|
||||
|
||||
nebula_configuration->get("VM_POLLING_INTERVAL", poll_period);
|
||||
|
||||
|
||||
nebula_configuration->get("VM_MAD", vmm_mads);
|
||||
|
||||
|
||||
vmm = new VirtualMachineManager(
|
||||
vmpool,
|
||||
hpool,
|
||||
@ -225,15 +290,15 @@ void Nebula::start()
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
rc = vmm->start();
|
||||
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Virtual Machine Manager");
|
||||
}
|
||||
|
||||
// ---- Life-cycle Manager ----
|
||||
}
|
||||
|
||||
// ---- Life-cycle Manager ----
|
||||
try
|
||||
{
|
||||
lcm = new LifeCycleManager(vmpool,hpool);
|
||||
@ -244,22 +309,22 @@ void Nebula::start()
|
||||
}
|
||||
|
||||
rc = lcm->start();
|
||||
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Life-cycle Manager");
|
||||
}
|
||||
|
||||
|
||||
// ---- Information Manager ----
|
||||
try
|
||||
{
|
||||
vector<const Attribute *> im_mads;
|
||||
time_t monitor_period;
|
||||
|
||||
|
||||
nebula_configuration->get("HOST_MONITORING_INTERVAL", monitor_period);
|
||||
|
||||
|
||||
nebula_configuration->get("IM_MAD", im_mads);
|
||||
|
||||
|
||||
im = new InformationManager(hpool,timer_period,monitor_period,im_mads);
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
@ -268,7 +333,7 @@ void Nebula::start()
|
||||
}
|
||||
|
||||
rc = im->start();
|
||||
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Information Manager");
|
||||
@ -278,9 +343,9 @@ void Nebula::start()
|
||||
try
|
||||
{
|
||||
vector<const Attribute *> tm_mads;
|
||||
|
||||
|
||||
nebula_configuration->get("TM_MAD", tm_mads);
|
||||
|
||||
|
||||
tm = new TransferManager(vmpool, hpool, tm_mads);
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
@ -289,24 +354,24 @@ void Nebula::start()
|
||||
}
|
||||
|
||||
rc = tm->start();
|
||||
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Transfer Manager");
|
||||
}
|
||||
|
||||
|
||||
// ---- Dispatch Manager ----
|
||||
try
|
||||
{
|
||||
{
|
||||
dm = new DispatchManager(vmpool,hpool);
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
rc = dm->start();
|
||||
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Dispatch Manager");
|
||||
@ -314,11 +379,11 @@ void Nebula::start()
|
||||
|
||||
// ---- Request Manager ----
|
||||
try
|
||||
{
|
||||
{
|
||||
int rm_port = 0;
|
||||
|
||||
nebula_configuration->get("PORT", rm_port);
|
||||
|
||||
|
||||
rm = new RequestManager(
|
||||
vmpool,
|
||||
hpool,
|
||||
@ -329,24 +394,24 @@ void Nebula::start()
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
{
|
||||
Nebula::log("ONE", Log::ERROR, "Error starting RM");
|
||||
NebulaLog::log("ONE", Log::ERROR, "Error starting RM");
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
rc = rm->start();
|
||||
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Request Manager");
|
||||
}
|
||||
|
||||
// ---- Hook Manager ----
|
||||
// ---- Hook Manager ----
|
||||
try
|
||||
{
|
||||
vector<const Attribute *> hm_mads;
|
||||
|
||||
|
||||
nebula_configuration->get("HM_MAD", hm_mads);
|
||||
|
||||
|
||||
hm = new HookManager(hm_mads,vmpool);
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
@ -355,12 +420,12 @@ void Nebula::start()
|
||||
}
|
||||
|
||||
rc = hm->start();
|
||||
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
throw runtime_error("Could not start the Hook Manager");
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Load mads
|
||||
// -----------------------------------------------------------
|
||||
@ -372,43 +437,43 @@ void Nebula::start()
|
||||
im->load_mads(0);
|
||||
tm->load_mads(0);
|
||||
hm->load_mads(0);
|
||||
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Wait for a SIGTERM or SIGINT signal
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
sigemptyset(&mask);
|
||||
|
||||
|
||||
sigaddset(&mask, SIGINT);
|
||||
sigaddset(&mask, SIGTERM);
|
||||
|
||||
|
||||
sigwait(&mask, &signal);
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// -----------------------------------------------------------
|
||||
// Stop the managers & free resources
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
vmm->trigger(VirtualMachineManager::FINALIZE,0);
|
||||
lcm->trigger(LifeCycleManager::FINALIZE,0);
|
||||
lcm->trigger(LifeCycleManager::FINALIZE,0);
|
||||
|
||||
tm->trigger(TransferManager::FINALIZE,0);
|
||||
dm->trigger(DispatchManager::FINALIZE,0);
|
||||
|
||||
im->finalize();
|
||||
|
||||
im->finalize();
|
||||
rm->finalize();
|
||||
hm->finalize();
|
||||
|
||||
//sleep to wait drivers???
|
||||
|
||||
|
||||
pthread_join(vmm->get_thread_id(),0);
|
||||
pthread_join(lcm->get_thread_id(),0);
|
||||
pthread_join(tm->get_thread_id(),0);
|
||||
pthread_join(dm->get_thread_id(),0);
|
||||
|
||||
|
||||
pthread_join(im->get_thread_id(),0);
|
||||
pthread_join(rm->get_thread_id(),0);
|
||||
pthread_join(hm->get_thread_id(),0);
|
||||
|
||||
Nebula::log("ONE", Log::INFO, "All modules finalized, exiting.\n");
|
||||
|
||||
NebulaLog::log("ONE", Log::INFO, "All modules finalized, exiting.\n");
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ lib_name='nebula_core'
|
||||
source_files=[
|
||||
'Nebula.cc',
|
||||
'NebulaTemplate.cc',
|
||||
'Log.cc'
|
||||
]
|
||||
|
||||
# Build library
|
||||
@ -48,10 +47,18 @@ env.Append(LIBS=[
|
||||
'nebula_vnm',
|
||||
'nebula_vm',
|
||||
'nebula_common',
|
||||
'sqlite3',
|
||||
'nebula_sql',
|
||||
'nebula_log',
|
||||
'crypto'
|
||||
])
|
||||
|
||||
# Sources to generate the library
|
||||
if env['sqlite']=='yes':
|
||||
env.Append(LIBS=['sqlite3'])
|
||||
|
||||
if env['mysql']=='yes':
|
||||
env.Append(LIBS=['mysqlclient'])
|
||||
|
||||
|
||||
if not env.GetOption('clean'):
|
||||
env.ParseConfig('../../share/scons/get_xmlrpc_config server')
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <algorithm>
|
||||
|
||||
#include "PoolSQL.h"
|
||||
|
||||
@ -36,49 +36,31 @@ const unsigned int PoolSQL::MAX_POOL_SIZE = 500;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
extern "C"
|
||||
int PoolSQL::init_cb(void *nil, int num, char **values, char **names)
|
||||
{
|
||||
int init_cb (
|
||||
void * _i,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names)
|
||||
lastOID = -1;
|
||||
|
||||
if ( values[0] != 0 )
|
||||
{
|
||||
int * i;
|
||||
lastOID = atoi(values[0]);
|
||||
}
|
||||
|
||||
i = static_cast<int *>(_i);
|
||||
|
||||
if ( (i == 0) || (num<=0) || (values[0] == 0) )
|
||||
{
|
||||
*i = -1;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
*i = atoi(values[0]);
|
||||
|
||||
return 0;
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
PoolSQL::PoolSQL(SqliteDB * _db, const char * table): Hookable(), db(_db)
|
||||
PoolSQL::PoolSQL(SqlDB * _db, const char * table): db(_db), lastOID(-1)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
pthread_mutex_init(&mutex,0);
|
||||
|
||||
// Get next id from the DB table
|
||||
|
||||
lastOID = -1;
|
||||
|
||||
if ( table != 0 )
|
||||
{
|
||||
oss << "SELECT MAX(oid) FROM " << table;
|
||||
set_callback(static_cast<Callbackable::Callback>(&PoolSQL::init_cb));
|
||||
|
||||
db->exec(oss,init_cb,(void *) &lastOID);
|
||||
}
|
||||
oss << "SELECT MAX(oid) FROM " << table;
|
||||
|
||||
db->exec(oss,this);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -93,10 +75,10 @@ PoolSQL::~PoolSQL()
|
||||
for ( it = pool.begin(); it != pool.end(); it++)
|
||||
{
|
||||
it->second->lock();
|
||||
|
||||
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
pthread_mutex_destroy(&mutex);
|
||||
@ -138,7 +120,7 @@ int PoolSQL::allocate(
|
||||
}
|
||||
|
||||
do_hooks(objsql, Hook::ALLOCATE);
|
||||
|
||||
|
||||
objsql->unlock();
|
||||
|
||||
delete objsql;
|
||||
@ -164,7 +146,7 @@ PoolObjectSQL * PoolSQL::get(
|
||||
index = pool.find(oid);
|
||||
|
||||
if ( index != pool.end() )
|
||||
{
|
||||
{
|
||||
if ( index->second->isValid() == false )
|
||||
{
|
||||
objectsql = 0;
|
||||
@ -184,7 +166,7 @@ PoolObjectSQL * PoolSQL::get(
|
||||
return objectsql;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
objectsql = create();
|
||||
|
||||
objectsql->oid = oid;
|
||||
@ -196,7 +178,7 @@ PoolObjectSQL * PoolSQL::get(
|
||||
delete objectsql;
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -228,7 +210,7 @@ void PoolSQL::replace()
|
||||
bool removed = false;
|
||||
int oid;
|
||||
int rc;
|
||||
|
||||
|
||||
map<int,PoolObjectSQL *>::iterator index;
|
||||
|
||||
while (!removed)
|
||||
@ -238,14 +220,14 @@ void PoolSQL::replace()
|
||||
|
||||
if ( index == pool.end())
|
||||
{
|
||||
oid_queue.pop();
|
||||
oid_queue.pop();
|
||||
break;
|
||||
}
|
||||
|
||||
rc = pthread_mutex_trylock(&(index->second->mutex));
|
||||
|
||||
if ( rc == EBUSY ) // In use by other thread, move to back
|
||||
{
|
||||
{
|
||||
oid_queue.pop();
|
||||
oid_queue.push(oid);
|
||||
}
|
||||
@ -254,8 +236,8 @@ void PoolSQL::replace()
|
||||
delete index->second;
|
||||
|
||||
pool.erase(index);
|
||||
|
||||
oid_queue.pop();
|
||||
|
||||
oid_queue.pop();
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
@ -273,7 +255,7 @@ void PoolSQL::clean()
|
||||
for ( it = pool.begin(); it != pool.end(); it++)
|
||||
{
|
||||
it->second->lock();
|
||||
|
||||
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
@ -284,33 +266,24 @@ void PoolSQL::clean()
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
int PoolSQL:: search_cb(void * _oids, int num, char **values, char **names)
|
||||
{
|
||||
vector<int> * oids;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static int search_cb(
|
||||
void * _oids,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names)
|
||||
{
|
||||
vector<int> * oids;
|
||||
|
||||
oids = static_cast<vector<int> *>(_oids);
|
||||
|
||||
|
||||
if ( num == 0 || values == 0 || values[0] == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
oids->push_back(atoi(values[0]));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
int PoolSQL::search(
|
||||
vector<int>& oids,
|
||||
const char * table,
|
||||
@ -318,14 +291,17 @@ int PoolSQL::search(
|
||||
{
|
||||
ostringstream sql;
|
||||
int rc;
|
||||
|
||||
|
||||
lock();
|
||||
|
||||
|
||||
set_callback(static_cast<Callbackable::Callback>(&PoolSQL::search_cb),
|
||||
static_cast<void *>(&oids));
|
||||
|
||||
sql << "SELECT oid FROM " << table << " WHERE " << where;
|
||||
|
||||
rc = db->exec(sql, search_cb, (void *) &oids);
|
||||
|
||||
|
||||
rc = db->exec(sql, this);
|
||||
|
||||
unlock();
|
||||
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
86
src/pool/test/SConstruct
Normal file
86
src/pool/test/SConstruct
Normal file
@ -0,0 +1,86 @@
|
||||
# --------------------------------------------------------------------------
|
||||
# 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.
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
sys.path.append("../../../share/scons")
|
||||
from lex_bison import *
|
||||
|
||||
# This is the absolute path where the project is located
|
||||
cwd="../../../"
|
||||
|
||||
# Environment that will be applied to each scons child
|
||||
main_env=Environment()
|
||||
main_env['ENV']['PATH']=os.environ['PATH']
|
||||
|
||||
# Add builders for flex and bison
|
||||
add_lex(main_env)
|
||||
add_bison(main_env)
|
||||
|
||||
# Include dirs
|
||||
main_env.Append(CPPPATH=[
|
||||
cwd + '/include',
|
||||
'/usr/include/cppunit/',
|
||||
])
|
||||
|
||||
# Library dirs
|
||||
main_env.Append(LIBPATH=[
|
||||
cwd + '/src/common',
|
||||
cwd + '/src/log',
|
||||
cwd + '/src/pool',
|
||||
cwd + '/src/sql',
|
||||
cwd + '/src/pool/test',
|
||||
cwd + '/src/nebula',
|
||||
])
|
||||
|
||||
main_env.Append(LIBS=[
|
||||
'nebula_pool',
|
||||
'nebula_common',
|
||||
'nebula_log',
|
||||
'nebula_core',
|
||||
'nebula_sql',
|
||||
'cppunit',
|
||||
'dl',
|
||||
'pthread',
|
||||
'test_object'
|
||||
])
|
||||
|
||||
# Compile flags
|
||||
main_env.Append(CPPFLAGS=[
|
||||
"-g",
|
||||
"-Wall"
|
||||
])
|
||||
|
||||
# MYSQL
|
||||
main_env.Append(LIBPATH=["/usr/lib/mysql"])
|
||||
main_env.Append(CPPPATH=["/usr/include/mysql"])
|
||||
|
||||
sqlite=ARGUMENTS.get('sqlite', 'yes')
|
||||
if sqlite=='yes':
|
||||
main_env.Append(CPPFLAGS=["-DSQLITE_DB"])
|
||||
main_env.Append(LIBS=[ 'sqlite3', ])
|
||||
|
||||
# MySQL
|
||||
mysql=ARGUMENTS.get('mysql', 'no')
|
||||
if mysql=='yes':
|
||||
main_env.Append(CPPFLAGS=["-DMYSQL_DB"])
|
||||
main_env.Append(LIBS=[ 'mysqlclient', ])
|
||||
|
||||
|
||||
main_env.StaticLibrary('test_object', ['TestPoolSQL.cc', 'TestPoolSQL.h'])
|
||||
main_env.Program('test','pool.cc')
|
||||
|
131
src/pool/test/TestPoolSQL.cc
Normal file
131
src/pool/test/TestPoolSQL.cc
Normal file
@ -0,0 +1,131 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 <limits.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <iomanip>
|
||||
|
||||
#include "TestPoolSQL.h"
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Database Access Functions */
|
||||
/* ************************************************************************** */
|
||||
|
||||
const char * TestObjectSQL::table = "test_pool";
|
||||
|
||||
const char * TestObjectSQL::db_names = "(oid,number,text)";
|
||||
|
||||
const char * TestObjectSQL::db_bootstrap = "CREATE TABLE test_pool ("
|
||||
"oid INTEGER, number INTEGER, text TEXT, PRIMARY KEY(oid))";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int TestObjectSQL::unmarshall(void * nil, int num, char **values, char **names)
|
||||
{
|
||||
if ((!values[OID]) ||
|
||||
(!values[NUMBER]) ||
|
||||
(!values[TEXT]) ||
|
||||
(num != LIMIT ))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
oid = atoi(values[OID]);
|
||||
number = atoi(values[NUMBER]);
|
||||
text = values[TEXT];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int TestObjectSQL::select(SqlDB *db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
int boid;
|
||||
|
||||
set_callback(
|
||||
static_cast<Callbackable::Callback>(&TestObjectSQL::unmarshall),0);
|
||||
oss << "SELECT * FROM " << table << " WHERE oid = " << oid;
|
||||
|
||||
boid = oid;
|
||||
oid = -1;
|
||||
|
||||
rc = db->exec(oss, this);
|
||||
|
||||
if ((rc != 0) || (oid != boid ))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int TestObjectSQL::insert(SqlDB *db)
|
||||
{
|
||||
return update(db);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int TestObjectSQL::update(SqlDB *db)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int rc;
|
||||
char * sql_text;
|
||||
|
||||
sql_text = db->escape_str(text.c_str());
|
||||
|
||||
oss << "INSERT OR REPLACE INTO " << table << " "<< db_names <<" VALUES ("
|
||||
<< oid << ","
|
||||
<< number << ","
|
||||
<< "'" << sql_text << "')";
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
db->free_str(sql_text);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int TestObjectSQL::drop(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
oss << "DELETE FROM " << table << " WHERE oid=" << oid;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
set_valid(false);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
102
src/pool/test/TestPoolSQL.h
Normal file
102
src/pool/test/TestPoolSQL.h
Normal file
@ -0,0 +1,102 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 TESTSQL_H_
|
||||
#define TESTSQL_H_
|
||||
|
||||
#include <string>
|
||||
#include "PoolSQL.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
// THE OBJECT
|
||||
class TestObjectSQL : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
//OBJECT ATTRIBUTES
|
||||
TestObjectSQL(int n=-1, string t="default"):number(n),text(t){};
|
||||
|
||||
~TestObjectSQL(){};
|
||||
|
||||
int number;
|
||||
|
||||
string text;
|
||||
|
||||
// OBJECTSQL INTERFACE
|
||||
int unmarshall(void * nil, int num, char **names, char ** values);
|
||||
|
||||
int select(SqlDB *db);
|
||||
|
||||
int insert(SqlDB *db);
|
||||
|
||||
int update(SqlDB *db);
|
||||
|
||||
int drop(SqlDB *db);
|
||||
|
||||
// DATABASE IMPLEMENTATION
|
||||
enum ColNames
|
||||
{
|
||||
OID = 0,
|
||||
NUMBER = 1,
|
||||
TEXT = 2,
|
||||
LIMIT = 3
|
||||
};
|
||||
|
||||
static const char * db_names;
|
||||
|
||||
static const char * db_bootstrap;
|
||||
|
||||
static const char * table;
|
||||
|
||||
static void bootstrap(SqlDB * db)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss.str(TestObjectSQL::db_bootstrap);
|
||||
|
||||
db->exec(oss,0);
|
||||
};
|
||||
};
|
||||
|
||||
// THE POOL
|
||||
class TestPool : public PoolSQL
|
||||
{
|
||||
|
||||
public:
|
||||
TestPool(SqlDB *db):PoolSQL(db,"test_pool"){};
|
||||
~TestPool(){};
|
||||
|
||||
TestObjectSQL * get(
|
||||
int oid,
|
||||
bool lock)
|
||||
{
|
||||
return static_cast<TestObjectSQL *>(PoolSQL::get(oid,lock));;
|
||||
}
|
||||
|
||||
int dump(std::ostringstream&, const std::string&){return -1;};
|
||||
|
||||
private:
|
||||
|
||||
TestObjectSQL * create()
|
||||
{
|
||||
return new TestObjectSQL;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
224
src/pool/test/pool.cc
Normal file
224
src/pool/test/pool.cc
Normal file
@ -0,0 +1,224 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <TestFixture.h>
|
||||
#include <TestAssert.h>
|
||||
#include <TestSuite.h>
|
||||
#include <TestCaller.h>
|
||||
#include <ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "PoolSQL.h"
|
||||
#include "TestPoolSQL.h"
|
||||
#include "SqliteDB.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
class PoolTest : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE (PoolTest);
|
||||
CPPUNIT_TEST (allocate_get);
|
||||
CPPUNIT_TEST (wrong_get);
|
||||
CPPUNIT_TEST (search);
|
||||
CPPUNIT_TEST (cache_test);
|
||||
CPPUNIT_TEST_SUITE_END ();
|
||||
|
||||
private:
|
||||
TestPool * pool;
|
||||
SqliteDB * db;
|
||||
|
||||
int create_allocate(int n, string st)
|
||||
{
|
||||
TestObjectSQL *obj = new TestObjectSQL(n,st);
|
||||
|
||||
return pool->allocate(obj);
|
||||
};
|
||||
|
||||
public:
|
||||
PoolTest(){};
|
||||
|
||||
~PoolTest(){};
|
||||
|
||||
void setUp()
|
||||
{
|
||||
string db_name = "test.db";
|
||||
unlink("test.db");
|
||||
|
||||
db = new SqliteDB(db_name);
|
||||
|
||||
TestObjectSQL::bootstrap(db);
|
||||
|
||||
pool = new TestPool(db);
|
||||
};
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
delete db;
|
||||
delete pool;
|
||||
};
|
||||
|
||||
/* ********************************************************************* */
|
||||
/* ********************************************************************* */
|
||||
|
||||
// Try to allocate two objects, and retrieve them
|
||||
void allocate_get()
|
||||
{
|
||||
int n1 = 3;
|
||||
int n2 = 7;
|
||||
string st1 = "text number one";
|
||||
string st2 = "another text";
|
||||
|
||||
TestObjectSQL *obj;
|
||||
int oid;
|
||||
|
||||
oid = create_allocate(n1,st1);
|
||||
// first element in the pool should have oid=0
|
||||
CPPUNIT_ASSERT(oid == 0);
|
||||
|
||||
oid = create_allocate(n2,st2);
|
||||
// second element in the pool should have oid=1
|
||||
CPPUNIT_ASSERT(oid == 1);
|
||||
|
||||
// ---------------------------------
|
||||
obj = pool->get(0, false);
|
||||
CPPUNIT_ASSERT(obj != 0);
|
||||
|
||||
CPPUNIT_ASSERT(obj->number == n1);
|
||||
CPPUNIT_ASSERT(obj->text == st1);
|
||||
|
||||
// ---------------------------------
|
||||
obj = pool->get(1, true);
|
||||
CPPUNIT_ASSERT(obj != 0);
|
||||
|
||||
CPPUNIT_ASSERT(obj->number == n2);
|
||||
CPPUNIT_ASSERT(obj->text == st2);
|
||||
obj->unlock();
|
||||
};
|
||||
|
||||
void wrong_get()
|
||||
{
|
||||
int n1 = 2;
|
||||
string st1 = "object 2";
|
||||
|
||||
TestObjectSQL *obj;
|
||||
int oid;
|
||||
|
||||
oid = create_allocate(n1,st1);
|
||||
|
||||
obj = pool->get(oid,true);
|
||||
CPPUNIT_ASSERT(obj != 0);
|
||||
|
||||
obj->drop(db);
|
||||
obj->unlock();
|
||||
|
||||
obj = pool->get(oid,true);
|
||||
CPPUNIT_ASSERT(obj == 0);
|
||||
|
||||
pool->clean();
|
||||
obj = pool->get(oid,true);
|
||||
CPPUNIT_ASSERT(obj == 0);
|
||||
};
|
||||
|
||||
void search()
|
||||
{
|
||||
int nA = 13;
|
||||
int nB = 17;
|
||||
string stA = "String value for number 13";
|
||||
string stB = "String value for number 17";
|
||||
|
||||
int oidA = create_allocate(nA, stA);
|
||||
int oidB = create_allocate(nB, stB);
|
||||
|
||||
vector<int> results;
|
||||
const char * table = "test_pool";
|
||||
string where = "text = '" + stB + "'";
|
||||
int ret;
|
||||
|
||||
ret = pool->search(results, table, where);
|
||||
CPPUNIT_ASSERT(ret == 0);
|
||||
CPPUNIT_ASSERT(results.size() == 1);
|
||||
CPPUNIT_ASSERT(results.at(0) == oidB);
|
||||
|
||||
results.erase(results.begin(), results.end());
|
||||
|
||||
where = "number < 18";
|
||||
|
||||
ret = pool->search(results, table, where);
|
||||
CPPUNIT_ASSERT(ret == 0);
|
||||
CPPUNIT_ASSERT(results.size() == 2);
|
||||
CPPUNIT_ASSERT(results.at(0) == oidA);
|
||||
CPPUNIT_ASSERT(results.at(1) == oidB);
|
||||
};
|
||||
|
||||
void cache_test()
|
||||
{
|
||||
TestObjectSQL *obj;
|
||||
TestObjectSQL *obj_lock;
|
||||
|
||||
//pin object in the cache, it can't be removed -
|
||||
for (int i=0 ; i < 499 ; i++)
|
||||
{
|
||||
create_allocate(i,"A Test object");
|
||||
|
||||
obj_lock = pool->get(i, true);
|
||||
CPPUNIT_ASSERT(obj_lock != 0);
|
||||
}
|
||||
|
||||
for (int i=499 ; i < 2000 ; i++)
|
||||
{
|
||||
create_allocate(i,"A Test object");
|
||||
}
|
||||
|
||||
for (int i=499; i < 2000 ; i++)
|
||||
{
|
||||
obj = pool->get(i, true);
|
||||
CPPUNIT_ASSERT(obj != 0);
|
||||
|
||||
CPPUNIT_ASSERT(obj->number == i);
|
||||
CPPUNIT_ASSERT(obj->text == "A Test object");
|
||||
obj->unlock();
|
||||
}
|
||||
|
||||
for (int i=0 ; i < 499 ; i++)
|
||||
{
|
||||
obj_lock = pool->get(i, false);//pin object in the cache, it can't be removed
|
||||
obj_lock->unlock();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
|
||||
NebulaLog::init_log_system(NebulaLog::FILE, Log::ERROR, "test.log");
|
||||
runner.addTest( PoolTest::suite() );
|
||||
runner.run();
|
||||
NebulaLog::finalize_log_system();
|
||||
|
||||
return 0;
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
#include <cerrno>
|
||||
|
||||
#include <sys/signal.h>
|
||||
@ -39,13 +39,13 @@ extern "C" void * rm_action_loop(void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
Nebula::log("ReM",Log::INFO,"Request Manager started.");
|
||||
NebulaLog::log("ReM",Log::INFO,"Request Manager started.");
|
||||
|
||||
rm = static_cast<RequestManager *>(arg);
|
||||
|
||||
rm->am.loop(0,0);
|
||||
|
||||
Nebula::log("ReM",Log::INFO,"Request Manager stopped.");
|
||||
NebulaLog::log("ReM",Log::INFO,"Request Manager stopped.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -98,7 +98,7 @@ int RequestManager::setup_socket()
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Can not open server socket: " << strerror(errno);
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -110,7 +110,7 @@ int RequestManager::setup_socket()
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Can not set socket options: " << strerror(errno);
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
close(socket_fd);
|
||||
|
||||
@ -130,7 +130,7 @@ int RequestManager::setup_socket()
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Can not bind to port " << port << " : " << strerror(errno);
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
close(socket_fd);
|
||||
|
||||
@ -148,7 +148,7 @@ int RequestManager::start()
|
||||
pthread_attr_t pattr;
|
||||
ostringstream oss;
|
||||
|
||||
Nebula::log("ReM",Log::INFO,"Starting Request Manager...");
|
||||
NebulaLog::log("ReM",Log::INFO,"Starting Request Manager...");
|
||||
|
||||
int rc = setup_socket();
|
||||
|
||||
@ -168,7 +168,7 @@ int RequestManager::start()
|
||||
pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
oss << "Starting XML-RPC server, port " << port << " ...";
|
||||
Nebula::log("ReM",Log::INFO,oss);
|
||||
NebulaLog::log("ReM",Log::INFO,oss);
|
||||
|
||||
pthread_create(&rm_xml_server_thread,&pattr,rm_xml_server_loop,(void *)this);
|
||||
|
||||
@ -184,13 +184,13 @@ void RequestManager::do_action(
|
||||
{
|
||||
if (action == ACTION_FINALIZE)
|
||||
{
|
||||
Nebula::log("ReM",Log::INFO,"Stopping Request Manager...");
|
||||
NebulaLog::log("ReM",Log::INFO,"Stopping Request Manager...");
|
||||
|
||||
pthread_cancel(rm_xml_server_thread);
|
||||
|
||||
pthread_join(rm_xml_server_thread,0);
|
||||
|
||||
Nebula::log("ReM",Log::INFO,"XML-RPC server stopped.");
|
||||
NebulaLog::log("ReM",Log::INFO,"XML-RPC server stopped.");
|
||||
|
||||
delete AbyssServer;
|
||||
|
||||
@ -204,7 +204,7 @@ void RequestManager::do_action(
|
||||
ostringstream oss;
|
||||
oss << "Unknown action name: " << action;
|
||||
|
||||
Nebula::log("ReM", Log::ERROR, oss);
|
||||
NebulaLog::log("ReM", Log::ERROR, oss);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -41,7 +43,7 @@ void RequestManager::VirtualMachineAction::execute(
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"VirtualMachineAction invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachineAction invoked");
|
||||
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
action = xmlrpc_c::value_string(paramList.getString(1));
|
||||
|
@ -15,6 +15,8 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -42,10 +44,10 @@ void RequestManager::VirtualMachineAllocate::execute(
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"VirtualMachineAllocate invoked");
|
||||
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachineAllocate invoked");
|
||||
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
vm_template = xmlrpc_c::value_string(paramList.getString(1));
|
||||
vm_template += "\n";
|
||||
@ -60,7 +62,7 @@ void RequestManager::VirtualMachineAllocate::execute(
|
||||
}
|
||||
|
||||
User::split_secret(session,username,password);
|
||||
|
||||
|
||||
// Now let's get the user
|
||||
user = VirtualMachineAllocate::upool->get(username,true);
|
||||
|
||||
@ -72,24 +74,24 @@ void RequestManager::VirtualMachineAllocate::execute(
|
||||
uid = user->get_uid();
|
||||
|
||||
user->unlock();
|
||||
|
||||
|
||||
rc = dm->allocate(uid,vm_template,&vid);
|
||||
|
||||
if ( rc != 0 )
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
goto error_allocate;
|
||||
|
||||
}
|
||||
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true));
|
||||
arrayData.push_back(xmlrpc_c::value_int(vid));
|
||||
|
||||
|
||||
// Copy arrayresult into retval mem space
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
*retval = *arrayresult;
|
||||
|
||||
delete arrayresult; // and get rid of the original
|
||||
|
||||
|
||||
|
||||
return;
|
||||
|
||||
@ -108,7 +110,7 @@ error_allocate:
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "Error parsing VM template";
|
||||
oss << "Error parsing VM template";
|
||||
}
|
||||
goto error_common;
|
||||
|
||||
@ -116,7 +118,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -46,7 +48,7 @@ void RequestManager::VirtualMachineDeploy::execute(
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"VirtualMachineDeploy invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachineDeploy invoked");
|
||||
|
||||
//Parse Arguments
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -40,7 +40,7 @@ void RequestManager::HostAllocate::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"HostAllocate method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"HostAllocate method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -62,7 +62,7 @@ void RequestManager::HostAllocate::execute(
|
||||
im_mad_name,
|
||||
vmm_mad_name,
|
||||
tm_mad_name);
|
||||
if ( rc != 0 )
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_host_allocate;
|
||||
}
|
||||
@ -92,7 +92,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -36,7 +36,7 @@ void RequestManager::HostDelete::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"HostDelete method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"HostDelete method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -82,7 +82,7 @@ error_host_get:
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
Nebula::log ("Rem",Log::ERROR,oss);
|
||||
NebulaLog::log ("Rem",Log::ERROR,oss);
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -36,7 +36,7 @@ void RequestManager::HostEnable::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"HostEnable method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"HostEnable method invoked");
|
||||
|
||||
// Get the parameters & host
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -91,7 +91,7 @@ error_host_get:
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false));
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -36,7 +36,7 @@ void RequestManager::HostInfo::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"HostInfo method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"HostInfo method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -87,7 +87,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -32,7 +32,7 @@ void RequestManager::HostPoolInfo::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"HostPoolInfo method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"HostPoolInfo method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -81,7 +81,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -35,7 +35,7 @@ void RequestManager::VirtualMachineInfo::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"VirtualMachineInfo method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachineInfo method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -74,7 +74,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -48,7 +50,7 @@ void RequestManager::VirtualMachineMigrate::execute(
|
||||
ostringstream oss;
|
||||
time_t thetime;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"VirtualMachineMigrate invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachineMigrate invoked");
|
||||
|
||||
//Parse Arguments
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -40,7 +40,7 @@ void RequestManager::VirtualMachinePoolInfo::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"VirtualMachinePoolInfo method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachinePoolInfo method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -119,7 +119,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -40,7 +40,7 @@ void RequestManager::UserAllocate::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"UserAllocate method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"UserAllocate method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -67,7 +67,7 @@ void RequestManager::UserAllocate::execute(
|
||||
// Now let's add the user
|
||||
rc = UserAllocate::upool->allocate(&uid,username,password,true);
|
||||
|
||||
if ( rc != 0 )
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_allocate;
|
||||
}
|
||||
@ -102,7 +102,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -36,7 +36,7 @@ void RequestManager::UserDelete::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"UserDelete method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"UserDelete method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -104,7 +104,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -36,7 +36,7 @@ void RequestManager::UserInfo::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"UserInfo method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"UserInfo method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -87,7 +87,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -33,7 +33,7 @@ void RequestManager::UserPoolInfo::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"UserPoolInfo method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"UserPoolInfo method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -79,7 +79,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -23,17 +23,17 @@
|
||||
void RequestManager::VirtualNetworkAllocate::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
{
|
||||
string session;
|
||||
string username;
|
||||
string password;
|
||||
string name;
|
||||
string stemplate;
|
||||
|
||||
|
||||
int nid;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
|
||||
User * user;
|
||||
|
||||
ostringstream oss;
|
||||
@ -42,7 +42,7 @@ void RequestManager::VirtualNetworkAllocate::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"VirtualNetworkAllocate method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualNetworkAllocate method invoked");
|
||||
|
||||
// Get the parameters & host
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -52,7 +52,7 @@ void RequestManager::VirtualNetworkAllocate::execute(
|
||||
{
|
||||
goto error_session;
|
||||
}
|
||||
|
||||
|
||||
// Now let's get the user
|
||||
user = VirtualNetworkAllocate::upool->get(username,true);
|
||||
|
||||
@ -64,19 +64,19 @@ void RequestManager::VirtualNetworkAllocate::execute(
|
||||
uid = user->get_uid();
|
||||
|
||||
user->unlock();
|
||||
|
||||
|
||||
rc = vnpool->allocate(uid,stemplate,&nid);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_vn_allocate;
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
goto error_vn_allocate;
|
||||
}
|
||||
|
||||
|
||||
//Result
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
|
||||
arrayData.push_back(xmlrpc_c::value_int(nid));
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
|
||||
|
||||
*retval = *arrayresult;
|
||||
|
||||
delete arrayresult;
|
||||
@ -93,11 +93,11 @@ error_get_user:
|
||||
goto error_common;
|
||||
|
||||
error_vn_allocate:
|
||||
oss << "Error allocating VN with template: " << endl << stemplate;
|
||||
oss << "Error allocating VN with template: " << endl << stemplate;
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
error_common:
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false));
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
@ -105,7 +105,7 @@ error_common:
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -39,7 +39,7 @@ void RequestManager::VirtualNetworkDelete::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"VirtualNetworkDelete method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualNetworkDelete method invoked");
|
||||
|
||||
// Get the parameters & host
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -88,7 +88,7 @@ error_vn_get:
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
Nebula::log ("Rem",Log::ERROR,oss);
|
||||
NebulaLog::log ("Rem",Log::ERROR,oss);
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -38,7 +38,7 @@ void RequestManager::VirtualNetworkInfo::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"VirtualNetworkInfo method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualNetworkInfo method invoked");
|
||||
|
||||
// Get the parameters & host
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -88,7 +88,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -40,7 +40,7 @@ void RequestManager::VirtualNetworkPoolInfo::execute(
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
Nebula::log("ReM",Log::DEBUG,"VirtualNetworkPoolInfo method invoked");
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualNetworkPoolInfo method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
@ -121,7 +121,7 @@ error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
Nebula::log("ReM",Log::ERROR,oss);
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
# SConstruct for src/nebula
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
@ -17,46 +15,90 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
import os
|
||||
Import('env')
|
||||
import sys
|
||||
import shutil
|
||||
sys.path.append("../../share/scons")
|
||||
|
||||
from lex_bison import *
|
||||
|
||||
# This is the absolute path where the project is located
|
||||
cwd=os.getcwd()
|
||||
env.Append(LIBPATH=cwd)
|
||||
|
||||
lib_name='nebula_scheduler'
|
||||
# Environment that will be applied to each scons child
|
||||
main_env=Environment()
|
||||
main_env['ENV']['PATH']=os.environ['PATH']
|
||||
|
||||
# Sources to generate the library
|
||||
source_files=[
|
||||
'Scheduler.cc',
|
||||
'SchedulerHost.cc',
|
||||
'SchedulerVirtualMachine.cc',
|
||||
]
|
||||
# Add builders for flex and bison
|
||||
add_lex(main_env)
|
||||
add_bison(main_env)
|
||||
|
||||
scheduler_names=[
|
||||
'mm_sched'
|
||||
]
|
||||
|
||||
# Build library
|
||||
env.StaticLibrary(lib_name, source_files)
|
||||
|
||||
env.Append(LIBS=[
|
||||
'sqlite3',
|
||||
'crypto',
|
||||
lib_name,
|
||||
'nebula_core',
|
||||
'nebula_host',
|
||||
'nebula_vm',
|
||||
'nebula_vnm',
|
||||
'nebula_pool',
|
||||
'nebula_template',
|
||||
'nebula_common',
|
||||
'nebula_um',
|
||||
# Include dirs
|
||||
main_env.Append(CPPPATH=[
|
||||
cwd + '/include/',
|
||||
cwd + '../../../include/'
|
||||
])
|
||||
|
||||
# Library dirs
|
||||
main_env.Append(LIBPATH=[
|
||||
cwd+'/src/xml',
|
||||
cwd+'/src/pool',
|
||||
cwd+'/src/sched',
|
||||
cwd+'/../log',
|
||||
cwd+'/../common',
|
||||
])
|
||||
|
||||
if not env.GetOption('clean'):
|
||||
env.ParseConfig('../../share/scons/get_xmlrpc_config client')
|
||||
# Compile flags
|
||||
main_env.Append(CPPFLAGS=[
|
||||
"-g",
|
||||
"-Wall"
|
||||
])
|
||||
|
||||
# Linking flags
|
||||
main_env.Append(LDFLAGS=["-g"])
|
||||
|
||||
# Build tests
|
||||
for sched in scheduler_names:
|
||||
env.Program(sched, sched+'.cc')
|
||||
################################################################################
|
||||
# EXTRA CONFIGURATION
|
||||
################################################################################
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# xmlrpc
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
xmlrpc_dir=ARGUMENTS.get('xmlrpc', 'none')
|
||||
|
||||
if xmlrpc_dir!='none':
|
||||
main_env.Append(LIBPATH=[xmlrpc_dir+"/lib"])
|
||||
main_env.Append(CPPPATH=[xmlrpc_dir+"/include"])
|
||||
|
||||
main_env.ParseConfig('../../share/scons/get_xmlrpc_config client')
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# build lex/bison
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
build_parsers=ARGUMENTS.get('parsers', 'no')
|
||||
|
||||
if build_parsers=='yes':
|
||||
main_env.Append(parsers='yes')
|
||||
else:
|
||||
main_env.Append(parsers='no')
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# libxml2
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
main_env.ParseConfig('xml2-config --libs --cflags')
|
||||
|
||||
################################################################################
|
||||
# SCONS scripts to build
|
||||
################################################################################
|
||||
|
||||
build_scripts=[
|
||||
'src/xml/SConstruct',
|
||||
'src/pool/SConstruct',
|
||||
'src/sched/SConstruct'
|
||||
]
|
||||
|
||||
for script in build_scripts:
|
||||
env=main_env.Clone()
|
||||
SConscript(script, exports='env')
|
||||
|
@ -1,177 +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 <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "SchedulerHost.h"
|
||||
#include "Scheduler.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void SchedulerHost::get_capacity(int& cpu, int& memory, int threshold)
|
||||
{
|
||||
int total_cpu;
|
||||
|
||||
memory = get_share_free_mem();
|
||||
cpu = get_share_free_cpu();
|
||||
|
||||
total_cpu = get_share_max_cpu();
|
||||
|
||||
/* eg. 96.7 >= 0.9 * 100, We need to round */
|
||||
if ( cpu >= threshold * total_cpu )
|
||||
{
|
||||
cpu = (int) ceil((float)cpu/100.0) * 100;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SchedulerHost::insert(SqliteDB *db)
|
||||
{
|
||||
Scheduler::log("HOST",Log::ERROR,
|
||||
"Scheduler can not insert hosts in database");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SchedulerHost::update(SqliteDB *db)
|
||||
{
|
||||
Scheduler::log("HOST",Log::ERROR,
|
||||
"Scheduler can not update hosts in database");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SchedulerHost::drop(SqliteDB *db)
|
||||
{
|
||||
Scheduler::log("HOST",Log::ERROR,
|
||||
"Scheduler can not delete hosts from database");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SchedulerHostPool::allocate(
|
||||
PoolObjectSQL *objsql)
|
||||
{
|
||||
Scheduler::log("HOST",Log::ERROR,
|
||||
"Scheduler can not allocate hosts in database");
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void SchedulerHostPool::bootstrap()
|
||||
{
|
||||
Scheduler::log("HOST",Log::ERROR,
|
||||
"Scheduler can not bootstrap database");
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* SchedulerHostPool */
|
||||
/* ************************************************************************** */
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static int set_up_cb (
|
||||
void * _hids,
|
||||
int num,
|
||||
char ** values,
|
||||
char ** names)
|
||||
{
|
||||
vector<int> * hids;
|
||||
|
||||
hids = static_cast<vector<int> *>(_hids);
|
||||
|
||||
if ((hids==0)||(num<=0)||(values[0]==0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
hids->push_back(atoi(values[0]));
|
||||
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SchedulerHostPool::set_up()
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Clean the pool to get updated data from db
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
clean();
|
||||
|
||||
hids.clear();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Load the ids (to get an updated list of hosts)
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
lock();
|
||||
|
||||
oss << "SELECT oid FROM " << Host::table
|
||||
<< " WHERE state != " << Host::DISABLED
|
||||
<< " AND state != " << Host::ERROR;
|
||||
|
||||
rc = db->exec(oss,set_up_cb,(void *) &hids);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
oss.str("");
|
||||
oss << "Discovered Hosts (enabled):";
|
||||
|
||||
for (unsigned int i=0 ; i < hids.size() ; i++)
|
||||
{
|
||||
oss << " " << hids[i];
|
||||
}
|
||||
|
||||
Scheduler::log("HOST",Log::DEBUG,oss);
|
||||
|
||||
unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -1,206 +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 <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "SchedulerHost.h"
|
||||
#include "Scheduler.h"
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* SchedulerVirtualMachine */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int SchedulerVirtualMachine::insert(SqliteDB *db)
|
||||
{
|
||||
Scheduler::log("VM",Log::ERROR,
|
||||
"Scheduler can not insert VMs in database");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SchedulerVirtualMachine::update(SqliteDB *db)
|
||||
{
|
||||
Scheduler::log("VM",Log::ERROR,
|
||||
"Scheduler can not update VMs in database");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SchedulerVirtualMachine::drop(SqliteDB *db)
|
||||
{
|
||||
Scheduler::log("VM",Log::ERROR,
|
||||
"Scheduler can not delete VMs in database");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void SchedulerVirtualMachine::set_priorities(vector<float>& total)
|
||||
{
|
||||
if ( hosts.size() != total.size() )
|
||||
{
|
||||
Scheduler::log("VM",Log::ERROR,"Wrong size for priority vector");
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned int i=0; i<hosts.size(); i++)
|
||||
{
|
||||
hosts[i]->priority = total[i];
|
||||
}
|
||||
|
||||
//Sort the shares using the priority
|
||||
|
||||
sort(hosts.begin(),hosts.end(),SchedulerVirtualMachine::host_cmp);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SchedulerVirtualMachine::get_host(
|
||||
int& hid,
|
||||
SchedulerHostPool * hpool)
|
||||
{
|
||||
vector<SchedulerVirtualMachine::Host *>::reverse_iterator i;
|
||||
|
||||
vector<int>::iterator j;
|
||||
SchedulerHost * host;
|
||||
|
||||
int cpu;
|
||||
int mem;
|
||||
int dsk;
|
||||
|
||||
get_requirements(cpu,mem,dsk);
|
||||
|
||||
for (i=hosts.rbegin();i!=hosts.rend();i++)
|
||||
{
|
||||
host = hpool->get((*i)->hid,false);
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (host->test_capacity(cpu,mem,dsk)==true)
|
||||
{
|
||||
host->add_capacity(cpu,mem,dsk);
|
||||
hid = (*i)->hid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
hid = -1;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Scheuler Virtual Machine :: Misc */
|
||||
/* ************************************************************************** */
|
||||
|
||||
ostream& operator<<(ostream& os, SchedulerVirtualMachine& vm)
|
||||
{
|
||||
vector<SchedulerVirtualMachine::Host *>::reverse_iterator i;
|
||||
vector<int>::iterator j;
|
||||
|
||||
for (i=vm.hosts.rbegin();i!=vm.hosts.rend();i++)
|
||||
{
|
||||
os << "\t" << (*i)->priority << "\t" << (*i)->hid << endl;
|
||||
}
|
||||
|
||||
return os;
|
||||
};
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* SchedulerVirtualMachinePool */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int SchedulerVirtualMachinePool::allocate(
|
||||
PoolObjectSQL *objsql)
|
||||
{
|
||||
Scheduler::log("HOST",Log::ERROR,
|
||||
"Scheduler can not allocate VMs in database");
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void SchedulerVirtualMachinePool::bootstrap()
|
||||
{
|
||||
Scheduler::log("HOST",Log::ERROR,
|
||||
"Scheduler can not bootstrap database");
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SchedulerVirtualMachinePool::set_up()
|
||||
{
|
||||
ostringstream oss;
|
||||
string where;
|
||||
int rc;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Clean the pool to get updated data from db
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
clean();
|
||||
|
||||
pending_vms.clear();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Load an updated list of pending VMs
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
oss << "state == " << VirtualMachine::PENDING;
|
||||
|
||||
where = oss.str();
|
||||
|
||||
rc = PoolSQL::search(
|
||||
pending_vms,
|
||||
VirtualMachine::table,
|
||||
where);
|
||||
|
||||
oss.str("");
|
||||
oss << "Pending virtual machines :";
|
||||
|
||||
|
||||
for (unsigned int i=0 ; i < pending_vms.size() ; i++)
|
||||
{
|
||||
oss << " " << pending_vms[i];
|
||||
}
|
||||
|
||||
Scheduler::log("VM",Log::DEBUG,oss);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
104
src/scheduler/include/Client.h
Normal file
104
src/scheduler/include/Client.h
Normal file
@ -0,0 +1,104 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 ONE_CLIENT_H_
|
||||
#define ONE_CLIENT_H_
|
||||
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#include <xmlrpc-c/client_simple.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "NebulaLog.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
// =============================================================================
|
||||
// Doc:
|
||||
// http://xmlrpc-c.sourceforge.net/doc/#clientexamplepp
|
||||
// http://xmlrpc-c.sourceforge.net/doc/libxmlrpc_client++.html#simple_client
|
||||
// =============================================================================
|
||||
|
||||
//TODO add documentation to the Client methods...
|
||||
|
||||
/**
|
||||
* This class represents the connection with the core and handles the
|
||||
* xml-rpc calls.
|
||||
*/
|
||||
class Client : public xmlrpc_c::clientSimple
|
||||
{
|
||||
public:
|
||||
//--------------------------------------------------------------------------
|
||||
// PUBLIC INTERFACE
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a new xml-rpc client with specified options.
|
||||
*
|
||||
* @param secret A string containing the ONE user:password tuple.
|
||||
* If not set, the auth. file will be assumed to be at $ONE_AUTH
|
||||
* @param endpoint Where the rpc server is listening, must be something
|
||||
* like "http://localhost:2633/RPC2". If not set, the endpoint will be set
|
||||
* to $ONE_XMLRPC.
|
||||
* @throws Exception if the authorization options are invalid
|
||||
*/
|
||||
Client( string secret = "",
|
||||
string endpoint = "")
|
||||
{
|
||||
set_one_auth(secret);
|
||||
set_one_endpoint(endpoint);
|
||||
|
||||
xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, 1024*MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
const string& get_oneauth()
|
||||
{
|
||||
return one_auth;
|
||||
}
|
||||
|
||||
const string& get_endpoint()
|
||||
{
|
||||
return one_endpoint;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// PRIVATE ATTRIBUTES AND METHODS
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
string one_auth;
|
||||
string one_endpoint;
|
||||
|
||||
void set_one_auth(string secret);
|
||||
|
||||
void set_one_endpoint(string endpoint);
|
||||
|
||||
int read_oneauth(string &secret);
|
||||
|
||||
int split_secret(const string secret, string& user, string& pass);
|
||||
|
||||
string sha1_digest(const string& pass);
|
||||
|
||||
/**
|
||||
* Default message size for XML data off the network
|
||||
*/
|
||||
static const int MESSAGE_SIZE;
|
||||
};
|
||||
|
||||
#endif /*ONECLIENT_H_*/
|
57
src/scheduler/include/HostPoolXML.h
Normal file
57
src/scheduler/include/HostPoolXML.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 HOST_POOL_XML_H_
|
||||
#define HOST_POOL_XML_H_
|
||||
|
||||
#include "PoolXML.h"
|
||||
#include "HostXML.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class HostPoolXML : public PoolXML
|
||||
{
|
||||
public:
|
||||
|
||||
HostPoolXML(Client* client):PoolXML(client){};
|
||||
|
||||
int set_up();
|
||||
|
||||
/**
|
||||
* Gets an object from the pool
|
||||
* @param oid the object unique identifier
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
HostXML * get(int oid) const
|
||||
{
|
||||
return static_cast<const HostXML *>(PoolXML::get(oid));
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
int get_suitable_nodes(vector<xmlNodePtr>& content)
|
||||
{
|
||||
return get_nodes("/HOST_POOL/HOST[STATE<3]", content);
|
||||
};
|
||||
|
||||
virtual void add_object(xmlNodePtr node);
|
||||
|
||||
virtual int load_info(xmlrpc_c::value &result);
|
||||
};
|
||||
|
||||
#endif /* HOST_POOL_XML_H_ */
|
107
src/scheduler/include/HostXML.h
Normal file
107
src/scheduler/include/HostXML.h
Normal file
@ -0,0 +1,107 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 HOST_XML_H_
|
||||
#define HOST_XML_H_
|
||||
|
||||
#include "ObjectXML.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class HostXML : public ObjectXML
|
||||
{
|
||||
public:
|
||||
|
||||
HostXML(const string &xml_doc):ObjectXML(xml_doc)
|
||||
{
|
||||
init_attributes();
|
||||
};
|
||||
|
||||
int get_hid() const
|
||||
{
|
||||
return oid;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the current host capacity
|
||||
* @param cpu the host free cpu, scaled according to a given threshold
|
||||
* @param memory the host free memory
|
||||
* @param threshold to consider the host totally free
|
||||
*/
|
||||
void get_capacity(int& cpu, int& memory, int threshold) const;
|
||||
|
||||
/**
|
||||
* Tests whether a new VM can be hosted by the host or not
|
||||
* @param cpu needed by the VM (percentage)
|
||||
* @param mem needed by the VM (in Kb)
|
||||
* @param disk needed by the VM
|
||||
* @return true if the share can host the VM
|
||||
*/
|
||||
bool test_capacity(int cpu, int mem, int disk) const
|
||||
{
|
||||
return (((max_cpu - cpu_usage ) >= cpu) &&
|
||||
((max_mem - mem_usage ) >= mem) &&
|
||||
((max_disk - disk_usage) >= disk));
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a new VM to the given share by incrementing the cpu,mem and disk
|
||||
* counters
|
||||
* @param cpu needed by the VM (percentage)
|
||||
* @param mem needed by the VM (in Kb)
|
||||
* @param disk needed by the VM
|
||||
* @return 0 on success
|
||||
*/
|
||||
void add_capacity(int cpu, int mem, int disk)
|
||||
{
|
||||
cpu_usage += cpu;
|
||||
mem_usage += mem;
|
||||
disk_usage += disk;
|
||||
|
||||
running_vms++;
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// TODO Check if any of these are not needed, and delete them.
|
||||
int oid;
|
||||
|
||||
// Host share values
|
||||
int disk_usage; /**< Disk allocated to VMs (in Mb). */
|
||||
int mem_usage; /**< Memory allocated to VMs (in Mb) */
|
||||
int cpu_usage; /**< CPU allocated to VMs (in percentage) */
|
||||
|
||||
int max_disk; /**< Total disk capacity (in Mb) */
|
||||
int max_mem; /**< Total memory capacity (in Mb) */
|
||||
int max_cpu; /**< Total cpu capacity (in percentage) */
|
||||
|
||||
int free_disk; /**< Free disk from the IM monitor */
|
||||
int free_mem; /**< Free memory from the IM monitor */
|
||||
int free_cpu; /**< Free cpu from the IM monitor */
|
||||
|
||||
int used_disk; /**< Used disk from the IM monitor */
|
||||
int used_mem; /**< Used memory from the IM monitor */
|
||||
int used_cpu; /**< Used cpu from the IM monitor */
|
||||
|
||||
int running_vms; /**< Number of running VMs in this Host */
|
||||
|
||||
|
||||
void init_attributes();
|
||||
};
|
||||
|
||||
#endif /* HOST_XML_H_ */
|
138
src/scheduler/include/ObjectXML.h
Normal file
138
src/scheduler/include/ObjectXML.h
Normal file
@ -0,0 +1,138 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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 OBJECT_XML_H_
|
||||
#define OBJECT_XML_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/xpath.h>
|
||||
#include <libxml/xpathInternals.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* This class represents a generic Object supported by a xml document.
|
||||
* The class provides basic methods to query attributes, and get xml nodes
|
||||
*/
|
||||
class ObjectXML
|
||||
{
|
||||
public:
|
||||
|
||||
// ---------------------- Constructors ------------------------------------
|
||||
|
||||
ObjectXML():xml(0),ctx(0){};
|
||||
|
||||
/**
|
||||
* Constructs an object using a XML document
|
||||
*/
|
||||
ObjectXML(const string &xml_doc);
|
||||
|
||||
/**
|
||||
* Constructs an object using a XML Node. The node is copied to the new
|
||||
* object
|
||||
*/
|
||||
ObjectXML(const xmlNodePtr node);
|
||||
|
||||
virtual ~ObjectXML();
|
||||
|
||||
/**
|
||||
* Access Object elements using Xpath
|
||||
* @param xpath_expr the Xpath of the element
|
||||
* @return a vector with the elements
|
||||
*/
|
||||
vector<string> operator[] (const char * xpath_expr);
|
||||
|
||||
/**
|
||||
* Get xml nodes by Xpath
|
||||
* @param xpath_expr the Xpath for the elements
|
||||
* @param content nodes for the given Xpath expression. The nodes are
|
||||
* returned as pointers to the object nodes.
|
||||
* @return the number of nodes found
|
||||
*/
|
||||
int get_nodes (const char * xpath_expr, vector<xmlNodePtr>& content);
|
||||
|
||||
/**
|
||||
* Updates the object representation with a new XML document. Previous
|
||||
* XML resources are freed
|
||||
* @param xml_doc the new xml document
|
||||
*/
|
||||
int update(const string &xml_doc);
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Lex & bison parser for requirements and rank expressions
|
||||
// ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Evaluates a requirement expression on the given host.
|
||||
* @param requirements string
|
||||
* @param result true if the host matches the requirements
|
||||
* @param errmsg string describing the error, must be freed by the
|
||||
* calling function
|
||||
* @return 0 on success
|
||||
*/
|
||||
int eval_bool(const string& expr, bool& result, char **errmsg);
|
||||
|
||||
/**
|
||||
* Evaluates a rank expression on the given host.
|
||||
* @param rank string
|
||||
* @param result of the rank evaluation
|
||||
* @param errmsg string describing the error, must be freed by the
|
||||
* calling function
|
||||
* @return 0 on success
|
||||
*/
|
||||
int eval_arith(const string& expr, int& result, char **errmsg);
|
||||
|
||||
/**
|
||||
* Function to write the Object in an output stream
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, ObjectXML& oxml)
|
||||
{
|
||||
xmlChar * mem;
|
||||
int size;
|
||||
|
||||
xmlDocDumpMemory(oxml.xml,&mem,&size);
|
||||
|
||||
string str(reinterpret_cast<char *>(mem));
|
||||
os << str;
|
||||
|
||||
xmlFree(mem);
|
||||
|
||||
return os;
|
||||
};
|
||||
|
||||
private:
|
||||
/**
|
||||
* XML representation of the Object
|
||||
*/
|
||||
xmlDocPtr xml;
|
||||
|
||||
/**
|
||||
* XPath Context to access Object elements
|
||||
*/
|
||||
xmlXPathContextPtr ctx;
|
||||
|
||||
/**
|
||||
* Parse a XML documents and initializes XPath contexts
|
||||
*/
|
||||
void xml_parse(const string &xml_doc);
|
||||
};
|
||||
|
||||
#endif /*OBJECT_XML_H_*/
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user