@Override public BackupStorageInventory reload(String uuid) { SftpBackupStorageVO vo = dbf.findByUuid(uuid, SftpBackupStorageVO.class); return SftpBackupStorageInventory.valueOf(vo); }
@Override public BackupStorage getBackupStorage(BackupStorageVO vo) { SftpBackupStorageVO lvo = dbf.findByUuid(vo.getUuid(), SftpBackupStorageVO.class); return new SftpBackupStorage(lvo); }
private BackupStorageMediator getBackupStorageMediator(String bsUuid) { BackupStorageVO bsvo = dbf.findByUuid(bsUuid, BackupStorageVO.class); BackupStorageMediator mediator = backupStorageMediators.get(bsvo.getType()); if (mediator == null) { throw new CloudRuntimeException(String.format("cannot find BackupStorageMediator for type[%s]", bsvo.getType())); } mediator.backupStorage = BackupStorageInventory.valueOf(bsvo); return mediator; }
@Override public Host getHost(HostVO vo) { KVMHostVO kvo = dbf.findByUuid(vo.getUuid(), KVMHostVO.class); KVMHostContext context = getHostContext(vo.getUuid()); if (context == null) { context = createHostContext(kvo); } return new KVMHost(kvo, context); }
private void validate(APISetVmInstanceDefaultCdRomMsg msg) { VmCdRomVO vmCdRomVO = dbf.findByUuid(msg.getUuid(), VmCdRomVO.class); if (vmCdRomVO.getDeviceId() == 0) { throw new ApiMessageInterceptionException(argerr("The CdRom[%s] Already the default", vmCdRomVO.getUuid())); } }
private void handle(APIDeleteGCJobMsg msg) { GarbageCollector gc = managedGarbageCollectors.get(msg.getUuid()); if (gc != null) { gc.cancel(); } GarbageCollectorVO vo = dbf.findByUuid(msg.getUuid(), GarbageCollectorVO.class); dbf.remove(vo); APIDeleteGCJobEvent evt = new APIDeleteGCJobEvent(msg.getId()); bus.publish(evt); }
@Override public void run(MessageReply reply) { if (reply.isSuccess()) { ApplianceVmVO vo = dbf.findByUuid(vmUuid, ApplianceVmVO.class); completion.success(ApplianceVmInventory.valueOf(vo)); } else { completion.fail(reply.getError()); } } });
private void handle(PrimaryStorageRemoveCachedImageMsg msg) { if (self.getAttachedClusterRefs().isEmpty()) { PrimaryStorageRemoveCachedImageReply reply = new PrimaryStorageRemoveCachedImageReply(); reply.setError(operr("primary storage[uuid:%s] doesn't attach to any cluster", self.getUuid())); bus.reply(msg, reply); return; } PrimaryStorageClusterRefVO ref = self.getAttachedClusterRefs().iterator().next(); ClusterVO cluster = dbf.findByUuid(ref.getClusterUuid(), ClusterVO.class); getBackend(HypervisorType.valueOf(cluster.getHypervisorType())).deleteImageCache(msg.getInventory()); }
private void validate(APIDetachPolicyFromUserGroupMsg msg) { PolicyVO policy = dbf.findByUuid(msg.getPolicyUuid(), PolicyVO.class); UserGroupVO group = dbf.findByUuid(msg.getGroupUuid(), UserGroupVO.class); if (!policy.getAccountUuid().equals(msg.getAccountUuid())) { throw new ApiMessageInterceptionException(argerr("policy[name: %s, uuid: %s] doesn't belong to the account[uuid: %s]", policy.getName(), policy.getUuid(), msg.getSession().getAccountUuid())); } if (!group.getAccountUuid().equals(msg.getAccountUuid())) { throw new ApiMessageInterceptionException(argerr("group[name: %s, uuid: %s] doesn't belong to the account[uuid: %s]", group.getName(), group.getUuid(), msg.getSession().getAccountUuid())); } }
private void validate(APIAttachPolicyToUserMsg msg) { PolicyVO policy = dbf.findByUuid(msg.getPolicyUuid(), PolicyVO.class); UserVO user = dbf.findByUuid(msg.getUserUuid(), UserVO.class); if (!policy.getAccountUuid().equals(msg.getAccountUuid())) { throw new ApiMessageInterceptionException(argerr("policy[name: %s, uuid: %s] doesn't belong to the account[uuid: %s]", policy.getName(), policy.getUuid(), msg.getSession().getAccountUuid())); } if (!user.getAccountUuid().equals(msg.getAccountUuid())) { throw new ApiMessageInterceptionException(argerr("user[name: %s, uuid: %s] doesn't belong to the account[uuid: %s]", user.getName(), user.getUuid(), msg.getSession().getAccountUuid())); } }
private void validate(APIAttachPolicyToUserGroupMsg msg) { PolicyVO policy = dbf.findByUuid(msg.getPolicyUuid(), PolicyVO.class); UserGroupVO group = dbf.findByUuid(msg.getGroupUuid(), UserGroupVO.class); if (!policy.getAccountUuid().equals(msg.getAccountUuid())) { throw new ApiMessageInterceptionException(argerr("policy[name: %s, uuid: %s] doesn't belong to the account[uuid: %s]", policy.getName(), policy.getUuid(), msg.getSession().getAccountUuid())); } if (!group.getAccountUuid().equals(msg.getAccountUuid())) { throw new ApiMessageInterceptionException(argerr("group[name: %s, uuid: %s] doesn't belong to the account[uuid: %s]", group.getName(), group.getUuid(), msg.getSession().getAccountUuid())); } }
private void validate(APIAddUserToGroupMsg msg) { UserVO user = dbf.findByUuid(msg.getUserUuid(), UserVO.class); UserGroupVO group = dbf.findByUuid(msg.getGroupUuid(), UserGroupVO.class); if (!user.getAccountUuid().equals(msg.getAccountUuid())) { throw new ApiMessageInterceptionException(argerr("user[name: %s, uuid: %s] doesn't belong to the account[uuid: %s]", user.getName(), user.getUuid(), msg.getSession().getAccountUuid())); } if (!group.getAccountUuid().equals(msg.getSession().getAccountUuid())) { throw new ApiMessageInterceptionException(argerr("group[name: %s, uuid: %s] doesn't belong to the account[uuid: %s]", group.getName(), group.getUuid(), msg.getSession().getAccountUuid())); } }
private void validate(APIUpdateSystemTagMsg msg) { SystemTagVO vo = dbf.findByUuid(msg.getUuid(), SystemTagVO.class); try { tagMgr.validateSystemTag(vo.getResourceUuid(), vo.getResourceType(), msg.getTag()); } catch (OperationFailureException oe) { throw new ApiMessageInterceptionException(oe.getErrorCode()); } }
@Override public void run(List<MessageReply> replies) { // if ChangeImage, resume rootVolumeUuid if (spec.getCurrentVmOperation() == VmInstanceConstant.VmOperation.ChangeImage) { VmInstanceVO vm = dbf.findByUuid(spec.getVmInventory().getUuid(), VmInstanceVO.class); vm.setRootVolumeUuid(spec.getVmInventory().getRootVolumeUuid()); dbf.update(vm); } chain.rollback(); } });
private void handle(APIDetachSecurityGroupFromL3NetworkMsg msg) { List<String> vmNicUuids = getVmNicUuidsToRemoveForDetachSecurityGroup(msg.getSecurityGroupUuid(), msg.getL3NetworkUuid()); if (!vmNicUuids.isEmpty()) { removeNicFromSecurityGroup(msg.getSecurityGroupUuid(), vmNicUuids); } detachSecurityGroupFromL3Network(msg.getSecurityGroupUuid(), msg.getL3NetworkUuid()); APIDetachSecurityGroupFromL3NetworkEvent evt = new APIDetachSecurityGroupFromL3NetworkEvent(msg.getId()); SecurityGroupVO vo = dbf.findByUuid(msg.getSecurityGroupUuid(), SecurityGroupVO.class); evt.setInventory(SecurityGroupInventory.valueOf(vo)); bus.publish(evt); }
@Override public void run(MessageReply reply) { for (VmNicExtensionPoint ext : pluginRgty.getExtensionList(VmNicExtensionPoint.class)) { ext.afterDelIpAddress(nic.getUuid(), ipInventory.getUuid()); } VmNicInventory nicInv = VmNicInventory.valueOf(dbf.findByUuid(nic.getUuid(), VmNicVO.class)); new DualStackNicSecondaryNetworksOperator().deleteSecondaryNetworksByVmNic(nicInv, l3.getUuid()); chain.rollback(); } });
@Override public KVMAgentCommands.NicTO completeNicInformation(L2NetworkInventory l2Network, VmNicInventory nic) { VxlanNetworkPoolVO vo = dbf.findByUuid(l2Network.getUuid(), VxlanNetworkPoolVO.class); KVMAgentCommands.NicTO to = new KVMAgentCommands.NicTO(); to.setMac(nic.getMac()); to.setUuid(nic.getUuid()); to.setDeviceId(nic.getDeviceId()); to.setNicInternalName(nic.getInternalName()); return to; }
private void validate(APICreateDataVolumeTemplateFromVolumeMsg msg) { VolumeVO vol = dbf.findByUuid(msg.getVolumeUuid(), VolumeVO.class); if (VolumeStatus.Ready != vol.getStatus()) { throw new ApiMessageInterceptionException(operr("volume[uuid:%s] is not Ready, it's %s", vol.getUuid(), vol.getStatus())); } if (VolumeState.Enabled != vol.getState()) { throw new ApiMessageInterceptionException(operr("volume[uuid:%s] is not Enabled, it's %s", vol.getUuid(), vol.getState())); } }
private void validate(APICreateDataVolumeTemplateFromVolumeSnapshotMsg msg) { VolumeSnapshotVO vsvo = dbf.findByUuid(msg.getSnapshotUuid(), VolumeSnapshotVO.class); if (VolumeSnapshotStatus.Ready != vsvo.getStatus()) { throw new ApiMessageInterceptionException(operr("volume snapshot[uuid:%s] is not Ready, it's %s", vsvo.getUuid(), vsvo.getStatus())); } if (VolumeSnapshotState.Enabled != vsvo.getState()) { throw new ApiMessageInterceptionException(operr("volume snapshot[uuid:%s] is not Enabled, it's %s", vsvo.getUuid(), vsvo.getState())); } }
protected void handle(APIChangeVipStateMsg msg) { VipVO vip = dbf.findByUuid(msg.getUuid(), VipVO.class); VipStateEvent sevt = VipStateEvent.valueOf(msg.getStateEvent()); vip.setState(vip.getState().nextState(sevt)); vip = dbf.updateAndRefresh(vip); APIChangeVipStateEvent evt = new APIChangeVipStateEvent(msg.getId()); evt.setInventory(VipInventory.valueOf(vip)); bus.publish(evt); }