@Override public Agent getHostAgentForDelegate(long agentId) { List<? extends Agent> result = create().select(AGENT.fields()) .from(AGENT) .join(HOST) .on(HOST.AGENT_ID.eq(AGENT.ID)) .join(INSTANCE_HOST_MAP) .on(INSTANCE_HOST_MAP.HOST_ID.eq(HOST.ID)) .join(INSTANCE) .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID)) .where(INSTANCE.AGENT_ID.eq(agentId)).fetchInto(AgentRecord.class); return result.size() == 0 ? null : result.get(0); }
@Override public List<Long> findVolumesInUseByServiceDriver(Long serviceId) { return create().select(VOLUME.ID) .from(VOLUME) .join(VOLUME_STORAGE_POOL_MAP) .on(VOLUME_STORAGE_POOL_MAP.VOLUME_ID.eq(VOLUME.ID)) .join(STORAGE_POOL) .on(VOLUME_STORAGE_POOL_MAP.STORAGE_POOL_ID.eq(STORAGE_POOL.ID)) .join(STORAGE_DRIVER) .on(STORAGE_DRIVER.ID.eq(STORAGE_POOL.STORAGE_DRIVER_ID)) .where(STORAGE_DRIVER.REMOVED.isNull() .and(STORAGE_DRIVER.SERVICE_ID.eq(serviceId)) .and(VOLUME.REMOVED.isNull())) .fetch().into(Long.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<? extends Volume> findNonRemovedVolumesOnPool(Long storagePoolId) { return create().select(VOLUME.fields()) .from(VOLUME) .join(VOLUME_STORAGE_POOL_MAP) .on(VOLUME_STORAGE_POOL_MAP.VOLUME_ID.eq(VOLUME.ID)) .join(STORAGE_POOL) .on(STORAGE_POOL.ID.eq(VOLUME_STORAGE_POOL_MAP.STORAGE_POOL_ID)) .where(VOLUME.REMOVED.isNull() .and(STORAGE_POOL.REMOVED.isNotNull())) .fetchInto(VolumeRecord.class); }
protected SelectConditionStep<Record3<String, Long, Long>> getHostQuery(List<String> orderedHostUUIDs, QueryOptions options) { return create() .select(HOST.UUID, HOST.ID, STORAGE_POOL.ID) .from(HOST) .leftOuterJoin(STORAGE_POOL_HOST_MAP) .on(STORAGE_POOL_HOST_MAP.HOST_ID.eq(HOST.ID) .and(STORAGE_POOL_HOST_MAP.REMOVED.isNull())) .join(STORAGE_POOL) .on(STORAGE_POOL.ID.eq(STORAGE_POOL_HOST_MAP.STORAGE_POOL_ID)) .leftOuterJoin(AGENT) .on(AGENT.ID.eq(HOST.AGENT_ID)) .where(getQueryOptionCondition(options, orderedHostUUIDs)); }
@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<Long> getAgentProviderIgnoreHealth(String providedServiceLabel, long accountId) { return Arrays.asList(create().select(INSTANCE.AGENT_ID) .from(INSTANCE) .join(INSTANCE_LABEL_MAP) .on(INSTANCE_LABEL_MAP.INSTANCE_ID.eq(INSTANCE.ID)) .join(LABEL) .on(LABEL.ID.eq(INSTANCE_LABEL_MAP.LABEL_ID).and(LABEL.KEY.eq(providedServiceLabel))) .where(INSTANCE.ACCOUNT_ID.eq(accountId) .and(INSTANCE.AGENT_ID.isNotNull()) .and(INSTANCE.SYSTEM.isTrue()) .and(INSTANCE.STATE.in(InstanceConstants.STATE_RUNNING, InstanceConstants.STATE_STARTING))) .orderBy(INSTANCE.AGENT_ID.asc()) .fetch().intoArray(INSTANCE.AGENT_ID)); }
private List<String> enumLabels(String nspname, String typname, Field<?> orderBy) { return create().select(PG_ENUM.ENUMLABEL) .from(PG_ENUM) .join(PG_TYPE).on(PG_ENUM.ENUMTYPID.eq(oid(PG_TYPE))) .join(PG_NAMESPACE).on(PG_TYPE.TYPNAMESPACE.eq(oid(PG_NAMESPACE))) .where(PG_NAMESPACE.NSPNAME.eq(nspname)) .and(PG_TYPE.TYPNAME.eq(typname)) .orderBy(orderBy) .fetch(PG_ENUM.ENUMLABEL); } }
@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); }
@Override public List<? extends StoragePoolHostMap> findBadPoolMapss(int limit) { return create().select(STORAGE_POOL_HOST_MAP.fields()) .from(STORAGE_POOL_HOST_MAP) .join(STORAGE_POOL) .on(STORAGE_POOL.ID.eq(STORAGE_POOL_HOST_MAP.STORAGE_POOL_ID)) .join(HOST) .on(HOST.ID.eq(STORAGE_POOL_HOST_MAP.HOST_ID)) .where(STORAGE_POOL_HOST_MAP.REMOVED.isNull() .and(HOST.STATE.eq(CommonStatesConstants.PURGED).or(STORAGE_POOL.STATE.eq(CommonStatesConstants.PURGED)))) .limit(limit) .fetchInto(StoragePoolHostMapRecord.class); }
@Override public List<? extends Volume> findBadNativeVolumes(int count) { return create().select(VOLUME.fields()) .from(VOLUME) .join(MOUNT) .on(MOUNT.VOLUME_ID.eq(VOLUME.ID)) .join(INSTANCE) .on(MOUNT.INSTANCE_ID.eq(INSTANCE.ID)) .where(INSTANCE.STATE.eq(CommonStatesConstants.PURGED) .and(VOLUME.STATE.eq(CommonStatesConstants.INACTIVE)) .and(INSTANCE.NATIVE_CONTAINER.isTrue())) .limit(count) .fetchInto(VolumeRecord.class); }
@Override public List<? extends IpAddress> findBadHostIpAddress(int count) { return create().select(IP_ADDRESS.fields()) .from(IP_ADDRESS) .join(HOST_IP_ADDRESS_MAP) .on(HOST_IP_ADDRESS_MAP.IP_ADDRESS_ID.eq(IP_ADDRESS.ID)) .join(HOST) .on(HOST.ID.eq(HOST_IP_ADDRESS_MAP.HOST_ID)) .where(HOST.STATE.eq(CommonStatesConstants.PURGED) .and(IP_ADDRESS.REMOVED.isNull()) .and(IP_ADDRESS.STATE.notIn(CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(IpAddressRecord.class); } }
protected List<? extends ConfigItemStatus> hostMigrationItems() { return create() .select(CONFIG_ITEM_STATUS.fields()) .from(CONFIG_ITEM_STATUS) .join(HOST) .on(HOST.ID.eq(CONFIG_ITEM_STATUS.HOST_ID)) .join(CONFIG_ITEM) .on(CONFIG_ITEM.NAME.eq(CONFIG_ITEM_STATUS.NAME)) .where(CONFIG_ITEM_STATUS.SOURCE_VERSION.isNotNull() .and(CONFIG_ITEM_STATUS.SOURCE_VERSION.ne(CONFIG_ITEM.SOURCE_VERSION)) .and(HOST.REMOVED.isNull())) .limit(BATCH_SIZE.get()) .fetchInto(ConfigItemStatusRecord.class); }
@Override public List<? extends Service> getServicesOnHost(long hostId) { return create().select(SERVICE.fields()) .from(SERVICE) .join(SERVICE_EXPOSE_MAP) .on(SERVICE_EXPOSE_MAP.SERVICE_ID.eq(SERVICE.ID)) .join(INSTANCE_HOST_MAP) .on(SERVICE_EXPOSE_MAP.INSTANCE_ID.eq(INSTANCE_HOST_MAP.INSTANCE_ID)) .where(INSTANCE_HOST_MAP.HOST_ID.eq(hostId)) .and(INSTANCE_HOST_MAP.REMOVED.isNull()) .and(SERVICE_EXPOSE_MAP.REMOVED.isNull()) .and(SERVICE.REMOVED.isNull()) .fetchInto(ServiceRecord.class); }
protected List<? extends ConfigItemStatus> serviceMigrationItems() { return create() .select(CONFIG_ITEM_STATUS.fields()) .from(CONFIG_ITEM_STATUS) .join(SERVICE) .on(SERVICE.ID.eq(CONFIG_ITEM_STATUS.SERVICE_ID)) .join(CONFIG_ITEM) .on(CONFIG_ITEM.NAME.eq(CONFIG_ITEM_STATUS.NAME)) .where(CONFIG_ITEM_STATUS.SOURCE_VERSION.isNotNull() .and(CONFIG_ITEM_STATUS.SOURCE_VERSION.ne(CONFIG_ITEM.SOURCE_VERSION)) .and(SERVICE.REMOVED.isNull())) .limit(BATCH_SIZE.get()) .fetchInto(ConfigItemStatusRecord.class); }
protected List<? extends ConfigItemStatus> accountMigrationItems() { return create() .select(CONFIG_ITEM_STATUS.fields()) .from(CONFIG_ITEM_STATUS) .join(ACCOUNT) .on(ACCOUNT.ID.eq(CONFIG_ITEM_STATUS.ACCOUNT_ID)) .join(CONFIG_ITEM) .on(CONFIG_ITEM.NAME.eq(CONFIG_ITEM_STATUS.NAME)) .where(CONFIG_ITEM_STATUS.SOURCE_VERSION.isNotNull() .and(CONFIG_ITEM_STATUS.SOURCE_VERSION.ne(CONFIG_ITEM.SOURCE_VERSION)) .and(ACCOUNT.REMOVED.isNull())) .limit(BATCH_SIZE.get()) .fetchInto(ConfigItemStatusRecord.class); }
protected List<? extends ConfigItemStatus> stackMigrationItems() { return create() .select(CONFIG_ITEM_STATUS.fields()) .from(CONFIG_ITEM_STATUS) .join(STACK) .on(STACK.ID.eq(CONFIG_ITEM_STATUS.STACK_ID)) .join(CONFIG_ITEM) .on(CONFIG_ITEM.NAME.eq(CONFIG_ITEM_STATUS.NAME)) .where(CONFIG_ITEM_STATUS.SOURCE_VERSION.isNotNull() .and(CONFIG_ITEM_STATUS.SOURCE_VERSION.ne(CONFIG_ITEM.SOURCE_VERSION)) .and(STACK.REMOVED.isNull())) .limit(BATCH_SIZE.get()) .fetchInto(ConfigItemStatusRecord.class); }
@Override public List<? extends StoragePool> findBadDockerPools(int count) { return create().select(STORAGE_POOL.fields()) .from(STORAGE_POOL) .join(STORAGE_POOL_HOST_MAP) .on(STORAGE_POOL_HOST_MAP.STORAGE_POOL_ID.eq(STORAGE_POOL.ID)) .join(HOST) .on(HOST.ID.eq(STORAGE_POOL_HOST_MAP.HOST_ID)) .where(STORAGE_POOL.REMOVED.isNull() .and(STORAGE_POOL.KIND.eq("docker")) .and(HOST.STATE.eq(CommonStatesConstants.PURGED)) .and(STORAGE_POOL.STATE.notIn(CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(StoragePoolRecord.class); }
@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); }
@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); }