コード例 #1
0
ファイル: InstanceDaoImpl.java プロジェクト: rancher/cattle
  @Override
  public List<? extends Instance> listNonRemovedInstances(Account account, boolean forService) {
    List<? extends Instance> serviceInstances =
        create()
            .select(INSTANCE.fields())
            .from(INSTANCE)
            .join(SERVICE_EXPOSE_MAP)
            .on(SERVICE_EXPOSE_MAP.INSTANCE_ID.eq(INSTANCE.ID))
            .where(INSTANCE.ACCOUNT_ID.eq(account.getId()))
            .and(INSTANCE.REMOVED.isNull())
            .fetchInto(InstanceRecord.class);
    if (forService) {
      return serviceInstances;
    }
    List<? extends Instance> allInstances =
        create()
            .select(INSTANCE.fields())
            .from(INSTANCE)
            .where(INSTANCE.ACCOUNT_ID.eq(account.getId()))
            .and(INSTANCE.REMOVED.isNull())
            .fetchInto(InstanceRecord.class);

    allInstances.removeAll(serviceInstances);
    return allInstances;
  }
コード例 #2
0
ファイル: InstanceDaoImpl.java プロジェクト: rancher/cattle
 @Override
 public List<? extends Instance> findUnallocatedInstanceByDeploymentUnitUuid(
     long accountId, String deploymentUnitUuid) {
   return create()
       .select(INSTANCE.fields())
       .from(INSTANCE)
       .leftOuterJoin(INSTANCE_HOST_MAP)
       .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID))
       .where(
           INSTANCE
               .REMOVED
               .isNull()
               .and(INSTANCE_HOST_MAP.ID.isNull())
               .and(INSTANCE.DEPLOYMENT_UNIT_UUID.eq(deploymentUnitUuid))
               .and(INSTANCE.ALLOCATION_STATE.eq(CommonStatesConstants.INACTIVE)))
       .fetchInto(InstanceRecord.class);
 }
コード例 #3
0
ファイル: InstanceDaoImpl.java プロジェクト: rancher/cattle
 @Override
 public List<? extends Instance> getNonRemovedInstanceOn(Long hostId) {
   return create()
       .select(INSTANCE.fields())
       .from(INSTANCE)
       .join(INSTANCE_HOST_MAP)
       .on(INSTANCE_HOST_MAP.HOST_ID.eq(hostId).and(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID)))
       .where(
           INSTANCE
               .REMOVED
               .isNull()
               .and(
                   INSTANCE.STATE.notIn(
                       InstanceConstants.STATE_ERROR,
                       InstanceConstants.STATE_ERRORING,
                       CommonStatesConstants.REMOVING)))
       .fetchInto(InstanceRecord.class);
 }
コード例 #4
0
ファイル: InstanceDaoImpl.java プロジェクト: rancher/cattle
  @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);
  }
コード例 #5
0
ファイル: InstanceDaoImpl.java プロジェクト: rancher/cattle
 @Override
 public List<? extends Instance> findBadInstances(int count) {
   return create()
       .select(INSTANCE.fields())
       .from(INSTANCE)
       .join(INSTANCE_HOST_MAP)
       .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID))
       .join(HOST)
       .on(INSTANCE_HOST_MAP.HOST_ID.eq(HOST.ID))
       .where(
           HOST.REMOVED
               .isNotNull()
               .and(INSTANCE.REMOVED.isNull())
               .and(
                   INSTANCE.STATE.notIn(
                       InstanceConstants.STATE_STOPPING, CommonStatesConstants.REMOVING)))
       .limit(count)
       .fetchInto(InstanceRecord.class);
 }