Beispiel #1
0
  @Override
  public HandlerResult handle(ProcessState state, ProcessInstance process) {
    IpAddress ipAddress = (IpAddress) state.getResource();
    Network network = objectManager.loadResource(Network.class, ipAddress.getNetworkId());
    if (!networkService.shouldAssignIpAddress(network)) {
      return null;
    }

    String assignedIp = ipAddress.getAddress();
    Long subnetId = ipAddress.getSubnetId();

    IPAssignment assignment = allocateIp(ipAddress, network);
    if (assignment != null) {
      assignedIp = assignment.getIpAddress();
      if (assignment.getSubnet() != null) {
        subnetId = assignment.getSubnet().getId();
      }
    }

    return new HandlerResult(
        IP_ADDRESS.ADDRESS, assignedIp,
        IP_ADDRESS.SUBNET_ID, subnetId,
        IP_ADDRESS.NAME,
            StringUtils.isBlank(ipAddress.getName()) ? assignedIp : ipAddress.getName());
  }
Beispiel #2
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;
 }
  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;
  }