@Transactional private void changeEipOwner(AccountResourceRefInventory ref, String newOwnerUuid) { String sql = "select eip.uuid" + " from VmInstanceVO vm, VmNicVO nic, EipVO eip" + " where vm.uuid = nic.vmInstanceUuid" + " and nic.uuid = eip.vmNicUuid" + " and vm.uuid = :uuid"; TypedQuery<String> q = dbf.getEntityManager().createQuery(sql, String.class); q.setParameter("uuid", ref.getResourceUuid()); List<String> eipUuids = q.getResultList(); if (eipUuids.isEmpty()) { logger.debug(String.format("Vm[uuid:%s] doesn't have any eip, there is no need to change owner of eip.", ref.getResourceUuid())); return; } for (String uuid : eipUuids) { acntMgr.changeResourceOwner(uuid, newOwnerUuid); } }
private void changeVmCdRomsOwner(String vmInstanceUuid, String newOwnerUuid) { List<String> vmCdRomUuids = Q.New(VmCdRomVO.class) .select(VmCdRomVO_.uuid) .eq(VmCdRomVO_.vmInstanceUuid, vmInstanceUuid) .listValues(); if (vmCdRomUuids.isEmpty()) { return; } for (String uuid :vmCdRomUuids) { acntMgr.changeResourceOwner(uuid, newOwnerUuid); } }
private void changeVolumeSnapshotOwner(AccountResourceRefInventory ref, String newOwnerUuid) { SimpleQuery<VolumeSnapshotVO> q = dbf.createQuery(VolumeSnapshotVO.class); q.select(VolumeSnapshotVO_.uuid); q.add(VolumeSnapshotVO_.volumeUuid, Op.EQ, ref.getResourceUuid()); List<String> spUuids = q.listValue(); for (String spUuid : spUuids) { acntMgr.changeResourceOwner(spUuid, newOwnerUuid); } }
private void changeVolumeOwner(AccountResourceRefInventory ref, String newOwnerUuid) { SimpleQuery<VolumeVO> q = dbf.createQuery(VolumeVO.class); q.select(VolumeVO_.uuid); q.add(VolumeVO_.vmInstanceUuid, Op.EQ, ref.getResourceUuid()); List<String> uuids = q.listValue(); for (String uuid : uuids) { acntMgr.changeResourceOwner(uuid, newOwnerUuid); } }
@Override public void resourceOwnerAfterChange(AccountResourceRefInventory ref, String newOwnerUuid) { if (!VmInstanceVO.class.getSimpleName().equals(ref.getResourceType())) { return; } // change root volume SimpleQuery<VmInstanceVO> q = dbf.createQuery(VmInstanceVO.class); q.select(VmInstanceVO_.rootVolumeUuid); q.add(VmInstanceVO_.uuid, Op.EQ, ref.getResourceUuid()); String rootVolumeUuid = q.findValue(); if (rootVolumeUuid == null) { return; } acntMgr.changeResourceOwner(rootVolumeUuid, newOwnerUuid); // change vmnic(s) SimpleQuery<VmNicVO> sq = dbf.createQuery(VmNicVO.class); sq.select(VmNicVO_.uuid); sq.add(VmNicVO_.vmInstanceUuid, Op.EQ, ref.getResourceUuid()); List<String> vmnics = sq.listValue(); if (vmnics.isEmpty()) { return; } for (String vmnicUuid : vmnics) { acntMgr.changeResourceOwner(vmnicUuid, newOwnerUuid); } changeVmCdRomsOwner(ref.getResourceUuid(), newOwnerUuid); }