Skip to content

Commit

Permalink
destroy service, RT: #4537, #5274
Browse files Browse the repository at this point in the history
  • Loading branch information
chris grzegorczyk committed Jan 9, 2012
1 parent 130aa1e commit f128331
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 83 deletions.
Expand Up @@ -419,7 +419,7 @@ private static void fireCallback( final Cluster parent,
} finally {
if ( !transitionCallback.isDone( ) ) {
LOG.debug( parent.getFullName( ) + " transition fell through w/o completing: " + messageCallback );
Logs.exhaust( ).debug( Exceptions.toUndeclared( parent.getFullName( ) + " transition fell through w/o completing: " + messageCallback ) );
Logs.extreme( ).debug( Exceptions.toUndeclared( parent.getFullName( ) + " transition fell through w/o completing: " + messageCallback ) );
transitionCallback.fire( );
}
}
Expand Down Expand Up @@ -535,7 +535,7 @@ public void fire( final Cluster t ) {
@Override
public void fire( final Cluster t ) {
if ( !t.pendingErrors.isEmpty( ) ) {
Logs.exhaust( ).error( t.pendingErrors );
Logs.extreme( ).error( t.pendingErrors );
}
LOG.debug( "Clearing error logs for: " + t );
t.clearExceptions( );
Expand Down Expand Up @@ -840,19 +840,19 @@ public void start( ) throws ServiceRegistrationException {
Thread.currentThread( ).interrupt( );
} catch ( final ServiceRegistrationException ex ) {
lastEx = ex;
Logs.exhaust( ).debug( ex, ex );
Logs.extreme( ).debug( ex, ex );
} catch ( final Exception ex ) {
lastEx = ex;
Logs.exhaust( ).debug( ex, ex );
Logs.extreme( ).debug( ex, ex );
}
}
Listeners.register( Hertz.class, this );
}
} catch ( final NoSuchElementException ex ) {
Logs.exhaust( ).debug( ex, ex );
Logs.extreme( ).debug( ex, ex );
throw ex;
} catch ( final Exception ex ) {
Logs.exhaust( ).debug( ex, ex );
Logs.extreme( ).debug( ex, ex );
throw new ServiceRegistrationException( "Failed to call start() on cluster " + this.configuration
+ " because of: "
+ ex.getMessage( ), ex );
Expand Down Expand Up @@ -882,7 +882,7 @@ public void enable( ) throws ServiceRegistrationException {
throw fail;
}
} catch ( final Exception ex ) {
Logs.exhaust( ).debug( ex, ex );
Logs.extreme( ).debug( ex, ex );
throw new ServiceRegistrationException( "Failed to call enable() on cluster " + this.configuration
+ " because of: "
+ ex.getMessage( ), ex );
Expand All @@ -900,7 +900,7 @@ public void disable( ) throws ServiceRegistrationException {
} catch ( final InterruptedException ex ) {
Thread.currentThread( ).interrupt( );
} catch ( final Exception ex ) {
Logs.exhaust( ).debug( ex, ex );
Logs.extreme( ).debug( ex, ex );
// throw new ServiceRegistrationException( "Failed to call disable() on cluster " + this.configuration
// + " because of: "
// + ex.getMessage( ), ex );
Expand All @@ -917,7 +917,7 @@ public void stop( ) throws ServiceRegistrationException {
} catch ( final InterruptedException ex ) {
Thread.currentThread( ).interrupt( );
} catch ( final Exception ex ) {
Logs.exhaust( ).debug( ex, ex );
Logs.extreme( ).debug( ex, ex );
throw new ServiceRegistrationException( "Failed to call stop() on cluster " + this.configuration
+ " because of: "
+ ex.getMessage( ), ex );
Expand Down Expand Up @@ -1195,7 +1195,7 @@ public T newInstance( ) {
throw ex;
} catch ( final Exception ex ) {
LOG.error( ex );
Logs.exhaust( ).error( ex, ex );
Logs.extreme( ).error( ex, ex );
throw Exceptions.toUndeclared( ex );
}
}
Expand Down
Expand Up @@ -9,43 +9,42 @@
import com.eucalyptus.scripting.Groovyness;
import com.eucalyptus.util.EucalyptusCloudException;
import com.eucalyptus.util.Exceptions;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

public class Properties {
private static Logger LOG = Logger.getLogger( Properties.class );

public DescribePropertiesResponseType describeProperties( DescribePropertiesType request ) throws EucalyptusCloudException {

public DescribePropertiesResponseType describeProperties( final DescribePropertiesType request ) throws EucalyptusCloudException {
if ( !Contexts.lookup( ).hasAdministrativePrivileges( ) ) {
throw new EucalyptusCloudException( "You are not authorized to interact with this service." );
}
DescribePropertiesResponseType reply = request.getReply( );
List<Property> props = reply.getProperties( );
if ( request.getProperties( ).isEmpty( ) ) {
for ( ConfigurableProperty entry : PropertyDirectory.getPropertyEntrySet( ) ) {
final Predicate<ConfigurableProperty> filter = new Predicate<ConfigurableProperty>( ) {
public boolean apply( final ConfigurableProperty input ) {
if ( request.getProperties( ).isEmpty( ) ) {
return true;
} else if ( request.getProperties( ).contains( input.getQualifiedName( ) ) ) {
return true;
} else {
for ( String propRequest : request.getProperties( ) ) {
if ( input.getQualifiedName( ).startsWith( propRequest ) ) {
return true;
}
}
}
return false;
}
};
for ( ConfigurableProperty entry : Iterables.filter( PropertyDirectory.getPropertyEntrySet( ), filter ) ) {
if ( filter.apply( entry ) ) {
String value = "********";
if ( !entry.getWidgetType( ).equals( ConfigurableFieldType.KEYVALUEHIDDEN ) )
value = entry.getValue( );
props.add( new Property( entry.getQualifiedName( ), value, entry.getDescription( ) ) );
}
} else {
for ( ConfigurableProperty entry : PropertyDirectory.getPropertyEntrySet( ) ) {
if ( request.getProperties( ).contains( entry.getQualifiedName( ) ) ) {
String value = "********";
if ( !entry.getWidgetType( ).equals( ConfigurableFieldType.KEYVALUEHIDDEN ) )
value = entry.getValue( );
props.add( new Property( entry.getQualifiedName( ), value, entry.getDescription( ) ) );
}
}
for ( String entrySetName : PropertyDirectory.getPropertyEntrySetNames( ) ) {
if ( request.getProperties( ).contains( entrySetName ) ) {
String value = "********";
for ( ConfigurableProperty entry : PropertyDirectory.getPropertyEntrySet( entrySetName ) ) {
if ( !entry.getWidgetType( ).equals( ConfigurableFieldType.KEYVALUEHIDDEN ) ) {
value = entry.getValue( );
}
props.add( new Property( entry.getQualifiedName( ), value, entry.getDescription( ) ) );
}
}
}
}
return reply;
}
Expand Down
Expand Up @@ -63,7 +63,7 @@
* @author chris grzegorczyk <grze@eucalyptus.com>
*/

import java.util.List;
import java.util.NoSuchElementException;
import javax.persistence.PersistenceException;
import org.apache.log4j.Logger;
import com.eucalyptus.component.ComponentId.Partition;
Expand All @@ -88,6 +88,8 @@ public Boolean checkAdd( String partition, String name, String host, Integer por
ServiceConfiguration existingName = null;
try {
existingName = ServiceConfigurations.lookupByName( this.getComponentId( ).getClass( ), name );
} catch ( NoSuchElementException ex1 ) {
LOG.trace( "Failed to find existing component registration for name: " + name );
} catch ( PersistenceException ex1 ) {
LOG.trace( "Failed to find existing component registration for name: " + name );
}
Expand All @@ -97,15 +99,19 @@ public Boolean checkAdd( String partition, String name, String host, Integer por
if ( !manyToOne ) {
if ( this.getComponentId( ).isPartitioned( ) ) {
if ( ServiceConfigurations.listPartition( this.getComponentId( ).getClass( ), partition ).size( ) >= 2 ) {
throw new ServiceRegistrationException( "Unable to register more than two services in a partition for component type: " + this.getComponentId( ).getName( ) );
throw new ServiceRegistrationException( "Unable to register more than two services in a partition for component type: "
+ this.getComponentId( ).getName( ) );
}
} else {
if ( ServiceConfigurations.list( this.getComponentId( ).getClass( ) ).size( ) >= 2 ) {
throw new ServiceRegistrationException( "Unable to register more than two services in a partition for component type: " + this.getComponentId( ).getName( ) );
throw new ServiceRegistrationException( "Unable to register more than two services in a partition for component type: "
+ this.getComponentId( ).getName( ) );
}
}
try {
existingHost = ServiceConfigurations.lookupByHost( this.getComponentId( ).getClass( ), host );
} catch ( NoSuchElementException ex1 ) {
LOG.trace( "Failed to find existing component registration for host: " + name );
} catch ( PersistenceException ex1 ) {
LOG.trace( "Failed to find existing component registration for host: " + host );
}
Expand All @@ -115,9 +121,21 @@ public Boolean checkAdd( String partition, String name, String host, Integer por
+ this.getComponentId( ).getName( ) );
}
}
/**
* @grze check here if we have an existing identical registration and return false in this case
* -- caller should handle it differently than an exception
*/
if ( existingName != null && existingHost != null ) {
return false;
} else if ( existingName == null && existingHost == null ) {
ServiceConfiguration maybeIdenticalConfig = existingName;
if ( existingName.equals( existingHost )
&& maybeIdenticalConfig.getName( ).equals( name )
&& maybeIdenticalConfig.getPartition( ).equals( partition )
&& maybeIdenticalConfig.getHostName( ).equals( host )
&& maybeIdenticalConfig.getPort( ).equals( port ) ) {
return false;
}
}
if ( existingName == null && existingHost == null ) {
return true;
} else if ( existingName != null ) {
throw new ServiceRegistrationException( "Component with name=" + name + " already exists with host=" + existingName.getHostName( ) );
Expand Down
Expand Up @@ -65,6 +65,7 @@

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.NoSuchElementException;
import java.util.concurrent.Future;
import javax.persistence.PersistenceException;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -116,7 +117,7 @@ public static boolean register( final ComponentId compId, String partitionName,
+ ":"
+ port );
if ( !builder.checkAdd( partition, name, hostName, port ) ) {
LOG.info( "Returning existing registration information for: "
LOG.info( "Returning existing registration information for: "
+ partition
+ "."
+ name
Expand All @@ -133,8 +134,8 @@ public static boolean register( final ComponentId compId, String partitionName,
Partition part = Partitions.lookup( newComponent );
part.syncKeysToDisk( );
Partition p = Partitions.lookup( newComponent );
Logs.exhaust( ).info( p.getCertificate( ) );
Logs.exhaust( ).info( p.getNodeCertificate( ) );
Logs.extreme( ).info( p.getCertificate( ) );
Logs.extreme( ).info( p.getNodeCertificate( ) );
}
ServiceConfigurations.store( newComponent );
try {
Expand Down Expand Up @@ -170,25 +171,49 @@ public void run( ) {
public static boolean deregister( final ComponentId compId, String name ) throws ServiceRegistrationException, EucalyptusCloudException {
final ServiceBuilder<?> builder = ServiceBuilders.lookup( compId );
LOG.info( "Using builder: " + builder.getClass( ).getSimpleName( ) );
boolean proceedOnError = false;
try {
if ( !checkRemove( builder, name ) ) {
LOG.info( builder.getClass( ).getSimpleName( ) + ": checkRemove failed." );
throw new ServiceRegistrationException( builder.getClass( ).getSimpleName( ) + ": checkRemove returned false. "
+
"It is unsafe to currently deregister, please check the logs for additional information." );
}
} catch ( final NoSuchElementException ex ) {
LOG.info( "Silently proceeding with deregister for non-existant configuration" );
proceedOnError = true;
} catch ( Exception e ) {
LOG.info( builder.getClass( ).getSimpleName( ) + ": checkRemove failed." );
throw new ServiceRegistrationException( builder.getClass( ).getSimpleName( ) + ": checkRemove failed with message: "
+ e.getMessage( ), e );
+ e.getMessage( ), e );
}
try{
final ServiceConfiguration conf = ServiceConfigurations.lookupByName( compId.getClass( ), name );
Topology.destroy( conf );
ServiceConfigurations.remove( conf );
}catch(Exception e){
LOG.info(builder.getClass().getSimpleName() + ": deregistration failed because of" + e.getMessage());
throw new ServiceRegistrationException(builder.getClass().getSimpleName() + ": deregistration failed because of" + e.getMessage(), e);
try {
ServiceConfiguration conf;
try {
conf = ServiceConfigurations.lookupByName( compId.getClass( ), name );
} catch ( NoSuchElementException ex1 ) {
conf = Components.lookup( compId.getClass( ) ).lookup( name );
}
try {
Topology.destroy( conf );
} catch ( Exception ex ) {
LOG.error( ex );
Logs.extreme( ).debug( ex, ex );
}
try {
ServiceConfigurations.remove( conf );
} catch ( Exception ex ) {
LOG.error( ex );
Logs.extreme( ).debug( ex, ex );
}
} catch ( Exception e ) {
if ( proceedOnError ) {
LOG.info( builder.getClass( ).getSimpleName( ) + ": deregistration error, but proceeding since config has been removed: " + e.getMessage( ) );
return true;
} else {
LOG.info( builder.getClass( ).getSimpleName( ) + ": deregistration failed because of" + e.getMessage( ) );
throw new ServiceRegistrationException( builder.getClass( ).getSimpleName( ) + ": deregistration failed because of: " + e.getMessage( ), e );
}
}
return true;
}
Expand All @@ -206,6 +231,8 @@ private static boolean checkRemove( ServiceBuilder builder, String name ) {
conf.setName( name );
ServiceConfigurations.lookup( conf );
return true;
} catch ( final NoSuchElementException ex ) {
throw ex;
} catch ( PersistenceException e ) {
throw Exceptions.toUndeclared( e );
} catch ( Exception e ) {
Expand Down
Expand Up @@ -51,18 +51,18 @@ private enum DatabaseProvider {
INSTANCE;

public <T extends ServiceConfiguration> List<T> list( final T example ) {
final EntityWrapper<T> db = EntityWrapper.get( example );
final EntityTransaction db = Entities.get( example.getClass( ) );
List<T> componentList;
try {
componentList = db.query( example );
componentList = Entities.query( example );
db.commit( );
return componentList;
} catch ( final PersistenceException ex ) {
LOG.trace( ex );
LOG.debug( ex );
db.rollback( );
throw ex;
} catch ( final Throwable ex ) {
LOG.trace( ex );
LOG.debug( ex );
db.rollback( );
throw new PersistenceException( "Service configuration lookup failed for: " + LogUtil.dumpObject( example ), ex );
}
Expand All @@ -75,30 +75,33 @@ public <T extends ServiceConfiguration> T lookup( final T example ) {
existingName = Entities.uniqueResult( example );
db.commit( );
return existingName;
} catch ( final NoSuchElementException ex ) {
db.rollback( );
throw ex;
} catch ( final PersistenceException ex ) {
LOG.trace( ex );
LOG.debug( ex );
db.rollback( );
throw ex;
} catch ( final Throwable ex ) {
LOG.trace( ex );
LOG.debug( ex );
db.rollback( );
throw new PersistenceException( "Service configuration lookup failed for: " + LogUtil.dumpObject( example ), ex );
}
}

public <T extends ServiceConfiguration> T store( T config ) {
final EntityWrapper<T> db = EntityWrapper.get( config );
final EntityTransaction db = Entities.get( config.getClass( ) );
try {
config = db.persist( config );
config = Entities.persist( config );
db.commit( );
EventRecord.here( ServiceConfigurations.class, EventClass.COMPONENT, EventType.COMPONENT_REGISTERED, config.toString( ) ).info( );
} catch ( final PersistenceException ex ) {
LOG.trace( ex );
LOG.debug( ex );
EventRecord.here( ServiceConfigurations.class, EventClass.COMPONENT, EventType.COMPONENT_REGISTERED, "FAILED", config.toString( ) ).error( );
db.rollback( );
throw ex;
} catch ( final Throwable ex ) {
LOG.trace( ex );
LOG.debug( ex );
EventRecord.here( ServiceConfigurations.class, EventClass.COMPONENT, EventType.COMPONENT_REGISTERED, "FAILED", config.toString( ) ).error( );
db.rollback( );
throw new PersistenceException( "Service configuration storing failed for: " + LogUtil.dumpObject( config ), ex );
Expand All @@ -107,21 +110,23 @@ public <T extends ServiceConfiguration> T store( T config ) {
}

public <T extends ServiceConfiguration> T remove( final T config ) {
final EntityWrapper<T> db = EntityWrapper.get( config );
final EntityTransaction db = Entities.get( config.getClass( ) );
try {
final T searchConfig = ( T ) config.getClass( ).newInstance( );
searchConfig.setName( config.getName( ) );
final T exists = db.getUnique( searchConfig );
db.delete( exists );
final T exists = Entities.uniqueResult( searchConfig );
Entities.delete( exists );
db.commit( );
EventRecord.here( ServiceConfigurations.class, EventClass.COMPONENT, EventType.COMPONENT_DEREGISTERED, config.toString( ) ).info( );
} catch ( final NoSuchElementException ex ) {
db.rollback( );
} catch ( final PersistenceException ex ) {
LOG.trace( ex );
LOG.debug( ex );
EventRecord.here( ServiceConfigurations.class, EventClass.COMPONENT, EventType.COMPONENT_DEREGISTERED, "FAILED", config.toString( ) ).error( );
db.rollback( );
throw ex;
} catch ( final Throwable ex ) {
LOG.trace( ex );
LOG.debug( ex );
EventRecord.here( ServiceConfigurations.class, EventClass.COMPONENT, EventType.COMPONENT_DEREGISTERED, "FAILED", config.toString( ) ).error( );
db.rollback( );
throw new PersistenceException( "Service configuration removal failed for: " + LogUtil.dumpObject( config ), ex );
Expand Down

0 comments on commit f128331

Please sign in to comment.