~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to clc/modules/msgs/conf/scripts/initialize_cloud.groovy

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
ImportĀ upstreamĀ versionĀ 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
22
 
 
23
 
 
24
Logger LOG = Logger.getLogger( Bootstrap.class );
 
25
 
 
26
if( BootstrapArgs.isInitializeSystem( ) ) {
 
27
  new DirectoryBootstrapper( ).load( );
 
28
  ServiceJarDiscovery.doSingleDiscovery(  new ComponentDiscovery( ) );
 
29
  [
 
30
    new ServiceBuilderDiscovery( ),
 
31
    new PersistenceContextDiscovery( )
 
32
  ].each{
 
33
    ServiceJarDiscovery.runDiscovery( it );
 
34
  }
 
35
  SystemCredentials.initialize( );
 
36
}
 
37
try {
 
38
  Databases.initialize( );
 
39
  try {
 
40
    props = [
 
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",
 
59
        ]
 
60
    for ( String ctx : PersistenceContexts.list( ) ) {
 
61
      Properties p = new Properties( );
 
62
      p.putAll( props );
 
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 );
 
70
      }
 
71
      PersistenceContexts.registerPersistenceContext( ctx, config );
 
72
    }
 
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() );
 
78
    }
 
79
    Databases.getBootstrapper( ).destroy( );
 
80
  } catch( Exception ex ) {
 
81
    Databases.getBootstrapper( ).destroy( );
 
82
    LOG.error( ex, ex );
 
83
    System.exit( 123 );
 
84
  }
 
85
} catch( Exception ex ) {
 
86
  Databases.getBootstrapper( ).destroy( );
 
87
  LOG.error( ex, ex );
 
88
}