@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); }
@Override public List<? extends InstanceHostMap> findBadInstanceHostMaps(int count) { return create() .select(INSTANCE_HOST_MAP.fields()) .from(INSTANCE_HOST_MAP) .join(INSTANCE) .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID)) .where( INSTANCE_HOST_MAP .REMOVED .isNull() .and(INSTANCE.STATE.eq(CommonStatesConstants.PURGED)) .and( INSTANCE_HOST_MAP.STATE.notIn( CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(InstanceHostMapRecord.class); }
@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); }
@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); }
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); }