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 static boolean isLocalStorage(String psUuid){ String psType = Q.New(PrimaryStorageVO.class) .select(PrimaryStorageVO_.type) .eq(PrimaryStorageVO_.uuid, psUuid) .findValue(); return LocalStorageConstants.LOCAL_STORAGE_TYPE.equals(psType); } }
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();
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; }
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()) ); } }
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(APIAttachL3NetworkToVmMsg msg) { VmInstanceVO vmInstanceVO = Q.New(VmInstanceVO.class).eq(VmInstanceVO_.uuid, msg.getVmInstanceUuid()).find(); if (vmInstanceVO.getType().equals(ApplianceVmConstant.APPLIANCE_VM_TYPE)){ validateIpRangeOverlapWithVm(msg.getL3NetworkUuid(), msg.getVmInstanceUuid()); } }
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(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 check(APIRecoverDataVolumeMsg msg, Map<String, Quota.QuotaPair> pairs) { String resourceTargetOwnerUuid = new QuotaUtil().getResourceOwnerAccountUuid(msg.getVolumeUuid()); long cnt = Q.New(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.volumeUuid, msg.getVolumeUuid()).count(); checkVolumeSnapshotNumQuota(msg.getSession().getAccountUuid(), resourceTargetOwnerUuid, cnt, pairs); }
@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()); }
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(); }