1
import java.util.Properties
2
import org.apache.log4j.Logger
3
import org.hibernate.ejb.Ejb3Configuration
4
import com.eucalyptus.bootstrap.Bootstrap
5
import com.eucalyptus.bootstrap.BootstrapArgs
6
import com.eucalyptus.bootstrap.Databases
7
import com.eucalyptus.bootstrap.ServiceJarDiscovery
8
import com.eucalyptus.component.ComponentDiscovery
9
import com.eucalyptus.component.ServiceBuilder
10
import com.eucalyptus.component.ServiceBuilders
11
import com.eucalyptus.component.ServiceConfiguration
12
import com.eucalyptus.component.ServiceConfigurations
13
import com.eucalyptus.component.ServiceUris
14
import com.eucalyptus.component.ServiceBuilders.ServiceBuilderDiscovery
15
import com.eucalyptus.component.auth.SystemCredentials
16
import com.eucalyptus.component.id.Eucalyptus
17
import com.eucalyptus.component.id.Eucalyptus.Database
18
import com.eucalyptus.entities.PersistenceContextDiscovery
19
import com.eucalyptus.entities.PersistenceContexts
20
import com.eucalyptus.system.DirectoryBootstrapper
21
import com.eucalyptus.util.Internets
24
Logger LOG = Logger.getLogger( Bootstrap.class );
26
if( BootstrapArgs.isInitializeSystem( ) ) {
27
new DirectoryBootstrapper( ).load( );
28
ServiceJarDiscovery.doSingleDiscovery( new ComponentDiscovery( ) );
30
new ServiceBuilderDiscovery( ),
31
new PersistenceContextDiscovery( )
33
ServiceJarDiscovery.runDiscovery( it );
35
SystemCredentials.initialize( );
38
Databases.initialize( );
41
"hibernate.archive.autodetection": "jar, class, hbm",
42
"hibernate.show_sql": "false",
43
"hibernate.format_sql": "false",
44
"hibernate.connection.autocommit": "true",
45
"hibernate.hbm2ddl.auto": "update",
46
"hibernate.generate_statistics": "true",
47
"hibernate.connection.driver_class": Databases.getDriverName( ),
48
"hibernate.connection.username": "eucalyptus",
49
"hibernate.connection.password": Databases.getPassword( ),
50
"hibernate.bytecode.use_reflection_optimizer": "true",
51
"hibernate.cglib.use_reflection_optimizer": "true",
52
"hibernate.dialect": Databases.getHibernateDialect( ),
53
"hibernate.cache.provider_class": "org.hibernate.cache.TreeCache",
54
"hibernate.cache.region.factory_class": "org.hibernate.cache.jbc2.SharedJBossCacheRegionFactory",
55
"hibernate.cache.region.jbc2.cfg.shared": "eucalyptus_jboss_cache.xml",
56
"hibernate.cache.use_second_level_cache": "true",
57
"hibernate.cache.use_query_cache": "true",
58
"hibernate.cache.use_structured_entries": "true",
60
for ( String ctx : PersistenceContexts.list( ) ) {
61
Properties p = new Properties( );
63
String ctxUrl = "jdbc:${ServiceUris.remote(Database.class,Internets.loopback( ),ctx)}";
64
p.put( "hibernate.connection.url", ctxUrl );
65
p.put("hibernate.cache.region_prefix", "eucalyptus_" + ctx + "_cache" );
66
Ejb3Configuration config = new Ejb3Configuration( );
67
config.setProperties( p );
68
for ( Class c : PersistenceContexts.listEntities( ctx ) ) {
69
config.addAnnotatedClass( c );
71
PersistenceContexts.registerPersistenceContext( ctx, config );
73
if( BootstrapArgs.isInitializeSystem( ) ) {
74
ServiceBuilder sb = ServiceBuilders.lookup( Eucalyptus.class );
75
final ServiceConfiguration newComponent = sb.newInstance( Eucalyptus.INSTANCE.name( ), Internets.localHostAddress( ), Internets.localHostAddress( ), 8773 );
76
ServiceConfigurations.store( newComponent );
77
LOG.info( "Added registration for this cloud controller: " + newComponent.toString() );
79
Databases.getBootstrapper( ).destroy( );
80
} catch( Exception ex ) {
81
Databases.getBootstrapper( ).destroy( );
85
} catch( Exception ex ) {
86
Databases.getBootstrapper( ).destroy( );