Permalink
Browse files

Fixes EUCA-2208

Allow instance to be restarted once bundling is completed
Merge branch 'team/clc-dev/EUCA-2208-MASTER' into testing

Conflicts:
	net/vnetwork.c
	node/handlers.c
	util/fault.c
  • Loading branch information...
2 parents cafbf39 + a2bde0f commit a3655461330d302703d2d674dc75878437f72525 @gelinasc gelinasc committed Oct 7, 2012
@@ -131,6 +131,35 @@ public void fire( CancelBundleTaskResponseType reply ) {
}
}
+ public static MessageCallback bundleRestartInstanceCallback( BundleRestartInstanceType request ) {
+ return new BundleRestartInstanceCallback( request );
+ }
+
+ public static class BundleRestartInstanceCallback extends MessageCallback<BundleRestartInstanceType, BundleRestartInstanceResponseType> {
+ private BundleRestartInstanceCallback( BundleRestartInstanceType request ) {
+ super( request );
+ }
+
+ @Override
+ public void fire( BundleRestartInstanceResponseType reply ) {
+ if ( !reply.get_return( ) ) {
+ LOG.info( "Attempt to restart bundle instance " + this.getRequest( ).getInstanceId( ) + " has failed." );
+ } else {
+ EntityTransaction db = Entities.get( VmInstance.class );
+ try {
+ VmInstance vm = VmInstances.lookup( this.getRequest( ).getInstanceId( ) );
+ vm.getRuntimeState( ).restartBundleTask( );
+ EventRecord.here( CancelBundleCallback.class, EventType.BUNDLE_RESTART, this.getRequest( ).toSimpleString( ), vm.getRuntimeState( ).getBundleTask( ).getBundleId( ),
+ vm.getInstanceId( ) ).info( );
+ db.commit( );
+ } catch ( Exception ex ) {
+ Logs.exhaust( ).error( ex, ex );
+ db.rollback( );
+ }
+ }
+ }
+ }
+
public static class BundleCallback extends MessageCallback<BundleInstanceType, BundleInstanceResponseType> {
private BundleCallback( BundleInstanceType request ) {
super( request );
@@ -103,6 +103,14 @@ public class BundleInstanceType extends VmBundleMessage {
public class BundleInstanceResponseType extends VmBundleMessage {
BundleTask task;
}
+
+public class BundleRestartInstanceType extends VmBundleMessage {
+ String instanceId;
+}
+public class BundleRestartInstanceResponseType extends VmBundleMessage {
+ BundleTask task;
+}
+
public class CancelBundleTaskType extends VmBundleMessage {
String bundleId;
String instanceId;
@@ -73,7 +73,7 @@
@Embeddable
public class VmBundleTask {
public enum BundleState {
- none( "none" ), pending( null ), storing( "bundling" ), canceling( null ), complete( "succeeded" ), failed( "failed" );
+ none( "none" ), pending( null ), storing( "bundling" ), canceling( null ), cancelled( "cancelled" ), complete( "succeeded" ), failed( "failed" );
private String mappedState;
BundleState( final String mappedState ) {
@@ -102,6 +102,7 @@
import com.eucalyptus.util.Exceptions;
import com.eucalyptus.util.async.AsyncRequests;
import com.eucalyptus.util.async.CheckedListenableFuture;
+import com.eucalyptus.vm.Bundles.BundleCallback;
import com.eucalyptus.vm.VmBundleTask.BundleState;
import com.eucalyptus.vm.VmInstance.Reason;
import com.eucalyptus.vm.VmInstance.VmState;
@@ -396,32 +397,44 @@ public Boolean cancelBundleTask( ) {
}
}
- public Boolean submittedBundleTask( ) {
- if ( this.getBundleTask( ) != null && this.getBundleTask( ).getState( ).ordinal( ) >= BundleState.storing.ordinal( ) ) {
- this.getBundleTask( ).setState( BundleState.storing );
- EventRecord.here( VmRuntimeState.class, EventType.BUNDLE_STARTING,
- this.vmInstance.getOwner( ).toString( ),
- this.getBundleTask( ).getBundleId( ),
- this.getVmInstance( ).getInstanceId( ),
- "" + this.getBundleTask( ).getState( ) ).info( );
- return true;
- } else if ( BundleState.canceling.equals( this.getBundleTaskState( ) ) ) {
- EventRecord.here( VmRuntimeState.class, EventType.BUNDLE_CANCELLED, this.vmInstance.getOwner( ).toString( ), this.getBundleTask( ).getBundleId( ),
+ public Boolean restartBundleTask( ) {
+ if ( this.getBundleTask( ) != null ) {
+ this.getBundleTask( ).setState( BundleState.none );
+ EventRecord.here( VmRuntimeState.class, EventType.BUNDLE_RESTART, this.vmInstance.getOwner( ).toString( ), this.getBundleTask( ).getBundleId( ),
this.getVmInstance( ).getInstanceId( ),
"" + this.getBundleTask( ).getState( ) ).info( );
- this.resetBundleTask( );
return true;
- } else {
- return false;
}
+ return false;
+ }
+
+ public Boolean submittedBundleTask( ) {
+ if ( this.getBundleTask( ) != null ) {
+ if ( BundleState.cancelled.equals( this.getBundleTaskState( ) ) ) {
+ EventRecord.here( VmRuntimeState.class, EventType.BUNDLE_CANCELLED, this.vmInstance.getOwner( ).toString( ), this.getBundleTask( ).getBundleId( ),
+ this.getVmInstance( ).getInstanceId( ),
+ "" + this.getBundleTask( ).getState( ) ).info( );
+ this.resetBundleTask( );
+ return true;
+ } else if ( this.getBundleTask( ).getState( ).ordinal( ) >= BundleState.storing.ordinal( ) ) {
+ this.getBundleTask( ).setState( BundleState.storing );
+ EventRecord.here( VmRuntimeState.class, EventType.BUNDLE_STARTING,
+ this.vmInstance.getOwner( ).toString( ),
+ this.getBundleTask( ).getBundleId( ),
+ this.getVmInstance( ).getInstanceId( ),
+ "" + this.getBundleTask( ).getState( ) ).info( );
+ return true;
+ }
+ }
+ return false;
}
public Boolean startBundleTask( final VmBundleTask task ) {
if ( !this.isBundling( ) ) {
this.bundleTask = task;
return true;
} else {
- if ( ( this.getBundleTask( ) != null ) && ( BundleState.failed.equals( task.getState() ) || BundleState.canceling.equals( task.getState() ) ) ) {
+ if ( ( this.getBundleTask( ) != null ) && ( BundleState.failed.equals( task.getState() ) || BundleState.canceling.equals( task.getState() ) || BundleState.cancelled.equals( task.getState() ) ) ) {
this.resetBundleTask( );
this.bundleTask = task;
return true;
@@ -496,14 +509,43 @@ public void updateBundleTaskState( String state ) {
updateBundleTaskState( next );
}
+ public void bundleRestartInstance(VmBundleTask bundleTask) {
+ BundleState state = bundleTask.getState();
+ if(BundleState.complete.equals(state) || BundleState.failed.equals(state) || BundleState.cancelled.equals(state)) {
+ final BundleRestartInstanceType request = new BundleRestartInstanceType();
+ final BundleRestartInstanceResponseType reply = request.getReply();
+
+ reply.set_return(true);
+ try {
+ LOG.info(EventRecord.here(BundleCallback.class, EventType.BUNDLE_RESTART, vmInstance.getOwner().getUserName(),
+ bundleTask.getBundleId(),
+ vmInstance.getInstanceId()));
+
+ ServiceConfiguration ccConfig = Topology.lookup(ClusterController.class, vmInstance.lookupPartition());
+ final Cluster cluster = Clusters.lookup(ccConfig );
+
+ request.setInstanceId(vmInstance.getInstanceId());
+ reply.setTask(Bundles.transform(bundleTask));
+ AsyncRequests.newRequest(Bundles.bundleRestartInstanceCallback(request)).dispatch(cluster.getConfiguration());
+ } catch (final Exception e) {
+ Logs.extreme().trace("Failed to find bundle task: " + bundleTask.getBundleId());
+ }
+ }
+ }
+
public void updateBundleTaskState( BundleState state ) {
if ( this.getBundleTask( ) != null ) {
final BundleState current = this.getBundleTask( ).getState( );
- if ( BundleState.complete.equals( state ) && !BundleState.complete.equals( current ) ) {
+ if ( BundleState.complete.equals( state ) && !BundleState.complete.equals( current ) && !BundleState.none.equals( current )) {
+ this.getBundleTask( ).setState( state );
+ bundleRestartInstance(this.getBundleTask());
+ } else if ( BundleState.failed.equals( state ) && !BundleState.failed.equals( current ) && !BundleState.none.equals( current )) {
this.getBundleTask( ).setState( state );
- } else if ( BundleState.failed.equals( state ) && !BundleState.failed.equals( current ) ) {
+ bundleRestartInstance(this.getBundleTask());
+ } else if ( BundleState.cancelled.equals( state ) && !BundleState.cancelled.equals( current ) && !BundleState.none.equals( current )) {
this.getBundleTask( ).setState( state );
- } else if ( BundleState.canceling.equals( current ) || BundleState.canceling.equals( state ) ) {
+ bundleRestartInstance(this.getBundleTask());
+ } else if ( BundleState.canceling.equals( state ) || BundleState.canceling.equals( current ) ) {
//
} else if ( BundleState.pending.equals( current ) && !BundleState.none.equals( state ) ) {
this.getBundleTask( ).setState( state );
@@ -112,6 +112,7 @@
BUNDLE_RESET,
BUNDLE_STARTED,
BUNDLE_STARTING,
+ BUNDLE_RESTART,
BUNDLE_TRANSITION,
CERTIFICATE_WRITE,
CHANNEL_WRITE,
@@ -225,6 +225,12 @@
<mapping name="BundleInstanceResponse" class="com.eucalyptus.vm.BundleInstanceResponseType" extends="edu.ucsb.eucalyptus.msgs.EucalyptusMessage">
<structure map-as="edu.ucsb.eucalyptus.msgs.EucalyptusMessage" />
</mapping>
+ <mapping name="BundleRestartInstance" class="com.eucalyptus.vm.BundleRestartInstanceType" extends="edu.ucsb.eucalyptus.msgs.EucalyptusMessage">
+ <value name="instanceId" field="instanceId" usage="required" />
+ </mapping>
+ <mapping name="BundleRestartInstanceResponse" class="com.eucalyptus.vm.BundleRestartInstanceResponseType" extends="edu.ucsb.eucalyptus.msgs.EucalyptusMessage">
+ <structure map-as="edu.ucsb.eucalyptus.msgs.EucalyptusMessage" />
+ </mapping>
<mapping name="CancelBundleTask" class="com.eucalyptus.vm.CancelBundleTaskType" extends="edu.ucsb.eucalyptus.msgs.EucalyptusMessage">
<value name="instanceId" field="instanceId" usage="required" />
</mapping>
@@ -240,4 +246,4 @@
<structure map-as="edu.ucsb.eucalyptus.msgs.EucalyptusMessage" />
<value name="consoleOutput" field="output" />
</mapping>
-</binding>
+</binding>
Oops, something went wrong.

0 comments on commit a365546

Please sign in to comment.