private boolean isLdapServerExist(){ if(Q.New(LdapServerVO.class).isExists()){ logger.warn("update ldapUid to ldapDn fail, There is no ldap server in the system"); return true; } return false; }
private boolean isBindingExist(){ if(Q.New(LdapAccountRefVO.class).isExists()){ logger.warn("update ldapUid to ldapDn fail, There is no bindings in the system"); return true; } return false; }
public boolean checkDuplicateMac(String hypervisorType, String mac) { return Q.New(VmNicVO.class) .eq(VmNicVO_.hypervisorType, hypervisorType) .eq(VmNicVO_.mac, mac.toLowerCase()) .isExists(); } }
private void validate(APIAddMonToCephPrimaryStorageMsg msg) { checkMonUrls(msg.getMonUrls()); List<String> hostnames = msg.getMonUrls().stream() .map(MonUri::new) .map(MonUri::getHostname) .collect(Collectors.toList()); if (Q.New(CephPrimaryStorageMonVO.class).in(CephPrimaryStorageMonVO_.hostname, hostnames).isExists()){ throw new ApiMessageInterceptionException(argerr("Adding the same Mon node is not allowed")); } }
private void validate(APIAddMonToCephBackupStorageMsg msg) { checkMonUrls(msg.getMonUrls()); List<String> hostnames = msg.getMonUrls().stream() .map(MonUri::new) .map(MonUri::getHostname) .collect(Collectors.toList()); if (Q.New(CephBackupStorageMonVO.class).in(CephBackupStorageMonVO_.hostname, hostnames).isExists()){ throw new ApiMessageInterceptionException(argerr("Adding the same Mon node is not allowed")); } } private void validate(APIUpdateCephBackupStorageMonMsg msg) {
private void validateLdapServerExist(){ if(!Q.New(LdapServerVO.class).isExists()){ throw new ApiMessageInterceptionException(argerr("There is no ldap server in the system, Please add a ldap server first.")); } }
public static boolean isIsoAttachedToVm(String vmUuid) { boolean exsit = Q.New(VmCdRomVO.class) .eq(VmCdRomVO_.vmInstanceUuid, vmUuid) .notNull(VmCdRomVO_.isoUuid) .isExists(); return exsit; }
private Boolean isLocalStorage(String psUuid) { return Q.New(PrimaryStorageVO.class) .eq(PrimaryStorageVO_.type, type.toString()) .eq(PrimaryStorageVO_.uuid, psUuid) .isExists(); }
@Override public boolean verifyCaptcha(String uuid, String verifyCode, String targetResourceIdentify) { if (Q.New(CaptchaVO.class) .eq(CaptchaVO_.uuid, uuid) .eq(CaptchaVO_.verifyCode, verifyCode) .eq(CaptchaVO_.targetResourceIdentity, targetResourceIdentify) .isExists()) { return true; } return false; }
private boolean isTagExisting(String resourceUuid, String tag, TagType type, String resourceType) { if (type == TagType.User) { return Q.New(UserTagVO.class).eq(UserTagVO_.resourceType, resourceType) .eq(UserTagVO_.tag, tag) .eq(UserTagVO_.resourceUuid, resourceUuid) .isExists(); } else { return Q.New(SystemTagVO.class).eq(SystemTagVO_.resourceType, resourceType) .eq(SystemTagVO_.tag, tag) .eq(SystemTagVO_.resourceUuid, resourceUuid) .isExists(); } }
private void handle(APIGetEipAttachableVmNicsMsg msg) { APIGetEipAttachableVmNicsReply reply = new APIGetEipAttachableVmNicsReply(); boolean isAttached = Q.New(EipVO.class).eq(EipVO_.uuid, msg.getEipUuid()).notNull(EipVO_.vmNicUuid).isExists(); reply.setInventories(isAttached ? new ArrayList<>() : getEipAttachableVmNics(msg)); bus.reply(msg, reply); }
@Override public void afterDeleteIpRange(IpRangeInventory ipRange) { String dhcpServerIp = getDHCPServerIP(ipRange.getL3NetworkUuid()); boolean ipRangeExisted = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, ipRange.getL3NetworkUuid()).isExists(); if (!ipRangeExisted && dhcpServerIp != null) { deleteDhcpServerIp(ipRange.getL3NetworkUuid(), dhcpServerIp); logger.debug(String.format("delete DHCP IP[%s] of the flat network[uuid:%s] as the IP range[uuid:%s] is deleted", dhcpServerIp, ipRange.getL3NetworkUuid(), ipRange.getUuid())); } }
private void validate(APIUpdateRoleMsg msg) { if (Q.New(RoleVO.class).in(RoleVO_.type, list(RoleType.Predefined, RoleType.System)).eq(RoleVO_.uuid, msg.getUuid()).isExists()) { throw new ApiMessageInterceptionException(argerr("cannot update a system or predefined role")); } }
private void validate(APIDeleteRoleMsg msg) { if (Q.New(RoleVO.class).in(RoleVO_.type, list(RoleType.Predefined, RoleType.System)).eq(RoleVO_.uuid, msg.getUuid()).isExists()) { throw new ApiMessageInterceptionException(argerr("cannot delete a system or predefined role")); } } }
@Override protected void scripts() { if (!q(LdapServerVO.class).eq(LdapServerVO_.uuid, msg.getUuid()).isExists()) { return; } LdapServerVO vo = q(LdapServerVO.class).eq(LdapServerVO_.uuid, msg.getUuid()).find(); remove(vo); flush(); } }.execute();
private void validate(APIAddCertificateToLoadBalancerListenerMsg msg) { LoadBalancerListenerVO vo = dbf.findByUuid(msg.getListenerUuid(), LoadBalancerListenerVO.class); if (!vo.getProtocol().equals(LoadBalancerConstants.LB_PROTOCOL_HTTPS)) { throw new ApiMessageInterceptionException(argerr("loadbalancer listener with type %s does not need certificate", vo.getProtocol())); } if (Q.New(LoadBalancerListenerCertificateRefVO.class).eq(LoadBalancerListenerCertificateRefVO_.listenerUuid, msg.getListenerUuid()).isExists()) { throw new ApiMessageInterceptionException(argerr("loadbalancer listener [uuid:%s] already had certificate", msg.getCertificateUuid(), msg.getListenerUuid())); } msg.setLoadBalancerUuid(vo.getLoadBalancerUuid()); }
@Override protected void scripts() { if (!q(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.volumeUuid, volumeUuid).isExists()) { return; } List<String> treeUuids = q(VolumeSnapshotVO.class).select(VolumeSnapshotVO_.treeUuid).eq(VolumeSnapshotVO_.volumeUuid, volumeUuid).listValues(); sql(VolumeSnapshotTreeVO.class).in(VolumeSnapshotTreeVO_.uuid, treeUuids).delete(); sql(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.volumeUuid, volumeUuid).delete(); } }.execute();
protected LocalStorageHypervisorFactory getHypervisorBackendFactoryByHostUuid(String hostUuid, boolean checkPsRef) { if (checkPsRef && !Q.New(LocalStorageHostRefVO.class) .eq(LocalStorageHostRefVO_.hostUuid, hostUuid) .eq(LocalStorageHostRefVO_.primaryStorageUuid, self.getUuid()).isExists()) { throw new OperationFailureException(operr("host[uuid:%s] cannot access local storage[uuid:%s], maybe it is detached", hostUuid, self.getUuid())); } SimpleQuery<HostVO> q = dbf.createQuery(HostVO.class); q.select(HostVO_.hypervisorType); q.add(HostVO_.uuid, Op.EQ, hostUuid); String hvType = q.findValue(); return getHypervisorBackendFactory(hvType); }
private void validate(APIRemoveCertificateFromLoadBalancerListenerMsg msg) { if (!Q.New(LoadBalancerListenerCertificateRefVO.class).eq(LoadBalancerListenerCertificateRefVO_.listenerUuid, msg.getListenerUuid()) .eq(LoadBalancerListenerCertificateRefVO_.certificateUuid, msg.getCertificateUuid()).isExists()) { throw new ApiMessageInterceptionException(argerr("certificate [uuid:%s] is not added to loadbalancer listener [uuid:%s]", msg.getCertificateUuid(), msg.getListenerUuid())); } LoadBalancerListenerVO vo = dbf.findByUuid(msg.getListenerUuid(), LoadBalancerListenerVO.class); msg.setLoadBalancerUuid(vo.getLoadBalancerUuid()); } }