~graziano.obertelli/eucalyptus/lp683800

« back to all changes in this revision

Viewing changes to clc/modules/msgs/src/main/java/com/eucalyptus/bootstrap/BootstrapFactory.java

- initial implementation of get/set property with support for static and db-singletons, tools in clc/tools/src/
- initial implementation of user control, tools in clc/tools/src
- basic stubs of client tools for register-component (only for CC right now)
- support for binding discovery (no need to seed bindings anymore)
- fixes invocation of defered initializers in the remote vs. local case
- support for pluggable "discovery" during bootstrap; e.g., see BootstrapperDiscovery

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
import com.eucalyptus.util.BaseDirectory;
78
78
import com.eucalyptus.util.EucalyptusProperties;
79
79
import com.eucalyptus.util.LogUtil;
80
 
import com.eucalyptus.util.ServiceJarFile;
81
80
import com.google.common.collect.Lists;
82
81
import com.google.common.collect.Multimap;
83
82
import com.google.common.collect.Multimaps;
105
104
      }
106
105
    }
107
106
  }
108
 
 
109
 
  public static void initBootstrappers( ) {
 
107
  
 
108
  public static void initDiscovery( ) {
110
109
    File libDir = new File( BaseDirectory.LIB.toString( ) );
111
110
    for ( File f : libDir.listFiles( ) ) {
112
111
      if ( f.getName( ).startsWith( Component.eucalyptus.name() ) && f.getName( ).endsWith( ".jar" ) && !f.getName( ).matches( ".*-ext-.*" ) ) {
113
112
        LOG.debug( "Found eucalyptus component jar: " + f.getName( ) );
114
 
        ServiceJarFile jar;
115
113
        try {
116
 
          jar = new ServiceJarFile( f );
 
114
          ServiceJarDiscovery.processFile( f );
117
115
        } catch ( IOException e ) {
118
116
          LOG.error( e.getMessage( ) );
119
117
          continue;
120
118
        }
121
 
        List<Bootstrapper> bsList = jar.getBootstrappers( );
122
 
        for ( Bootstrapper bootstrap : bsList ) {
123
 
          for ( Resource r : Resource.values( ) ) {
124
 
            if ( r.providedBy( bootstrap.getClass( ) ) || Resource.Final.equals( r ) ) {
125
 
              Provides provides = bootstrap.getClass( ).getAnnotation( Provides.class );
126
 
              if( provides == null ) {
127
 
                LOG.info( "-X Skipping bootstrapper " + bootstrap.getClass( ).getSimpleName( ) + " since Provides is not specified." );
128
 
              } else {
129
 
                Component component = provides.component( );
130
 
                if ( component != null && !component.isEnabled( ) ) {
131
 
                  LOG.info( "-X Skipping bootstrapper " + bootstrap.getClass( ).getSimpleName( ) + " since Provides.component=" + component.toString( ) + " is disabled." );
132
 
                  break;
133
 
                }
134
 
                if ( checkDepends( bootstrap ) ) {
135
 
                  try {
136
 
                    r.add( bootstrap );
137
 
                  } catch ( Throwable e ) {
138
 
                    LOG.fatal( e, e );
139
 
                    for( Bootstrapper exists : r.getBootstrappers( ) ) {
140
 
                      if( exists.equals( bootstrap ) ) {
141
 
                        LOG.fatal( "Duplicate bootstrapper registration: " + exists.getClass( ) + 
142
 
                        "\n==> Old definition source: " + exists.getClass( ).getProtectionDomain( ).getCodeSource( ).getLocation( ).getPath( ) +
143
 
                        "\n==> New definition source: " + f.getAbsolutePath( ) );
144
 
                      }
145
 
                    }
146
 
                    System.exit( 1 );
147
 
                  }
148
 
                  LOG.info( "-> Associated bootstrapper " + bootstrap.getClass( ).getSimpleName( ) + " with resource " + r.toString( ) + "." );
149
 
                  break;
150
 
                }
 
119
      }
 
120
    }
 
121
    ServiceJarDiscovery.runDiscovery( );
 
122
  }
 
123
 
 
124
  public static void initBootstrappers( ) {
 
125
    for ( Bootstrapper bootstrap : BootstrapperDiscovery.getBootstrappers( ) ) {
 
126
      for ( Resource r : Resource.values( ) ) {
 
127
        if ( r.providedBy( bootstrap.getClass( ) ) || Resource.Final.equals( r ) ) {
 
128
          Provides provides = bootstrap.getClass( ).getAnnotation( Provides.class );
 
129
          if ( provides == null ) {
 
130
            LOG.info( "-X Skipping bootstrapper " + bootstrap.getClass( ).getSimpleName( ) + " since Provides is not specified." );
 
131
          } else {
 
132
            Component component = provides.component( );
 
133
            if ( component != null && !component.isEnabled( ) ) {
 
134
              LOG.info( "-X Skipping bootstrapper " + bootstrap.getClass( ).getSimpleName( ) + " since Provides.component=" + component.toString( )
 
135
                        + " is disabled." );
 
136
              break;
 
137
            }
 
138
            if ( checkDepends( bootstrap ) ) {
 
139
              try {
 
140
                r.add( bootstrap );
 
141
              } catch ( Throwable e ) {
 
142
                LOG.fatal( e, e );
 
143
                System.exit( 1 );
151
144
              }
 
145
              LOG.info( "-> Associated bootstrapper " + bootstrap.getClass( ).getSimpleName( ) + " with resource " + r.toString( ) + "." );
 
146
              break;
152
147
            }
153
148
          }
154
149
        }
155
 
        try {
156
 
                        jar.close();
157
 
                } catch (IOException e) {
158
 
                        LOG.error(e);
159
 
                }
160
150
      }
161
151
    }
162
152
  }