1
package edu.ucsb.eucalyptus.cloud.cluster;
3
import edu.ucsb.eucalyptus.cloud.*;
4
import edu.ucsb.eucalyptus.transport.client.Client;
5
import edu.ucsb.eucalyptus.msgs.*;
6
import edu.ucsb.eucalyptus.util.EucalyptusProperties;
7
import org.apache.log4j.Logger;
8
import org.apache.axis2.AxisFault;
10
class VmRunCallback extends QueuedEventCallback<VmRunType> {
12
private static Logger LOG = Logger.getLogger( VmRunCallback.class );
14
private ClusterAllocator parent;
15
private ResourceToken token;
17
public VmRunCallback( final ClusterAllocator parent, final ResourceToken token ) {
22
public void process( final Client clusterClient, final VmRunType msg ) throws Exception {
23
LOG.info( String.format( EucalyptusProperties.DEBUG_FSTRING, EucalyptusProperties.TokenState.submitted, token ) );
24
Clusters.getInstance().lookup( token.getCluster() ).getState().submitResourceAllocation( token );
25
for ( String vmId : msg.getInstanceIds() )
26
parent.msgMap.put( ClusterAllocator.State.ROLLBACK,
27
new QueuedEvent<TerminateInstancesType>(
28
new TerminateCallback( ),
29
new TerminateInstancesType( vmId, msg ) ) );
30
VmRunResponseType reply = null;
32
reply = ( VmRunResponseType ) clusterClient.send( msg );
33
Clusters.getInstance().lookup( token.getCluster() ).getState().redeemToken( token );
34
LOG.info( String.format( EucalyptusProperties.DEBUG_FSTRING, EucalyptusProperties.TokenState.redeemed, token ) );
35
if ( reply.get_return() ) {
36
for ( VmInfo vmInfo : reply.getVms() )
37
VmInstances.getInstance().lookup( vmInfo.getInstanceId() ).getNetworkConfig().setIpAddress( vmInfo.getNetParams().getIpAddress() );
39
this.parent.getRollback().lazySet( true );
41
} catch ( AxisFault axisFault ) { throw axisFault; }