2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2008, 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. */
/* -------------------------------------------------------------------------- */
# ifndef NEBULA_H_
# define NEBULA_H_
# include <sqlite3.h>
# include "Log.h"
# include "NebulaTemplate.h"
# include "VirtualMachinePool.h"
2008-11-13 19:21:17 +03:00
# include "VirtualNetworkPool.h"
2008-06-17 20:27:32 +04:00
# include "HostPool.h"
# include "VirtualMachineManager.h"
# include "LifeCycleManager.h"
# include "InformationManager.h"
# include "TransferManager.h"
# include "DispatchManager.h"
# include "RequestManager.h"
class Nebula
{
public :
2008-06-18 19:58:44 +04:00
2008-06-17 20:27:32 +04:00
static Nebula & instance ( )
{
static Nebula nebulad ;
return nebulad ;
} ;
// ---------------------------------------------------------------
2008-06-18 19:58:44 +04:00
// Logging
2008-06-17 20:27:32 +04:00
// ---------------------------------------------------------------
static void log (
const char * module ,
const Log : : MessageType type ,
const ostringstream & message ,
2008-06-18 19:58:44 +04:00
const char * filename = 0 ,
Log : : MessageType clevel = Log : : ERROR )
2008-06-17 20:27:32 +04:00
{
2008-06-18 19:58:44 +04:00
static Log nebula_log ( filename , clevel , ios_base : : trunc ) ;
static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER ;
2008-06-17 20:27:32 +04:00
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 ;
} ;
2008-11-13 19:21:17 +03:00
VirtualNetworkPool * get_vnpool ( )
{
return vnpool ;
} ;
2008-06-17 20:27:32 +04:00
// --------------------------------------------------------------
// Manager Accessors
// --------------------------------------------------------------
VirtualMachineManager * get_vmm ( )
{
return vmm ;
} ;
LifeCycleManager * get_lcm ( )
{
return lcm ;
} ;
InformationManager * get_im ( )
{
return im ;
} ;
TransferManager * get_tm ( )
{
return tm ;
} ;
DispatchManager * get_dm ( )
{
return dm ;
} ;
// --------------------------------------------------------------
// Environment & Configuration
// --------------------------------------------------------------
2008-11-13 19:21:17 +03:00
const string & get_nebula_location ( )
2008-06-17 20:27:32 +04:00
{
return nebula_location ;
} ;
2008-11-13 19:21:17 +03:00
const string & get_nebula_hostname ( )
{
return hostname ;
} ;
2008-06-17 20:27:32 +04:00
static string version ( )
{
2008-11-13 19:21:17 +03:00
return " ONE1.1 " ;
2008-06-17 20:27:32 +04:00
} ;
void start ( ) ;
void get_configuration_attribute (
const char * name ,
string & value ) const
{
string _name ( name ) ;
nebula_configuration - > Template : : get ( _name , value ) ;
} ;
private :
// -----------------------------------------------------------------------
//Constructors and = are private to only access the class through instance
// -----------------------------------------------------------------------
2008-11-13 19:21:17 +03:00
Nebula ( ) : nebula_configuration ( 0 ) , db ( 0 ) , vmpool ( 0 ) , hpool ( 0 ) , vnpool ( 0 ) , lcm ( 0 ) ,
2008-06-17 20:27:32 +04:00
vmm ( 0 ) , im ( 0 ) , tm ( 0 ) , dm ( 0 ) , rm ( 0 ) { } ;
~ Nebula ( )
{
if ( vmpool ! = 0 )
{
delete vmpool ;
}
if ( hpool ! = 0 )
{
delete hpool ;
}
if ( vmm ! = 0 )
{
delete vmm ;
}
if ( lcm ! = 0 )
{
delete lcm ;
}
if ( im ! = 0 )
{
delete im ;
}
if ( tm ! = 0 )
{
delete tm ;
}
if ( dm ! = 0 )
{
delete dm ;
}
if ( rm ! = 0 )
{
delete rm ;
}
if ( nebula_configuration ! = 0 )
{
delete nebula_configuration ;
}
if ( db ! = 0 )
{
delete db ;
}
} ;
Nebula ( Nebula const & ) { } ;
Nebula & operator = ( Nebula const & ) { return * this ; } ;
// ---------------------------------------------------------------
// Environment variables
// ---------------------------------------------------------------
string nebula_location ;
2008-11-13 19:21:17 +03:00
string hostname ;
2008-06-17 20:27:32 +04:00
// ---------------------------------------------------------------
// Configuration
// ---------------------------------------------------------------
NebulaTemplate * nebula_configuration ;
// ---------------------------------------------------------------
// Nebula Pools
// ---------------------------------------------------------------
2008-11-13 19:21:17 +03:00
SqliteDB * db ;
2008-06-17 20:27:32 +04:00
VirtualMachinePool * vmpool ;
2008-11-13 19:21:17 +03:00
HostPool * hpool ;
VirtualNetworkPool * vnpool ;
2008-06-17 20:27:32 +04:00
// ---------------------------------------------------------------
// Nebula Managers
// ---------------------------------------------------------------
LifeCycleManager * lcm ;
VirtualMachineManager * vmm ;
InformationManager * im ;
TransferManager * tm ;
DispatchManager * dm ;
RequestManager * rm ;
// ---------------------------------------------------------------
// Implementation functions
// ---------------------------------------------------------------
friend void nebula_signal_handler ( int sig ) ;
} ;
# endif /*NEBULA_H_*/