public class ScriptLoadBalancer extends java.lang.Object implements ClusterLoadBalancer
ClusterLoadBalancerinterface which uses user a supplied script to make decisions based on the list of clusters and the job request supplied.
The contract between the script and the Java code is that the script will be supplied global variables
jobRequest which will be JSON strings representing the list (array) of clusters
matching the cluster criteria tags and the job request that kicked off this evaluation. The code expects the script
to either return the id of the cluster if one is selected or null if none was selected.
Note: this LoadBalancer implementation intentionally returns 'null' (a.k.a. 'no preference') in case of error, rather throwing an exception. For example if the script cannot be loaded, or if an invalid cluster is returned. TODO: this logic of falling back to 'no preference' in case of error should be moved out of this implementation and into the service using this interface.
|Modifier and Type||Class and Description|
|Constructor and Description|
|Modifier and Type||Method and Description|
Return best cluster to run job on.
public ScriptLoadBalancer(org.springframework.core.task.AsyncTaskExecutor asyncTaskExecutor, org.springframework.scheduling.TaskScheduler taskScheduler, GenieFileTransferService fileTransferService, org.springframework.core.env.Environment environment, com.fasterxml.jackson.databind.ObjectMapper mapper, io.micrometer.core.instrument.MeterRegistry registry)
asyncTaskExecutor- The asynchronous task executor to use to run the load balancer script in
taskScheduler- The task scheduler to schedule the script refresh task with
fileTransferService- The file transfer service to use to download the script
environment- The program environment to get properties from
mapper- The object mapper to use to serialize objects to JSON for binding with scripts
registry- The metrics registry to use for collecting metrics
public Cluster selectCluster(@Nonnull @NonNull @NotEmpty @NonNull @NotEmpty java.util.Set<Cluster> clusters, @Nonnull @NonNull @NonNull JobRequest jobRequest) throws GenieException
clusters- An immutable, non-empty list of available clusters to choose from
jobRequest- The job request these clusters are being load balanced for
GenieException- if there is any error