private void deleteListenersForLoadBalancer(String lbUuid) { List<LoadBalancerListenerVO> listenerVOS = Q.New(LoadBalancerListenerVO.class) .eq(LoadBalancerListenerVO_.loadBalancerUuid, lbUuid) .list(); if (listenerVOS != null && !listenerVOS.isEmpty()) { logger.debug(String.format("delete loadBalancerListeners[%s] for loadBalancer[uuid:%s]", listenerVOS.stream().map(vo -> vo.getUuid()).collect(Collectors.toList()), lbUuid)); listenerVOS.forEach(vo -> dbf.remove(vo)); } }
public boolean checkDuplicateMac(String hypervisorType, String mac) { return Q.New(VmNicVO.class) .eq(VmNicVO_.hypervisorType, hypervisorType) .eq(VmNicVO_.mac, mac.toLowerCase()) .isExists(); } }
private String getAvailableHostUuidForOperation() { List<String> hostUuids = Q.New(PrimaryStorageHostRefVO.class). eq(PrimaryStorageHostRefVO_.primaryStorageUuid, self.getUuid()).select(PrimaryStorageHostRefVO_.hostUuid).listValues(); if (hostUuids == null || hostUuids.size() == 0) { return null; } return hostUuids.get(0); }
@Override public void call() { List<WebhookVO> vos = Q.New(WebhookVO.class).eq(WebhookVO_.type, EventFacade.WEBHOOK_TYPE).list(); vos = vos.stream().filter( vo -> event.getPath().matches( createRegexFromGlob(vo.getOpaque().replaceAll("\\{.*\\}", ".*")) )).collect(Collectors.toList()); if (!vos.isEmpty()) { postToWebhooks(WebhookInventory.valueOf(vos), JSONObjectUtil.toJsonString(event)); } } }.call();
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) {
public static List<String> getIsoUuidByVmUuid(String vmUuid) { List<String> isoUuids = Q.New(VmCdRomVO.class) .select(VmCdRomVO_.isoUuid) .eq(VmCdRomVO_.vmInstanceUuid, vmUuid) .notNull(VmCdRomVO_.isoUuid) .listValues(); return isoUuids; }
public static Integer getIsoDeviceId(String vmUuid, String isoUuid) { VmCdRomVO vmCdRomVO = Q.New(VmCdRomVO.class) .eq(VmCdRomVO_.vmInstanceUuid, vmUuid) .eq(VmCdRomVO_.isoUuid, isoUuid) .find(); if (vmCdRomVO == null) { return null; } return vmCdRomVO.getDeviceId(); }
private LdapTemplateContextSource readLdapServerConfiguration() { LdapServerVO ldapServerVO = Q.New(LdapServerVO.class).find(); LdapServerInventory ldapServerInventory = LdapServerInventory.valueOf(ldapServerVO); return new LdapUtil().loadLdap(ldapServerInventory); }
@Override public void prepareDbInitialValue() { List<VipVO> vipVOS = Q.New(VipVO.class).isNull(VipVO_.prefixLen).list(); for (VipVO vip : vipVOS) { vip.setPrefixLen(NetworkUtils.getPrefixLengthFromNetwork(vip.getNetmask())); } if (!vipVOS.isEmpty()) { dbf.updateCollection(vipVOS); } } }
static VmCdRomVO getEmptyCdRom(String vmUuid) { VmCdRomVO cdRomVO = Q.New(VmCdRomVO.class) .eq(VmCdRomVO_.vmInstanceUuid, vmUuid) .isNull(VmCdRomVO_.isoUuid) .orderBy(VmCdRomVO_.deviceId, SimpleQuery.Od.ASC) .limit(1) .find(); return cdRomVO; }
@Override protected void scripts() { if(Q.New(CephPrimaryStorageVO.class).eq(CephPrimaryStorageVO_.fsid, fsid).find() == null){ SQL.New(CephCapacityVO.class).eq(CephCapacityVO_.fsid, fsid).delete(); } } }.execute();
private void validate(APIDeleteLongJobMsg msg) { LongJobState state = Q.New(LongJobVO.class) .select(LongJobVO_.state) .eq(LongJobVO_.uuid, msg.getUuid()) .findValue(); if (state != LongJobState.Succeeded && state != LongJobState.Canceled && state != LongJobState.Failed) { throw new ApiMessageInterceptionException(argerr("delete longjob only when it's succeeded, canceled, or failed")); } }
private void validate(APIUpdateLoadBalancerListenerMsg msg) { String loadBalancerUuid = Q.New(LoadBalancerListenerVO.class). select(LoadBalancerListenerVO_.loadBalancerUuid). eq(LoadBalancerListenerVO_.uuid,msg. getLoadBalancerListenerUuid()).findValue(); msg.setLoadBalancerUuid(loadBalancerUuid); bus.makeTargetServiceIdByResourceUuid(msg, LoadBalancerConstants.SERVICE_ID, loadBalancerUuid); }
private void validate(final APIGetCandidatePrimaryStoragesForCreatingVmMsg msg) { ImageMediaType mediaType = Q.New(ImageVO.class).eq(ImageVO_.uuid, msg.getImageUuid()).select(ImageVO_.mediaType).findValue(); if (ImageMediaType.ISO == mediaType && msg.getRootDiskOfferingUuid() == null) { throw new ApiMessageInterceptionException(argerr("rootVolumeOffering is needed when image media type is ISO")); } }
private void validate(APICreateVxlanVtepMsg msg) { long count = Q.New(VtepVO.class).eq(VtepVO_.hostUuid, msg.getHostUuid()).eq(VtepVO_.poolUuid, msg.getPoolUuid()).count(); if (count > 0) { throw new ApiMessageInterceptionException(argerr("vxlan vtep address for host [uuid : %s] and pool [uuid : %s] pair already existed", msg.getHostUuid(), msg.getPoolUuid()) ); } }
@Override public Result getMessageParams(APIMessage message) { APILogInByAccountMsg msg = (APILogInByAccountMsg) message; String resourceIdentity = Q.New(AccountVO.class).select(AccountVO_.uuid).eq(AccountVO_.name, msg.getAccountName()).findValue(); Result r = new Result(); r.setCaptchaUuid(msg.getCaptchaUuid()); r.setTargetResourceIdentity(resourceIdentity); r.setVerifyCode(msg.getVerifyCode()); return r; } }
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()); }
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(APIGetEipAttachableVmNicsMsg msg) { if (msg.getVipUuid() == null && msg.getEipUuid() == null) { throw new ApiMessageInterceptionException(argerr("either eipUuid or vipUuid must be set")); } if (msg.getEipUuid() != null) { EipState state = Q.New(EipVO.class).select(EipVO_.state).eq(EipVO_.uuid,msg.getEipUuid()).findValue(); if (state != EipState.Enabled) { throw new ApiMessageInterceptionException(operr("eip[uuid:%s] is not in state of Enabled, cannot get attachable vm nic", msg.getEipUuid())); } } }
@Override public void success() { logger.debug(String.format("successfully acquired vip[uuid:%s, name:%s, ip:%s] on service[%s]", self.getUuid(), self.getName(), self.getIp(), s.getServiceProvider())); VipUseForList useForList = new VipUseForList(self.getUseFor()); useForList.add(s.getUseFor()); VipVO vo = Q.New(VipVO.class).eq(VipVO_.uuid, self.getUuid()).find(); vo.setUseFor(useForList.toString()); dbf.updateAndRefresh(vo); addPeerL3NetworkUuid(s.getPeerL3NetworkUuid()); completion.success(); }