Пример #1
0
 /**
  * analyze and react upon changes on the monitoredVms. relevant changes would be persisted and
  * state transitions and internal commands would take place accordingly.
  */
 public void perform() {
   try {
     refreshExistingVmJobList();
     refreshVmStats();
     afterVMsRefreshTreatment();
     vdsManager.vmsMonitoringInitFinished();
   } catch (RuntimeException ex) {
     log.error(
         "Failed during vms monitoring on host {} error is: {}", vdsManager.getVdsName(), ex);
     log.error("Exception:", ex);
   } finally {
     unlockVmsManager();
   }
 }
Пример #2
0
  /**
   * lock Vms which has db entity i.e they are managed by a VmManager
   *
   * @param pair
   * @return true if lock acquired
   */
  private boolean tryLockVmForUpdate(Pair<VM, VmInternalData> pair) {
    Guid vmId = getVmId(pair);

    if (vmId != null) {
      VmManager vmManager = getResourceManager().getVmManager(vmId);

      if (vmManager.trylock()) {
        if (!vmManager.isLatestData(pair.getSecond(), vdsManager.getVdsId())) {
          log.warn(
              "skipping VM '{}' from this monitoring cycle"
                  + " - newer VM data was already processed",
              vmId);
          vmManager.unlock();
        } else if (vmManager.getVmDataChangedTime() != null
            && fetchTime - vmManager.getVmDataChangedTime() <= 0) {
          log.warn(
              "skipping VM '{}' from this monitoring cycle"
                  + " - the VM data has changed since fetching the data",
              vmId);
          vmManager.unlock();
        } else {
          // store the locked managers to finally release them at the end of the cycle
          vmManagers.put(vmId, vmManager);
          return true;
        }
      } else {
        log.debug(
            "skipping VM '{}' from this monitoring cycle" + " - the VM is locked by its VmManager ",
            getVmId(pair));
      }
    }
    return false;
  }
Пример #3
0
 /**
  * gets VM full information for the given list of VMs
  *
  * @param vmsToUpdate
  * @return
  */
 protected Map[] getVmInfo(List<String> vmsToUpdate) {
   // TODO refactor commands to use vdsId only - the whole vds object here is useless
   VDS vds = new VDS();
   vds.setId(vdsManager.getVdsId());
   Map[] result = {};
   VDSReturnValue vdsReturnValue =
       getResourceManager()
           .runVdsCommand(
               VDSCommandType.FullList, new FullListVDSCommandParameters(vds, vmsToUpdate));
   if (vdsReturnValue.getSucceeded()) {
     result = (Map[]) (vdsReturnValue.getReturnValue());
   }
   return result;
 }
Пример #4
0
  protected void processExternallyManagedVms() {
    // Fetching for details from the host
    // and marking the VMs for addition
    List<String> vmsToQuery = new ArrayList<>(externalVms.size());
    for (Pair<VM, VmInternalData> pair : externalVms) {
      vmsToQuery.add(pair.getSecond().getVmDynamic().getId().toString());
    }
    if (!vmsToQuery.isEmpty()) {
      // Query VDSM for VMs info, and creating a proper VMStatic to be used when importing them
      Map[] vmsInfo = getVmInfo(vmsToQuery);
      for (Map vmInfo : vmsInfo) {
        Guid vmId = Guid.createGuidFromString((String) vmInfo.get(VdsProperties.vm_guid));
        VmStatic vmStatic = new VmStatic();
        vmStatic.setId(vmId);
        vmStatic.setCreationDate(new Date());
        vmStatic.setVdsGroupId(vdsManager.getVdsGroupId());
        String vmNameOnHost = (String) vmInfo.get(VdsProperties.vm_name);

        if (StringUtils.equals(
            Config.<String>getValue(ConfigValues.HostedEngineVmName), vmNameOnHost)) {
          // its a hosted engine VM -> import it and skip the external VM phase
          importHostedEngineVM(vmInfo);
          continue;
        } else {
          vmStatic.setName(String.format(EXTERNAL_VM_NAME_FORMAT, vmNameOnHost));
          vmStatic.setOrigin(OriginType.EXTERNAL);
        }

        vmStatic.setNumOfSockets(
            VdsBrokerObjectsBuilder.parseIntVdsProperty(vmInfo.get(VdsProperties.num_of_cpus)));
        vmStatic.setMemSizeMb(
            VdsBrokerObjectsBuilder.parseIntVdsProperty(vmInfo.get(VdsProperties.mem_size_mb)));
        vmStatic.setSingleQxlPci(false);

        externalVmsToAdd.add(vmStatic);
        log.info(
            "Importing VM '{}' as '{}', as it is running on the on Host, but does not exist in the engine.",
            vmNameOnHost,
            vmStatic.getName());
      }
    }
  }
Пример #5
0
 private void processVmsWithDevicesChange() {
   // Handle VM devices were changed (for 3.1 cluster and above)
   if (!VmDeviceCommonUtils.isOldClusterVersion(vdsManager.getGroupCompatibilityVersion())) {
     // If there are vms that require updating,
     // get the new info from VDSM in one call, and then update them all
     if (!vmsWithChangedDevices.isEmpty()) {
       ArrayList<String> vmsToUpdate = new ArrayList<>(vmsWithChangedDevices.size());
       for (Pair<VM, VmInternalData> pair : vmsWithChangedDevices) {
         Guid vmId = pair.getFirst().getId();
         // update only if the vm marked to change, otherwise it might have skipped because data
         // invalidated
         // this ensure the vmManager lock is taken
         if (vmDynamicToSave.containsKey(vmId)) {
           vmDynamicToSave.get(vmId).setHash(pair.getSecond().getVmDynamic().getHash());
           vmsToUpdate.add(vmId.toString());
         } else {
           log.warn("VM '{}' not in changed list, skipping devices update.", vmId);
         }
       }
       updateVmDevices(vmsToUpdate);
     }
   }
 }
Пример #6
0
  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());
  }