/** * Analyze the VM data pair Skip analysis on VMs which cannot be locked note: metrics calculation * like memCommited and vmsCoresCount should be calculated *before* this filtering. */ private void refreshVmStats() { for (Pair<VM, VmInternalData> monitoredVm : monitoredVms) { // TODO filter out migratingTo VMs if no action is taken on them if (tryLockVmForUpdate(monitoredVm)) { VmAnalyzer vmAnalyzer = getVmAnalyzer(monitoredVm); vmAnalyzers.add(vmAnalyzer); vmAnalyzer.analyze(); if (vmAnalyzer.isExternalVm()) { externalVms.add(new Pair<>(vmAnalyzer.getDbVm(), vmAnalyzer.getVdsmVm())); } } } processExternallyManagedVms(); processVmsWithDevicesChange(); saveVmsToDb(); }
private void afterVMsRefreshTreatment() { Collection<Guid> movedToDownVms = new ArrayList<>(); List<Guid> succeededToRunVms = new ArrayList<>(); // now loop over the result and act for (VmAnalyzer vmAnalyzer : vmAnalyzers) { // rerun all vms from rerun list if (vmAnalyzer.isRerun()) { log.error( "Rerun VM '{}'. Called from VDS '{}'", vmAnalyzer.getDbVm().getId(), vdsManager.getVdsName()); ResourceManager.getInstance() .rerunFailedCommand(vmAnalyzer.getDbVm().getId(), vdsManager.getVdsId()); } if (vmAnalyzer.isSuccededToRun()) { vdsManager.succeededToRunVm(vmAnalyzer.getDbVm().getId()); succeededToRunVms.add(vmAnalyzer.getDbVm().getId()); } // Refrain from auto-start HA VM during its re-run attempts. if (vmAnalyzer.isAutoVmToRun() && !vmAnalyzer.isRerun()) { autoVmsToRun.add(vmAnalyzer.getDbVm().getId()); } // process all vms that their ip changed. if (vmAnalyzer.isClientIpChanged()) { final VmDynamic vmDynamic = vmAnalyzer.getVdsmVm().getVmDynamic(); getVdsEventListener().processOnClientIpChange(vmDynamic.getId(), vmDynamic.getClientIp()); } // process all vms that powering up. if (vmAnalyzer.isPoweringUp()) { getVdsEventListener().processOnVmPoweringUp(vmAnalyzer.getVdsmVm().getVmDynamic().getId()); } if (vmAnalyzer.isMovedToDown()) { movedToDownVms.add(vmAnalyzer.getDbVm().getId()); } if (vmAnalyzer.isRemoveFromAsync()) { ResourceManager.getInstance().removeAsyncRunningVm(vmAnalyzer.getDbVm().getId()); } if (vmAnalyzer.isHostedEngineUnmanaged()) { // @since 3.6 - we take existing HE VM and reimport it importHostedEngineVM( getVmInfo( Collections.singletonList( vmAnalyzer.getVdsmVm().getVmDynamic().getId().toString()))[0]); } } getVdsEventListener().updateSlaPolicies(succeededToRunVms, vdsManager.getVdsId()); // run all vms that crashed that marked with auto startup getVdsEventListener().runFailedAutoStartVMs(autoVmsToRun); // process all vms that went down getVdsEventListener().processOnVmStop(movedToDownVms, vdsManager.getVdsId()); getVdsEventListener() .refreshHostIfAnyVmHasHostDevices(succeededToRunVms, vdsManager.getVdsId()); }