예제 #1
0
 protected Instance getInstanceForPrimaryIp(IpAddress ipAddress) {
   if (IpAddressConstants.ROLE_PRIMARY.equals(ipAddress.getRole())) {
     for (Nic nic : getObjectManager().mappedChildren(ipAddress, Nic.class)) {
       if (nic.getDeviceNumber() != null && nic.getDeviceNumber() == 0) {
         Instance instance = getObjectManager().loadResource(Instance.class, nic.getInstanceId());
         if (instance != null) {
           return instance;
         }
       }
     }
   }
   return null;
 }
예제 #2
0
  protected String getIpAddress(
      ServiceInstanceData serviceInstanceData,
      boolean isSource,
      Map<Long, IpAddress> instanceIdToHostIpMap) {
    Nic nic = serviceInstanceData.getNic();
    ServiceExposeMap exposeMap = serviceInstanceData.getExposeMap();
    IpAddress ipAddr = serviceInstanceData.getIpAddress();
    String ip = null;

    if (isSource
        && serviceInstanceData
            .getService()
            .getKind()
            .equalsIgnoreCase(ServiceDiscoveryConstants.KIND.SERVICE.name())) {
      if (ipAddr != null) {
        ip = ipAddr.getAddress();
      }
    } else {
      if (ipAddr != null) {
        ip = ipAddr.getAddress();
      } else {
        ip = exposeMap.getIpAddress();
      }
    }

    if (nic == null || nic.getDeviceNumber().equals(0)) {
      return ip;
    } else {
      IpAddress hostIp = instanceIdToHostIpMap.get(nic.getInstanceId());
      if (hostIp != null) {
        if (isSource) {
          return "default";
        }
        return hostIp.getAddress();
      }
    }
    return null;
  }
예제 #3
0
  @Override
  protected void populateContext(
      Agent agent, Instance instance, ConfigItem item, ArchiveContext context) {
    context.getData().put("hostnameGenerator", new HostnameGenerator());
    context.getData().put("instance", instance);
    context.getData().put("agent", agent);

    List<? extends NetworkService> services = networkInfo.networkServices(instance);
    Map<String, NetworkServiceInfo> servicesMap = new HashMap<String, NetworkServiceInfo>();
    Map<String, Subnet> subnetMap = new HashMap<String, Subnet>();
    List<Nic> nics = new ArrayList<Nic>();
    List<Subnet> subnets = new ArrayList<Subnet>();
    Set<String> serviceSet = new HashSet<String>();

    Map<Nic, Subnet> nicToSubnet = networkInfo.getNicsAndSubnet(instance);
    Network primaryNetwork = null;
    Map<Long, Network> networks = networkInfo.networks(instance);
    Map<String, IpAddress> ipAddresses = new HashMap<String, IpAddress>();

    for (NetworkService service : services) {
      serviceSet.add(service.getKind());

      NetworkServiceInfo info = servicesMap.get(service.getKind());
      if (info == null) {
        info = new NetworkServiceInfo(service);
        servicesMap.put(service.getKind(), info);
      }

      for (Map.Entry<Nic, Subnet> entry : nicToSubnet.entrySet()) {
        Nic nic = entry.getKey();
        Subnet subnet = entry.getValue();

        if (subnetMap.put(nic.getId().toString(), subnet) == null) {
          nics.add(nic);
          if (subnet != null) {
            subnets.add(subnet);
          }
        }

        if (!ipAddresses.containsKey(nic.getUuid())) {
          ipAddresses.put(nic.getUuid(), ipAddressDao.getPrimaryIpAddress(nic));
        }

        if (primaryNetwork == null && nic.getDeviceNumber() != null && nic.getDeviceNumber() == 0) {
          primaryNetwork = networks.get(nic.getNetworkId());
        }

        if (service.getNetworkId().equals(nic.getNetworkId())) {
          if (!info.getNicIds().contains(nic.getId())) {
            info.getNicIds().add(nic.getId());
            info.getNics().add(nic);
            info.getNicNames().add("eth" + nic.getDeviceNumber());
          }
        }
      }

      if (!info.getNetworkIds().contains(service.getNetworkId())) {
        info.getNetworkIds().add(service.getNetworkId());
        info.getNetworks().add(networks.get(service.getNetworkId()));
      }
    }

    context.getData().put("nics", nics);
    context.getData().put("nicToSubnet", subnetMap);
    context.getData().put("subnets", subnets);
    context.getData().put("primaryIpAddresses", ipAddresses);
    context.getData().put("services", servicesMap);
    context.getData().put("serviceSet", serviceSet);
    context.getData().put("primaryNetwork", primaryNetwork);
  }