Пример #1
0
  protected void populateResolveInfo(
      final boolean isVIPProvider,
      final Map<Long, IpAddress> instanceIdToHostIpMap,
      ServiceDnsEntryData serviceData,
      Service clientService,
      Map<String, Map<String, String>> resolve,
      Map<String, String> resolveCname,
      Service targetService,
      ServiceInstanceData targetInstance) {
    String targetInstanceName =
        targetInstance.getInstance() == null ? null : targetInstance.getInstance().getName();

    boolean self = clientService.getId().equals(targetService.getId());
    String dnsName =
        getDnsName(targetService, serviceData.getConsumeMap(), targetInstance.getExposeMap(), self);

    String targetIp =
        isVIPProvider
            ? clientService.getVip()
            : getIpAddress(targetInstance, false, instanceIdToHostIpMap);
    if (targetIp != null) {
      Map<String, String> ips = resolve.get(dnsName);
      if (ips == null) {
        ips = new HashMap<>();
      }
      ips.put(targetIp, targetInstanceName);

      resolve.put(dnsName, ips);
    } else {
      String cname = targetInstance.getExposeMap().getHostName();
      if (cname != null) {
        resolveCname.put(dnsName, cname);
      }
    }
  }
 @Override
 public void setVIP(Service service) {
   String requestedVip = service.getVip();
   String vip = getServiceVIP(service, requestedVip);
   if (vip != null || requestedVip != null) {
     service.setVip(vip);
     objectManager.persist(service);
   }
 }
 @Override
 public void releaseVip(Service service) {
   String vip = service.getVip();
   if (vip == null) {
     return;
   }
   List<Subnet> subnets =
       objectManager.find(
           Subnet.class,
           SUBNET.ACCOUNT_ID,
           service.getAccountId(),
           SUBNET.KIND,
           SubnetConstants.KIND_VIP_SUBNET);
   if (subnets.isEmpty()) {
     return;
   }
   Subnet subnet = subnets.get(0);
   poolManager.releaseResource(subnet, service);
 }