private void validate(APIGetPortForwardingAttachableVmNicsMsg msg) { SimpleQuery<PortForwardingRuleVO> q = dbf.createQuery(PortForwardingRuleVO.class); q.select(PortForwardingRuleVO_.state, PortForwardingRuleVO_.vmNicUuid); q.add(PortForwardingRuleVO_.uuid, Op.EQ, msg.getRuleUuid()); Tuple t = q.findTuple(); PortForwardingRuleState state = t.get(0, PortForwardingRuleState.class); if (state != PortForwardingRuleState.Enabled) { throw new ApiMessageInterceptionException(operr("Port forwarding rule[uuid:%s] is not in state of Enabled, current state is %s", msg.getRuleUuid(), state)); } String vmNicUuid = t.get(1, String.class); if (vmNicUuid != null) { return ; } }
private void setServiceId(APIMessage msg) { if (msg instanceof VolumeSnapshotMessage) { VolumeSnapshotMessage vmsg = (VolumeSnapshotMessage) msg; SimpleQuery<VolumeSnapshotVO> q = dbf.createQuery(VolumeSnapshotVO.class); q.select(VolumeSnapshotVO_.volumeUuid, VolumeSnapshotVO_.treeUuid); q.add(VolumeSnapshotVO_.uuid, SimpleQuery.Op.EQ, vmsg.getSnapshotUuid()); Tuple t = q.findTuple(); String volumeUuid = t.get(0, String.class); String treeUuid = t.get(1, String.class); vmsg.setVolumeUuid(volumeUuid); vmsg.setTreeUuid(treeUuid); String resourceUuid = volumeUuid != null ? volumeUuid : treeUuid; bus.makeTargetServiceIdByResourceUuid(msg, VolumeSnapshotConstant.SERVICE_ID, resourceUuid); } }
q.select(KVMHostVO_.username, KVMHostVO_.password, KVMHostVO_.port); q.add(KVMHostVO_.uuid, Op.EQ, struct.getDestHostUuid()); Tuple t = q.findTuple();
private void validate(APIRevertVolumeFromSnapshotMsg msg) { SimpleQuery<VolumeSnapshotVO> q = dbf.createQuery(VolumeSnapshotVO.class); q.select(VolumeSnapshotVO_.state, VolumeSnapshotVO_.volumeUuid); q.add(VolumeSnapshotVO_.uuid, Op.EQ, msg.getUuid()); Tuple t = q.findTuple(); VolumeSnapshotState state = t.get(0, VolumeSnapshotState.class); if (state != VolumeSnapshotState.Enabled) { throw new ApiMessageInterceptionException(operr("volume snapshot[uuid:%s] is in state %s, cannot revert volume to it", msg.getUuid(), state)); } String volUuid = t.get(1, String.class); if (volUuid == null) { throw new ApiMessageInterceptionException(operr("original volume for snapshot[uuid:%s] has been deleted, cannot revert volume to it", msg.getUuid())); } }
sq.select(VolumeSnapshotVO_.volumeUuid, VolumeSnapshotVO_.treeUuid); sq.add(VolumeSnapshotVO_.uuid, Op.EQ, suuid); Tuple t = sq.findTuple(); String volumeUuid = t.get(0, String.class); String treeUuid = t.get(1, String.class);
q.select(VmInstanceVO_.type, VmInstanceVO_.state); q.add(VmInstanceVO_.uuid, Op.EQ, msg.getVmInstanceUuid()); Tuple t = q.findTuple(); String type = t.get(0, String.class); VmInstanceState state = t.get(1, VmInstanceState.class);
private void validate(APIUpdateVirtualRouterOfferingMsg msg) { if (msg.getIsDefault() != null) { if (!new QuotaUtil().isAdminAccount(msg.getSession().getAccountUuid())) { throw new ApiMessageInterceptionException(err(IdentityErrors.PERMISSION_DENIED, "cannot change the default field of a virtual router offering; only admin can do the operation" )); } } if (msg.getImageUuid() != null) { SimpleQuery<ImageVO> q = dbf.createQuery(ImageVO.class); q.select(ImageVO_.mediaType, ImageVO_.format); q.add(ImageVO_.uuid, Op.EQ, msg.getImageUuid()); Tuple t = q.findTuple(); ImageMediaType type = t.get(0, ImageMediaType.class); String format = t.get(1, String.class); if (type != ImageMediaType.RootVolumeTemplate) { throw new ApiMessageInterceptionException(argerr("image[uuid:%s]'s mediaType is %s, the mediaType of a virtual router image must be %s", msg.getImageUuid(), type, ImageMediaType.RootVolumeTemplate)); } if (ImageConstant.ISO_FORMAT_STRING.equals(format)) { throw new ApiMessageInterceptionException(argerr("image[uuid:%s] is of format %s, cannot be used for virtual router", msg.getImageUuid(), format)); } } } private Boolean isNetworkAddressEqual(String networkUuid1, String networkUuid2) {
iq.select(InstanceOfferingVO_.state, InstanceOfferingVO_.type); iq.add(InstanceOfferingVO_.uuid, Op.EQ, msg.getInstanceOfferingUuid()); Tuple inst = iq.findTuple(); InstanceOfferingState istate = inst.get(0, InstanceOfferingState.class); String itype = inst.get(1, String.class); imgq.select(ImageVO_.state, ImageVO_.system, ImageVO_.mediaType, ImageVO_.status); imgq.add(ImageVO_.uuid, Op.EQ, msg.getImageUuid()); Tuple imgt = imgq.findTuple(); ImageState imgState = imgt.get(0, ImageState.class); if (imgState == ImageState.Disabled) { hq.select(HostVO_.state, HostVO_.status); hq.add(HostVO_.uuid, Op.EQ, msg.getHostUuid()); Tuple t = hq.findTuple(); HostState hostState = t.get(0, HostState.class); if (hostState == HostState.Disabled) {
q.select(LocalStorageResourceRefVO_.hostUuid, LocalStorageResourceRefVO_.primaryStorageUuid); q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, spec.getVmInventory().getRootVolumeUuid()); Tuple t = q.findTuple(); final String hostUuid = t.get(0, String.class); String priUuid = t.get(1, String.class);
private NeedReplyMessage makeMsg(final String suuid, boolean volumeDeletion) { SimpleQuery<VolumeSnapshotVO> sq = dbf.createQuery(VolumeSnapshotVO.class); sq.select(VolumeSnapshotVO_.volumeUuid, VolumeSnapshotVO_.treeUuid); sq.add(VolumeSnapshotVO_.uuid, Op.EQ, suuid); Tuple t = sq.findTuple(); String volumeUuid = t.get(0, String.class); String treeUuid = t.get(1, String.class); VolumeSnapshotDeletionMsg msg = new VolumeSnapshotDeletionMsg(); msg.setSnapshotUuid(suuid); msg.setTreeUuid(treeUuid); msg.setVolumeUuid(volumeUuid); msg.setVolumeDeletion(volumeDeletion); String resourceUuid = volumeUuid != null ? volumeUuid : treeUuid; bus.makeTargetServiceIdByResourceUuid(msg, VolumeSnapshotConstant.SERVICE_ID, resourceUuid); if (volumeUuid == null) { return msg; } // To delete a volume snapshot, we need first to be synchronized in the volume queue. VolumeSnapshotOverlayMsg omsg = new VolumeSnapshotOverlayMsg(); omsg.setMessage(msg); omsg.setVolumeUuid(volumeUuid); bus.makeTargetServiceIdByResourceUuid(omsg, VolumeConstant.SERVICE_ID, volumeUuid); return omsg; }
private void validate(APIGetDataVolumeAttachableVmMsg msg) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.vmInstanceUuid, VolumeVO_.state, VolumeVO_.status, VolumeVO_.type); q.add(VolumeVO_.uuid, Op.EQ, msg.getVolumeUuid()); Tuple t = q.findTuple(); VolumeType type = t.get(3, VolumeType.class); if (type == VolumeType.Root) { throw new ApiMessageInterceptionException(argerr("volume[uuid:%s] is Root volume, can not be attach to vm", msg.getVolumeUuid())); } // As per issue #1696, we do not report error if the volume has been attached. // Instead, an empty list will be returned later when handling this message. VolumeState state = t.get(1, VolumeState.class); if (state != VolumeState.Enabled) { throw new ApiMessageInterceptionException(argerr("volume[uuid:%s] is in state[%s], data volume can only be attached when state is %s", msg.getVolumeUuid(), state, VolumeState.Enabled)); } VolumeStatus status = t.get(2, VolumeStatus.class); if (status != VolumeStatus.Ready && status != VolumeStatus.NotInstantiated) { throw new ApiMessageInterceptionException(argerr("volume[uuid:%s] is in status[%s], data volume can only be attached when status is %s or %S", msg.getVolumeUuid(), status, VolumeStatus.Ready, VolumeStatus.NotInstantiated)); } }
private void validate(APIDeleteDataVolumeMsg msg) { if (!dbf.isExist(msg.getUuid(), VolumeVO.class)) { APIDeleteDataVolumeEvent evt = new APIDeleteDataVolumeEvent(msg.getId()); bus.publish(evt); throw new StopRoutingException(); } SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.type, VolumeVO_.status); q.add(VolumeVO_.uuid, Op.EQ, msg.getVolumeUuid()); Tuple t = q.findTuple(); VolumeType type = t.get(0, VolumeType.class); if (type == VolumeType.Root) { throw new ApiMessageInterceptionException(argerr("volume[uuid:%s] is Root volume, can't be deleted", msg.getVolumeUuid())); } VolumeStatus status = t.get(1, VolumeStatus.class); if (status == VolumeStatus.Deleted) { throw new ApiMessageInterceptionException(operr("volume[uuid:%s] is already in status of deleted", msg.getVolumeUuid())); } }
q.select(PortForwardingRuleVO_.vmNicUuid, PortForwardingRuleVO_.state); q.add(PortForwardingRuleVO_.uuid, Op.EQ, msg.getRuleUuid()); Tuple t = q.findTuple();
imq.select(ImageVO_.mediaType, ImageVO_.format); imq.add(ImageVO_.uuid, Op.EQ, msg.getImageUuid()); Tuple t = imq.findTuple();
q.select(VmInstanceVO_.state, VmInstanceVO_.hostUuid); q.add(VmInstanceVO_.uuid, Op.EQ, volume.getVmInstanceUuid()); Tuple t = q.findTuple(); VmInstanceState state = t.get(0, VmInstanceState.class); hostUuid = t.get(1, String.class);
q.select(EipVO_.state, EipVO_.vmNicUuid, EipVO_.vipUuid); q.add(EipVO_.uuid, Op.EQ, msg.getEipUuid()); Tuple t = q.findTuple(); String vmNicUuid = t.get(1, String.class); if (vmNicUuid != null) {
q.select(VmInstanceVO_.state, VmInstanceVO_.hostUuid); q.add(VmInstanceVO_.uuid, Op.EQ, volume.getVmInstanceUuid()); Tuple t = q.findTuple(); VmInstanceState state = t.get(0, VmInstanceState.class); hostUuid = t.get(1, String.class);
l3q.select(L3NetworkVO_.state, L3NetworkVO_.system, L3NetworkVO_.category, L3NetworkVO_.type); l3q.add(L3NetworkVO_.uuid, Op.EQ, msg.getL3NetworkUuid()); Tuple t = l3q.findTuple(); L3NetworkState l3state = t.get(0, L3NetworkState.class);
sq.select(VolumeSnapshotVO_.volumeUuid, VolumeSnapshotVO_.treeUuid); sq.add(VolumeSnapshotVO_.uuid, Op.EQ, msg.getVolumeSnapshotUuid()); Tuple t = sq.findTuple(); String volumeUuid = t.get(0, String.class); String treeUuid = t.get(1, String.class);