Example #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);
  }
Example #2
0
  protected List<ServiceInstanceData> getServiceInstanceInstancesData(
      long accountId, boolean client, long vnetId) {
    MultiRecordMapper<ServiceInstanceData> mapper =
        new MultiRecordMapper<ServiceInstanceData>() {
          @Override
          protected ServiceInstanceData map(List<Object> input) {
            Service service = (Service) input.get(0);
            IpAddress ip = (IpAddress) input.get(1);
            Instance instance = (Instance) input.get(2);
            ServiceExposeMap exposeMap = (ServiceExposeMap) input.get(3);
            Nic nic = (Nic) input.get(4);
            ServiceInstanceData data =
                new ServiceInstanceData(service, ip, instance, exposeMap, nic);
            return data;
          }
        };

    ServiceTable service = mapper.add(SERVICE);
    IpAddressTable ipAddress = mapper.add(IP_ADDRESS);
    InstanceTable instance = mapper.add(INSTANCE);
    ServiceExposeMapTable exposeMap = mapper.add(SERVICE_EXPOSE_MAP);
    NicTable nic = mapper.add(NIC);

    Condition condition = null;
    if (client) {
      condition = ipAddress.ROLE.eq(IpAddressConstants.ROLE_PRIMARY).and(nic.VNET_ID.eq(vnetId));
    } else {
      condition =
          (ipAddress.ROLE.isNull().and(ipAddress.ADDRESS.isNull()))
              .or(ipAddress.ROLE.eq(IpAddressConstants.ROLE_PRIMARY))
              .and(
                  instance
                      .HEALTH_STATE
                      .isNull()
                      .or(instance.HEALTH_STATE.eq(HealthcheckConstants.HEALTH_STATE_HEALTHY)));
    }

    return create()
        .select(mapper.fields())
        .from(service)
        .join(exposeMap)
        .on(service.ID.eq(exposeMap.SERVICE_ID))
        .leftOuterJoin(instance)
        .on(instance.ID.eq(exposeMap.INSTANCE_ID))
        .leftOuterJoin(nic)
        .on(nic.INSTANCE_ID.eq(exposeMap.INSTANCE_ID))
        .leftOuterJoin(IP_ADDRESS_NIC_MAP)
        .on(IP_ADDRESS_NIC_MAP.NIC_ID.eq(nic.ID))
        .leftOuterJoin(ipAddress)
        .on(IP_ADDRESS_NIC_MAP.IP_ADDRESS_ID.eq(ipAddress.ID))
        .where(service.ACCOUNT_ID.eq(accountId))
        .and(service.REMOVED.isNull())
        .and(exposeMap.REMOVED.isNull())
        .and(nic.REMOVED.isNull())
        .and(ipAddress.REMOVED.isNull())
        .and(instance.REMOVED.isNull())
        .and(
            instance
                .STATE
                .isNull()
                .or(
                    instance.STATE.in(
                        InstanceConstants.STATE_RUNNING, InstanceConstants.STATE_STARTING)))
        .and(condition)
        .fetch()
        .map(mapper);
  }