Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

EUCA-4128 euca-describe-volumes (verbose) takes a long time to return…

… with results
  • Loading branch information...
commit d6d042ce819570e89e62fff1ba13327a063c741d 1 parent 9933983
@mmunn1 mmunn1 authored
View
86 clc/modules/cluster-manager/src/main/java/com/eucalyptus/blockstorage/VolumeManager.java
@@ -62,9 +62,11 @@
package com.eucalyptus.blockstorage;
+import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.ExecutionException;
+import javax.persistence.EntityTransaction;
import org.apache.log4j.Logger;
import com.eucalyptus.auth.AuthException;
import com.eucalyptus.auth.principal.AccountFullName;
@@ -279,50 +281,58 @@ public DescribeVolumesResponseType DescribeVolumes( DescribeVolumesType request
}
};
Set<String> allowedVolumeIds = Entities.asTransaction( Volume.class, lookupVolumeIds ).apply( volumeIds );
- final Function<String, Volume> lookupVolume = new Function<String, Volume>( ) {
-
- @Override
- public Volume apply( String input ) {
- try {
- Volume foundVol = Entities.uniqueResult( Volume.named( ownerFullName, input ) );
- if ( State.ANNIHILATED.equals( foundVol.getState( ) ) ) {
- Entities.delete( foundVol );
- //Volumes.fireUsageEvent( foundVol, VolumeEvent.forVolumeDelete() );
- reply.getVolumeSet( ).add( foundVol.morph( new edu.ucsb.eucalyptus.msgs.Volume( ) ) );
- return foundVol;
- } else if ( RestrictedTypes.filterPrivileged( ).apply( foundVol ) ) {
- AttachedVolume attachedVolume = null;
- try {
- VmVolumeAttachment attachment = VmInstances.lookupVolumeAttachment( input );
- attachedVolume = VmVolumeAttachment.asAttachedVolume( attachment.getVmInstance( ) ).apply( attachment );
- } catch ( NoSuchElementException ex ) {
- if ( State.BUSY.equals( foundVol.getState( ) ) ) {
- foundVol.setState( State.EXTANT );
+ final EntityTransaction db = Entities.get( VmInstance.class );
+ try {
+ final List<VmInstance> vms = Entities.query( VmInstance.create( ) );
+ final Function<String, Volume> lookupVolume = new Function<String, Volume>( ) {
+ @Override
+ public Volume apply( String input ) {
+ try {
+ Volume foundVol = Entities.uniqueResult( Volume.named( ownerFullName, input ) );
+ if ( State.ANNIHILATED.equals( foundVol.getState( ) ) ) {
+ Entities.delete( foundVol );
+ //Volumes.fireUsageEvent( foundVol, VolumeEvent.forVolumeDelete() );
+ reply.getVolumeSet( ).add( foundVol.morph( new edu.ucsb.eucalyptus.msgs.Volume( ) ) );
+ return foundVol;
+ } else if ( RestrictedTypes.filterPrivileged( ).apply( foundVol ) ) {
+ AttachedVolume attachedVolume = null;
+ try {
+ VmVolumeAttachment attachment = VmInstances.lookupVolumeAttachment( input , vms );
+ attachedVolume = VmVolumeAttachment.asAttachedVolume( attachment.getVmInstance( ) ).apply( attachment );
+ } catch ( NoSuchElementException ex ) {
+ if ( State.BUSY.equals( foundVol.getState( ) ) ) {
+ foundVol.setState( State.EXTANT );
+ }
+ }
+ edu.ucsb.eucalyptus.msgs.Volume msgTypeVolume = foundVol.morph( new edu.ucsb.eucalyptus.msgs.Volume( ) );
+ if ( attachedVolume != null ) {
+ msgTypeVolume.setStatus( "in-use" );
+ msgTypeVolume.getAttachmentSet( ).add( attachedVolume );
}
+ reply.getVolumeSet( ).add( msgTypeVolume );
+ return foundVol;
}
- edu.ucsb.eucalyptus.msgs.Volume msgTypeVolume = foundVol.morph( new edu.ucsb.eucalyptus.msgs.Volume( ) );
- if ( attachedVolume != null ) {
- msgTypeVolume.setStatus( "in-use" );
- msgTypeVolume.getAttachmentSet( ).add( attachedVolume );
+ } catch ( NoSuchElementException ex ) {
+ throw ex;
+ } catch ( TransactionException ex ) {
+ throw Exceptions.toUndeclared( ex );
}
- reply.getVolumeSet( ).add( msgTypeVolume );
- return foundVol;
+ throw new NoSuchElementException( "Failed to lookup volume: " + input );
}
- } catch ( NoSuchElementException ex ) {
- throw ex;
- } catch ( TransactionException ex ) {
- throw Exceptions.toUndeclared( ex );
+ };
+ for ( String volId : allowedVolumeIds ) {
+ try {
+ Volume vol = Entities.asTransaction( Volume.class, lookupVolume ).apply( volId );
+ } catch ( Exception ex ) {
+ Logs.extreme( ).debug( ex, ex );
}
- throw new NoSuchElementException( "Failed to lookup volume: " + input );
- }
-
- };
- for ( String volId : allowedVolumeIds ) {
- try {
- Volume vol = Entities.asTransaction( Volume.class, lookupVolume ).apply( volId );
- } catch ( Exception ex ) {
- Logs.extreme( ).debug( ex, ex );
}
+ db.commit( );
+ } catch (Exception ex) {
+ Logs.extreme( ).error( ex , ex );
+ throw ex;
+ } finally {
+ if ( db.isActive() ) db.rollback();
}
return reply;
}
View
22 clc/modules/cluster-manager/src/main/java/com/eucalyptus/vm/VmInstances.java
@@ -348,6 +348,28 @@ public static VmVolumeAttachment lookupVolumeAttachment( final String volumeId )
}
}
+ public static VmVolumeAttachment lookupVolumeAttachment( final String volumeId , final List<VmInstance> vms ) {
+ VmVolumeAttachment ret = null;
+ try {
+ for ( VmInstance vm : vms ) {
+ try {
+ ret = vm.lookupVolumeAttachment( volumeId );
+ if ( ret.getVmInstance( ) == null ) {
+ ret.setVmInstance( vm );
+ }
+ } catch ( NoSuchElementException ex ) {
+ continue;
+ }
+ }
+ if ( ret == null ) {
+ throw new NoSuchElementException( "VmVolumeAttachment: no volume attachment for " + volumeId );
+ }
+ return ret;
+ } catch ( Exception ex ) {
+ throw new NoSuchElementException( ex.getMessage( ) );
+ }
+ }
+
public static VmInstance lookupByPublicIp( final String ip ) throws NoSuchElementException {
final EntityTransaction db = Entities.get( VmInstance.class );
try {
Please sign in to comment.
Something went wrong with that request. Please try again.