64
64
package com.eucalyptus.bootstrap;
66
66
import java.util.concurrent.atomic.AtomicBoolean;
68
67
import org.apache.log4j.Logger;
69
68
import org.hsqldb.Server;
70
69
import org.hsqldb.persist.HsqlProperties;
70
import com.eucalyptus.bootstrap.Bootstrap.Stage;
72
71
import com.eucalyptus.event.ClockTick;
73
72
import com.eucalyptus.event.Event;
74
73
import com.eucalyptus.event.EventListener;
75
74
import com.eucalyptus.event.ListenerRegistry;
76
import com.eucalyptus.util.DatabaseUtil;
77
import com.eucalyptus.util.DebugUtil;
78
import com.eucalyptus.util.FailScriptFailException;
79
import com.eucalyptus.util.GroovyUtil;
75
import com.eucalyptus.scripting.ScriptExecutionFailedException;
76
import com.eucalyptus.scripting.groovy.GroovyUtil;
77
import com.eucalyptus.system.Threads;
80
78
import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
82
@Provides( resource = Resource.Database )
83
@Depends( resources = Resource.SystemCredentials, local = Component.eucalyptus )
80
@Provides(Component.db)
81
@RunDuring(Bootstrap.Stage.DatabaseInit)
82
@DependsLocal(Component.eucalyptus)
84
83
public class LocalDatabaseBootstrapper extends Bootstrapper implements EventListener, Runnable, DatabaseBootstrapper {
85
84
private static Logger LOG = Logger.getLogger( LocalDatabaseBootstrapper.class );
86
85
private static DatabaseBootstrapper singleton;
120
public boolean load( Resource current ) throws Exception {
118
public boolean load( Stage current ) throws Exception {
122
LOG.debug( "Initializing SSL just in case: " + Class.forName( "com.eucalyptus.auth.util.SslSetup" ) );
120
LOG.debug( "Initializing SSL just in case: " + ClassLoader.getSystemClassLoader().loadClass( "com.eucalyptus.auth.util.SslSetup" ) );
123
121
} catch ( Throwable t ) {}
125
LOG.debug( "Initializing db password: " + Class.forName( "com.eucalyptus.auth.util.Hashes" ) );
123
LOG.debug( "Initializing db password: " + ClassLoader.getSystemClassLoader().loadClass( "com.eucalyptus.auth.util.Hashes" ) );
126
124
} catch ( Throwable t ) {}
127
125
createDatabase( );
140
138
private static AtomicBoolean hup = new AtomicBoolean( false );
141
139
public void hup( ) {
142
140
if( hup.compareAndSet( false, true ) ) {
143
DebugUtil.printDebugDetails( );
145
142
if ( this.db != null ) {
146
143
this.db.checkRunning( true );
159
156
private void createDatabase( ) {
161
158
GroovyUtil.evaluateScript( "before_database.groovy" );//TODO: move this ASAP!
162
} catch ( FailScriptFailException e ) {
159
} catch ( ScriptExecutionFailedException e ) {
163
160
LOG.fatal( e, e );
164
161
LOG.fatal( "Failed to initialize the database layer." );
165
162
System.exit( -1 );
167
164
this.db = new Server( );
168
165
this.db.setProperties( new HsqlProperties( DatabaseConfig.getProperties( ) ) );
169
SystemBootstrapper.makeSystemThread( this ).start( );
166
Threads.newThread( this ).start( );
171
168
GroovyUtil.evaluateScript( "after_database.groovy" );//TODO: move this ASAP!
172
} catch ( FailScriptFailException e ) {
169
} catch ( ScriptExecutionFailedException e ) {
173
170
LOG.fatal( e, e );
174
171
LOG.fatal( "Failed to initialize the persistence layer." );
175
172
System.exit( -1 );
180
177
public boolean start( ) throws Exception {
181
178
this.waitForDatabase( );
183
GroovyUtil.evaluateScript( "startup.groovy" );
184
} catch ( Exception e ) {
189
180
GroovyUtil.evaluateScript( "after_persistence.groovy" );//TODO: move this ASAP!
190
} catch ( FailScriptFailException e ) {
181
} catch ( ScriptExecutionFailedException e ) {
191
182
LOG.fatal( e, e );
192
183
LOG.fatal( "Failed to initialize the persistence layer." );
193
184
System.exit( -1 );