Skip to content

Commit

Permalink
Merge of the OpenNebulaXML branch (-r535:HEAD)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.opennebula.org/one/trunk@667 3034c82b-c49b-4eb3-8279-a7acafdc01c0
  • Loading branch information
ruben committed Jul 9, 2009
1 parent 34c3d06 commit 8270748
Show file tree
Hide file tree
Showing 117 changed files with 7,536 additions and 1,474 deletions.
2 changes: 2 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ main_env.Append(LIBPATH=[
cwd+'/src/rm',
cwd+'/src/vnm',
cwd+'/src/hm',
cwd+'/src/um',
])

# Compile flags
Expand Down Expand Up @@ -135,6 +136,7 @@ build_scripts=[
'src/scheduler/SConstruct',
'src/vnm/SConstruct',
'src/hm/SConstruct',
'src/um/SConstruct',
]

for script in build_scripts:
Expand Down
9 changes: 9 additions & 0 deletions include/DispatchManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ class DispatchManager : public ActionListener
int resume(
int vid);

/**
* Restart a previusly deployed VM.
* @param vid VirtualMachine identification
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
* in a wrong a state
*/
int restart(
int vid);

/**
* Ends a VM life cycle inside ONE.
* @param vid VirtualMachine identification
Expand Down
35 changes: 35 additions & 0 deletions include/History.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ class History:public ObjectSQL

~History(){};

/**
* Function to write the History Record in an output stream
*/
friend ostream& operator<<(ostream& os, const History& history);

/**
* Function to print the History 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 History 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;

private:
friend class VirtualMachine;

Expand Down Expand Up @@ -192,6 +213,20 @@ class History:public ObjectSQL
* @return 0 on success
*/
int unmarshall(int num, char **names, char ** values);

/**
* Function to unmarshall a History 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);
};

#endif /*HISTORY_H_*/
105 changes: 67 additions & 38 deletions include/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@

using namespace std;

extern "C" int host_select_cb (void * _host, int num,char ** values, char ** names);

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);
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

Expand Down Expand Up @@ -54,6 +61,20 @@ class Host : public PoolObjectSQL
*/
friend ostream& operator<<(ostream& os, Host& h);

/**
* Function to print the Host 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 Host 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 Host unique identifier HID, that matches the OID of the object
* @return HID Host identifier
Expand All @@ -62,15 +83,6 @@ class Host : public PoolObjectSQL
{
return oid;
};

/**
* Check if the host is managed
* @return true if the host is managed
*/
bool isManaged() const
{
return managed;
}

/**
* Check if the host is enabled
Expand Down Expand Up @@ -310,15 +322,17 @@ class Host : public PoolObjectSQL
// -------------------------------------------------------------------------
// Friends
// -------------------------------------------------------------------------

friend class HostPool;

friend int host_select_cb (
void * _host,
int num,
char ** values,
char ** names);

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);
// -------------------------------------------------------------------------
// Host Description
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -349,26 +363,21 @@ class Host : public PoolObjectSQL
* 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;

/**
* This tells if this host pertains to a local managed cluster
*/
bool managed;

time_t last_monitored;

// -------------------------------------------------------------------------
// Host Attributes
// -------------------------------------------------------------------------

/**
* The Host template, holds the Host attributes.
*/
HostTemplate host_template;
HostTemplate host_template;

/**
* This map holds pointers to all the Host's HostShares
* The Share represents the logical capacity associated with the host
*/
HostShare host_share;
HostShare host_share;

// -------------------------------------------------------------------------
// Lex & bison
Expand All @@ -386,22 +395,34 @@ class Host : public PoolObjectSQL
/**
* Function to unmarshall a Host object
* @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);

/**
* Function to unmarshall a Host object in to an output stream in XML
* @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);
/**
* Bootstraps the database table(s) associated to the Host
*/
static void bootstrap(SqliteDB * db)
{
db->exec(Host::db_bootstrap);

db->exec(HostTemplate::db_bootstrap);

db->exec(HostShare::db_bootstrap);

db->exec(HostTemplate::db_bootstrap);
};

protected:
Expand All @@ -414,8 +435,7 @@ class Host : public PoolObjectSQL
string _hostname="",
string _im_mad_name="",
string _vmm_mad_name="",
string _tm_mad_name="",
bool _managed=true);
string _tm_mad_name="");

virtual ~Host();

Expand All @@ -431,9 +451,8 @@ class Host : public PoolObjectSQL
IM_MAD = 3,
VM_MAD = 4,
TM_MAD = 5,
LAST_MON_TIME = 6,
MANAGED = 7,
LIMIT = 8
LAST_MON_TIME = 6,
LIMIT = 7
};

static const char * db_names;
Expand Down Expand Up @@ -468,7 +487,17 @@ class Host : public PoolObjectSQL
* @param db pointer to the db
* @return 0 on success
*/
virtual int drop(SqliteDB *db);
virtual int drop(SqliteDB *db);

/**
* Dumps the contect of a set of Host 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
* @return 0 on success
*/
static int dump(SqliteDB * db, ostringstream& oss, const string& where);
};

#endif /*HOST_H_*/
59 changes: 43 additions & 16 deletions include/HostPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class HostPool : public PoolSQL
string hostname,
string im_mad_name,
string vmm_mad_name,
string tm_mad_name,
bool managed = true);
string tm_mad_name);

/**
* Function to get a Host from the pool, if the object is not in memory
Expand All @@ -78,36 +77,37 @@ class HostPool : public PoolSQL
};


/** Drops a host from the cache & DB, the host mutex MUST BE locked
/** Drops a host from the DB, the host mutex MUST BE locked
* @param host pointer to Host
*/
int drop(Host * host)
{
int rc = host->drop(db);

if ( rc == 0)
{
remove(static_cast<PoolObjectSQL *>(host));
}

return rc;
return host->drop(db);
};

/**
* Bootstraps the database table(s) associated to the Host pool
*/
void bootstrap()
static void bootstrap(SqliteDB *_db)
{
Host::bootstrap(db);
Host::bootstrap(_db);
};

/**
* Get the 10 least monitored hosts
* param discovered hosts map to store the retrieved hosts hids and hostnames are
* return int 0 if success
* @param discovered hosts, map to store the retrieved hosts hids and
* hostnames
* @return int 0 if success
*/
int discover(map<int, string> * discovered_hosts);

/**
* 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 add_capacity(int oid,int cpu, int mem, int disk)
{
Host * host = get(oid, true);
Expand All @@ -121,7 +121,13 @@ class HostPool : public PoolSQL
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);
Expand All @@ -135,6 +141,27 @@ class HostPool : public PoolSQL
host->unlock();
}
};

/**
* Dumps the HOST 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 << "<HOST_POOL>";

rc = Host::dump(db,oss,where);

oss << "</HOST_POOL>";

return rc;
}

private:
/**
Expand Down
Loading

0 comments on commit 8270748

Please sign in to comment.