public boolean exists(String key) { SimpleQuery<JsonLabelVO> q = dbf.createQuery(JsonLabelVO.class); q.add(JsonLabelVO_.labelKey, Op.EQ, key); return q.isExists(); }
private boolean isRootVolumeOnLocalStorage(String rootVolumeUuid) { SimpleQuery<LocalStorageResourceRefVO> q = dbf.createQuery(LocalStorageResourceRefVO.class); q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, rootVolumeUuid); return q.isExists(); }
@Override public boolean isL3NetworksNeedingNetworkServiceByVirtualRouter(List<String> l3Uuids, String nsType) { if (l3Uuids == null || l3Uuids.isEmpty()) { return false; } SimpleQuery<NetworkServiceL3NetworkRefVO> q = dbf.createQuery(NetworkServiceL3NetworkRefVO.class); q.add(NetworkServiceL3NetworkRefVO_.l3NetworkUuid, Op.IN, l3Uuids); q.add(NetworkServiceL3NetworkRefVO_.networkServiceType, Op.EQ, nsType); // no need to specify provider type, L3 networks identified by candidates are served by virtual router or vyos return q.isExists(); }
@Override public boolean isL3NetworkNeedingNetworkServiceByVirtualRouter(String l3Uuid, String nsType) { if (l3Uuid == null) { return false; } SimpleQuery<NetworkServiceL3NetworkRefVO> q = dbf.createQuery(NetworkServiceL3NetworkRefVO.class); q.add(NetworkServiceL3NetworkRefVO_.l3NetworkUuid, Op.EQ, l3Uuid); q.add(NetworkServiceL3NetworkRefVO_.networkServiceType, Op.EQ, nsType); // no need to specify provider type, L3 networks identified by candidates are served by virtual router or vyos return q.isExists(); }
public boolean hasTag(String resourceUuid, Class resourceClass) { SimpleQuery<SystemTagVO> q = dbf.createQuery(SystemTagVO.class); q.add(SystemTagVO_.resourceType, Op.EQ, resourceClass.getSimpleName()); q.add(SystemTagVO_.resourceUuid, Op.EQ, resourceUuid); q.add(SystemTagVO_.tag, useOp(), useTagFormat()); return q.isExists(); }
private void exceptionIsVolumeIsDeleted(String volumeUuid) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.add(VolumeVO_.uuid, Op.EQ, volumeUuid); q.add(VolumeVO_.status, Op.EQ, VolumeStatus.Deleted); if (q.isExists()) { throw new ApiMessageInterceptionException(operr("the volume[uuid:%s] is in status of deleted, cannot do the operation", volumeUuid)); } }
private void validate(APICreateAccountMsg msg) { SimpleQuery<AccountVO> q = dbf.createQuery(AccountVO.class); q.add(AccountVO_.name, Op.EQ, msg.getName()); if (q.isExists()) { throw new ApiMessageInterceptionException(argerr("unable to create an account. An account already called %s", msg.getName())); } }
@Override public void applianceVmPrepareBootstrapInfo(VmInstanceSpec spec, Map<String, Object> info) { SimpleQuery<ApplianceVmVO> q = dbf.createQuery(ApplianceVmVO.class); q.add(ApplianceVmVO_.applianceVmType, Op.EQ, VyosConstants.VYOS_VM_TYPE); q.add(ApplianceVmVO_.uuid, Op.EQ, spec.getVmInventory().getUuid()); if (!q.isExists()) { return; } logger.debug("add vyos password to vrouter"); info.put(VyosConstants.BootstrapInfoKey.vyosPassword.toString(), VirtualRouterGlobalConfig.VYOS_PASSWORD.value()); } }
private void validate(APIAddKVMHostMsg msg) { SimpleQuery<KVMHostVO> q = dbf.createQuery(KVMHostVO.class); q.add(KVMHostVO_.managementIp, Op.EQ, msg.getManagementIp()); if (q.isExists()) { throw new ApiMessageInterceptionException(argerr("there has been a kvm host having management ip[%s]", msg.getManagementIp())); } }
private void validate(APIRecoverDataVolumeMsg msg) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.add(VolumeVO_.uuid, Op.EQ, msg.getVolumeUuid()); q.add(VolumeVO_.status, Op.EQ, VolumeStatus.Deleted); if (!q.isExists()) { throw new ApiMessageInterceptionException(operr("the volume[uuid:%s] is not in status of deleted. This is operation is to recover a deleted data volume", msg.getVolumeUuid())); } }
private void validate(APIAttachBackupStorageToZoneMsg msg) { SimpleQuery<BackupStorageZoneRefVO> q = dbf.createQuery(BackupStorageZoneRefVO.class); q.add(BackupStorageZoneRefVO_.backupStorageUuid, Op.EQ, msg.getBackupStorageUuid()); q.add(BackupStorageZoneRefVO_.zoneUuid, Op.EQ, msg.getZoneUuid()); if (q.isExists()) { throw new ApiMessageInterceptionException(operr("backup storage[uuid:%s] has been attached to zone[uuid:%s]", msg.getBackupStorageUuid(), msg.getZoneUuid())); } } }
private void validate(APIDetachL2NetworkFromClusterMsg msg) { SimpleQuery<L2NetworkClusterRefVO> q = dbf.createQuery(L2NetworkClusterRefVO.class); q.add(L2NetworkClusterRefVO_.clusterUuid, Op.EQ, msg.getClusterUuid()); q.add(L2NetworkClusterRefVO_.l2NetworkUuid, Op.EQ, msg.getL2NetworkUuid()); if (!q.isExists()) { throw new ApiMessageInterceptionException(operr("l2Network[uuid:%s] has not attached to cluster[uuid:%s]", msg.getL2NetworkUuid(), msg.getClusterUuid())); } }
private void validate(APIDetachPrimaryStorageFromClusterMsg msg) { SimpleQuery<PrimaryStorageClusterRefVO> q = dbf.createQuery(PrimaryStorageClusterRefVO.class); q.add(PrimaryStorageClusterRefVO_.clusterUuid, Op.EQ, msg.getClusterUuid()); q.add(PrimaryStorageClusterRefVO_.primaryStorageUuid, Op.EQ, msg.getPrimaryStorageUuid()); if (!q.isExists()) { throw new ApiMessageInterceptionException(argerr("primary storage[uuid:%s] has not been attached to cluster[uuid:%s] yet", msg.getPrimaryStorageUuid(), msg.getClusterUuid())); } }
private void validate(APICreateUserGroupMsg msg) { SimpleQuery<UserGroupVO> q = dbf.createQuery(UserGroupVO.class); q.add(UserGroupVO_.accountUuid, Op.EQ, msg.getAccountUuid()); q.add(UserGroupVO_.name, Op.EQ, msg.getName()); if (q.isExists()) { throw new ApiMessageInterceptionException(argerr("unable to create a group. A group called %s is already under the account[uuid:%s]", msg.getName(), msg.getAccountUuid())); } }
private void validate(APICreateUserMsg msg) { SimpleQuery<UserVO> q = dbf.createQuery(UserVO.class); q.add(UserVO_.accountUuid, Op.EQ, msg.getAccountUuid()); q.add(UserVO_.name, Op.EQ, msg.getName()); if (q.isExists()) { throw new ApiMessageInterceptionException(argerr("unable to create a user. A user called %s is already under the account[uuid:%s]", msg.getName(), msg.getAccountUuid())); } }
private void validate(APIDetachBackupStorageFromZoneMsg msg) { SimpleQuery<BackupStorageZoneRefVO> q = dbf.createQuery(BackupStorageZoneRefVO.class); q.add(BackupStorageZoneRefVO_.backupStorageUuid, Op.EQ, msg.getBackupStorageUuid()); q.add(BackupStorageZoneRefVO_.zoneUuid, Op.EQ, msg.getZoneUuid()); if (!q.isExists()) { throw new ApiMessageInterceptionException(operr("backup storage[uuid:%s] has not been attached to zone[uuid:%s]", msg.getBackupStorageUuid(), msg.getZoneUuid())); } }
private void validate(APIDetachSecurityGroupFromL3NetworkMsg msg) { SimpleQuery<SecurityGroupL3NetworkRefVO> q = dbf.createQuery(SecurityGroupL3NetworkRefVO.class); q.add(SecurityGroupL3NetworkRefVO_.l3NetworkUuid, Op.EQ, msg.getL3NetworkUuid()); q.add(SecurityGroupL3NetworkRefVO_.securityGroupUuid, Op.EQ, msg.getSecurityGroupUuid()); if (!q.isExists()) { throw new ApiMessageInterceptionException(operr("security group[uuid:%s] has not attached to l3Network[uuid:%s], can't detach", msg.getSecurityGroupUuid(), msg.getL3NetworkUuid())); } }
private void validate(APIRemoveDnsFromL3NetworkMsg msg) { SimpleQuery<L3NetworkDnsVO> q = dbf.createQuery(L3NetworkDnsVO.class); q.add(L3NetworkDnsVO_.dns, Op.EQ, msg.getDns()); q.add(L3NetworkDnsVO_.l3NetworkUuid, Op.EQ, msg.getL3NetworkUuid()); if (!q.isExists()) { APIRemoveDnsFromL3NetworkEvent evt = new APIRemoveDnsFromL3NetworkEvent(msg.getId()); bus.publish(evt); throw new StopRoutingException(); } }
private void validate(APIAddDnsToL3NetworkMsg msg) { validateIpAddress(msg.getL3NetworkUuid(), msg.getDns(), "DNS"); SimpleQuery<L3NetworkDnsVO> q = dbf.createQuery(L3NetworkDnsVO.class); q.add(L3NetworkDnsVO_.l3NetworkUuid, Op.EQ, msg.getL3NetworkUuid()); q.add(L3NetworkDnsVO_.dns, Op.EQ, msg.getDns()); if (q.isExists()) { throw new ApiMessageInterceptionException(operr("there has been a DNS[%s] on L3 network[uuid:%s]", msg.getDns(), msg.getL3NetworkUuid())); } }
private void validate(APIRemoveHostRouteFromL3NetworkMsg msg) { if (!NetworkUtils.isCidr(msg.getPrefix())) { throw new ApiMessageInterceptionException(argerr("prefix [%s] is not a IPv4 network cidr", msg.getL3NetworkUuid())); } SimpleQuery<L3NetworkHostRouteVO> q = dbf.createQuery(L3NetworkHostRouteVO.class); q.add(L3NetworkHostRouteVO_.l3NetworkUuid, Op.EQ, msg.getL3NetworkUuid()); q.add(L3NetworkHostRouteVO_.prefix, Op.EQ, msg.getPrefix()); if (!q.isExists()) { throw new ApiMessageInterceptionException(operr("there is no hostroute for prefix[%s] on L3 network[uuid:%s]", msg.getPrefix(), msg.getL3NetworkUuid())); } } }