private NetworkServiceProviderVO getRouterVO() { SimpleQuery<NetworkServiceProviderVO> query = dbf.createQuery(NetworkServiceProviderVO.class); query.add(NetworkServiceProviderVO_.type, Op.EQ, VIRTUAL_ROUTER_PROVIDER_TYPE); return query.find(); }
private ClusterVO findClusterByUuid(String uuid) { SimpleQuery<ClusterVO> query = dbf.createQuery(ClusterVO.class); query.add(ClusterVO_.uuid, Op.EQ, uuid); return query.find(); }
public GlobalConfigVO reload() { SimpleQuery<GlobalConfigVO> q = dbf.createQuery(GlobalConfigVO.class); q.add(GlobalConfigVO_.category, Op.EQ, category); q.add(GlobalConfigVO_.name, Op.EQ, name); return q.find(); }
public String getResourceType(String resourceUuid) { SimpleQuery<AccountResourceRefVO> q = dbf.createQuery(AccountResourceRefVO.class); q.add(AccountResourceRefVO_.resourceUuid, SimpleQuery.Op.EQ, resourceUuid); AccountResourceRefVO accResRefVO = q.find(); return accResRefVO.getResourceType(); }
public JsonLabelInventory get(String key) { SimpleQuery<JsonLabelVO> q = dbf.createQuery(JsonLabelVO.class); q.add(JsonLabelVO_.labelKey, Op.EQ, key); JsonLabelVO vo = q.find(); return vo == null ? null : JsonLabelInventory.valueOf(vo); }
public LocalStorageHostRefVO findByPrimaryKey(String hostUuid, String primaryStorageUuid) { SimpleQuery<LocalStorageHostRefVO> hq = dbf.createQuery(LocalStorageHostRefVO.class); hq.add(LocalStorageHostRefVO_.hostUuid, SimpleQuery.Op.EQ, hostUuid); hq.add(LocalStorageHostRefVO_.primaryStorageUuid, SimpleQuery.Op.EQ, primaryStorageUuid); LocalStorageHostRefVO ref = hq.find(); return ref; }
private WorkFlowVO getFlowVOByPosition(int position) { SimpleQuery<WorkFlowVO> query = dbf.createQuery(WorkFlowVO.class); query.add(WorkFlowVO_.position, Op.EQ, position); query.add(WorkFlowVO_.chainUuid, Op.EQ, chainvo.getUuid()); WorkFlowVO vo = query.find(); assert vo != null : "Where is WorkFlowVO for position: " + position; return vo; }
private void deleteResourceRefVO(String resourceUuid) { SimpleQuery<LocalStorageResourceRefVO> q = dbf.createQuery(LocalStorageResourceRefVO.class); q.add(LocalStorageResourceRefVO_.primaryStorageUuid, Op.EQ, self.getUuid()); q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, resourceUuid); LocalStorageResourceRefVO ref = q.find(); dbf.remove(ref); }
public SystemTagInventory getTagInventory(String resourceUuid) { SimpleQuery<SystemTagVO> q = dbf.createQuery(SystemTagVO.class); q.add(SystemTagVO_.resourceUuid, Op.EQ, resourceUuid); q.add(SystemTagVO_.resourceType, Op.EQ, getResourceClass().getSimpleName()); q.add(SystemTagVO_.tag, Op.LIKE, useTagFormat()); SystemTagVO vo = q.find(); return vo == null ? null : SystemTagInventory.valueOf(vo); }
@Deferred public JsonLabelInventory createIfAbsent(String key, Object obj, String resourceUuid) { GLock lock = new GLock(LOCK, TimeUnit.MINUTES.toSeconds(2)); lock.lock(); Defer.defer(lock::unlock); SimpleQuery<JsonLabelVO> q = dbf.createQuery(JsonLabelVO.class); q.add(JsonLabelVO_.labelKey, Op.EQ, key); JsonLabelVO vo = q.find(); return vo == null ? create(key, obj, resourceUuid) : JsonLabelInventory.valueOf(vo); }
private void validate(APILocalStorageGetVolumeMigratableHostsMsg msg) { APILocalStorageGetVolumeMigratableReply reply = new APILocalStorageGetVolumeMigratableReply(); SimpleQuery<LocalStorageResourceRefVO> q = dbf.createQuery(LocalStorageResourceRefVO.class); q.add(LocalStorageResourceRefVO_.resourceType, Op.EQ, VolumeVO.class.getSimpleName()); q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, msg.getVolumeUuid()); LocalStorageResourceRefVO ref = q.find(); if (ref == null) { reply.setInventories(new ArrayList<HostInventory>()); bus.reply(msg, reply); throw new StopRoutingException(); } msg.setPrimaryStorageUuid(ref.getPrimaryStorageUuid()); }
private void validateAPIChangeResourceOwnerMsg(APIChangeResourceOwnerMsg msg) { SimpleQuery<AccountResourceRefVO> q = dbf.createQuery(AccountResourceRefVO.class); q.add(AccountResourceRefVO_.resourceUuid, Op.EQ, msg.getResourceUuid()); AccountResourceRefVO ref = q.find(); if (ref == null || !VolumeVO.class.getSimpleName().equals(ref.getResourceType())) { return; } SimpleQuery<VolumeVO> vq = dbf.createQuery(VolumeVO.class); vq.add(VolumeVO_.uuid, Op.EQ, ref.getResourceUuid()); vq.add(VolumeVO_.type, Op.EQ, VolumeType.Root); if (vq.isExists()) { throw new OperationFailureException(operr("the resource[uuid:%s] is a ROOT volume, you cannot change its owner, instead," + "change the owner of the VM the root volume belongs to", ref.getResourceUuid())); } }
private void handle(DetachL2NetworkFromClusterMsg msg) { SimpleQuery<L2NetworkClusterRefVO> query = dbf.createQuery(L2NetworkClusterRefVO.class); query.add(L2NetworkClusterRefVO_.clusterUuid, Op.EQ, msg.getClusterUuid()); query.add(L2NetworkClusterRefVO_.l2NetworkUuid, Op.EQ, msg.getL2NetworkUuid()); L2NetworkClusterRefVO rvo = query.find(); if (rvo != null) { dbf.remove(rvo); } DetachL2NetworkFromClusterReply reply = new DetachL2NetworkFromClusterReply(); bus.reply(msg, reply); }
@Override public void run(final ReturnValueCompletion<Object> completion) { SimpleQuery<ImageCacheVO> query = dbf.createQuery(ImageCacheVO.class); query.add(ImageCacheVO_.primaryStorageUuid, SimpleQuery.Op.EQ, primaryStorage.getUuid()); query.add(ImageCacheVO_.imageUuid, SimpleQuery.Op.EQ, image.getInventory().getUuid()); ImageCacheVO cvo = query.find(); if (cvo != null) { useExistingCache(cvo, completion); return; } download(completion); }
protected void carryOnRollback() { logger.debug(String.format("Restart to roll back flows in work AsyncWorkFlowChain[uuid:%s]", chainvo.getUuid())); SimpleQuery<WorkFlowVO> query = dbf.createQuery(WorkFlowVO.class); query.add(WorkFlowVO_.chainUuid, Op.EQ, chainvo.getUuid()); query.add(WorkFlowVO_.reason, Op.NOT_NULL); WorkFlowVO failedFlow = query.find(); rollback(); WorkFlowContext ctx = WorkFlowContext.fromBytes(failedFlow.getContext()); ErrorCode err = ErrorCode.fromString(failedFlow.getReason()); tellCallbackFailure(ctx, err); }
private void handle(APIRemoveUserFromGroupMsg msg) { SimpleQuery<UserGroupUserRefVO> q = dbf.createQuery(UserGroupUserRefVO.class); q.add(UserGroupUserRefVO_.groupUuid, Op.EQ, msg.getGroupUuid()); q.add(UserGroupUserRefVO_.userUuid, Op.EQ, msg.getUserUuid()); UserGroupUserRefVO ref = q.find(); if (ref != null) { dbf.remove(ref); } bus.publish(new APIRemoveUserFromGroupEvent(msg.getId())); }
private void handle(APIDetachPolicyFromUserGroupMsg msg) { SimpleQuery<UserGroupPolicyRefVO> q = dbf.createQuery(UserGroupPolicyRefVO.class); q.add(UserGroupPolicyRefVO_.groupUuid, Op.EQ, msg.getGroupUuid()); q.add(UserGroupPolicyRefVO_.policyUuid, Op.EQ, msg.getPolicyUuid()); UserGroupPolicyRefVO ref = q.find(); if (ref != null) { dbf.remove(ref); } bus.publish(new APIDetachPolicyFromUserGroupEvent(msg.getId())); }
private void handle(APIDetachPolicyFromUserMsg msg) { SimpleQuery<UserPolicyRefVO> q = dbf.createQuery(UserPolicyRefVO.class); q.add(UserPolicyRefVO_.policyUuid, Op.EQ, msg.getPolicyUuid()); q.add(UserPolicyRefVO_.userUuid, Op.EQ, msg.getUserUuid()); UserPolicyRefVO ref = q.find(); if (ref != null) { dbf.remove(ref); } bus.publish(new APIDetachPolicyFromUserEvent(msg.getId())); }
@Override public void vmIpChanged(VmInstanceInventory vm, VmNicInventory nic, UsedIpInventory oldIp, UsedIpInventory newIp) { SimpleQuery<EipVO> q = dbf.createQuery(EipVO.class); q.add(EipVO_.vmNicUuid, Op.EQ, nic.getUuid()); q.add(EipVO_.guestIp, Op.EQ, oldIp.getIp()); EipVO eip = q.find(); if (eip == null) { return; } eip.setGuestIp(newIp.getIp()); dbf.update(eip); logger.debug(String.format("update the EIP[uuid:%s, name:%s]'s guest IP from %s to %s for the nic[uuid:%s]", eip.getUuid(), eip.getName(), oldIp.getIp(), newIp.getIp(), nic.getUuid())); }
private void handle(APIUpdateQuotaMsg msg) { SimpleQuery<QuotaVO> q = dbf.createQuery(QuotaVO.class); q.add(QuotaVO_.identityUuid, Op.EQ, msg.getIdentityUuid()); q.add(QuotaVO_.name, Op.EQ, msg.getName()); QuotaVO quota = q.find(); if (quota == null) { throw new OperationFailureException(argerr("cannot find Quota[name: %s] for the account[uuid: %s]", msg.getName(), msg.getIdentityUuid())); } quota.setValue(msg.getValue()); quota = dbf.updateAndRefresh(quota); APIUpdateQuotaEvent evt = new APIUpdateQuotaEvent(msg.getId()); evt.setInventory(QuotaInventory.valueOf(quota)); bus.publish(evt); }