private void updateDB(ExternalSchedulerDiscoveryResult discoveryResult) {
    List<PolicyUnit> allPolicyUnits = getPolicyUnitDao().getAll();
    List<PolicyUnit> foundInBoth = new LinkedList<PolicyUnit>();
    for (ExternalSchedulerDiscoveryUnit unit : discoveryResult.getFilters()) {
      PolicyUnit found = compareToDB(allPolicyUnits, unit, PolicyUnitType.Filter);
      if (found != null) {
        foundInBoth.add(found);
      }
    }
    for (ExternalSchedulerDiscoveryUnit unit : discoveryResult.getScores()) {
      PolicyUnit found = compareToDB(allPolicyUnits, unit, PolicyUnitType.Weight);
      if (found != null) {
        foundInBoth.add(found);
      }
    }
    for (ExternalSchedulerDiscoveryUnit unit : discoveryResult.getBalance()) {
      PolicyUnit found = compareToDB(allPolicyUnits, unit, PolicyUnitType.LoadBalancing);
      if (found != null) {
        foundInBoth.add(found);
      }
    }

    allPolicyUnits.removeAll(foundInBoth);
    // found in the db but not found in discovery, mark as such
    markExternalPoliciesAsDisabled(allPolicyUnits);

    SchedulingManager.getInstance().reloadPolicyUnits();
  }
예제 #2
0
  protected boolean initVdss() {
    setVdsIdRef(getVm().getRunOnVds());
    Guid vdsToRunOn =
        SchedulingManager.getInstance()
            .schedule(
                getVdsGroup(),
                getVm(),
                getVdsBlackList(),
                getVdsWhiteList(),
                getDestinationVdsId(),
                new ArrayList<String>(),
                new VdsFreeMemoryChecker(this),
                getCorrelationId());
    setDestinationVdsId(vdsToRunOn);
    if (vdsToRunOn != null && !Guid.Empty.equals(vdsToRunOn)) {
      getRunVdssList().add(vdsToRunOn);
    }
    VmHandler.updateVmGuestAgentVersion(getVm());

    if (vdsToRunOn != null && vdsToRunOn.equals(Guid.Empty)) {
      return false;
    }

    if (getDestinationVds() == null || getVds() == null) {
      return false;
    }

    return true;
  }
예제 #3
0
  /**
   * A general method for run vm validations. used in runVmCommand and in VmPoolCommandBase
   *
   * @param messages
   * @param vmDisks
   * @param storagePool
   * @param vdsBlackList - hosts that we already tried to run on
   * @param vdsWhiteList - initial host list, mainly runOnSpecificHost (runOnce/migrateToHost)
   * @param destVds
   * @param vdsGroup
   * @return
   */
  public boolean canRunVm(
      List<String> messages,
      StoragePool storagePool,
      List<Guid> vdsBlackList,
      List<Guid> vdsWhiteList,
      Guid destVds,
      VDSGroup vdsGroup) {

    if (vm.getStatus() == VMStatus.Paused) {
      // if the VM is paused, we should only check the VDS status
      // as the rest of the checks were already checked before
      return validate(validateVdsStatus(vm), messages);
    }

    return validateVmProperties(vm, runVmParam.getCustomProperties(), messages)
        && validate(
            validateBootSequence(vm, runVmParam.getBootSequence(), getVmDisks(), activeIsoDomainId),
            messages)
        && validate(validateDisplayType(), messages)
        && validate(new VmValidator(vm).vmNotLocked(), messages)
        && validate(getSnapshotValidator().vmNotDuringSnapshot(vm.getId()), messages)
        && validate(validateVmStatusUsingMatrix(vm), messages)
        && validate(validateStoragePoolUp(vm, storagePool, getVmImageDisks()), messages)
        && validate(
            validateIsoPath(
                vm, runVmParam.getDiskPath(), runVmParam.getFloppyPath(), activeIsoDomainId),
            messages)
        && validate(vmDuringInitialization(vm), messages)
        && validate(validateStatelessVm(vm, runVmParam.getRunAsStateless()), messages)
        && validate(validateStorageDomains(vm, isInternalExecution, getVmImageDisks()), messages)
        && validate(validateImagesForRunVm(vm, getVmImageDisks()), messages)
        && validate(validateMemorySize(vm), messages)
        && SchedulingManager.getInstance()
            .canSchedule(vdsGroup, vm, vdsBlackList, vdsWhiteList, destVds, messages);
  }
 private boolean canScheduleVm(VM vm) {
   List<Guid> blacklist = new ArrayList<>();
   if (getVdsId() != null) {
     blacklist.add(getVdsId());
   }
   return schedulingManager.canSchedule(
       getVdsGroup(),
       vm,
       blacklist, // blacklist only contains the host we're putting to maintenance
       Collections.<Guid>emptyList(), // no whitelist
       vm.getDedicatedVmForVdsList(),
       new ArrayList<>());
 }
  protected boolean checkRemoveEditValidations() {
    Guid clusterPolicyId = getParameters().getClusterPolicyId();
    if (clusterPolicyId == null) {
      return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID);
    }
    ClusterPolicy clusterPolicy = schedulingManager.getClusterPolicy(clusterPolicyId);
    if (clusterPolicy == null) {
      return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID);
    }
    if (clusterPolicy.isLocked()) {
      return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID);
    }

    return true;
  }
  protected boolean checkAddEditValidations() {
    List<ClusterPolicy> clusterPolicies = schedulingManager.getClusterPolicies();
    if (getClusterPolicy() == null) {
      return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID);
    }
    for (ClusterPolicy clusterPolicy : clusterPolicies) {
      if (!clusterPolicy.getId().equals(getClusterPolicy().getId())
          && clusterPolicy.getName().equals(getClusterPolicy().getName())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_NAME_INUSE);
      }
    }
    Map<Guid, PolicyUnitImpl> map = schedulingManager.getPolicyUnitsMap();
    Set<Guid> existingPolicyUnits = new HashSet<>();
    // check filter policy units
    if (getClusterPolicy().getFilters() != null) {
      for (Guid filterId : getClusterPolicy().getFilters()) {
        if (isPolicyUnitExists(filterId, existingPolicyUnits)) {
          return failValidation(
              EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT);
        }
        PolicyUnitImpl policyUnitImpl = map.get(filterId);
        if (policyUnitImpl == null) {
          return failValidation(
              EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
        }
        if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.FILTER) {
          return failValidation(
              EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_FILTER_NOT_IMPLEMENTED);
        }
      }
    }
    // check filters positions (there could be only one filter attached to first (-1) and last (-1)
    if (getClusterPolicy().getFilterPositionMap() != null) {
      boolean hasFirst = false;
      boolean hasLast = false;
      for (Integer position : getClusterPolicy().getFilterPositionMap().values()) {
        if (position == -1) {
          if (!hasFirst) {
            hasFirst = true;
          } else {
            return failValidation(
                EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_ONLY_ONE_FILTER_CAN_BE_FIRST);
          }
        } else if (position == 1) {
          if (!hasLast) {
            hasLast = true;
          } else {
            return failValidation(
                EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_ONLY_ONE_FILTER_CAN_BE_LAST);
          }
        }
      }
    }
    // check function policy units
    if (getClusterPolicy().getFunctions() != null) {
      for (Pair<Guid, Integer> functionPair : getClusterPolicy().getFunctions()) {
        if (isPolicyUnitExists(functionPair.getFirst(), existingPolicyUnits)) {
          return failValidation(
              EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT);
        }
        PolicyUnitImpl policyUnitImpl = map.get(functionPair.getFirst());
        if (policyUnitImpl == null) {
          return failValidation(
              EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
        }
        if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.WEIGHT) {
          return failValidation(
              EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_FUNCTION_NOT_IMPLEMENTED);
        }
        if (functionPair.getSecond() < 0) {
          return failValidation(
              EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_FUNCTION_FACTOR_NEGATIVE);
        }
      }
    }
    // check balance policy unit
    if (getClusterPolicy().getBalance() != null) {
      PolicyUnitImpl policyUnitImpl = map.get(getClusterPolicy().getBalance());
      if (policyUnitImpl == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
      }
      if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.LOAD_BALANCING) {
        return failValidation(
            EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_BALANCE_NOT_IMPLEMENTED);
      }
    }

    List<ValidationError> validationErrors =
        SimpleCustomPropertiesUtil.getInstance()
            .validateProperties(
                schedulingManager.getCustomPropertiesRegexMap(getClusterPolicy()),
                getClusterPolicy().getParameterMap());
    if (!validationErrors.isEmpty()) {
      SimpleCustomPropertiesUtil.getInstance()
          .handleCustomPropertiesError(validationErrors, getReturnValue().getValidationMessages());
      return false;
    }
    return true;
  }
예제 #7
0
  @Override
  protected boolean canDoAction() {
    final VM vm = getVm();

    if (vm == null) {
      return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_NOT_FOUND);
    }

    if (!canRunActionOnNonManagedVm()) {
      return false;
    }

    if (!FeatureSupported.isMigrationSupported(
        getVdsGroup().getArchitecture(), getVdsGroup().getcompatibility_version())) {
      return failCanDoAction(VdcBllMessages.MIGRATION_IS_NOT_SUPPORTED);
    }

    // If VM is pinned to host, no migration can occur
    if (vm.getMigrationSupport() == MigrationSupport.PINNED_TO_HOST) {
      return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_IS_PINNED_TO_HOST);
    }

    if (vm.getMigrationSupport() == MigrationSupport.IMPLICITLY_NON_MIGRATABLE
        && !getParameters().isForceMigrationForNonMigratableVm()) {
      return failCanDoAction(
          VdcBllMessages
              .ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE_AND_IS_NOT_FORCED_BY_USER_TO_MIGRATE);
    }

    switch (vm.getStatus()) {
      case MigratingFrom:
        return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_MIGRATION_IN_PROGRESS);

      case NotResponding:
        return failCanDoAction(
            VdcBllMessages.ACTION_TYPE_FAILED_VM_STATUS_ILLEGAL,
            LocalizedVmStatus.from(VMStatus.NotResponding));

      case Paused:
        if (vm.getVmPauseStatus() == VmPauseStatus.EIO) {
          return failCanDoAction(VdcBllMessages.MIGRATE_PAUSED_EIO_VM_IS_NOT_SUPPORTED);
        }
        break;

      default:
    }

    if (!vm.isQualifyToMigrate()) {
      return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_IS_NOT_RUNNING);
    }

    VmValidator vmValidator = new VmValidator(vm);

    if (!validate(
        vmValidator.vmNotHavingPluggedDiskSnapshots(
            VdcBllMessages.ACTION_TYPE_FAILED_VM_HAS_PLUGGED_DISK_SNAPSHOT))) {
      return false;
    }

    if (getDestinationVds() != null && getDestinationVds().getStatus() != VDSStatus.Up) {
      addCanDoActionMessage(VdcBllMessages.VAR__HOST_STATUS__UP);
      return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VDS_STATUS_ILLEGAL);
    }

    return validate(new SnapshotsValidator().vmNotDuringSnapshot(vm.getId()))
        // This check was added to prevent migration of VM while its disks are being migrated
        // TODO: replace it with a better solution
        && validate(
            new DiskImagesValidator(ImagesHandler.getPluggedActiveImagesForVm(vm.getId()))
                .diskImagesNotLocked())
        && SchedulingManager.getInstance()
            .canSchedule(
                getVdsGroup(),
                getVm(),
                getVdsBlackList(),
                getParameters().getInitialHosts(),
                getDestinationVdsId(),
                getReturnValue().getCanDoActionMessages());
  }
예제 #8
0
 @Override
 public void updateSchedulingStats(VDS vds) {
   schedulingManager.updateHostSchedulingStats(vds);
 }