@Override public void updateNullUpdatedHosts() { if (HOST_REMOVE_DELAY.get() < 0) { return; } create().update(HOST) .set(HOST.REMOVE_AFTER, new Date(System.currentTimeMillis() + HOST_REMOVE_DELAY.get() * 1000)) .where(HOST.REMOVE_AFTER.isNull()) .execute(); }
@Override public Agent getAgentByUri(String uri) { return create() .selectFrom(AGENT) .where(AGENT.URI.eq(uri) .and(AGENT.REMOVED.isNull())) .fetchAny(); }
@Override public List<Long> getInstanceIdsForAccount(long accountId) { return create() .select(INSTANCE.ID) .from(INSTANCE) .where(INSTANCE.REMOVED.isNull() .and(INSTANCE.ACCOUNT_ID.eq(accountId))) .fetchInto(Long.class); } }
@Override public List<? extends ServiceConsumeMap> findConsumedMapsToRemove(long serviceId) { return create() .selectFrom(SERVICE_CONSUME_MAP) .where( SERVICE_CONSUME_MAP.SERVICE_ID.eq(serviceId) .and((SERVICE_CONSUME_MAP.REMOVED.isNull(). or(SERVICE_CONSUME_MAP.STATE.eq(CommonStatesConstants.REMOVING))))). fetchInto(ServiceConsumeMapRecord.class); }
@Override public Service getServiceByExternalId(Long accountId, String externalId) { return create().selectFrom(SERVICE) .where(SERVICE.ACCOUNT_ID.eq(accountId)) .and(SERVICE.REMOVED.isNull()) .and(SERVICE.EXTERNAL_ID.eq(externalId)) .fetchAny(); }
@Override public Nic getPrimaryNic(long instanceId) { return create() .selectFrom(NIC) .where(NIC.INSTANCE_ID.eq(instanceId) .and(NIC.DEVICE_NUMBER.eq(0)) .and(NIC.REMOVED.isNull())) .fetchAny(); }
@Override public Account getAccountById(Long id) { return create() .selectFrom(ACCOUNT) .where( ACCOUNT.ID.eq(id) .and(ACCOUNT.STATE.ne(CommonStatesConstants.PURGED)) .and(ACCOUNT.REMOVED.isNull()) ).fetchOne(); }
@Override public Instance getInstance(Agent agent) { return create() .selectFrom(INSTANCE) .where(INSTANCE.AGENT_ID.eq(agent.getId()) .and(INSTANCE.REMOVED.isNull()) .and(INSTANCE.STATE.notIn(InstanceConstants.STATE_ERROR, InstanceConstants.STATE_ERRORING, CommonStatesConstants.REMOVING))) .fetchOne(); }
@Override public Map<String, Host> getHosts(long agentId) { List<? extends Host> hostList = create() .select(HOST.fields()) .from(HOST) .where( HOST.AGENT_ID.eq(agentId) .and(HOST.REMOVED.isNull())) .fetchInto(HostRecord.class); return groupByReportedUUid(hostList); }
@Override public Credential getCredential(String accessKey) { return create() .selectFrom(CREDENTIAL) .where(CREDENTIAL.KIND.eq(RegisterConstants.KIND_CREDENTIAL_REGISTRATION_TOKEN) .and(CREDENTIAL.PUBLIC_VALUE.eq(accessKey)) .and(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE)) .and(CREDENTIAL.REMOVED.isNull())) .fetchOne(); }
@Override public boolean isUnique(UserPreference userPreference, long accountId) { return create().selectFrom(USER_PREFERENCE) .where(USER_PREFERENCE.NAME.eq(userPreference.getName()) .and(USER_PREFERENCE.ACCOUNT_ID.eq(accountId)).and(USER_PREFERENCE.REMOVED.isNull())).fetch().size() == 0; } }
@Override public List<? extends Service> getSkipServices(long accountId) { return create() .select(SERVICE.fields()) .from(SERVICE) .where(SERVICE.ACCOUNT_ID.eq(accountId) .and(SERVICE.REMOVED.isNull()) .and(SERVICE.SKIP.isTrue())) .fetchInto(ServiceRecord.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); }
@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 boolean isSchedulerServiceEnabled(Long accountId) { return create() .select(SERVICE.ID) .from(SERVICE) .where(SERVICE.ACCOUNT_ID.equal(accountId) .and(SERVICE.SYSTEM.isTrue()) .and(SERVICE.REMOVED.isNull()) .and(SERVICE.STATE.notIn(INACTIVE_STATES)) .and(SERVICE.DATA.like("%io.rancher.container.agent_service.scheduling%"))).fetch().size() > 0; } }
@Override public List<? extends ProjectMember> findBadProjectMembers(int count) { return create().select(PROJECT_MEMBER.fields()) .from(PROJECT_MEMBER) .join(ACCOUNT) .on(ACCOUNT.ID.eq(PROJECT_MEMBER.PROJECT_ID)) .where(ACCOUNT.STATE.eq(CommonStatesConstants.PURGED) .and(PROJECT_MEMBER.REMOVED.isNull()) .and(PROJECT_MEMBER.STATE.notIn(CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(ProjectMemberRecord.class); }
@Override public List<? extends Volume> findBadVolumes(int count) { return create().select(VOLUME.fields()) .from(VOLUME) .join(ACCOUNT) .on(ACCOUNT.ID.eq(VOLUME.ACCOUNT_ID)) .where(VOLUME.REMOVED.isNull() .and(ACCOUNT.STATE.eq(CommonStatesConstants.PURGED)) .and(VOLUME.STATE.notIn(CommonStatesConstants.DEACTIVATING, CommonStatesConstants.REMOVING))) .limit(count) .fetchInto(VolumeRecord.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); }