@Override public void vmJustBeforeDeleteFromDb(VmInstanceInventory inv) { deleteStaleSnapshotRecords(inv.getRootVolumeUuid()); }
@Transactional(readOnly = true) private boolean needLink(VmInstanceInventory inv) { String sql = "select ps.type from PrimaryStorageVO ps, VolumeVO vol where ps.uuid = vol.primaryStorageUuid" + " and vol.uuid = :uuid"; TypedQuery<String> q = dbf.getEntityManager().createQuery(sql, String.class); q.setParameter("uuid", inv.getRootVolumeUuid()); List<String> res = q.getResultList(); if (res.isEmpty()) { return false; } String type = res.get(0); return FusionstorConstants.FUSIONSTOR_PRIMARY_STORAGE_TYPE.equals(type); }
@Override public void vmStateChanged(VmInstanceInventory vm, VmInstanceState oldState, VmInstanceState newState) { if (newState == VmInstanceState.Destroyed && vm != null && vm.getRootVolumeUuid() != null) { SQL.New(VolumeVO.class).eq(VolumeVO_.uuid, vm.getRootVolumeUuid()) .set(VolumeVO_.status, VolumeStatus.Deleted) .update(); } } }
@Override @Transactional(readOnly = true) public void preRecoverVm(VmInstanceInventory vm) { String rootVolUuid = vm.getRootVolumeUuid(); String sql = "select ps.uuid" + " from PrimaryStorageVO ps, VolumeVO vol" + " where ps.uuid = vol.primaryStorageUuid" + " and vol.uuid = :uuid" + " and ps.type = :pstype"; TypedQuery<String> q = dbf.getEntityManager().createQuery(sql, String.class); q.setParameter("uuid", rootVolUuid); q.setParameter("pstype", LocalStorageConstants.LOCAL_STORAGE_TYPE); String psuuid = dbf.find(q); if (psuuid == null) { return; } sql = "select count(ref)" + " from LocalStorageResourceRefVO ref" + " where ref.resourceUuid = :uuid" + " and ref.resourceType = :rtype"; TypedQuery<Long> rq = dbf.getEntityManager().createQuery(sql, Long.class); rq.setParameter("uuid", rootVolUuid); rq.setParameter("rtype", VolumeVO.class.getSimpleName()); long count = rq.getSingleResult(); if (count == 0) { throw new OperationFailureException(operr("unable to recover the vm[uuid:%s, name:%s]. The vm's root volume is on the local" + " storage[uuid:%s]; however, the host on which the root volume is has been deleted", vm.getUuid(), vm.getName(), psuuid)); } }
@Override public void run(FlowTrigger trigger, Map data) { final VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); if (spec.getVmInventory().getRootVolumeUuid() == null) { if (!Q.New(VolumeVO.class).eq(VolumeVO_.uuid, spec.getVmInventory().getRootVolumeUuid()).isExists()) { trigger.next(); return; new VmExpungeRootVolumeValidator().validate(spec.getVmInventory().getUuid(), spec.getVmInventory().getRootVolumeUuid()); msg.setVolumeUuid(spec.getVmInventory().getRootVolumeUuid()); bus.makeTargetServiceIdByResourceUuid(msg, VolumeConstant.SERVICE_ID, msg.getVolumeUuid()); bus.send(msg, new CloudBusCallBack(trigger) {
@Override public void run(MessageReply reply) { if (!reply.isSuccess()) { logger.warn(String.format("failed to expunge the root volume[uuid:%s] of the vm[uuid:%s, name:%s], %s", spec.getVmInventory().getRootVolumeUuid(), spec.getVmInventory().getUuid(), spec.getVmInventory().getName(), reply.getError())); trigger.fail(reply.getError()); return; } trigger.next(); } });
@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(); } });
if (VolumeStatus.NotInstantiated.toString().equals(volume.getStatus()) && VmAllocatePrimaryStorageForAttachingDiskFlow.class.getName().equals(nextFlowName)) { if (isRootVolumeOnLocalStorage(spec.getVmInventory().getRootVolumeUuid())) { return new LocalStorageAllocateCapacityForAttachingVolumeFlow(); } else if (spec.getCurrentVmOperation() == VmOperation.Migrate && isRootVolumeOnLocalStorage(spec.getVmInventory().getRootVolumeUuid()) && VmMigrateOnHypervisorFlow.class.getName().equals(nextFlowName)) { if (KVMConstant.KVM_HYPERVISOR_TYPE.equals(spec.getVmInventory().getHypervisorType())) {
@Override public void preAttachVolume(VmInstanceInventory vm, final VolumeInventory volume) { SimpleQuery<LocalStorageResourceRefVO> q = dbf.createQuery(LocalStorageResourceRefVO.class); q.add(LocalStorageResourceRefVO_.resourceUuid, Op.IN, list(vm.getRootVolumeUuid(), volume.getUuid())); q.groupBy(LocalStorageResourceRefVO_.hostUuid); long count = q.count(); q = dbf.createQuery(LocalStorageResourceRefVO.class); q.select(LocalStorageResourceRefVO_.hostUuid); q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, vm.getRootVolumeUuid()); String rootHost = q.findValue(); " The root volume[uuid:%s] is on the host[uuid:%s] but the data volume[uuid: %s]" + " is on the host[uuid: %s]", volume.getUuid(), vm.getUuid(), vm.getRootVolumeUuid(), rootHost, volume.getUuid(), dataHost));
q.add(VolumeVO_.uuid, Op.EQ, spec.getVmInventory().getRootVolumeUuid()); final String psUuid = q.findValue();
q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, spec.getVmInventory().getRootVolumeUuid()); Tuple t = q.findTuple(); final String hostUuid = t.get(0, String.class);
if (vol.getUuid().equals(inv.getRootVolumeUuid())) { spec.setDestRootVolume(vol); spec.setRequiredPrimaryStorageUuidForRootVolume(vol.getPrimaryStorageUuid());
q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, spec.getVmInventory().getRootVolumeUuid()); final LocalStorageResourceRefVO ref = q.find();
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()); }