1
1
package com.eucalyptus.cluster.handlers;
3
import java.util.concurrent.atomic.AtomicBoolean;
3
import java.util.concurrent.atomic.AtomicInteger;
5
4
import org.apache.log4j.Logger;
6
5
import org.jboss.netty.channel.ChannelHandlerContext;
7
6
import org.jboss.netty.channel.ChannelPipelineCoverage;
8
7
import org.jboss.netty.channel.MessageEvent;
8
import com.eucalyptus.binding.BindingException;
10
9
import com.eucalyptus.bootstrap.Component;
11
10
import com.eucalyptus.cluster.Cluster;
11
import com.eucalyptus.cluster.VmTypes;
12
12
import com.eucalyptus.cluster.util.ClusterUtil;
13
import com.eucalyptus.entities.VmType;
13
14
import com.eucalyptus.event.Event;
15
import com.eucalyptus.http.MappingHttpResponse;
14
16
import com.eucalyptus.util.LogUtil;
15
import com.eucalyptus.ws.BindingException;
16
import com.eucalyptus.ws.MappingHttpResponse;
17
import com.eucalyptus.vm.SystemState;
18
18
import edu.ucsb.eucalyptus.cloud.VmDescribeResponseType;
19
19
import edu.ucsb.eucalyptus.cloud.VmDescribeType;
20
20
import edu.ucsb.eucalyptus.cloud.VmInfo;
21
import edu.ucsb.eucalyptus.cloud.cluster.VmTypes;
22
import edu.ucsb.eucalyptus.cloud.entities.VmType;
23
import edu.ucsb.eucalyptus.cloud.ws.SystemState;
24
21
import edu.ucsb.eucalyptus.msgs.VmTypeInfo;
26
@ChannelPipelineCoverage("one")
23
@ChannelPipelineCoverage( "one" )
27
24
public class VmStateHandler extends AbstractClusterMessageDispatcher {
28
private static Logger LOG = Logger.getLogger( NetworkStateHandler.class );
29
private AtomicBoolean init = new AtomicBoolean( false );
25
private static Logger LOG = Logger.getLogger( NetworkStateHandler.class );
26
private AtomicInteger init = new AtomicInteger( 0 );
30
28
public VmStateHandler( Cluster cluster ) throws BindingException {
35
33
public void trigger( ) {
36
34
VmDescribeType msg = new VmDescribeType( );
37
msg.setUserId( Component.eucalyptus.name() );
38
msg.setEffectiveUserId( Component.eucalyptus.name() );
35
msg.setUserId( Component.eucalyptus.name( ) );
36
msg.setEffectiveUserId( Component.eucalyptus.name( ) );
43
41
public void fireEvent( Event event ) {
44
42
super.fireTimedStatefulTrigger( event );
48
46
public void upstreamMessage( ChannelHandlerContext ctx, MessageEvent e ) {
49
47
if ( e.getMessage( ) instanceof MappingHttpResponse ) {
50
48
MappingHttpResponse resp = ( MappingHttpResponse ) e.getMessage( );
51
VmDescribeResponseType reply = (VmDescribeResponseType) resp.getMessage( );
49
VmDescribeResponseType reply = ( VmDescribeResponseType ) resp.getMessage( );
52
50
if ( reply != null ) {
53
reply.setOriginCluster( this.getCluster( ).getConfiguration( ).getName( ) );
54
for ( VmInfo vmInfo : reply.getVms( ) ) {
55
vmInfo.setPlacement( this.getCluster( ).getConfiguration( ).getName( ) );
56
VmTypeInfo typeInfo = vmInfo.getInstanceType( );
57
if ( typeInfo.getName( ) == null || "".equals( typeInfo.getName( ) ) ) {
58
for ( VmType t : VmTypes.list( ) ) {
59
if ( t.getCpu( ).equals( typeInfo.getCores( ) ) && t.getDisk( ).equals( typeInfo.getDisk( ) ) && t.getMemory( ).equals( typeInfo.getMemory( ) ) ) {
60
typeInfo.setName( t.getName( ) );
51
reply.setOriginCluster( this.getCluster( ).getConfiguration( ).getName( ) );
52
for ( VmInfo vmInfo : reply.getVms( ) ) {
53
vmInfo.setPlacement( this.getCluster( ).getConfiguration( ).getName( ) );
54
VmTypeInfo typeInfo = vmInfo.getInstanceType( );
55
if ( typeInfo.getName( ) == null || "".equals( typeInfo.getName( ) ) ) {
56
for ( VmType t : VmTypes.list( ) ) {
57
if ( t.getCpu( ).equals( typeInfo.getCores( ) ) && t.getDisk( ).equals( typeInfo.getDisk( ) ) && t.getMemory( ).equals( typeInfo.getMemory( ) ) ) {
58
typeInfo.setName( t.getName( ) );
65
SystemState.handle( reply );
67
if( this.init.compareAndSet( false, true ) ) {
69
ClusterUtil.registerClusterStateHandler( this.getCluster( ), new AddressStateHandler( this.getCluster( ) ) );
70
} catch ( Exception e1 ) {
63
SystemState.handle( reply );
64
if( this.init.addAndGet( 1 ) == 2 ) {
66
ClusterUtil.registerClusterStateHandler( this.getCluster( ), new AddressStateHandler( this.getCluster( ) ) );
67
} catch ( Exception e1 ) {
70
this.getCluster( ).start( );
71
LOG.info( LogUtil.header( "Starting threads for cluster: " + this.getCluster( ) ) );
73
this.getCluster( ).start( );
74
LOG.info( LogUtil.header( "Starting threads for cluster: " + this.getCluster( ) ) );
80
public void advertiseEvent( Event event ) {
78
public void advertiseEvent( Event event ) {}