private static SelectJoinStep<Record11<UUID, UUID, String, String, String, String, String, String, UUID, String, String>> selectRepositoryEntry(DSLContext tx) { return tx.select(REPOSITORIES.REPO_ID, REPOSITORIES.PROJECT_ID, REPOSITORIES.REPO_NAME, REPOSITORIES.REPO_URL, REPOSITORIES.REPO_BRANCH, REPOSITORIES.REPO_COMMIT_ID, REPOSITORIES.REPO_PATH, REPOSITORIES.META.cast(String.class), SECRETS.SECRET_ID, SECRETS.SECRET_NAME, SECRETS.STORE_TYPE) .from(REPOSITORIES) .leftOuterJoin(SECRETS).on(SECRETS.SECRET_ID.eq(REPOSITORIES.SECRET_ID)); }
@Override public List<Instance> getUnmappedDeploymentUnitInstances(String deploymentUnitUuid) { List<? extends Instance> instanceRecords = create() .select(INSTANCE.fields()) .from(INSTANCE) .leftOuterJoin(INSTANCE_HOST_MAP) .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID).and(INSTANCE_HOST_MAP.REMOVED.isNull())) .where(INSTANCE.REMOVED.isNull()) .and(INSTANCE.DEPLOYMENT_UNIT_UUID.eq(deploymentUnitUuid)) .and(INSTANCE_HOST_MAP.ID.isNull()) .fetchInto(InstanceRecord.class); List<Instance> instances = new ArrayList<Instance>(); for (Instance i : instanceRecords) { instances.add(i); } return instances; }
@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; } }
SERVICE.NAME, STACK.ID, STACK.NAME) .from(SERVICE_CONSUME_MAP) .leftOuterJoin(SERVICE) .on(SERVICE.ID.eq(SERVICE_CONSUME_MAP.CONSUMED_SERVICE_ID)) .leftOuterJoin(STACK)
public List<ResourceAccessEntry> getAccessLevel(UUID orgId, String name) { List<ResourceAccessEntry> resourceAccessList = new ArrayList<>(); try (DSLContext tx = DSL.using(cfg)) { Result<Record4<UUID, UUID, String, String>> teamAccess = tx.select( SECRET_TEAM_ACCESS.TEAM_ID, SECRET_TEAM_ACCESS.SECRET_ID, TEAMS.TEAM_NAME, SECRET_TEAM_ACCESS.ACCESS_LEVEL) .from(SECRET_TEAM_ACCESS) .leftOuterJoin(TEAMS).on(TEAMS.TEAM_ID.eq(SECRET_TEAM_ACCESS.TEAM_ID)) .where(SECRET_TEAM_ACCESS.SECRET_ID.eq(getByName(orgId, name).getId())) .fetch(); for (Record4<UUID, UUID, String, String> t : teamAccess) { resourceAccessList.add(new ResourceAccessEntry(t.get(SECRET_TEAM_ACCESS.TEAM_ID), null, t.get(TEAMS.TEAM_NAME), ResourceAccessLevel.valueOf(t.get(SECRET_TEAM_ACCESS.ACCESS_LEVEL)))); } } return resourceAccessList; }
public List<ResourceAccessEntry> getAccessLevel(UUID projectId) { List<ResourceAccessEntry> resourceAccessList = new ArrayList<>(); try (DSLContext tx = DSL.using(cfg)) { Result<Record5<UUID, UUID, String, String, String>> teamsAccess = tx.select( PROJECT_TEAM_ACCESS.TEAM_ID, PROJECT_TEAM_ACCESS.PROJECT_ID, TEAMS.TEAM_NAME, ORGANIZATIONS.ORG_NAME, PROJECT_TEAM_ACCESS.ACCESS_LEVEL) .from(PROJECT_TEAM_ACCESS) .leftOuterJoin(TEAMS).on(TEAMS.TEAM_ID.eq(PROJECT_TEAM_ACCESS.TEAM_ID)) .leftOuterJoin(PROJECTS).on(PROJECTS.PROJECT_ID.eq(projectId)) .leftOuterJoin(ORGANIZATIONS).on(ORGANIZATIONS.ORG_ID.eq(PROJECTS.ORG_ID)) .where(PROJECT_TEAM_ACCESS.PROJECT_ID.eq(projectId)) .fetch(); for (Record5<UUID, UUID, String, String, String> t : teamsAccess) { resourceAccessList.add(new ResourceAccessEntry(t.get(PROJECT_TEAM_ACCESS.TEAM_ID), t.get(ORGANIZATIONS.ORG_NAME), t.get(TEAMS.TEAM_NAME), ResourceAccessLevel.valueOf(t.get(PROJECT_TEAM_ACCESS.ACCESS_LEVEL)))); } } return resourceAccessList; }
field(ROUTINES.ROUTINE_DEFINITION.likeRegex(".*(?i:(\\w+\\s+)+aggregate\\s+function).*")).as("aggregate")) .from(ROUTINES) .leftOuterJoin(ELEMENT_TYPES) .on(ROUTINES.ROUTINE_SCHEMA.equal(ELEMENT_TYPES.OBJECT_SCHEMA)) .and(ROUTINES.ROUTINE_NAME.equal(ELEMENT_TYPES.OBJECT_NAME))
.select(LABEL.ID) .from(LABEL) .leftOuterJoin(INSTANCE_LABEL_MAP).on(LABEL.ID.eq(INSTANCE_LABEL_MAP.LABEL_ID)) .leftOuterJoin(HOST_LABEL_MAP).on(LABEL.ID.eq(HOST_LABEL_MAP.LABEL_ID)) .where(INSTANCE_LABEL_MAP.ID.isNull())
@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); }
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 Image> findBadImages(int count) { return create().select(IMAGE.fields()) .from(IMAGE) .leftOuterJoin(INSTANCE) .on(IMAGE.ID.eq(INSTANCE.IMAGE_ID)) .where((INSTANCE.STATE.eq(CommonStatesConstants.PURGED).or(INSTANCE.ID.isNull())) .and(IMAGE.REMOVED.isNull()) .and(IMAGE.STATE.notIn(CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(ImageRecord.class); }
@Override public List<? extends Volume> identifyUnmappedVolumes(long accountId, Set<Long> volumeIds) { List<VolumeRecord> volumes = create() .selectDistinct(VOLUME.fields()) .from(VOLUME) .leftOuterJoin(VOLUME_STORAGE_POOL_MAP) .on(VOLUME_STORAGE_POOL_MAP.VOLUME_ID.eq(VOLUME.ID)) .where(VOLUME.ID.in(volumeIds) .and((VOLUME.REMOVED.isNull()))) .and(VOLUME.ACCOUNT_ID.eq(accountId)) .and(VOLUME_STORAGE_POOL_MAP.ID.isNull()) .fetchInto(VolumeRecord.class); return volumes; }
@Override public Map<Long, Long> findStoragePoolHostsByDriver(Long accountId, Long storageDriverId) { final Map<Long, Long> result = new HashMap<>(); create().select(HOST.ID, STORAGE_POOL.ID) .from(HOST) .leftOuterJoin(STORAGE_POOL_HOST_MAP) .on(STORAGE_POOL_HOST_MAP.HOST_ID.eq(HOST.ID)) .leftOuterJoin(STORAGE_POOL) .on(STORAGE_POOL_HOST_MAP.STORAGE_POOL_ID.eq(STORAGE_POOL.ID) .and(STORAGE_POOL.STORAGE_DRIVER_ID.eq(storageDriverId))) .where(STORAGE_POOL.REMOVED.isNull() .and(STORAGE_POOL_HOST_MAP.REMOVED.isNull()) .and(HOST.ACCOUNT_ID.eq(accountId)) .and(HOST.REMOVED.isNull())) .fetchInto(new RecordHandler<Record2<Long, Long>>() { @Override public void next(Record2<Long, Long> record) { Long hostId = record.getValue(HOST.ID); Long storagePoolId = record.getValue(STORAGE_POOL.ID); if (!result.containsKey(hostId) || storagePoolId != null) { result.put(hostId, storagePoolId); } } }); return result; }
@Override public List<? extends Host> getActiveHosts(long accountId) { return create() .select(HOST.fields()) .from(HOST) .leftOuterJoin(AGENT) .on(AGENT.ID.eq(HOST.AGENT_ID)) .where( AGENT.ID.isNull() .or(AGENT.STATE.in(CommonStatesConstants.ACTIVE, AgentConstants.STATE_FINISHING_RECONNECT, AgentConstants.STATE_RECONNECTED)) .and(HOST.REMOVED.isNull()) .and(HOST.ACCOUNT_ID.eq(accountId)) .and(HOST.STATE.in(CommonStatesConstants.ACTIVATING, CommonStatesConstants.ACTIVE, CommonStatesConstants.UPDATING_ACTIVE))) .fetchInto(Host.class); }
TypeInfo.MAXIMUM_SCALE) .from(FUNCTION_ALIASES) .leftOuterJoin(TYPE_INFO) .on(FunctionAliases.DATA_TYPE.equal(TypeInfo.DATA_TYPE))
@Override public List<? extends Stack> getStacksToUpgrade(Collection<String> currentIds) { return create().select(STACK.fields()) .from(STACK) .leftOuterJoin(SCHEDULED_UPGRADE) .on(SCHEDULED_UPGRADE.STACK_ID.eq(STACK.ID) .and(SCHEDULED_UPGRADE.REMOVED.isNull()) .and(SCHEDULED_UPGRADE.FINISHED.isNull())) .where(STACK.REMOVED.isNull() .and(STACK.SYSTEM.isTrue()) .and(STACK.EXTERNAL_ID.notIn(currentIds)) .and(SCHEDULED_UPGRADE.ID.isNull())) .fetchInto(StackRecord.class); }
@Override public List<? extends Stack> getStacksThatMatch(Collection<String> currentIds) { return create().select(STACK.fields()) .from(STACK) .leftOuterJoin(SCHEDULED_UPGRADE) .on(SCHEDULED_UPGRADE.STACK_ID.eq(STACK.ID) .and(SCHEDULED_UPGRADE.REMOVED.isNull()) .and(SCHEDULED_UPGRADE.FINISHED.isNull())) .where(STACK.REMOVED.isNull() .and(STACK.SYSTEM.isTrue()) .and(STACK.EXTERNAL_ID.in(currentIds)) .and(SCHEDULED_UPGRADE.ID.isNull())) .fetchInto(StackRecord.class); }
private SelectConditionStep<Record> schemaQuery(long accountId, String role) { return create() .select() .from(DYNAMIC_SCHEMA).leftOuterJoin(DYNAMIC_SCHEMA_ROLE) .on(DYNAMIC_SCHEMA_ROLE.DYNAMIC_SCHEMA_ID.eq(DYNAMIC_SCHEMA.ID)) .where(DYNAMIC_SCHEMA.ACCOUNT_ID.eq(accountId) .and(DYNAMIC_SCHEMA_ROLE.ROLE.eq(role)) .and(DYNAMIC_SCHEMA.STATE.ne(CommonStatesConstants.PURGED))) .or(DYNAMIC_SCHEMA.ACCOUNT_ID.eq(accountId) .and(DYNAMIC_SCHEMA_ROLE.ROLE.isNull()) .and(DYNAMIC_SCHEMA.STATE.ne(CommonStatesConstants.PURGED))) .or(DYNAMIC_SCHEMA_ROLE.ROLE.eq(role) .and(DYNAMIC_SCHEMA.ACCOUNT_ID.isNull()) .and(DYNAMIC_SCHEMA.STATE.ne(CommonStatesConstants.PURGED))); }
@Override public List<? extends Volume> findSharedOrUnmappedVolumes(long accountId, String volumeName) { List<VolumeRecord> volumes = create() .selectDistinct(VOLUME.fields()) .from(VOLUME) .leftOuterJoin(VOLUME_STORAGE_POOL_MAP) .on(VOLUME_STORAGE_POOL_MAP.VOLUME_ID.eq(VOLUME.ID)) .leftOuterJoin(STORAGE_POOL) .on(VOLUME_STORAGE_POOL_MAP.STORAGE_POOL_ID.eq(STORAGE_POOL.ID)) .where(VOLUME.NAME.eq(volumeName) .and((VOLUME.REMOVED.isNull()))) .and(VOLUME.ACCOUNT_ID.eq(accountId)) .and(STORAGE_POOL.KIND.notIn(LOCAL_POOL_KINDS).or(STORAGE_POOL.KIND.isNull())) .and(STORAGE_POOL.REMOVED.isNull()) .fetchInto(VolumeRecord.class); return volumes; }
POLICY_LINKS.USER_ID) .from(POLICY_LINKS) .leftOuterJoin(POLICIES).on(POLICY_LINKS.POLICY_ID.eq(POLICIES.POLICY_ID));