~ubuntu-branches/ubuntu/maverick/eucalyptus/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Dave Walker (Daviey)
  • Date: 2010-07-21 17:27:10 UTC
  • mfrom: (1.1.38 upstream)
  • Revision ID: james.westby@ubuntu.com-20100721172710-7xv07dmdqgivc3t9
Tags: 2.0~bzr1211-0ubuntu1
* New major upstream version merge, 2.0 (r1211).
* debian/patches/:
  - 01-wsdl-stubs.patch, debian/wsdl.md5sums: wsdl stubs updated.
  - 02-Makefile.patch: Updated to reflect new code layout.
  - 07-local_support_euca_conf-in.patch: Updated to reflect new code layout.
  - 08-ubuntu-default-networking.patch: Refreshed.
  - 09-small-128-192MB.patch: Updated to point to new location.
  - 10-disable-iscsi.patch: Refreshed.
  - 11-state-cleanup-memleakfix.patch: Removed, fixed upstream.
  - 15-fix-default-ramdisk.patch: Updated to point to new location.
  - 16-kvm_libvirt_xml_default_use_kvm.patch: Updated to reflect changes.
  - 17-fix_walrus_OOM_errors.patch: Removed, fixed upstream.
  - 18-priv_security.patch: Updated to reflect upstream changes.
  - 20-brute-force-webui.patch: Updated to reflect upstream changes. 
  - 21-eucalyptus-1.7-with-gwt-1.6.4.patch: New patch, allows 
    eucalyptus-1.7 to be built against gwt 1.6.4. Based on patch courtesy 
    of Dmitrii Zagorodnov, upstream. (LP: #597330)
* debian/eucalyptus-java-common.links: 
  - Changed symlink for groovy, point to groovy.all.jar, making compatiable 
    with groovy versions >1.7. (LP: #595421)
  - Added ant.jar & jetty-rewrite-handler.jar as they are now required.
* debian/control
  - & debian/build-jars: Added libjavassist-java and libjetty-extra-java as 
    build dependencies.
  - Added libjetty-extra-java as a dependency of eucalyptus-java-common
* The binary resulting jar's have been renamed from eucalyptus-*-1.6.2.jar
  to eucalyptus-*-main.jar:    
  - debian/eucalyptus-cc.upstart
  - debian/eucalyptus-cloud.install
  - debian/eucalyptus-common.eucalyptus.upstart
  - debian/eucalyptus-java-common.install
  - debian/eucalyptus-network.upstart
  - debian/eucalyptus-sc.install
  - debian/eucalyptus-walrus.install
* debian/eucalyptus-java-common.install: New upstream jars that have been
  installed:
  - eucalyptus-db-hsqldb-ext-main.jar
  - eucalyptus-component-main.jar
* debian/control:
  - Updated Standards Version to 3.8.4 (no change)
  - Updated the upstream Homepage to: http://open.eucalyptus.com/
  - Changed Vcs-Bzr to reflect new location of Ubuntu hosted development branch.
  - Made the Build Dependency of groovy and the binary eucalyptus-java-common
    package depend on version >=1.7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
package com.eucalyptus.bootstrap;
65
65
 
66
66
import java.net.URI;
67
 
import java.net.URISyntaxException;
 
67
import java.util.Arrays;
68
68
import java.util.List;
69
 
 
 
69
import java.util.NavigableSet;
70
70
import org.apache.log4j.Logger;
71
 
 
 
71
import com.eucalyptus.component.Components;
 
72
import com.eucalyptus.component.Service;
72
73
import com.eucalyptus.util.NetworkUtil;
73
74
 
 
75
@Deprecated
74
76
public enum Component {
75
 
  bootstrap( "vm://EucalyptusRequestQueue" ),
76
 
  eucalyptus( "vm://EucalyptusRequestQueue" ),
77
 
  walrus( "vm://BukkitInternal" ),
78
 
  dns( "vm://DNSControlInternal" ),
79
 
  storage( "vm://StorageInternal" ),
80
 
  db( "jdbc:hsqldb:hsqls://127.0.0.1:9001/eucalyptus" ),
81
 
  cluster( "vm://ClusterSink" ),
82
 
  jetty( "vm://HttpServer" ),
 
77
  bootstrap( true ),
 
78
  component( true ),
 
79
  eucalyptus( true ),
 
80
  walrus( true ),
 
81
  dns( true ),
 
82
  storage( false ),
 
83
  db( true ),
 
84
  jetty( true ),
 
85
  configuration( true ),
 
86
  cluster( false ),
83
87
  any( true );
84
 
  private static Logger      LOG         = Logger.getLogger( Component.class );
85
 
  private boolean            local       = false;
86
 
 
87
 
  private boolean            enabled     = false;
88
 
  private boolean            initialized = true;//FIXME: set this in some useful way
89
 
  private boolean            hasKeys     = false;
90
 
  private String             hostAddress;
91
 
  private int                port        = 8773;
92
 
  private String             localUri;
93
 
  private URI                uri;
94
 
  private String             propertyKey;
95
 
  private ResourceProvider   resourceProvider;
96
 
  private List<Bootstrapper> bootstrappers;
97
 
 
98
 
  private Component( ) {
99
 
    this.hostAddress = "localhost";
100
 
    this.propertyKey = "euca." + this.name( ) + ".host";
101
 
  }
102
 
 
103
 
  private Component( String uri ) {
104
 
    this( );
105
 
    this.localUri = uri;
106
 
    this.setUri( uri );
107
 
  }
108
 
 
109
 
  private Component( boolean whatever ) {
110
 
    this( );
111
 
    this.local = true;
112
 
    this.enabled = true;
113
 
  }
114
 
 
115
 
  public void markHasKeys( ) {
116
 
    this.hasKeys = true;
117
 
  }
118
 
 
119
 
  public boolean isHasKeys( ) {
120
 
    return hasKeys;
121
 
  }
122
 
 
123
 
  public void markEnabled( ) {
124
 
    this.enabled = true;
125
 
  }
126
 
 
127
 
  public void markDisabled( ) {
128
 
    this.enabled = false;
129
 
  }
130
 
 
131
 
  public boolean isEnabled( ) {
132
 
    return enabled;
133
 
  }
134
 
 
135
 
  public boolean isLocal( ) {
136
 
    return local;
137
 
  }
138
 
 
139
 
  public void markLocal( ) {
140
 
    this.local = true;
141
 
  }
142
 
 
143
 
  public ResourceProvider getResourceProvider( ) {
144
 
    return resourceProvider;
145
 
  }
146
 
 
147
 
  public void setResourceProvider( ResourceProvider resourceProvider ) {
148
 
    this.resourceProvider = resourceProvider;
149
 
  }
150
 
 
151
 
  public List<Bootstrapper> getBootstrappers( ) {
152
 
    return bootstrappers;
153
 
  }
154
 
 
155
 
  public boolean add( Bootstrapper arg0 ) {
156
 
    return bootstrappers.add( arg0 );
157
 
  }
158
 
 
159
 
  public String getHostAddress( ) {
160
 
    return this.hostAddress;
161
 
  }
162
 
 
163
 
  public void setHostAddress( String address ) {
164
 
    boolean isLocal = false;
165
 
    try {
166
 
      isLocal = NetworkUtil.testLocal( address );
167
 
    } catch ( Exception e1 ) {
168
 
    }
169
 
    if ( isLocal ) {
170
 
      this.local = true;
171
 
      this.hostAddress = "localhost";
172
 
      this.setUri( this.localUri );
173
 
    } else {
174
 
      this.local = false;
175
 
      this.hostAddress = address;
176
 
      this.setUri( makeUri( address ) );
177
 
    }
178
 
  }
179
 
 
180
 
  public String makeUri( String address ) {
181
 
    if ( Component.db.equals( this ) ) {
182
 
      return String.format( "jdbc:hsqldb:hsqls://%s:%d/eucalyptus", address, 9001 );
183
 
    } else {
184
 
      return String.format( "http://%s:%d/internal/%s", address, 8773, this.localUri.replaceAll( "vm://", "" ) );
185
 
    }
186
 
  }
187
 
 
188
 
  public String getPropertyKey( ) {
189
 
    return propertyKey;
190
 
  }
191
 
 
 
88
  private static Logger LOG = Logger.getLogger( Component.class );
 
89
  private final Boolean singleton;
 
90
  
 
91
  private Component( Boolean singleton ) {
 
92
    this.singleton = singleton;
 
93
  }
 
94
  
 
95
  public Boolean isEnabled( ) {
 
96
    return Components.lookup( this ).isEnabled( );
 
97
  }
 
98
  
 
99
  public Boolean isLocal( ) {
 
100
    return Components.lookup( this ).isLocal( );
 
101
  }
 
102
  
 
103
  public String getLocalAddress( ) {
 
104
    return this.getLocalUri( ).toASCIIString( );
 
105
  }
 
106
  
192
107
  public URI getUri( ) {
193
 
    return uri;
194
 
  }
195
 
 
196
 
  private void setUri( String uri ) {
197
 
    try {
198
 
      this.uri = new URI( uri );
199
 
      System.setProperty( this.propertyKey, this.uri.toASCIIString( ) );
200
 
      if ( LOG != null ) LOG.info( String.format( "-> Setting address of component %s to %s=%s", this.name( ), this.propertyKey, this.uri.toASCIIString( ) ) );
201
 
    } catch ( Exception e ) {
202
 
      System.setProperty( this.propertyKey, this.localUri );
203
 
      if ( LOG != null ) LOG.info( String.format( "-> Setting address of component %s to %s=%s", this.name( ), this.propertyKey, this.localUri ) );
 
108
    com.eucalyptus.component.Component c = Components.lookup( this );
 
109
    NavigableSet<Service> services = c.getServices( );
 
110
    if( this.isSingleton( ) && services.size( ) != 1 ) {
 
111
        throw new RuntimeException( "Singleton component has "+services.size()+" registered services (Should be exactly 1)." );
 
112
    } else if( this.isSingleton( ) && services.size( ) == 1 ) {
 
113
      return services.first( ).getUri( );
 
114
    } else {
 
115
      for( Service s : services ) {
 
116
        if( s.isLocal( ) ) {
 
117
          return s.getUri( );
 
118
        }
 
119
      }
 
120
      throw new RuntimeException( "Attempting to get the URI for a service which is either not a singleton or has no locally defined service endpoint." );
204
121
    }
205
122
  }
206
123
 
207
 
  public int getPort( ) {
208
 
    return port;
209
 
  }
210
 
 
211
 
  public void setPort( int port ) {
212
 
    this.port = port;
 
124
  public URI getLocalUri( ) {
 
125
    return Components.lookup( this ).getConfiguration( ).getLocalUri( );
 
126
  }
 
127
  
 
128
  public Boolean isSingleton( ) {
 
129
    return this.singleton;
 
130
  }
 
131
  
 
132
  public static List<Component> list( ) {
 
133
    return Arrays.asList( Component.values( ) );
213
134
  }
214
135
 
215
136
  public String getRegistryKey( String hostName ) {
216
 
    try {
217
 
      if ( NetworkUtil.testLocal( hostName ) ) return this.name( ) + "@localhost";
218
 
    } catch ( Exception e ) {
219
 
    }
220
 
    return this.name( ) + "@" + hostName;
221
 
  }
222
 
 
223
 
  public String getLocalAddress( ) {
224
 
    return localUri;
225
 
  }
226
 
 
227
 
  public URI getLocalUri( ) {
228
 
    if ( Component.db.equals( this ) ) { return null; }
229
 
    try {
230
 
      return new URI( this.localUri );
231
 
    } catch ( URISyntaxException e ) {
232
 
      LOG.fatal( "Failed to construct the default local URI object.", e );
233
 
      System.exit( 1 );
234
 
      return null;
235
 
    }
236
 
  }
237
 
 
238
 
  public boolean isInitialized( ) {
239
 
    return initialized;
240
 
  }
241
 
 
242
 
  public void setInitialized( boolean initialized ) {
243
 
    this.initialized = initialized;
244
 
  }
245
 
 
 
137
    if( NetworkUtil.testLocal( hostName ) ) {
 
138
      return this.name( ) + "@localhost";
 
139
    } else {
 
140
      return this.name( ) + "@" + hostName;
 
141
    }
 
142
  }
 
143
  
246
144
}