Source:
public void updateDnsEntryForLoadBalancers(Stack stack) { Set<LoadBalancer> loadBalancers = loadBalancerPersistenceService.findByStackId(stack.getId()); if (loadBalancers.isEmpty()) { LOGGER.info("No load balancers in stack {}", stack.getId()); return; } LOGGER.info("Update load balancer DNS entries"); String userCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); for (LoadBalancer loadBalancer : loadBalancers) { Optional<String> endpoint = Optional.ofNullable(loadBalancer.getEndpoint()); if (endpoint.isEmpty()) { LOGGER.error("No endpoint set for load balancer. Can't register domain."); } else { if (loadBalancer.getDns() != null && loadBalancer.getHostedZoneId() != null) { LOGGER.info("Creating load balancer DNS entry with endpoint name: '{}', environment name: '{}' and cloud DNS: '{}'", endpoint.get(), environment.getName(), loadBalancer.getDns()); getDnsManagementService().createOrUpdateDnsEntryWithCloudDns(userCrn, accountId, endpoint.get(), environment.getName(), loadBalancer.getDns(), loadBalancer.getHostedZoneId()); } else if (loadBalancer.getIp() != null) { LOGGER.info("Creating load balancer DNS entry with endpoint name: '{}', environment name: '{}' and IP: '{}'", endpoint.get(), environment.getName(), loadBalancer.getIp()); getDnsManagementService().createOrUpdateDnsEntryWithIp(userCrn, accountId, endpoint.get(), environment.getName(), false, List.of(loadBalancer.getIp())); } else { LOGGER.warn("Could not find IP or cloud DNS info for load balancer with endpoint ." + "DNS registration will be skipped.", loadBalancer.getEndpoint()); } loadBalancer.setFqdn(getDomainNameProvider().getFullyQualifiedEndpointName( endpoint.get(), environment.getName(), getWorkloadSubdomain(userCrn))); } } }

Target:
public void updateDnsEntryForLoadBalancers(Stack stack) { Set<LoadBalancer> loadBalancers = loadBalancerPersistenceService.findByStackId(stack.getId()); if (loadBalancers.isEmpty()) { LOGGER.info("No load balancers in stack {}", stack.getId()); return; } LOGGER.info("Update load balancer DNS entries"); String userCrn = ThreadBasedUserCrnProvider.getUserCrn(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn()); for (LoadBalancer loadBalancer : loadBalancers) { Optional<String> endpoint = Optional.ofNullable(loadBalancer.getEndpoint()); if (endpoint.isEmpty()) { LOGGER.error("No endpoint set for load balancer. Can't register domain."); } else { if (loadBalancer.getDns() != null && loadBalancer.getHostedZoneId() != null) { LOGGER.info("Creating load balancer DNS entry with endpoint name: '{}', environment name: '{}' and cloud DNS: '{}'", endpoint.get(), environment.getName(), loadBalancer.getDns()); getDnsManagementService().createOrUpdateDnsEntryWithCloudDns(userCrn, accountId, endpoint.get(), environment.getName(), loadBalancer.getDns(), loadBalancer.getHostedZoneId()); } else if (loadBalancer.getIp() != null) { LOGGER.info("Creating load balancer DNS entry with endpoint name: '{}', environment name: '{}' and IP: '{}'", endpoint.get(), environment.getName(), loadBalancer.getIp()); getDnsManagementService().createOrUpdateDnsEntryWithIp(userCrn, accountId, endpoint.get(), environment.getName(), false, List.of(loadBalancer.getIp())); } else { LOGGER.warn("Could not find IP or cloud DNS info for load balancer with endpoint ." + "DNS registration will be skipped.", loadBalancer.getEndpoint()); continue; } loadBalancer.setFqdn(getDomainNameProvider().getFullyQualifiedEndpointName( endpoint.get(), environment.getName(), getWorkloadSubdomain(userCrn))); loadBalancerPersistenceService.save(loadBalancer); LOGGER.info("Set load balancer's FQDN to {}.", loadBalancer.getFqdn()); } } }