Skip to content
Browse files

make sure to setup local detachment state before sending request to S…

…C or NC.
  • Loading branch information...
2 parents 3a9402e + 51d1b47 commit 11f33b946ac94b208639eed11f952f2451f70499 @grze grze committed Jan 6, 2012
View
11 clc/modules/cluster-manager/src/main/java/com/eucalyptus/blockstorage/VolumeManager.java
@@ -433,18 +433,19 @@ public DetachVolumeResponseType detach( DetachVolumeType request ) throws Eucaly
LOG.error( ex, ex );
throw new EucalyptusCloudException( "Failed to lookup SC for partition: " + vm.getPartition( ), ex );
}
+ request.setVolumeId( volume.getVolumeId( ) );
+ request.setRemoteDevice( volume.getRemoteDevice( ) );
+ request.setDevice( volume.getDevice( ).replaceAll( "unknown,requested:", "" ) );
+ request.setInstanceId( vm.getInstanceId( ) );
+ VolumeDetachCallback ncDetach = new VolumeDetachCallback( request );
try {
AsyncRequests.sendSync( scVm, new DetachStorageVolumeType( cluster.getNode( vm.getServiceTag( ) ).getIqn( ), volume.getVolumeId( ) ) );
} catch ( Exception e ) {
LOG.debug( e );
Logs.extreme( ).debug( e, e );
//GRZE: attach is idempotent, failure here is ok. throw new EucalyptusCloudException( e.getMessage( ) );
}
- request.setVolumeId( volume.getVolumeId( ) );
- request.setRemoteDevice( volume.getRemoteDevice( ) );
- request.setDevice( volume.getDevice( ).replaceAll( "unknown,requested:", "" ) );
- request.setInstanceId( vm.getInstanceId( ) );
- AsyncRequests.newRequest( new VolumeDetachCallback( request ) ).dispatch( cluster.getConfiguration( ) );
+ AsyncRequests.newRequest( ncDetach ).dispatch( cluster.getConfiguration( ) );
EventRecord.here( VolumeManager.class, EventClass.VOLUME, EventType.VOLUME_DETACH )
.withDetails( vm.getOwner( ).toString( ), volume.getVolumeId( ), "instance", vm.getInstanceId( ) )
.withDetails( "cluster", ccConfig.getFullName( ).toString( ) ).info( );
View
9 ...s/cluster-manager/src/main/java/com/eucalyptus/cluster/callback/VolumeDetachCallback.java
@@ -65,12 +65,14 @@
import org.apache.log4j.Logger;
import com.eucalyptus.entities.Entities;
+import com.eucalyptus.util.Exceptions;
import com.eucalyptus.util.LogUtil;
import com.eucalyptus.util.async.ConnectionException;
import com.eucalyptus.util.async.FailedRequestException;
import com.eucalyptus.util.async.MessageCallback;
import com.eucalyptus.vm.VmInstance;
import com.eucalyptus.vm.VmInstances;
+import com.eucalyptus.vm.VmVolumeAttachment;
import com.eucalyptus.vm.VmVolumeAttachment.AttachmentState;
import com.google.common.base.Function;
import edu.ucsb.eucalyptus.msgs.AttachedVolume;
@@ -85,8 +87,13 @@ public VolumeDetachCallback( DetachVolumeType request ) {
super( request );
final Function<String, VmInstance> removeVolAttachment = new Function<String, VmInstance>( ) {
public VmInstance apply( final String input ) {
+ String volumeId = VolumeDetachCallback.this.getRequest( ).getVolumeId( );
VmInstance vm = VmInstances.lookup( input );
- vm.updateVolumeAttachment( VolumeDetachCallback.this.getRequest( ).getVolumeId( ), AttachmentState.detaching );
+ VmVolumeAttachment volumeAttachment = vm.lookupVolumeAttachment( volumeId );
+ if ( !VmVolumeAttachment.AttachmentState.attached.equals( volumeAttachment.getAttachmentState( ) ) ) {
+ throw Exceptions.toUndeclared( "Failed to detach volume which is already detaching: " + volumeId );
+ }
+ vm.updateVolumeAttachment( volumeId, AttachmentState.detaching );
return vm;
}
};

0 comments on commit 11f33b9

Please sign in to comment.
Something went wrong with that request. Please try again.