@Override public List<DnsEntryData> getServiceDnsData( final Instance instance, final boolean isVIPProvider) { MultiRecordMapper<ServiceDnsEntryData> mapper = new MultiRecordMapper<ServiceDnsEntryData>() { @Override protected ServiceDnsEntryData map(List<Object> input) { Service clientService = (Service) input.get(0); Service targetService = (Service) input.get(1); ServiceConsumeMap consumeMap = (ServiceConsumeMap) input.get(2); ServiceDnsEntryData data = new ServiceDnsEntryData(clientService, targetService, consumeMap); return data; } }; ServiceTable clientService = mapper.add(SERVICE); ServiceTable targetService = mapper.add(SERVICE); ServiceConsumeMapTable serviceConsumeMap = mapper.add(SERVICE_CONSUME_MAP); // there are 2 conditions below linked with OR clause // first condition - means to return all non-dns clientService + target service map within the // same stack // that are not linked // second condition - return only clientService + targetService with explicit links Condition condition = (clientService .KIND .ne(ServiceDiscoveryConstants.KIND.DNSSERVICE.name()) .and(targetService.ENVIRONMENT_ID.eq(clientService.ENVIRONMENT_ID)) .and(serviceConsumeMap.ID.isNull())) .or( serviceConsumeMap .ID .isNotNull() .and(serviceConsumeMap.REMOVED.isNull()) .and( serviceConsumeMap.STATE.in( CommonStatesConstants.ACTIVATING, CommonStatesConstants.ACTIVE))); List<ServiceDnsEntryData> serviceDnsEntries = create() .select(mapper.fields()) .from(clientService) .join(targetService) .on(targetService.ACCOUNT_ID.eq(clientService.ACCOUNT_ID)) .leftOuterJoin(serviceConsumeMap) .on( serviceConsumeMap .SERVICE_ID .eq(clientService.ID) .and(serviceConsumeMap.CONSUMED_SERVICE_ID.eq(targetService.ID)) .and(serviceConsumeMap.REMOVED.isNull())) .where(targetService.REMOVED.isNull()) .and(clientService.REMOVED.isNull()) .and(condition) .fetch() .map(mapper); Nic nic = ntwkDao.getPrimaryNic(instance.getId()); long vnetId = nic.getVnetId(); return convertToDnsEntryData(isVIPProvider, serviceDnsEntries, instance.getAccountId(), vnetId); }