@Override public List<String> getServiceNames() { try (Connection conn = datasource.getConnection()) { return context.get(conn) .selectDistinct(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME) .from(ZIPKIN_ANNOTATIONS) .where(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.isNotNull() .and(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.ne(""))) .fetch(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME); } catch (SQLException e) { throw new RuntimeException("Error querying for " + e + ": " + e.getMessage()); } }
@Override public List<String> getServiceNames() { try (Connection conn = datasource.getConnection()) { return context.get(conn) .selectDistinct(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME) .from(ZIPKIN_ANNOTATIONS) .where(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.isNotNull() .and(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.ne(""))) .fetch(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME); } catch (SQLException e) { throw new RuntimeException("Error querying for " + e + ": " + e.getMessage()); } }
@Override public List<String> getServiceNames() { try (Connection conn = datasource.getConnection()) { return context(conn) .selectDistinct(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME) .from(ZIPKIN_ANNOTATIONS) .where(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.isNotNull() .and(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.ne(""))) .fetch(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME); } catch (SQLException e) { throw new RuntimeException("Error querying for " + e + ": " + e.getMessage()); } }
@Override public List<String> getServiceNames() { try (Connection conn = datasource.getConnection()) { return context.get(conn) .selectDistinct(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME) .from(ZIPKIN_ANNOTATIONS) .where(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.isNotNull() .and(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.ne(""))) .fetch(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME); } catch (SQLException e) { throw new RuntimeException("Error querying for " + e + ": " + e.getMessage()); } }
@Override public List<Long> getLinkedAccounts(long accountId) { List<Long> accountIds = new ArrayList<>(); List<Long> linkedToAccounts = Arrays.asList(create().select(ACCOUNT_LINK.LINKED_ACCOUNT_ID) .from(ACCOUNT_LINK) .where(ACCOUNT_LINK.ACCOUNT_ID.eq(accountId) .and(ACCOUNT_LINK.LINKED_ACCOUNT_ID.isNotNull()) .and(ACCOUNT_LINK.REMOVED.isNull())) .fetch().intoArray(ACCOUNT_LINK.LINKED_ACCOUNT_ID)); List<Long> linkedFromAccounts = Arrays.asList(create().select(ACCOUNT_LINK.ACCOUNT_ID) .from(ACCOUNT_LINK) .where(ACCOUNT_LINK.LINKED_ACCOUNT_ID.eq(accountId) .and(ACCOUNT_LINK.REMOVED.isNull())) .fetch().intoArray(ACCOUNT_LINK.ACCOUNT_ID)); accountIds.addAll(linkedToAccounts); accountIds.addAll(linkedFromAccounts); return accountIds; }
@Override public List<? extends InstanceLink> findServiceBasedInstanceLinks(long instanceId) { return create() .select(INSTANCE_LINK.fields()) .from(INSTANCE_LINK) .where(INSTANCE_LINK.INSTANCE_ID.eq(instanceId) .and(INSTANCE_LINK.SERVICE_CONSUME_MAP_ID.isNotNull()) .and(INSTANCE_LINK.REMOVED.isNull())) .fetchInto(InstanceLinkRecord.class); }
@Override public List<? extends Agent> findAgentsToRemove() { if (startTime == null) { startTime = System.currentTimeMillis(); } if ((System.currentTimeMillis() - startTime) <= (HostDao.HOST_REMOVE_START_DELAY.get() * 1000)) { return Collections.emptyList(); } List<? extends Agent> agents = create().select(AGENT.fields()) .from(AGENT) .leftOuterJoin(HOST) .on(HOST.AGENT_ID.eq(AGENT.ID)) .where(HOST.ID.isNull().or(HOST.REMOVED.isNotNull()) .and(AGENT.STATE.eq(AgentConstants.STATE_DISCONNECTED))) .fetchInto(AgentRecord.class); // This is purging old pre-1.2 agent delegates List<? extends Agent> oldAgents = create().select(AGENT.fields()) .from(AGENT) .where(AGENT.REMOVED.isNull().and(AGENT.URI.like("delegate%"))) .fetchInto(AgentRecord.class); List<Agent> result = new ArrayList<>(agents); result.addAll(oldAgents); return result; } }
@Override public List<? extends ServiceExposeMap> getNonRemovedServiceHostnameMaps(long serviceId) { return create() .select(SERVICE_EXPOSE_MAP.fields()) .from(SERVICE_EXPOSE_MAP) .where(SERVICE_EXPOSE_MAP.SERVICE_ID.eq(serviceId)) .and(SERVICE_EXPOSE_MAP.REMOVED.isNull() .and(SERVICE_EXPOSE_MAP.STATE.notIn(CommonStatesConstants.REMOVED, CommonStatesConstants.REMOVING)) .and(SERVICE_EXPOSE_MAP.HOST_NAME.isNotNull())) .fetchInto(ServiceExposeMapRecord.class); }
@Override public List<? extends ServiceExposeMap> getNonRemovedServiceIpMaps(long serviceId) { return create() .select(SERVICE_EXPOSE_MAP.fields()) .from(SERVICE_EXPOSE_MAP) .where(SERVICE_EXPOSE_MAP.SERVICE_ID.eq(serviceId)) .and(SERVICE_EXPOSE_MAP.REMOVED.isNull() .and(SERVICE_EXPOSE_MAP.STATE.notIn(CommonStatesConstants.REMOVED, CommonStatesConstants.REMOVING)) .and(SERVICE_EXPOSE_MAP.IP_ADDRESS.isNotNull())) .fetchInto(ServiceExposeMapRecord.class); }
@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); }
public List<ApiKeyEntry> poll(int days) { return txResult(tx -> tx.select(API_KEYS.KEY_ID, API_KEYS.KEY_NAME, API_KEYS.EXPIRED_AT, API_KEYS.USER_ID) .from(API_KEYS) .where(API_KEYS.EXPIRED_AT.isNotNull() .and(currentTimestamp().greaterOrEqual(trunc(API_KEYS.EXPIRED_AT).minus(days)) .and(API_KEYS.LAST_NOTIFIED_AT.isNull() .or(API_KEYS.LAST_NOTIFIED_AT.lessOrEqual(API_KEYS.EXPIRED_AT.minus(days)))))) .fetch(this::toEntry)); }
@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)); }
@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); }
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); }
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); }
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); }
private void fetchExternalServiceLinks(final MetaHelperInfo helperInfo, final OutputStream os) { Condition condition = SERVICE_CONSUME_MAP.ACCOUNT_ID.eq(helperInfo.getAccount().getId()); if (!helperInfo.getOtherAccountsServicesIds().isEmpty()) { condition = SERVICE_CONSUME_MAP.ACCOUNT_ID.eq(helperInfo.getAccount().getId()).or( SERVICE_CONSUME_MAP.SERVICE_ID.in(helperInfo.getOtherAccountsServicesIds())); } create() .select(SERVICE_CONSUME_MAP.NAME, SERVICE_CONSUME_MAP.CONSUMED_SERVICE, SERVICE.UUID) .from(SERVICE_CONSUME_MAP) .join(SERVICE) .on(SERVICE_CONSUME_MAP.SERVICE_ID.eq(SERVICE.ID)) .where(SERVICE_CONSUME_MAP.REMOVED.isNull()) .and(SERVICE.REMOVED.isNull()) .and(SERVICE_CONSUME_MAP.CONSUMED_SERVICE.isNotNull()) .and(condition) .fetchInto(new RecordHandler<Record3<String, String, String>>() { @Override public void next(Record3<String, String, String> record) { String serviceUUID = record.getValue(SERVICE.UUID); String linkAlias = record.getValue(SERVICE_CONSUME_MAP.NAME); String consumedService = record.getValue(SERVICE_CONSUME_MAP.CONSUMED_SERVICE); ServiceLinkMetaData data = new ServiceLinkMetaData(serviceUUID, consumedService, linkAlias); writeToJson(os, data); } }); }
public List<String> poll() { @SuppressWarnings("unchecked") Field<? extends Number> i = (Field<? extends Number>) PgUtils.interval("1 second"); return txResult(tx -> { List<String> ids = tx.select(TASKS.TASK_ID) .from(TASKS) .where(TASKS.TASK_INTERVAL.greaterThan(0L).and(TASKS.STARTED_AT.isNull() .or(TASKS.FINISHED_AT.isNotNull() .and(TASKS.FINISHED_AT.plus(TASKS.TASK_INTERVAL.mul(i)).lessOrEqual(currentTimestamp()))))) .forUpdate() .skipLocked() .fetch(TASKS.TASK_ID); if (ids.isEmpty()) { return ids; } tx.update(TASKS) .set(TASKS.STARTED_AT, currentTimestamp()) .set(TASKS.TASK_STATUS, value("RUNNING")) .set(TASKS.FINISHED_AT, (Timestamp)null) .set(TASKS.LAST_UPDATED_AT, currentTimestamp()) .where(TASKS.TASK_ID.in(ids)) .execute(); return ids; }); }
protected List<? extends ConfigItemStatus> agentMigrationItems() { return create() .select(CONFIG_ITEM_STATUS.fields()) .from(CONFIG_ITEM_STATUS) .join(AGENT) .on(AGENT.ID.eq(CONFIG_ITEM_STATUS.AGENT_ID)) .join(CONFIG_ITEM) .on(CONFIG_ITEM.NAME.eq(CONFIG_ITEM_STATUS.NAME)) .leftOuterJoin(INSTANCE) .on(INSTANCE.AGENT_ID.eq(AGENT.ID)) .where(CONFIG_ITEM_STATUS.SOURCE_VERSION.isNotNull() .and(CONFIG_ITEM_STATUS.SOURCE_VERSION.ne(CONFIG_ITEM.SOURCE_VERSION)) .and(AGENT.STATE.in(CommonStatesConstants.ACTIVE, CommonStatesConstants.ACTIVATING, AgentConstants.STATE_RECONNECTING, AgentConstants.STATE_FINISHING_RECONNECT, AgentConstants.STATE_RECONNECTED)) .and(INSTANCE.STATE.isNull().or(INSTANCE.STATE.eq(InstanceConstants.STATE_RUNNING)))) .orderBy(AGENT.ID.asc()) .limit(BATCH_SIZE.get()) .fetchInto(ConfigItemStatusRecord.class); }