@Override public boolean isAssigned(Client client, String itemName) { ConfigItemStatus status = create() .selectFrom(CONFIG_ITEM_STATUS) .where( CONFIG_ITEM_STATUS.NAME.eq(itemName) .and(targetObjectCondition(client))) .fetchAny(); return status != null; }
@Override public Agent getAgentByUri(String uri) { return create() .selectFrom(AGENT) .where(AGENT.URI.eq(uri) .and(AGENT.REMOVED.isNull())) .fetchAny(); }
@Override public Instance getInstanceByUuidOrExternalId(Long accountId, String uuid, String externalId) { Instance instance = null; Condition condition = INSTANCE.ACCOUNT_ID.eq(accountId).and(INSTANCE.STATE.notIn(CommonStatesConstants.PURGED, CommonStatesConstants.PURGING)); if(StringUtils.isNotEmpty(uuid)) { instance = create() .selectFrom(INSTANCE) .where(condition .and(INSTANCE.UUID.eq(uuid))) .fetchAny(); } if (instance == null && StringUtils.isNotEmpty(externalId)) { instance = create() .selectFrom(INSTANCE) .where(condition .and(INSTANCE.EXTERNAL_ID.eq(externalId))) .fetchAny(); } return instance; }
@Override public boolean canCreate(Long hostId, String event) { if (!ContainerEventConstants.EVENT_START.equals(event)) { return true; } Record1<Integer> count = create().select(DSL.count()) .from(CONTAINER_EVENT) .where(CONTAINER_EVENT.HOST_ID.eq(hostId) .and(CONTAINER_EVENT.STATE.notEqual(CommonStatesConstants.CREATED))) .fetchAny(); return count.value1() < MAX_EVENTS.get(); }
@Override public Stack getStackByExternalId(Long accountId, String externalId) { return create().selectFrom(STACK) .where(STACK.ACCOUNT_ID.eq(accountId)) .and(STACK.REMOVED.isNull()) .and(STACK.EXTERNAL_ID.eq(externalId)) .fetchAny(); }
@Override public String getAgentState(long agentId) { Record1<String> r = create().select(AGENT.STATE) .from(AGENT) .where(AGENT.ID.eq(agentId) .and(AGENT.REMOVED.isNull())).fetchAny(); return r == null ? null : r.value1(); }
@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 Instance getInstanceByAgent(Long agentId) { if (agentId == null) { return null; } return create() .selectFrom(INSTANCE) .where(INSTANCE.AGENT_ID.eq(agentId) .and(INSTANCE.REMOVED.isNull()) .and(INSTANCE.STATE.notIn(InstanceConstants.STATE_ERROR, InstanceConstants.STATE_ERRORING, CommonStatesConstants.REMOVING))) .fetchAny(); }
protected ActiveSetting getSettingByName(String name, Configuration config, boolean checkDb) { if (name == null) { return null; } Object value = config.getProperty(name); Configuration source = null; if (config instanceof ConcurrentCompositeConfiguration) { source = ((ConcurrentCompositeConfiguration) config).getSource(name); } else if (config instanceof CompositeConfiguration) { source = ((CompositeConfiguration) config).getSource(name); } if (value != null) { value = value.toString(); } ActiveSetting activeSetting = new ActiveSetting(name, value, toString(source)); if (checkDb) { Setting setting = create().selectFrom(SETTING).where(SETTING.NAME.eq(name)).fetchAny(); if (setting != null) { activeSetting.setSetting(setting); } } return activeSetting; }
@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 Identity getIdentity(Long id, IdFormatter idFormatter) { Account account = getAccountById(id); if (account == null || account.getKind().equalsIgnoreCase(ProjectConstants.TYPE) || !accountDao.isActiveAccount(account)) { return null; } Credential credential = create() .selectFrom(CREDENTIAL) .where(CREDENTIAL.KIND.equalIgnoreCase(CredentialConstants.KIND_PASSWORD) .and(CREDENTIAL.ACCOUNT_ID.eq(id)) .and(CREDENTIAL.STATE.equalIgnoreCase(CommonStatesConstants.ACTIVE))).fetchAny(); String accountId = idFormatter != null ? (String) idFormatter.formatId(objectManager.getType(Account.class), account.getId()) : String.valueOf(id); return new Identity(ProjectConstants.RANCHER_ID, accountId, account.getName(), null, null, credential == null ? null : credential.getPublicValue(), false); }
@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(); }
.where(CREDENTIAL.PUBLIC_VALUE.eq(username) .and(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE) .and(CREDENTIAL.KIND.eq(CredentialConstants.KIND_PASSWORD)))).fetchAny() != null){ throw new ClientVisibleException(ResponseCodes.CONFLICT, "UsernameIsTaken", "Username: " + username +" is taken", null);
@Override public Long incrementRevision(long accountId) { Record1<Long> row = create().select(ACCOUNT.REVISION) .from(ACCOUNT) .where(ACCOUNT.ID.eq(accountId)) .fetchAny(); if (row == null) { return 0L; } create().update(ACCOUNT) .set(ACCOUNT.REVISION, ACCOUNT.REVISION.plus(1)) .where(ACCOUNT.ID.eq(accountId)) .execute(); return row.value1() + 1; } }
@Override public void createVolumeInStoragePool(Map<String, Object> volumeData, String volumeName, StoragePool storagePool) { Record record = create() .select(VOLUME.fields()) .from(VOLUME) .join(VOLUME_STORAGE_POOL_MAP) .on(VOLUME_STORAGE_POOL_MAP.VOLUME_ID.eq(VOLUME.ID) .and(VOLUME_STORAGE_POOL_MAP.STORAGE_POOL_ID.eq(storagePool.getId()))) .join(STORAGE_POOL) .on(VOLUME_STORAGE_POOL_MAP.STORAGE_POOL_ID.eq(STORAGE_POOL.ID)) .and(STORAGE_POOL.REMOVED.isNull()) .where(VOLUME.NAME.eq(volumeName) .and((VOLUME.REMOVED.isNull().or(VOLUME.STATE.eq(CommonStatesConstants.REMOVING))))) .and(VOLUME.ACCOUNT_ID.eq(storagePool.getAccountId())) .fetchAny(); if (record != null) { return; } Volume volume = resourceDao.createAndSchedule(Volume.class, volumeData); Map<String, Object> vspm = new HashMap<String, Object>(); vspm.put("volumeId", volume.getId()); vspm.put("storagePoolId", storagePool.getId()); resourceDao.createAndSchedule(VolumeStoragePoolMap.class, vspm); }
@Override public Volume findVolumeByExternalId(Long storagePoolId, String externalId) { Record record = create() .select(VOLUME.fields()) .from(VOLUME) .join(VOLUME_STORAGE_POOL_MAP) .on(VOLUME_STORAGE_POOL_MAP.STORAGE_POOL_ID.eq(storagePoolId)) .where(VOLUME.EXTERNAL_ID.eq(externalId) .or(VOLUME.EXTERNAL_ID.eq(VolumeUtils.externalId(externalId))) .and((VOLUME.REMOVED.isNull().or(VOLUME.STATE.eq(CommonStatesConstants.REMOVING))))) .fetchAny(); return record == null ? null : record.into(VolumeRecord.class); }
@Override public StoragePool associateVolumeToPool(Long volumeId, Long storageDriverId, Long hostId) { Record record = create().select(STORAGE_POOL.fields()) .from(STORAGE_POOL) .join(STORAGE_POOL_HOST_MAP) .on(STORAGE_POOL_HOST_MAP.STORAGE_POOL_ID.eq(STORAGE_POOL.ID)) .where(STORAGE_POOL.STORAGE_DRIVER_ID.eq(storageDriverId) .and(STORAGE_POOL_HOST_MAP.HOST_ID.eq(hostId))) .fetchAny(); if (record == null) { return null; } StoragePool storagePool = record.into(StoragePoolRecord.class); VolumeStoragePoolMap map = genericMapDao.findNonRemoved(VolumeStoragePoolMap.class, StoragePool.class, storagePool.getId(), Volume.class, volumeId); if (map == null) { resourceDao.createAndSchedule(VolumeStoragePoolMap.class, VOLUME_STORAGE_POOL_MAP.VOLUME_ID, volumeId, VOLUME_STORAGE_POOL_MAP.STORAGE_POOL_ID, storagePool.getId()); } return storagePool; }
@Override public Host getHost(Agent agent) { Record record = create() .select(HOST.fields()) .from(INSTANCE) .join(INSTANCE_HOST_MAP) .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID) .and(INSTANCE_HOST_MAP.REMOVED.isNull())) .join(HOST) .on(INSTANCE_HOST_MAP.HOST_ID.eq(HOST.ID)) .where(INSTANCE.AGENT_ID.eq(agent.getId()) .and(INSTANCE.REMOVED.isNull().and( INSTANCE.STATE.notIn(InstanceConstants.STATE_ERROR, InstanceConstants.STATE_ERRORING, CommonStatesConstants.REMOVING))) .and(HOST.REMOVED.isNull())) .fetchAny(); return record == null ? null : record.into(Host.class); }