@Override public void success() { logger.debug(String.format("vm[uuid:%s, name:%s] migrated to host[uuid:%s], cleanup its old rules on host[uuid:%s] if needed", inv.getUuid(), inv.getName(), inv.getHostUuid(), srcHostUuid)); }
@Override public void fail(ErrorCode errorCode) { N.New(VmInstanceVO.class, inv.getUuid()).warn_("after migration, failed to apply EIPs[uuids:%s] to the vm[uuid:%s, name:%s] on the destination host[uuid:%s], %s", eips.stream().map(e -> e.vip).collect(Collectors.toList()), inv.getUuid(), inv.getName(), inv.getHostUuid(), errorCode); } });
@Override public void fail(ErrorCode errorCode) { logger.debug(String.format("vm[uuid:%s, name:%s] migrated to host[uuid:%s], failed to cleanup its old rules on host[uuid:%s] if needed", inv.getUuid(), inv.getName(), inv.getHostUuid(), srcHostUuid)); createFailureHostTask(inv.getLastHostUuid()); } });
@Override public void fail(ErrorCode errorCode) { logger.warn(String.format("failed to release userdata on the source host[uuid:%s]" + " for the migrated VM[uuid: %s, name:%s], %s. GC will take care it", srcHostUuid, inv.getUuid(), inv.getName(), errorCode)); UserdataReleseGC gc = new UserdataReleseGC(); gc.struct = struct; gc.submit(UserdataReleseGC.INTERVAL, TimeUnit.SECONDS); } });
@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 @Transactional(readOnly = true) public void run() { String sql = "select count(*)" + " from EipVO eip, VipVO vip" + " where eip.vipUuid = vip.uuid" + " and vip.l3NetworkUuid = :l3Uuid" + " and eip.vmNicUuid in (:nicUuids)"; TypedQuery<Long> q = dbf.getEntityManager().createQuery(sql, Long.class); q.setParameter("l3Uuid", l3.getUuid()); q.setParameter("nicUuids", nicUuids); Long count = q.getSingleResult(); if (count > 0) { throw new OperationFailureException(operr("unable to attach the L3 network[uuid:%s, name:%s] to the vm[uuid:%s, name:%s]," + " because the L3 network is providing EIP to one of the vm's nic", l3.getUuid(), l3.getName(), vm.getUuid(), vm.getName())); } } }.run();
private void connected() { String info = String.format("successfully connected to appliance vm[uuid:%s, name:%s, ip:%s], deploying agent now ...", spec.getVmInventory().getUuid(), spec.getVmInventory().getName(), mgmtIp); logger.debug(info); chain.next(); }
@Override public void handle(Map data) { logger.debug(String.format("successfully released network services for vm[uuid:%s, name:%s]", spec.getVmInventory().getUuid(), spec.getVmInventory().getName())); completion.done(); } }).start();
@Override public void next(List<HostVO> candidates) { DebugUtils.Assert(candidates != null, "cannot pass null to next() method"); DebugUtils.Assert(!candidates.isEmpty(), "cannot pass empty candidates to next() method"); result = candidates; VmInstanceInventory vm = allocationSpec.getVmInstance(); logger.debug(String.format("[Host Allocation]: flow[%s] successfully found %s candidate hosts for vm[uuid:%s, name:%s]", lastFlow.getClass().getName(), result.size(), vm.getUuid(), vm.getName())); if (logger.isTraceEnabled()) { StringBuilder sb = new StringBuilder("[Host Allocation Details]:"); for (HostVO vo : result) { sb.append(String.format("\ncandidate host[name:%s, uuid:%s, zoneUuid:%s, clusterUuid:%s, hypervisorType:%s]", vo.getName(), vo.getUuid(), vo.getZoneUuid(), vo.getClusterUuid(), vo.getHypervisorType())); } logger.trace(sb.toString()); } if (it.hasNext()) { runFlow(it.next()); return; } done(); }
private boolean countDown(String msg) { retry.value--; if (retry.value <= 0) { ErrorCode toutErr = touterr("connecting appliance vm[uuid:%s, name:%s, ip:%s] timeout, unable to ssh in[%s]", spec.getVmInventory().getUuid(), spec.getVmInventory().getName(), mgmtIp, msg); logger.warn(toutErr.getDetails()); chain.fail(toutErr); return true; } else { logger.debug(String.format("appliance vm[uuid:%s, name:%s, ip:%s] is still not ready, unable to ssh in[%s], continue ... will be timeout after %s seconds", spec.getVmInventory().getUuid(), spec.getVmInventory().getName(), mgmtIp, msg, interval*retry.value)); return false; } }
@Override public void failedToMigrateVm(final VmInstanceInventory inv, final String destHostUuid, ErrorCode reason) { RuleCalculator cal = new RuleCalculator(); cal.vmNicUuids = CollectionUtils.transformToList(inv.getVmNics(), new Function<String, VmNicInventory>() { @Override public String call(VmNicInventory arg) { return arg.getUuid(); } }); cal.vmStates = asList(VmInstanceState.Unknown); List<HostRuleTO> htos = cal.calculate(); logger.debug(String.format("vm[uuid:%s, name:%s] failed to migrate to host[uuid:%s], recover its rules on previous host[uuid:%s]", inv.getUuid(), inv.getName(), destHostUuid, inv.getHostUuid())); applyRules(htos); }
@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(MessageReply reply) { if (!reply.isSuccess()) { logger.warn(String.format("failed to roll back vm[uuid:%s, name:%s] on host[uuid:%s, ip:%s], %s", spec.getVmInventory().getUuid(), spec.getVmInventory().getName(), spec.getDestHost().getUuid(), spec.getDestHost().getName(), reply.getError())); } trigger.rollback(); } });
@Override public void run(MessageReply reply) { if (!reply.isSuccess()) { logger.warn(String.format("failed to release snat[%s] on virtual router[name:%s, uuid:%s] for vm[uuid: %s, name: %s], %s", struct, vr.getName(), vr.getUuid(), vmInstanceInventory.getUuid(), vmInstanceInventory.getName(), reply.getError())); //TODO GC } else { VirtualRouterAsyncHttpCallReply re = reply.castReply(); RemoveSNATRsp ret = re.toResponse(RemoveSNATRsp.class); if (!ret.isSuccess()) { String err = String.format( "virtual router[uuid:%s, ip:%s] failed to release snat[%s] for vm[uuid:%s, name:%s] on L3Network[uuid:%s, name:%s], because %s", vr.getUuid(), vr.getManagementNic().getIp(), JSONObjectUtil.toJsonString(info), vmInstanceInventory.getUuid(), vmInstanceInventory.getName(), struct.getL3Network().getUuid(), struct.getL3Network().getName(), ret.getError()); logger.warn(err); //TODO GC } else { String msg = String.format( "virtual router[uuid:%s, ip:%s] released snat[%s] for vm[uuid:%s, name:%s] on L3Network[uuid:%s, name:%s], because %s", vr.getUuid(), vr.getManagementNic().getIp(), JSONObjectUtil.toJsonString(info), vmInstanceInventory.getUuid(), vmInstanceInventory.getName(), struct.getL3Network().getUuid(), struct.getL3Network().getName(), ret.getError()); logger.warn(msg); } } releaseSnat(it, vmInstanceInventory, completion); } });
@Override public void run(MessageReply reply) { if (reply.isSuccess()) { chain.next(); } else { if (spec.isGcOnStopFailure() && reply.getError().isError(HostErrors.OPERATION_FAILURE_GC_ELIGIBLE)) { StopVmGC gc = new StopVmGC(); gc.inventory = spec.getVmInventory(); gc.hostUuid = spec.getVmInventory().getHostUuid(); gc.NAME = String.format("gc-stop-vm-%s-%s-on-host-%s", gc.inventory.getUuid(), gc.inventory.getName(), gc.hostUuid); gc.submit(); chain.next(); } else { chain.fail(reply.getError()); } } } });
"1. if the backup storage is attached to the zone where the VM[name: %s, uuid:%s] is in\n" + "2. if the backup storage is in connected status, if not, try reconnecting it", imageUuid, spec.getVmInventory().getZoneUuid(), spec.getVmInventory().getName(), spec.getVmInventory().getUuid()) ); } else { "1. if the backup storage is attached to the zone where the VM[name: %s, uuid:%s] is in\n" + "2. if the backup storage is in connected status, if not, try reconnecting it", imageUuid, spec.getVmInventory().getName(), spec.getVmInventory().getUuid()) );
extEmitter.beforeRebootVmOnKvm(KVMHostInventory.valueOf(getSelf()), vminv); } catch (KVMException e) { String err = String.format("failed to reboot vm[uuid:%s name:%s] on kvm host[uuid:%s, ip:%s], because %s", vminv.getUuid(), vminv.getName(), self.getUuid(), self.getManagementIp(), e.getMessage()); logger.warn(err, e);
extEmitter.beforeStopVmOnKvm(KVMHostInventory.valueOf(getSelf()), vminv); } catch (KVMException e) { ErrorCode err = operr("failed to stop vm[uuid:%s name:%s] on kvm host[uuid:%s, ip:%s], because %s", vminv.getUuid(), vminv.getName(), self.getUuid(), self.getManagementIp(), e.getMessage()); throw new OperationFailureException(err);
extEmitter.beforeDestroyVmOnKvm(KVMHostInventory.valueOf(getSelf()), vminv); } catch (KVMException e) { ErrorCode err = operr("failed to destroy vm[uuid:%s name:%s] on kvm host[uuid:%s, ip:%s], because %s", vminv.getUuid(), vminv.getName(), self.getUuid(), self.getManagementIp(), e.getMessage()); throw new OperationFailureException(err);
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()); }