protected Condition inHostList(List<String> hostUUIDs) { if (hostUUIDs == null || hostUUIDs.isEmpty()) { return DSL.trueCondition(); } return HOST.UUID.in(hostUUIDs); }
public void removeUsers(DSLContext tx, UUID teamId, Collection<UUID> userIds) { if (userIds == null || userIds.isEmpty()) { return; } tx.deleteFrom(USER_TEAMS) .where(USER_TEAMS.TEAM_ID.eq(teamId) .and(USER_TEAMS.USER_ID.in(userIds))) .execute(); }
@Override public List<? extends ConfigItemStatus> listItems(ConfigUpdateRequest request) { Set<String> names = new HashSet<String>(); for ( ConfigUpdateItem item : request.getItems() ) { names.add(item.getName()); } return create() .selectFrom(CONFIG_ITEM_STATUS) .where( CONFIG_ITEM_STATUS.NAME.in(names) .and(targetObjectCondition(request.getClient()))) .fetch(); }
public boolean isInAnyTeam(DSLContext tx, UUID orgId, UUID userId, TeamRole... roles) { SelectConditionStep<Record1<UUID>> teamIds = select(TEAMS.TEAM_ID).from(TEAMS).where(TEAMS.ORG_ID.eq(orgId)); return tx.fetchExists(selectFrom(USER_TEAMS) .where(USER_TEAMS.USER_ID.eq(userId) .and(USER_TEAMS.TEAM_ID.in(teamIds)) .and(USER_TEAMS.TEAM_ROLE.in(Utils.toString(roles))))); }
private boolean hasAccessLevel(DSLContext tx, UUID inventoryId, UUID userId, ResourceAccessLevel... levels) { SelectConditionStep<Record1<UUID>> teamIds = select(USER_TEAMS.TEAM_ID) .from(USER_TEAMS) .where(USER_TEAMS.USER_ID.eq(userId)); return tx.fetchExists(selectFrom(INVENTORY_TEAM_ACCESS) .where(INVENTORY_TEAM_ACCESS.INVENTORY_ID.eq(inventoryId) .and(INVENTORY_TEAM_ACCESS.TEAM_ID.in(teamIds)) .and(INVENTORY_TEAM_ACCESS.ACCESS_LEVEL.in(Utils.toString(levels))))); }
private boolean hasAccessLevel(DSLContext tx, UUID secretId, UUID userId, ResourceAccessLevel... levels) { SelectConditionStep<Record1<UUID>> teamIds = select(USER_TEAMS.TEAM_ID) .from(USER_TEAMS) .where(USER_TEAMS.USER_ID.eq(userId)); return tx.fetchExists(selectFrom(SECRET_TEAM_ACCESS) .where(SECRET_TEAM_ACCESS.SECRET_ID.eq(secretId) .and(SECRET_TEAM_ACCESS.TEAM_ID.in(teamIds)) .and(SECRET_TEAM_ACCESS.ACCESS_LEVEL.in(Utils.toString(levels))))); }
protected Condition elligibleHostCondition() { return AGENT.ID.isNull().or(AGENT.STATE.eq(CommonStatesConstants.ACTIVE)) .and(HOST.STATE.in(CommonStatesConstants.ACTIVE, CommonStatesConstants.UPDATING_ACTIVE)) .and(STORAGE_POOL.STATE.eq(CommonStatesConstants.ACTIVE)); }
private Condition getMultiAccountInstanceSearchCondition(final MetaHelperInfo helperInfo) { Condition condition = INSTANCE.ACCOUNT_ID.eq(helperInfo.getAccount().getId()); if (!helperInfo.getOtherAccountsServicesIds().isEmpty()) { condition = INSTANCE.ACCOUNT_ID.eq(helperInfo.getAccount().getId()).or( SERVICE_EXPOSE_MAP.SERVICE_ID.in(helperInfo.getOtherAccountsServicesIds())); } return condition; }
private int countRunning(DSLContext tx, UUID prjId) { return tx.selectCount() .from(PROCESS_QUEUE) .where(PROCESS_QUEUE.PROJECT_ID.eq(prjId).and(PROCESS_QUEUE.CURRENT_STATUS.in(RUNNING_PROCESS_STATUSES))) .fetchOne(0, int.class); }
public void updateRunning(Set<String> runningTasks) { tx(tx -> { tx.update(TASKS) .set(TASKS.LAST_UPDATED_AT, currentTimestamp()) .where(TASKS.TASK_ID.in(runningTasks)) .execute(); }); }
@Override public List<? extends Host> getHosts(Long accountId, List<String> uuids) { return create() .selectFrom(HOST) .where(HOST.ACCOUNT_ID.eq(accountId) .and(HOST.STATE.notIn(CommonStatesConstants.REMOVED, CommonStatesConstants.REMOVING)) .and(HOST.UUID.in(uuids))).fetch(); }
@Override public List<? extends Network> getActiveNetworks(Long accountId) { return create().select(NETWORK.fields()) .from(NETWORK) .where(NETWORK.ACCOUNT_ID.eq(accountId) .and(NETWORK.STATE.in(CommonStatesConstants.ACTIVATING, CommonStatesConstants.ACTIVE, CommonStatesConstants.UPDATING_ACTIVE))) .fetchInto(NetworkRecord.class); }
public boolean hasUser(DSLContext tx, UUID teamId, UUID userId, TeamRole... roles) { SelectConditionStep<UserTeamsRecord> q = tx.selectFrom(USER_TEAMS) .where(USER_TEAMS.TEAM_ID.eq(teamId) .and(USER_TEAMS.USER_ID.eq(userId))); if (roles != null && roles.length != 0) { q.and(USER_TEAMS.TEAM_ROLE.in(Utils.toString(roles))); } return tx.fetchExists(q); }
public int failStalled(Field<Timestamp> cutoff) { return txResult(tx -> tx.update(AGENT_COMMANDS) .set(AGENT_COMMANDS.COMMAND_STATUS, Status.FAILED.toString()) .where(AGENT_COMMANDS.COMMAND_STATUS.in(Status.CREATED.toString()) .and(AGENT_COMMANDS.CREATED_AT.lessThan(cutoff))) .execute()); } }
@Override public Account getAccountByUuid(String uuid) { return create() .selectFrom(ACCOUNT) .where(ACCOUNT.UUID.eq(uuid) .and(ACCOUNT.STATE.in(getActiveStates()))) .orderBy(ACCOUNT.ID.asc()).limit(1).fetchOne(); }
@Override public Account getAdminAccount() { return create() .selectFrom(ACCOUNT) .where(ACCOUNT.STATE.in(getActiveStates()) .and(ACCOUNT.KIND.eq(AccountConstants.ADMIN_KIND))) .orderBy(ACCOUNT.ID.asc()).limit(1).fetchOne(); }
@Override public List<? extends Service> getActiveServices(long accountId) { return create() .select(SERVICE.fields()) .from(SERVICE) .where(SERVICE.ACCOUNT_ID.eq(accountId)) .and(SERVICE.REMOVED.isNull()) .and(SERVICE.STATE.in(sdService.getServiceActiveStates())) .fetchInto(ServiceRecord.class); }
public boolean hasRole(DSLContext tx, UUID orgId, TeamRole role) { SelectConditionStep<Record1<UUID>> teamIds = select(TEAMS.TEAM_ID).from(TEAMS).where(TEAMS.ORG_ID.eq(orgId)); return tx.fetchExists(select(USER_TEAMS.USER_ID) .from(USER_TEAMS) .where(USER_TEAMS.TEAM_ROLE.eq(role.toString()) .and(USER_TEAMS.TEAM_ID.in(teamIds)))); }
@Override public Account getAdminAccountExclude(long accountId) { return create() .selectFrom(ACCOUNT) .where(ACCOUNT.STATE.in(getAccountActiveStates()) .and(ACCOUNT.KIND.eq(AccountConstants.ADMIN_KIND)) .and(ACCOUNT.ID.ne(accountId))) .orderBy(ACCOUNT.ID.asc()).limit(1).fetchOne(); }
@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); }