public class ScriptLoadBalancer extends java.lang.Object implements ClusterLoadBalancer
ClusterLoadBalancer
interface 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
clusters
and 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 |
---|---|
protected static class |
ScriptLoadBalancer.Evaluator |
protected static class |
ScriptLoadBalancer.Loader |
Constructor and Description |
---|
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)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Cluster |
selectCluster(@NonNull @NotEmpty java.util.Set<Cluster> clusters,
@NonNull JobRequest jobRequest)
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 intaskScheduler
- The task scheduler to schedule the script refresh task withfileTransferService
- The file transfer service to use to download the scriptenvironment
- The program environment to get properties frommapper
- The object mapper to use to serialize objects to JSON for binding with scriptsregistry
- The metrics registry to use for collecting metricspublic Cluster selectCluster(@Nonnull @NonNull @NotEmpty @NonNull @NotEmpty java.util.Set<Cluster> clusters, @Nonnull @NonNull @NonNull JobRequest jobRequest) throws GenieException
selectCluster
in interface ClusterLoadBalancer
clusters
- An immutable, non-empty list of available clusters to choose fromjobRequest
- The job request these clusters are being load balanced forGenieException
- if there is any error