示例#1
0
  @Override
  public List<IpAddressToServiceIndex> getIpToIndex(Service service) {
    MultiRecordMapper<IpAddressToServiceIndex> mapper =
        new MultiRecordMapper<IpAddressToServiceIndex>() {
          @Override
          protected IpAddressToServiceIndex map(List<Object> input) {
            ServiceIndex index = (ServiceIndex) input.get(0);
            IpAddress ip = (IpAddress) input.get(1);
            Subnet subnet = (Subnet) input.get(2);
            IpAddressToServiceIndex data = new IpAddressToServiceIndex(index, ip, subnet);
            return data;
          }
        };

    ServiceIndexTable serviceIndex = mapper.add(SERVICE_INDEX);
    IpAddressTable ipAddress = mapper.add(IP_ADDRESS);
    SubnetTable subnet = mapper.add(SUBNET);
    ServiceExposeMapTable exposeMap = mapper.add(SERVICE_EXPOSE_MAP, SERVICE_EXPOSE_MAP.REMOVED);

    return create()
        .select(mapper.fields())
        .from(INSTANCE)
        .join(exposeMap)
        .on(exposeMap.INSTANCE_ID.eq(INSTANCE.ID))
        .join(NIC)
        .on(NIC.INSTANCE_ID.eq(exposeMap.INSTANCE_ID))
        .join(IP_ADDRESS_NIC_MAP)
        .on(IP_ADDRESS_NIC_MAP.NIC_ID.eq(NIC.ID))
        .join(ipAddress)
        .on(IP_ADDRESS_NIC_MAP.IP_ADDRESS_ID.eq(ipAddress.ID))
        .join(serviceIndex)
        .on(serviceIndex.ID.eq(INSTANCE.SERVICE_INDEX_ID))
        .join(subnet)
        .on(ipAddress.SUBNET_ID.eq(subnet.ID))
        .where(exposeMap.SERVICE_ID.eq(service.getId()))
        .and(exposeMap.REMOVED.isNull())
        .and(NIC.REMOVED.isNull())
        .and(ipAddress.REMOVED.isNull())
        .and(ipAddress.ADDRESS.isNotNull())
        .and(INSTANCE.REMOVED.isNull())
        .and(ipAddress.ROLE.eq(IpAddressConstants.ROLE_PRIMARY))
        .fetch()
        .map(mapper);
  }
示例#2
0
  private List<PublicEndpoint> getPublicEndpointsInternal(
      long accountId, Long serviceId, Long hostId) {
    MultiRecordMapper<PublicEndpoint> mapper =
        new MultiRecordMapper<PublicEndpoint>() {
          @Override
          protected PublicEndpoint map(List<Object> input) {
            Instance instance = (Instance) input.get(0);
            Port port = (Port) input.get(1);
            Host host = (Host) input.get(2);

            String address = "";
            IpAddress ip = (IpAddress) input.get(3);
            if (ip != null) {
              address = ip.getAddress();
            } else {
              address = DataAccessor.fieldString(port, PortConstants.FIELD_BIND_ADDR);
            }

            ServiceExposeMap exposeMap = (ServiceExposeMap) input.get(4);
            Long serviceId = exposeMap != null ? exposeMap.getServiceId() : null;
            PublicEndpoint data =
                new PublicEndpoint(
                    address, port.getPublicPort(), host.getId(), instance.getId(), serviceId);
            return data;
          }
        };

    InstanceTable instance = mapper.add(INSTANCE, INSTANCE.ID, INSTANCE.ACCOUNT_ID);
    PortTable port = mapper.add(PORT);
    HostTable host = mapper.add(HOST, HOST.ID);
    IpAddressTable ipAddress = mapper.add(IP_ADDRESS, IP_ADDRESS.ID, IP_ADDRESS.ADDRESS);
    ServiceExposeMapTable exposeMap =
        mapper.add(
            SERVICE_EXPOSE_MAP, SERVICE_EXPOSE_MAP.INSTANCE_ID, SERVICE_EXPOSE_MAP.SERVICE_ID);

    Condition condition = null;
    if (serviceId != null && hostId != null) {
      condition = host.ID.eq(hostId).and(exposeMap.SERVICE_ID.eq(serviceId));
    } else if (hostId != null) {
      condition = host.ID.eq(hostId);
    } else if (serviceId != null) {
      condition = (exposeMap.SERVICE_ID.eq(serviceId));
    }

    return create()
        .select(mapper.fields())
        .from(instance)
        .join(port)
        .on(port.INSTANCE_ID.eq(instance.ID))
        .join(INSTANCE_HOST_MAP)
        .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(instance.ID))
        .join(host)
        .on(INSTANCE_HOST_MAP.HOST_ID.eq(host.ID))
        .leftOuterJoin(ipAddress)
        .on(port.PUBLIC_IP_ADDRESS_ID.eq(ipAddress.ID))
        .leftOuterJoin(exposeMap)
        .on(exposeMap.INSTANCE_ID.eq(instance.ID))
        .where(instance.ACCOUNT_ID.eq(accountId))
        .and(instance.REMOVED.isNull())
        .and(port.REMOVED.isNull())
        .and(host.REMOVED.isNull())
        .and(ipAddress.REMOVED.isNull())
        .and(exposeMap.REMOVED.isNull())
        .and(port.PUBLIC_PORT.isNotNull())
        .and(
            port.STATE.in(
                CommonStatesConstants.ACTIVATING,
                CommonStatesConstants.ACTIVE,
                CommonStatesConstants.UPDATING_ACTIVE))
        .and(condition)
        .fetch()
        .map(mapper);
  }