@Transactional private void detachDataVolumes(VmInstanceSpec spec) { List<String> dataVolumeUuids = CollectionUtils.transformToList(spec.getVmInventory().getAllVolumes(), new Function<String, VolumeInventory>() { @Override public String call(VolumeInventory arg) { return VolumeType.Data.toString().equals(arg.getType()) ? arg.getUuid() : null; } }); if (dataVolumeUuids == null || dataVolumeUuids.isEmpty()) { return; } //NOTE(weiw): not using batch sql to avoid deadlock for (String volumeUuid: dataVolumeUuids) { String sql = "update VolumeVO vol set vol.vmInstanceUuid = null where vol.uuid in (:uuids)"; Query q = dbf.getEntityManager().createQuery(sql); q.setParameter("uuids", volumeUuid); q.executeUpdate(); } } }
private ErrorCode refuseLiveMigrationForLocalStorage(VmInstanceInventory vm) { List<String> volUuids = CollectionUtils.transformToList(vm.getAllVolumes(), VolumeInventory::getUuid); String sql = "select count(ps)" + " from PrimaryStorageVO ps, VolumeVO vol" + " where ps.uuid = vol.primaryStorageUuid" + " and vol.uuid in (:volUuids)" + " and ps.type = :ptype"; TypedQuery<Long> q = dbf.getEntityManager().createQuery(sql, Long.class); q.setParameter("volUuids", volUuids); q.setParameter("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE); q.setMaxResults(1); Long count = q.getSingleResult(); if (count > 0) { return operr("unable to live migrate with local storage. The vm[uuid:%s] has volumes on local storage," + "to protect your data, please stop the vm and do the volume migration", vm.getUuid()); } return null; }
List<String> vmAllVolumeUuids = CollectionUtils.transformToList(vm.getAllVolumes(), new Function<String, VolumeInventory>() { @Override public String call(VolumeInventory arg) {
@Override public void allocate() { VmInstanceInventory vm = spec.getVmInstance(); Set<String> psuuids = CollectionUtils.transformToSet(vm.getAllVolumes(), new Function<String, VolumeInventory>() { @Override public String call(VolumeInventory arg) { return arg.getPrimaryStorageUuid(); } }); candidates = allocate(psuuids, vm); if (candidates.isEmpty()) { fail(String.format("no host found in clusters that have attached to primary storage%s", psuuids)); } else { next(candidates); } } }
List<String> requiredPsUuids = CollectionUtils.transformToList(vm.getAllVolumes(), new Function<String, VolumeInventory>() { @Override public String call(VolumeInventory arg) {
@Override public void releaseVmResource(VmInstanceSpec spec, Completion completion) { VmInstanceInventory inv = spec.getVmInventory(); if (spec.getCurrentVmOperation() != VmOperation.Destroy) { completion.success(); return; } // only has root volume if (inv.getAllVolumes().size() == 1) { completion.success(); return; } detachDataVolume(inv); completion.success(); } }
if (vm.getAllVolumes().size() > 1) { return operr("unable to live migrate vm[uuid:%s] with data volumes on local storage." + " Need detach all data volumes first.", vm.getUuid());
if (spec.getVmInventory().getAllVolumes().size() > 1) { detachDataVolumes(spec); List<VolumeDeletionStruct> ctx = CollectionUtils.transformToList(spec.getVmInventory().getAllVolumes(), new Function<VolumeDeletionStruct, VolumeInventory>() { @Override public VolumeDeletionStruct call(VolumeInventory arg) {
if (inv.getAllVolumes().size() > 1) { throw new CloudRuntimeException(String.format("why the deleted vm[uuid:%s] has data volumes??? %s", self.getUuid(), JSONObjectUtil.toJsonString(inv.getAllVolumes())));
for (VolumeInventory vol : spec.getVmInstance().getAllVolumes()) { volumeSize += vol.getSize(); volUuids.add(vol.getUuid());
for(VolumeInventory volume : spec.getVmInstance().getAllVolumes()){ final LocalStorageResourceRefVO ref = Q.New(LocalStorageResourceRefVO.class) .eq(LocalStorageResourceRefVO_.resourceUuid, volume.getUuid())
for (VolumeInventory vol : inv.getAllVolumes()) { if (vol.getUuid().equals(inv.getRootVolumeUuid())) { spec.setDestRootVolume(vol);
public VmInstanceInventory(VmInstanceInventory origin) { VmInstanceInventory inv; try { inv = (VmInstanceInventory) origin.clone(); } catch (CloneNotSupportedException e) { throw new CloudRuntimeException(e); } this.setClusterUuid(inv.getClusterUuid()); this.setCreateDate(inv.getCreateDate()); this.setDescription(inv.getDescription()); this.setHostUuid(inv.getHostUuid()); this.setHypervisorType(inv.getHypervisorType()); this.setImageUuid(inv.getImageUuid()); this.setInstanceOfferingUuid(inv.getInstanceOfferingUuid()); this.setLastHostUuid(inv.getLastHostUuid()); this.setLastOpDate(inv.getLastOpDate()); this.setName(inv.getName()); this.setRootVolumeUuid(inv.getRootVolumeUuid()); this.setState(inv.getState()); this.setType(inv.getType()); this.setUuid(inv.getUuid()); this.setZoneUuid(inv.getZoneUuid()); this.setAllVolumes(inv.getAllVolumes()); this.setVmNics(inv.getVmNics()); this.setInternalId(inv.getInternalId()); this.setCpuNum(inv.getCpuNum()); this.setCpuSpeed(inv.getCpuSpeed()); this.setMemorySize(inv.getMemorySize()); this.setAllocatorStrategy(inv.getAllocatorStrategy()); }