@Override public String call(HostInventory arg) { return arg.getUuid(); } });
@Override public void connectionReestablished(HostInventory inv) throws HostException { if (!KVMConstant.KVM_HYPERVISOR_TYPE.equals(inv.getHypervisorType())) { return; } FutureCompletion completion = new FutureCompletion(null); createSecret(inv.getUuid(), inv.getClusterUuid(), new Completion(completion) { @Override public void success() { completion.success(); } @Override public void fail(ErrorCode errorCode) { completion.fail(errorCode); } }); completion.await(); if (!completion.isSuccess()) { throw new OperationFailureException(completion.getErrorCode()); } }
@Override public HostInventory getHostInventory(HostVO vo) { return HostInventory.valueOf(vo); }
private void realize(final Iterator<HostInventory> it, final FlowTrigger trigger) { if (!it.hasNext()) { trigger.next(); return; } HostInventory host = it.next(); realizeNetwork(host.getUuid(), host.getHypervisorType(), new Completion(trigger) { @Override public void success() { realize(it, trigger); } @Override public void fail(ErrorCode errorCode) { trigger.fail(errorCode); } }); }
@Override public void run(List<MessageReply> replies) { if (!action.isActionCode(CascadeConstant.DELETION_FORCE_DELETE_CODE)) { for (MessageReply r : replies) { if (!r.isSuccess()) { completion.fail(r.getError()); return; } } } List<String> uuids = new ArrayList<String>(); for (MessageReply r : replies) { HostInventory hinv = hinvs.get(replies.indexOf(r)); uuids.add(hinv.getUuid()); logger.debug(String.format("delete host[uuid:%s, name:%s]", hinv.getUuid(), hinv.getName())); } dbf.removeByPrimaryKeys(uuids, HostVO.class); completion.success(); } });
@Override public void connectionReestablished(HostInventory inv) throws HostException { //TODO: make connect async List<L2NetworkInventory> l2s = getL2Networks(inv.getClusterUuid()); if (l2s.isEmpty()) { return; } FutureCompletion completion = new FutureCompletion(null); prepareNetwork(l2s.iterator(), inv.getUuid(), completion); completion.await(TimeUnit.SECONDS.toMillis(600)); if (!completion.isSuccess()) { throw new OperationFailureException(completion.getErrorCode()); } }
@Override public void run(FlowTrigger trigger, Map data) { VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); changeVmStateInDb(struct.getStrategy() == VmCreationStrategy.InstantStart ? VmInstanceStateEvent.running : VmInstanceStateEvent.paused, ()-> { self.setLastHostUuid(spec.getDestHost().getUuid()); self.setHostUuid(spec.getDestHost().getUuid()); self.setClusterUuid(spec.getDestHost().getClusterUuid()); self.setZoneUuid(spec.getDestHost().getZoneUuid()); self.setHypervisorType(spec.getDestHost().getHypervisorType()); self.setRootVolumeUuid(spec.getDestRootVolume().getUuid()); }); logger.debug(String.format("vm[uuid:%s] is started ..", self.getUuid())); VmInstanceInventory inv = VmInstanceInventory.valueOf(self); extEmitter.afterStartNewCreatedVm(inv); trigger.next(); } });
throw new OperationFailureException(operr("The chosen host[uuid:%s] to perform storage migration is lost", msg.getHostUuid())); HostInventory host = HostInventory.valueOf(hostVO); .eq(PrimaryStorageClusterRefVO_.clusterUuid, host.getClusterUuid()) .eq(PrimaryStorageClusterRefVO_.primaryStorageUuid, dstPsInv.getUuid()) .isExists(); logger.info(String.format("no need to mount nfs ps[uuid:%s] to host[uuid:%s]", dstPsInv.getUuid(), host.getUuid())); new KvmCommandSender(host.getUuid()).send(cmd, NFS_TO_NFS_MIGRATE_BITS_PATH, wrapper -> { NfsToNfsMigrateBitsRsp rsp = wrapper.getResponse(NfsToNfsMigrateBitsRsp.class); return rsp.isSuccess() ? null : operr("%s", rsp.getError());
@Override protected void handle(final InstantiateVolumeOnPrimaryStorageMsg msg) { if (msg.getDestHost() == null) { String hostUuid = getAvailableHostUuidForOperation(); if (hostUuid == null) { throw new OperationFailureException(operr("the shared mount point primary storage[uuid:%s, name:%s] cannot find any " + "available host in attached clusters for instantiating the volume", self.getUuid(), self.getName())); } msg.setDestHost(HostInventory.valueOf(dbf.findByUuid(hostUuid, HostVO.class))); } HypervisorFactory f = getHypervisorFactoryByHostUuid(msg.getDestHost().getUuid()); HypervisorBackend bkd = f.getHypervisorBackend(self); bkd.handle(msg, new ReturnValueCompletion<InstantiateVolumeOnPrimaryStorageReply>(msg) { @Override public void success(InstantiateVolumeOnPrimaryStorageReply reply) { bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { InstantiateVolumeOnPrimaryStorageReply reply = new InstantiateVolumeOnPrimaryStorageReply(); reply.setError(errorCode); bus.reply(msg, reply); } }); }
@Override public void handle(final Map data) { VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); HostInventory host = spec.getDestHost(); self = changeVmStateInDb(VmInstanceStateEvent.running, ()-> { self.setZoneUuid(host.getZoneUuid()); self.setClusterUuid(host.getClusterUuid()); self.setLastHostUuid(lastHostUuid); self.setHostUuid(host.getUuid()); }); VmInstanceInventory vm = VmInstanceInventory.valueOf(self); extEmitter.afterMigrateVm(vm, vm.getLastHostUuid()); completion.success(); } }).error(new FlowErrorHandler(completion) {
Map<String, VmInstanceState> states = new HashMap<String, VmInstanceState>(ret.getStates().size()); Set<String> vmsToSkipSet = new HashSet<>(vmsToSkip.keySet()); Collection<String> vmUuidsInDeleteVmGC = DeleteVmGC.queryVmInGC(host.getUuid(), ret.getStates().keySet()); reportVmState(host.getUuid(), states, vmsToSkipSet); completion.success(); } else { ErrorCode errorCode = operr("unable to do vm sync on host[uuid:%s, ip:%s] because %s", host.getUuid(), host.getManagementIp(), ret.getError()); completion.fail(errorCode);
@Override public void afterHostConnected(HostInventory inv) { if (inv.getStatus().equals(HostStatus.Connected.toString())){ List<String> vmUuids = Q.New(VmInstanceVO.class).select(VmInstanceVO_.uuid) .eq(VmInstanceVO_.hostUuid, inv.getUuid()) .listValues(); if(vmUuids.isEmpty()){ return; } new While<>(vmUuids).step((vmUuid, completion) -> { VmCheckOwnStateMsg msg = new VmCheckOwnStateMsg(); msg.setVmInstanceUuid(vmUuid); bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, vmUuid); bus.send(msg, new CloudBusCallBack(completion) { @Override public void run(MessageReply reply) { if(!reply.isSuccess()){ logger.warn(String.format("the host[uuid:%s] connected, but the vm[uuid:%s] fails to " + "update it's state , %s", inv.getUuid(), vmUuid, reply.getError())); } completion.done(); } }); }, 200).run(new NopeNoErrorCompletion()); } } }
if (!KVMConstant.KVM_HYPERVISOR_TYPE.equals(d.getInventory().getHypervisorType())) { return false; .anyMatch(ref -> ref.getClusterUuid().equals(d.getInventory().getClusterUuid()))) { return false;
@Transactional private List<PrimaryStorageVO> getPrimaryStorageHostShouldMount(HostInventory host) { String sql = "select p from PrimaryStorageVO p where p.type = :type and p.uuid in (select ref.primaryStorageUuid from PrimaryStorageClusterRefVO ref where ref.clusterUuid = :clusterUuid)"; TypedQuery<PrimaryStorageVO> query = dbf.getEntityManager().createQuery(sql, PrimaryStorageVO.class); query.setParameter("type", NfsPrimaryStorageConstant.NFS_PRIMARY_STORAGE_TYPE); query.setParameter("clusterUuid", host.getClusterUuid()); return query.getResultList(); }
@Override public String getAllocatorStrategy(HostInventory host) { if (host != null && !"KVM".equals(host.getHypervisorType())) { return null; } return PrimaryStorageConstant.DEFAULT_PRIMARY_STORAGE_ALLOCATION_STRATEGY_TYPE; } }
@Override public void connectionReestablished(HostInventory inv) throws HostException { //TODO: make connect async List<L2NetworkInventory> l2s = getL2Networks(inv.getClusterUuid()); if (l2s.isEmpty()) { return; } FutureCompletion completion = new FutureCompletion(null); prepareNetwork(l2s.iterator(), inv.getUuid(), completion); completion.await(TimeUnit.SECONDS.toMillis(600)); if (!completion.isSuccess()) { throw new OperationFailureException(completion.getErrorCode()); } }
private void realize(final Iterator<HostInventory> it, final FlowTrigger trigger) { if (!it.hasNext()) { trigger.next(); return; } HostInventory host = it.next(); realizeNetwork(host.getUuid(), host.getHypervisorType(), new Completion(trigger) { @Override public void success() { realize(it, trigger); } @Override public void fail(ErrorCode errorCode) { trigger.fail(errorCode); } }); }
HostInventory hinv = HostInventory.valueOf(hvo); spec.setDestHost(hinv); msg.setSize(volume.getSize()); msg.setPurpose(PrimaryStorageAllocationPurpose.CreateVolume.toString()); msg.setRequiredHostUuid(hinv.getUuid()); msg.setDiskOfferingUuid(volume.getDiskOfferingUuid()); msg.setServiceId(bus.makeLocalServiceId(PrimaryStorageConstant.SERVICE_ID));
@Override public void run(MessageReply reply) { if (!reply.isSuccess()) { complete.fail(reply.getError()); return; } CreateVritualRouterBootstrapIsoRsp rsp = ((KVMHostAsyncHttpCallReply)reply).toResponse(CreateVritualRouterBootstrapIsoRsp.class); if (!rsp.isSuccess()) { ErrorCode err = operr("failed to create VirtualRouterBootstrapIso[%s] on kvm host[uuid:%s, ip:%s] for virtual router[uuid:%s], because %s", iso.getIsoPath(), vrSpec.getDestHost().getUuid(), vrSpec.getDestHost().getManagementIp(), iso.getVirtualRouterUuid(), rsp.getError()); complete.fail(err); return; } complete.success(); } });
@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(); } });