~ccheney/ubuntu/lucid/eucalyptus/lucid-sru

« back to all changes in this revision

Viewing changes to clc/modules/cluster-manager/src/edu/ucsb/eucalyptus/cloud/cluster/VmRunCallback.java

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2009-02-11 02:45:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090211024539-0jhzbpg3hk6nu1yg
Tags: upstream-1.5~bzr139
ImportĀ upstreamĀ versionĀ 1.5~bzr139

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package edu.ucsb.eucalyptus.cloud.cluster;
 
2
 
 
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;
 
9
 
 
10
class VmRunCallback extends QueuedEventCallback<VmRunType> {
 
11
 
 
12
  private static Logger LOG = Logger.getLogger( VmRunCallback.class );
 
13
 
 
14
  private ClusterAllocator parent;
 
15
  private ResourceToken token;
 
16
 
 
17
  public VmRunCallback( final ClusterAllocator parent, final ResourceToken token ) {
 
18
    this.parent = parent;
 
19
    this.token = token;
 
20
  }
 
21
 
 
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;
 
31
    try {
 
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() );
 
38
      } else {
 
39
        this.parent.getRollback().lazySet( true );
 
40
      }
 
41
    } catch ( AxisFault axisFault ) { throw axisFault; }
 
42
  }
 
43
 
 
44
}