1
package com.eucalyptus.sla;
3
import com.eucalyptus.cluster.Cluster;
4
import com.eucalyptus.cluster.Clusters;
5
import edu.ucsb.eucalyptus.cloud.ResourceToken;
6
import edu.ucsb.eucalyptus.cloud.VmAllocationInfo;
7
import com.eucalyptus.util.NotEnoughResourcesAvailable;
9
public class LeastFullFirst implements ResourceAllocator {
12
public void allocate( VmAllocationInfo vmInfo ) throws Exception {
14
Clusters.getInstance().listValues().collect{ Cluster it ->
15
clusterMap[it] = it.getNodeState( ).getAvailability( vmInfo.getRequest( ).getInstanceType( ) )
18
def leastFull = clusterMap.sort{ it.value }.find{ it }
19
def amount = [leastFull.value.getAvailable(), vmInfo.request.maxCount].min();
20
if( amount < vmInfo.request.minCount ) {
21
throw new NotEnoughResourcesAvailable("Not enough resources (${leastFull.value} < ${vmInfo.request.minCount}: vm instances.") ;
23
def allocation = leastFull.key.getNodeState().getResourceAllocation(vmInfo.request.correlationId, vmInfo.request.userId, vmInfo.request.instanceType, amount)
24
vmInfo.getAllocationTokens( ).add( allocation );
28
public void fail( VmAllocationInfo vmInfo, Throwable t ) {
29
vmInfo.allocationTokens.each { ResourceToken it ->
30
Clusters.getInstance().lookup( it.getCluster( ) ).getNodeState( ).releaseToken( it )