if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Registering API {}", apiId);
}
// Gets the API
Api api = dataManager.getApiById(apiId, true);
// Get context Ids (because apis are incomplete on Gateway only machines)
List<ApiIds> ids = api.getContextIds();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Browsing {} contexts for API #{}", ids.size(), apiId);
}
// Get or create the Api Context map for this API
Map<String, List<TargetReference>> map = getApiMap(apiId);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Size of api context map for api id {}: {}", apiId, map.size());
}
// Browsing API Contexts
for(ApiIds id : ids) {
// Get the ApiContext by its ID (this map is populated on all gateways)
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Getting api context for api id {}", apiId);
}
APIContext context = dataManager.getApiContextById(id.getApiContextId());
// Shouldn't be null...
if(context != null) {
// Prepare the list of TargetReference
List<TargetReference> targetReferences = new ArrayList<TargetReference>();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Registering Context {} ({} TargetHosts)", context.getId(), context.getTargetHosts().size());
}
// Store requested HealthCheck service for later use
ITargetHealthCheckService healthCheckService = null;
String healthCheckServiceName = null;
LoadBalancing lbConfig = context.getLoadBalancing();
if(lbConfig.getTargetHealthCheck() != null) {
healthCheckServiceName = lbConfig.getTargetHealthCheck().getType();
}
if(healthCheckServiceName != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Will use HealthCheck service ", healthCheckServiceName);
}
// Getting corresponding HealthCheck Service
healthCheckService = targetHealthCheckServices.get(healthCheckServiceName);
if(healthCheckService != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Found a HealthCheckService ({}) for this name: {}", healthCheckService.getClass().getName(), healthCheckServiceName);
}
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No HealthCheckService found for this name: {}", healthCheckServiceName);
}
}
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Will NOT use HealthCheck service for following targets");
}
}
// For each TargetHost, check if there is already a corresponding ManagedTargetHost
for(TargetHost targetHost : context.getTargetHosts()) {
/*
* If the api has its own proxy settings, they were automatically set by the DataManager while loading the api. Nothing to do.
* If the api uses global proxy settings, we have to retrieve a reference on this shared instance
*/
targetHost.setForwardProxy( api.isUseGlobalProxy() ? globalForwardProxy : api.getForwardProxy() );
// Using a "hash differentiation string":
// We need to take into account the HealthCheckService associated to a TargetHost
// Ex: API #1 (http://www.apple.com|Ping), API #2 (http://www.apple.com|Telnet), API #3 (http://www.apple.com|Ping)
// API #1 and #3 must have the same "Managed target" and #2 another one