in packages/aws-rfdk/lib/core/lib/load-balancer-manager.ts [109:186]
public registerWorkerFleet(
fleet: IMonitorableFleet,
healthCheckConfig: HealthCheckConfig,
healthMonitorProps: HealthMonitorProps): {
loadBalancer: ApplicationLoadBalancer,
listener: ApplicationListener,
targetGroup: ApplicationTargetGroup
} {
let loadBalancerParent = null;
let listenerParent = null;
let targetGroupParent = null;
// iterate through each load balancer and try registering to each one.
for (const [loadBalancer, loadBalancerMeta] of this.loadBalancerMap.entries()) {
try {
const {listener, targetGroup} = loadBalancerMeta.registerWorkerFleet(
loadBalancer,
fleet,
healthCheckConfig,
healthMonitorProps);
loadBalancerParent = loadBalancer;
listenerParent = listener;
targetGroupParent = targetGroup;
break;
} catch (e) {
// suppress all AWSLimitExhaustedError, we will scale in case of this error
/* istanbul ignore next */
if (!(e instanceof AWSLimitExhaustedError)) {
/* istanbul ignore next */
throw e;
}
}
}
// Check if fleet was not registered.
if (!loadBalancerParent) {
// If this section is reached, no load balancer was found which could
// accommodate fleet, create a new one and register
loadBalancerParent = this.createLoadBalancer(
this.healthMonitorScope,
this.loadBalancerMap.size,
healthMonitorProps);
const loadBalancerManager = new LoadBalancerManager();
// Add it to the map
this.loadBalancerMap.set(loadBalancerParent, loadBalancerManager);
// try registering the fleet to the new load balancer
try {
const {listener, targetGroup} = loadBalancerManager.registerWorkerFleet(
loadBalancerParent,
fleet,
healthCheckConfig,
healthMonitorProps);
listenerParent = listener;
targetGroupParent = targetGroup;
} catch (e) {
throw e;
}
}
/* istanbul ignore next */
if (!loadBalancerParent || !listenerParent || !targetGroupParent) {
/* istanbul ignore next */
throw new Error('Fleet registered successfully but a parent was found null');
}
return {
loadBalancer: loadBalancerParent,
listener: listenerParent,
targetGroup: targetGroupParent,
};
}