64
64
package com.eucalyptus.bootstrap;
66
66
import java.net.URI;
67
import java.net.URISyntaxException;
67
import java.util.Arrays;
68
68
import java.util.List;
69
import java.util.NavigableSet;
70
70
import org.apache.log4j.Logger;
71
import com.eucalyptus.component.Components;
72
import com.eucalyptus.component.Service;
72
73
import com.eucalyptus.util.NetworkUtil;
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" ),
85
configuration( true ),
84
private static Logger LOG = Logger.getLogger( Component.class );
85
private boolean local = false;
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;
94
private String propertyKey;
95
private ResourceProvider resourceProvider;
96
private List<Bootstrapper> bootstrappers;
98
private Component( ) {
99
this.hostAddress = "localhost";
100
this.propertyKey = "euca." + this.name( ) + ".host";
103
private Component( String uri ) {
109
private Component( boolean whatever ) {
115
public void markHasKeys( ) {
119
public boolean isHasKeys( ) {
123
public void markEnabled( ) {
127
public void markDisabled( ) {
128
this.enabled = false;
131
public boolean isEnabled( ) {
135
public boolean isLocal( ) {
139
public void markLocal( ) {
143
public ResourceProvider getResourceProvider( ) {
144
return resourceProvider;
147
public void setResourceProvider( ResourceProvider resourceProvider ) {
148
this.resourceProvider = resourceProvider;
151
public List<Bootstrapper> getBootstrappers( ) {
152
return bootstrappers;
155
public boolean add( Bootstrapper arg0 ) {
156
return bootstrappers.add( arg0 );
159
public String getHostAddress( ) {
160
return this.hostAddress;
163
public void setHostAddress( String address ) {
164
boolean isLocal = false;
166
isLocal = NetworkUtil.testLocal( address );
167
} catch ( Exception e1 ) {
171
this.hostAddress = "localhost";
172
this.setUri( this.localUri );
175
this.hostAddress = address;
176
this.setUri( makeUri( address ) );
180
public String makeUri( String address ) {
181
if ( Component.db.equals( this ) ) {
182
return String.format( "jdbc:hsqldb:hsqls://%s:%d/eucalyptus", address, 9001 );
184
return String.format( "http://%s:%d/internal/%s", address, 8773, this.localUri.replaceAll( "vm://", "" ) );
188
public String getPropertyKey( ) {
88
private static Logger LOG = Logger.getLogger( Component.class );
89
private final Boolean singleton;
91
private Component( Boolean singleton ) {
92
this.singleton = singleton;
95
public Boolean isEnabled( ) {
96
return Components.lookup( this ).isEnabled( );
99
public Boolean isLocal( ) {
100
return Components.lookup( this ).isLocal( );
103
public String getLocalAddress( ) {
104
return this.getLocalUri( ).toASCIIString( );
192
107
public URI getUri( ) {
196
private void setUri( String uri ) {
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( );
115
for( Service s : services ) {
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." );
207
public int getPort( ) {
211
public void setPort( int port ) {
124
public URI getLocalUri( ) {
125
return Components.lookup( this ).getConfiguration( ).getLocalUri( );
128
public Boolean isSingleton( ) {
129
return this.singleton;
132
public static List<Component> list( ) {
133
return Arrays.asList( Component.values( ) );
215
136
public String getRegistryKey( String hostName ) {
217
if ( NetworkUtil.testLocal( hostName ) ) return this.name( ) + "@localhost";
218
} catch ( Exception e ) {
220
return this.name( ) + "@" + hostName;
223
public String getLocalAddress( ) {
227
public URI getLocalUri( ) {
228
if ( Component.db.equals( this ) ) { return null; }
230
return new URI( this.localUri );
231
} catch ( URISyntaxException e ) {
232
LOG.fatal( "Failed to construct the default local URI object.", e );
238
public boolean isInitialized( ) {
242
public void setInitialized( boolean initialized ) {
243
this.initialized = initialized;
137
if( NetworkUtil.testLocal( hostName ) ) {
138
return this.name( ) + "@localhost";
140
return this.name( ) + "@" + hostName;