Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
decker
committed
Jul 29, 2009
1 parent
b6aa95c
commit 8db6bd4
Showing
392 changed files
with
52,424 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...ules/cluster-manager/src/main/java/edu/ucsb/eucalyptus/cloud/FailScriptFailException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package edu.ucsb.eucalyptus.cloud; | ||
|
||
import com.eucalyptus.util.EucalyptusCloudException; | ||
|
||
public class FailScriptFailException extends EucalyptusCloudException { | ||
|
||
public FailScriptFailException() | ||
{ | ||
} | ||
|
||
public FailScriptFailException( final String message ) | ||
{ | ||
super( message ); | ||
} | ||
|
||
public FailScriptFailException( final String message, final Throwable cause ) | ||
{ | ||
super( message, cause ); | ||
} | ||
|
||
public FailScriptFailException( final Throwable cause ) | ||
{ | ||
super( cause ); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...modules/cluster-manager/src/main/java/edu/ucsb/eucalyptus/cloud/FilenamePrefixFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package edu.ucsb.eucalyptus.cloud; | ||
|
||
import java.io.*; | ||
|
||
public class FilenamePrefixFilter implements FilenameFilter | ||
{ | ||
private String prefix; | ||
|
||
FilenamePrefixFilter( final String prefix ) | ||
{ | ||
this.prefix = prefix; | ||
} | ||
|
||
public boolean accept( final File dir, final String name ) | ||
{ | ||
return name.startsWith( this.prefix ); | ||
} | ||
|
||
|
||
} |
101 changes: 101 additions & 0 deletions
101
clc/modules/cluster-manager/src/main/java/edu/ucsb/eucalyptus/cloud/SLAs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package edu.ucsb.eucalyptus.cloud; | ||
|
||
import edu.ucsb.eucalyptus.cloud.cluster.*; | ||
import edu.ucsb.eucalyptus.util.*; | ||
import edu.ucsb.eucalyptus.msgs.RunInstancesType; | ||
import groovy.lang.*; | ||
import org.apache.log4j.Logger; | ||
|
||
import javax.script.ScriptEngineManager; | ||
import java.io.File; | ||
import java.util.*; | ||
import java.util.concurrent.ConcurrentSkipListSet; | ||
|
||
public class SLAs { | ||
|
||
private static Logger LOG = Logger.getLogger( SLAs.class ); | ||
|
||
static String RULES_DIR_NAME = BaseDirectory.CONF.toString() + File.separator + "rules"; | ||
static String ALLOC_RULES_DIR_NAME = RULES_DIR_NAME + File.separator + "allocation"; | ||
static String TIMER_RULES_DIR_NAME = RULES_DIR_NAME + File.separator + "timer"; | ||
static String STATE_RULES_DIR_NAME = RULES_DIR_NAME + File.separator + "state"; | ||
|
||
ScriptEngineManager mgr = new ScriptEngineManager(); | ||
|
||
public List<ResourceToken> doVmAllocation( VmAllocationInfo vmAllocInfo ) throws FailScriptFailException, NotEnoughResourcesAvailable { | ||
Collection<Cluster> clusterList = Clusters.getInstance().getEntries(); | ||
SortedSet<ClusterNodeState> clusterStateList = new ConcurrentSkipListSet<ClusterNodeState>( ClusterNodeState.getComparator( vmAllocInfo.getVmTypeInfo() ) ); | ||
|
||
//:: prepare the cluster state list ::// | ||
for ( Cluster c : clusterList ) clusterStateList.add( c.getNodeState() ); | ||
|
||
//:: find the right allocator to invoke ::// | ||
Allocator blah = this.getAllocator(); | ||
RunInstancesType request = vmAllocInfo.getRequest(); | ||
List<ResourceToken> allocTokenList = blah.allocate( request.getCorrelationId(), request.getUserId(), | ||
vmAllocInfo.getVmTypeInfo().getName(), | ||
request.getMinCount(), request.getMaxCount(), | ||
clusterStateList ); | ||
return allocTokenList; | ||
} | ||
|
||
public void doNetworkAllocation( String userId, List<ResourceToken> rscTokens, List<Network> networks ) throws NotEnoughResourcesAvailable { | ||
for ( ResourceToken token : rscTokens ) /*<--- for each cluster */ | ||
for ( Network network : networks ) {/*<--- for each network to allocate */ | ||
try { | ||
Networks.getInstance().lookup( network.getName() ); | ||
} catch ( NoSuchElementException e ) { | ||
Networks.getInstance().register( network ); | ||
} | ||
try { | ||
token.getNetworkTokens().add( allocateClusterVlan( userId, token.getCluster(), network.getName() ) ); | ||
} catch ( NetworkAlreadyExistsException e ) {} | ||
} | ||
} | ||
|
||
private NetworkToken allocateClusterVlan( final String userId, final String clusterName, final String networkName ) throws NotEnoughResourcesAvailable, NetworkAlreadyExistsException { | ||
ClusterState clusterState = Clusters.getInstance().lookup( clusterName ).getState(); | ||
Network existingNet = Networks.getInstance().lookup( networkName ); | ||
|
||
NetworkToken networkToken = clusterState.getNetworkAllocation( userId, existingNet.getNetworkName() ); | ||
LOG.info( String.format( EucalyptusProperties.DEBUG_FSTRING, EucalyptusProperties.TokenState.preallocate, networkToken ) ); | ||
|
||
if ( existingNet.hasToken( networkToken.getCluster() ) ) { | ||
LOG.info( String.format( EucalyptusProperties.DEBUG_FSTRING, EucalyptusProperties.TokenState.returned, networkToken ) ); | ||
clusterState.releaseNetworkAllocation( networkToken ); | ||
throw new NetworkAlreadyExistsException(); | ||
} else { | ||
LOG.info( String.format( EucalyptusProperties.DEBUG_FSTRING, EucalyptusProperties.TokenState.accepted, networkToken ) ); | ||
existingNet.addTokenIfAbsent( networkToken ); | ||
return networkToken; | ||
} | ||
} | ||
|
||
private Allocator getAllocator() throws FailScriptFailException { | ||
Object blah = null; | ||
try { | ||
blah = this.getGroovyObject( ALLOC_RULES_DIR_NAME + File.separator + "default.groovy" ); | ||
} | ||
catch ( FailScriptFailException e ) { | ||
LOG.error( e, e ); | ||
} | ||
if ( !( blah instanceof Allocator ) ) throw new FailScriptFailException( blah.getClass() + " does not implement " + Allocator.class ); | ||
return ( Allocator ) blah; | ||
} | ||
|
||
public Object getGroovyObject( String fileName ) throws FailScriptFailException { | ||
GroovyObject groovyObject = null; | ||
try { | ||
ClassLoader parent = getClass().getClassLoader(); | ||
GroovyClassLoader loader = new GroovyClassLoader( parent ); | ||
Class groovyClass = loader.parseClass( new File( fileName ) ); | ||
|
||
groovyObject = ( GroovyObject ) groovyClass.newInstance(); | ||
} | ||
catch ( Exception e ) { | ||
throw new FailScriptFailException( e ); | ||
} | ||
return groovyObject; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
clc/modules/cluster-manager/src/main/java/edu/ucsb/eucalyptus/cloud/cluster/Allocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package edu.ucsb.eucalyptus.cloud.cluster; | ||
|
||
import edu.ucsb.eucalyptus.cloud.ResourceToken; | ||
|
||
import java.util.*; | ||
|
||
public interface Allocator { | ||
|
||
public abstract List<ResourceToken> allocate( String requestId, String userName, String vmtype, int min, int max, SortedSet<ClusterNodeState> clusters ) throws NotEnoughResourcesAvailable; | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
...luster-manager/src/main/java/edu/ucsb/eucalyptus/cloud/cluster/AssignAddressCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package edu.ucsb.eucalyptus.cloud.cluster; | ||
|
||
import edu.ucsb.eucalyptus.msgs.*; | ||
import com.eucalyptus.ws.client.Client; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
public class AssignAddressCallback extends QueuedEventCallback<AssignAddressType> { | ||
|
||
private static Logger LOG = Logger.getLogger( AssignAddressCallback.class ); | ||
|
||
private VmInstance parent; | ||
|
||
public AssignAddressCallback( final VmInstance parent ) { | ||
this.parent = parent; | ||
} | ||
|
||
public void process( final Client clusterClient, final AssignAddressType msg ) throws Exception { | ||
AssignAddressResponseType reply = null; | ||
try { | ||
reply = ( AssignAddressResponseType ) clusterClient.send( msg ); | ||
LOG.debug( "Assign [" + msg.getSource() + "] => [" + msg.getDestination() + "]" ); | ||
this.parent.getNetworkConfig().setIgnoredPublicIp( msg.getSource() ); | ||
} catch ( Exception e ) {} | ||
} | ||
|
||
} |
Oops, something went wrong.