@Override public List<Port> getUsedPortsForHostExcludingInstance(long hostId, long instanceId) { return create() .select(PORT.fields()) .from(PORT) .join(INSTANCE_HOST_MAP) .on(PORT.INSTANCE_ID.eq(INSTANCE_HOST_MAP.INSTANCE_ID)) .join(INSTANCE) .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID)) .leftOuterJoin(SERVICE_EXPOSE_MAP) .on(SERVICE_EXPOSE_MAP.INSTANCE_ID.eq(INSTANCE.ID)) .where( INSTANCE_HOST_MAP .HOST_ID .eq(hostId) .and(INSTANCE.REMOVED.isNull()) .and(INSTANCE.ID.ne(instanceId)) .and( INSTANCE.STATE.in( InstanceConstants.STATE_STARTING, InstanceConstants.STATE_RESTARTING, InstanceConstants.STATE_RUNNING)) .and(INSTANCE_HOST_MAP.REMOVED.isNull()) .and(PORT.REMOVED.isNull()) .and(SERVICE_EXPOSE_MAP.UPGRADE.eq(false).or(SERVICE_EXPOSE_MAP.UPGRADE.isNull()))) .fetchInto(Port.class); }
@Override public List<? extends Host> findHosts(long accountId, long instanceId) { return create() .select(HOST.fields()) .from(INSTANCE) .join(INSTANCE_HOST_MAP) .on(INSTANCE.ID.eq(INSTANCE_HOST_MAP.INSTANCE_ID)) .join(HOST) .on(HOST.ID.eq(INSTANCE_HOST_MAP.HOST_ID)) .where( HOST.REMOVED .isNull() .and(INSTANCE_HOST_MAP.REMOVED.isNull()) .and(INSTANCE.ID.eq(instanceId))) .fetchInto(HostRecord.class); }
@Override public List<? extends InstanceLink> findBadInstanceLinks(int count) { return create() .select(INSTANCE_LINK.fields()) .from(INSTANCE_LINK) .join(INSTANCE) .on(INSTANCE.ID.eq(INSTANCE_LINK.TARGET_INSTANCE_ID)) .where(INSTANCE.STATE.eq(CommonStatesConstants.PURGED)) .limit(count) .fetchInto(InstanceLinkRecord.class); }
@Override public List<? extends Nic> findBadNics(int count) { return create() .select(NIC.fields()) .from(NIC) .join(INSTANCE) .on(INSTANCE.ID.eq(NIC.INSTANCE_ID)) .where( NIC.REMOVED .isNull() .and(INSTANCE.STATE.eq(CommonStatesConstants.PURGED)) .and( NIC.STATE.notIn( CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(NicRecord.class); }
@Override public List<? extends Instance> findInstanceByServiceName(long accountId, String serviceName) { return create() .select(INSTANCE.fields()) .from(INSTANCE) .join(SERVICE_EXPOSE_MAP) .on(INSTANCE.ID.eq(SERVICE_EXPOSE_MAP.INSTANCE_ID)) .join(SERVICE) .on(SERVICE.ID.eq(SERVICE_EXPOSE_MAP.SERVICE_ID)) .where( INSTANCE .STATE .eq(InstanceConstants.STATE_RUNNING) .and(INSTANCE.ACCOUNT_ID.eq(accountId)) .and(SERVICE_EXPOSE_MAP.REMOVED.isNull()) .and(SERVICE.REMOVED.isNull()) .and(SERVICE.NAME.eq(serviceName))) .fetchInto(InstanceRecord.class); }
@Override public boolean isInstanceImageKind(long instanceId, String kind) { return create() .select(STORAGE_POOL.fields()) .from(STORAGE_POOL) .join(IMAGE_STORAGE_POOL_MAP) .on(STORAGE_POOL.ID.eq(IMAGE_STORAGE_POOL_MAP.STORAGE_POOL_ID)) .join(IMAGE) .on(IMAGE.ID.eq(IMAGE_STORAGE_POOL_MAP.IMAGE_ID)) .join(INSTANCE) .on(INSTANCE.IMAGE_ID.eq(IMAGE.ID)) .where( INSTANCE .ID .eq(instanceId) .and(IMAGE_STORAGE_POOL_MAP.REMOVED.isNull()) .and(STORAGE_POOL.KIND.eq(kind))) .fetch() .size() > 0; }
@Override public List<Long> getInstancesWithVolumeMounted(long volumeId, long currentInstanceId) { return create() .select(INSTANCE.ID) .from(INSTANCE) .join(MOUNT) .on(MOUNT.INSTANCE_ID.eq(INSTANCE.ID).and(MOUNT.VOLUME_ID.eq(volumeId))) .join(INSTANCE_HOST_MAP) .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID)) .where( INSTANCE .REMOVED .isNull() .and(INSTANCE.ID.ne(currentInstanceId)) .and(INSTANCE_HOST_MAP.STATE.notIn(IHM_STATES)) .and( (INSTANCE .HEALTH_STATE .isNull() .or(INSTANCE.HEALTH_STATE.eq(HealthcheckConstants.HEALTH_STATE_HEALTHY))))) .fetchInto(Long.class); }