public void start() throws Exception { LOG.info("Initializing Docker Job Plugin"); Jenkins jenkins = Jenkins.getInstance(); LoadBalancer existingLoadBalancer = firstNonNull(jenkins.getQueue().getLoadBalancer(), NULL_LOAD_BALANCER); DockerJobLoadBalancer dockerLoadBalancer = new DockerJobLoadBalancer(jenkins, existingLoadBalancer); LOG.log(FINE, "Injecting docker job plugin load balancer: fallback={0}", existingLoadBalancer); jenkins.getQueue().setLoadBalancer(dockerLoadBalancer); }
/** * Replaces {@link LoadBalancer} registered to Jenkins to ScoringLoadBalancer. * * The {@link LoadBalancer} originally registered are used as one to fall back. */ @Initializer(after=InitMilestone.PLUGINS_STARTED, fatal=false) public static void installLoadBalancer() { LOGGER.info("Replace LoadBalancer to ScoringLoadBalancer"); Queue q = Jenkins.getInstance().getQueue(); LoadBalancer fallback = q.getLoadBalancer(); q.setLoadBalancer(new ScoringLoadBalancer(fallback)); }
public DockerJobLoadBalancer(Jenkins jenkins, LoadBalancer fallback) { _jenkins = checkNotNull(jenkins); _fallback = checkNotNull(fallback); }
/** * @return {@link LoadBalancer} to fall back */ public LoadBalancer getFallback() { return fallback; }
/** * Constructor. * * @param fallback LoadBalancer to fall back. Specify originally registered LoadBalancer. */ public ScoringLoadBalancer(LoadBalancer fallback) { this.fallback = fallback; }