@Override public Multimap<Cell, Long> getAllTimestamps(final TableReference tableRef, final Set<Cell> cells, final long timestamp) throws InsufficientConsistencyException { if (cells.isEmpty()) { return ImmutableMultimap.of(); } Multimap<Cell, Long> toReturn = ArrayListMultimap.create(); for (List<Cell> partition : Iterables.partition(cells, batchSizeForReads)) { toReturn.putAll(run(ctx -> { Result<? extends Record> records = ctx .select(A_ROW_NAME, A_COL_NAME, A_TIMESTAMP) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .join(values(ctx, toRows(Sets.newHashSet(partition)), TEMP_TABLE_1, ROW_NAME, COL_NAME)) .on(A_ROW_NAME.eq(T1_ROW_NAME) .and(A_COL_NAME.eq(T1_COL_NAME))) .where(A_TIMESTAMP.lessThan(timestamp)) .fetch(); Multimap<Cell, Long> results = ArrayListMultimap.create(records.size() / 4, 4); for (Record record : records) { results.put( Cell.create(record.getValue(A_ROW_NAME), record.getValue(A_COL_NAME)), record.getValue(A_TIMESTAMP)); } return results; })); } return toReturn; }
private Result<? extends Record> fetchValues(DSLContext ctx, TableReference tableRef, Select<? extends Record> subQuery) { return ctx.select(A_ROW_NAME, A_COL_NAME, A_TIMESTAMP, A_VALUE) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .join(subQuery.asTable(TEMP_TABLE_2)) .on(A_ROW_NAME.eq(T2_ROW_NAME) .and(A_COL_NAME.eq(T2_COL_NAME)) .and(A_TIMESTAMP.eq(T2_MAX_TIMESTAMP))) .fetch(); }
private Select<? extends Record> getLatestTimestampQueryManyTimestamps(DSLContext ctx, TableReference tableRef, RowN[] rows) { return ctx.select(A_ROW_NAME, A_COL_NAME, DSL.max(A_TIMESTAMP).as(MAX_TIMESTAMP)) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .join(values(ctx, rows, TEMP_TABLE_1, ROW_NAME, COL_NAME, TIMESTAMP)) .on(A_ROW_NAME.eq(T1_ROW_NAME) .and(A_COL_NAME.eq(T1_COL_NAME))) .where(A_TIMESTAMP.lessThan(T1_TIMESTAMP)) .groupBy(A_ROW_NAME, A_COL_NAME); }
@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); }
@Override public Service getServiceByServiceIndexId(long serviceIndexId) { Record record = create() .select(SERVICE.fields()) .from(SERVICE) .join(SERVICE_INDEX).on(SERVICE.ID.eq(SERVICE_INDEX.SERVICE_ID)) .where(SERVICE_INDEX.ID.eq(serviceIndexId)) .fetchAny(); return record == null ? null : record.into(Service.class); }
@Override public String getPublicCA() { Record1<String> r = create().select(CERTIFICATE.CERT_CHAIN) .from(CERTIFICATE) .join(ACCOUNT) .on(ACCOUNT.ID.eq(CERTIFICATE.ACCOUNT_ID)) .where(CERTIFICATE.STATE.eq(CommonStatesConstants.ACTIVE) .and(ACCOUNT.UUID.like("system-ha-%"))) .fetchAny(); return r == null ? null : r.value1(); }
@Override public List<? extends Service> findLinkedServices(long serviceId) { return create() .select(SERVICE.fields()) .from(SERVICE) .join(SERVICE_CONSUME_MAP) .on(SERVICE_CONSUME_MAP.CONSUMED_SERVICE_ID.eq(SERVICE.ID)) .where( SERVICE_CONSUME_MAP.SERVICE_ID.eq(serviceId) .and(SERVICE_CONSUME_MAP.REMOVED.isNull())).fetchInto(Service.class); }
@Override public List<? extends Service> findServicesForInstanceId(long instanceId){ return create().select(SERVICE.fields()) .from(SERVICE) .join(SERVICE_EXPOSE_MAP) .on(SERVICE_EXPOSE_MAP.SERVICE_ID.eq(SERVICE.ID)) .where(SERVICE_EXPOSE_MAP.INSTANCE_ID.eq(instanceId)) .and(SERVICE_EXPOSE_MAP.REMOVED.isNull()) .and(SERVICE.REMOVED.isNull()) .fetchInto(ServiceRecord.class); }
protected List<? extends ConfigItemStatus> serviceOutOfSyncItems() { return create() .select(CONFIG_ITEM_STATUS.fields()) .from(CONFIG_ITEM_STATUS) .join(SERVICE) .on(SERVICE.ID.eq(CONFIG_ITEM_STATUS.SERVICE_ID)) .where(CONFIG_ITEM_STATUS.REQUESTED_VERSION.ne(CONFIG_ITEM_STATUS.APPLIED_VERSION) .and(SERVICE.REMOVED.isNull())) .limit(BATCH_SIZE.get()) .fetchInto(ConfigItemStatusRecord.class); }
protected List<? extends ConfigItemStatus> stackOutOfSyncItems() { return create() .select(CONFIG_ITEM_STATUS.fields()) .from(CONFIG_ITEM_STATUS) .join(STACK) .on(STACK.ID.eq(CONFIG_ITEM_STATUS.STACK_ID)) .where(CONFIG_ITEM_STATUS.REQUESTED_VERSION.ne(CONFIG_ITEM_STATUS.APPLIED_VERSION) .and(STACK.REMOVED.isNull())) .limit(BATCH_SIZE.get()) .fetchInto(ConfigItemStatusRecord.class); }
protected List<? extends ConfigItemStatus> accountOutOfSyncItems() { return create() .select(CONFIG_ITEM_STATUS.fields()) .from(CONFIG_ITEM_STATUS) .join(ACCOUNT) .on(ACCOUNT.ID.eq(CONFIG_ITEM_STATUS.ACCOUNT_ID)) .where(CONFIG_ITEM_STATUS.REQUESTED_VERSION.ne(CONFIG_ITEM_STATUS.APPLIED_VERSION) .and(ACCOUNT.REMOVED.isNull())) .limit(BATCH_SIZE.get()) .fetchInto(ConfigItemStatusRecord.class); }
protected List<? extends ConfigItemStatus> hostOutOfSyncItems() { return create() .select(CONFIG_ITEM_STATUS.fields()) .from(CONFIG_ITEM_STATUS) .join(HOST) .on(HOST.ID.eq(CONFIG_ITEM_STATUS.HOST_ID)) .where(CONFIG_ITEM_STATUS.REQUESTED_VERSION.ne(CONFIG_ITEM_STATUS.APPLIED_VERSION) .and(HOST.REMOVED.isNull())) .limit(BATCH_SIZE.get()) .fetchInto(ConfigItemStatusRecord.class); }
@Override public List<? extends Network> findBadNetworks(int count) { return create().select(NETWORK.fields()) .from(NETWORK) .join(ACCOUNT) .on(ACCOUNT.ID.eq(NETWORK.ACCOUNT_ID)) .where(NETWORK.REMOVED.isNull() .and(ACCOUNT.STATE.eq(CommonStatesConstants.PURGED)) .and(NETWORK.STATE.notIn(CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(NetworkRecord.class); }
@Override public List<? extends UserPreference> findBadUserPreference(int count) { return create().select(USER_PREFERENCE.fields()) .from(USER_PREFERENCE) .join(ACCOUNT) .on(ACCOUNT.ID.eq(USER_PREFERENCE.ACCOUNT_ID)) .where(USER_PREFERENCE.REMOVED.isNull() .and(ACCOUNT.STATE.eq(CommonStatesConstants.PURGED)) .and(USER_PREFERENCE.STATE.notIn(CommonStatesConstants.REMOVING, CommonStatesConstants.DEACTIVATING))) .limit(count) .fetchInto(UserPreferenceRecord.class); }
@Override public List<? extends GenericObject> findBadGO(int count) { return create().select(GENERIC_OBJECT.fields()) .from(GENERIC_OBJECT) .join(ACCOUNT) .on(ACCOUNT.ID.eq(GENERIC_OBJECT.ACCOUNT_ID)) .where(GENERIC_OBJECT.REMOVED.isNull() .and(ACCOUNT.STATE.eq(CommonStatesConstants.PURGED)) .and(GENERIC_OBJECT.STATE.notIn(CommonStatesConstants.REMOVING, CommonStatesConstants.DEACTIVATING))) .limit(count) .fetchInto(GenericObjectRecord.class); }
@Override public List<? extends Mount> findBadMounts(int count) { return create().select(MOUNT.fields()) .from(MOUNT) .join(VOLUME) .on(VOLUME.ID.eq(MOUNT.VOLUME_ID)) .where(VOLUME.STATE.eq(CommonStatesConstants.PURGED) .and(MOUNT.REMOVED.isNull()) .and(MOUNT.STATE.notIn(CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(MountRecord.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 StoragePool> findBadPools(int count) { return create().select(STORAGE_POOL.fields()) .from(STORAGE_POOL) .join(ACCOUNT) .on(ACCOUNT.ID.eq(STORAGE_POOL.ACCOUNT_ID)) .where(STORAGE_POOL.REMOVED.isNull() .and(ACCOUNT.STATE.eq(CommonStatesConstants.PURGED)) .and(STORAGE_POOL.STATE.notIn(CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(StoragePoolRecord.class); }
@Override public List<? extends VolumeStoragePoolMap> findBandVolumeStoragePoolMap(int count) { return create().select(VOLUME_STORAGE_POOL_MAP.fields()) .from(VOLUME_STORAGE_POOL_MAP) .join(VOLUME) .on(VOLUME.ID.eq(VOLUME_STORAGE_POOL_MAP.VOLUME_ID)) .where(VOLUME.STATE.eq(CommonStatesConstants.PURGED) .and(VOLUME_STORAGE_POOL_MAP.REMOVED.isNull()) .and(VOLUME_STORAGE_POOL_MAP.STATE.notIn(CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(VolumeStoragePoolMapRecord.class); }
@Override public List<? extends Instance> getInstancesWithHealtcheckEnabled(long accountId) { return create().select(INSTANCE.fields()) .from(INSTANCE) .join(HEALTHCHECK_INSTANCE) .on(HEALTHCHECK_INSTANCE.INSTANCE_ID.eq(INSTANCE.ID)) .and(HEALTHCHECK_INSTANCE.REMOVED.isNull()) .and(INSTANCE.REMOVED.isNull()) .and(INSTANCE.STATE.in(InstanceConstants.STATE_STARTING, InstanceConstants.STATE_RUNNING) .and(INSTANCE.ACCOUNT_ID.eq(accountId))) .fetchInto(InstanceRecord.class); }