private org.ovirt.engine.core.common.businessentities.VmPool setUpEntityExpectations(
      org.ovirt.engine.core.common.businessentities.VmPool entity, int index) {
    expect(entity.getVmPoolId()).andReturn(GUIDS[index]).anyTimes();
    expect(entity.getVdsGroupId()).andReturn(GUIDS[2]).anyTimes();
    expect(entity.getName()).andReturn(NAMES[index]).anyTimes();
    expect(entity.getVmPoolType()).andReturn(VmPoolType.Automatic).anyTimes();
    expect(entity.getVmPoolDescription()).andReturn(DESCRIPTIONS[index]).anyTimes();

    return entity;
  }
  private void updateProperties() {
    final VmPool pool = getEntity();

    setName(pool.getName());
    setDescription(pool.getVmPoolDescription());

    AsyncQuery _asyncQuery = new AsyncQuery();

    _asyncQuery.setModel(this);
    _asyncQuery.asyncCallback =
        new INewAsyncCallback() {
          @Override
          public void onSuccess(Object model, Object result) {
            // currently, only query that is being invoked asynchrounously in
            // this context is GetVmDataByPoolIdQuery. If more async queries will be needed,
            // refactor to "switch ... case...".
            if (result != null) {
              setvm((VM) ((VdcQueryReturnValue) result).getReturnValue());
            }
            PoolGeneralModel poolGeneralModel = (PoolGeneralModel) model;
            if (getvm() != null) {
              poolGeneralModel.setTemplate(vmTemplateNameRenderer.render(getvm()));
              poolGeneralModel.setCpuInfo(
                  ConstantsManager.getInstance()
                      .getMessages()
                      .cpuInfoLabel(
                          getvm().getNumOfCpus(),
                          getvm().getNumOfSockets(),
                          getvm().getCpuPerSocket(),
                          getvm().getThreadsPerCpu()));
              poolGeneralModel.setMonitorCount(getvm().getNumOfMonitors());

              poolGeneralModel.setOS(getvm().getVmOsId());

              poolGeneralModel.setDefinedMemory(getvm().getVmMemSizeMb() + " MB"); // $NON-NLS-1$
              poolGeneralModel.setMinAllocatedMemory(
                  getvm().getMinAllocatedMem() + " MB"); // $NON-NLS-1$

              Translator translator = EnumTranslator.getInstance();
              setDefaultDisplayType(translator.translate(getvm().getDefaultDisplayType()));

              poolGeneralModel.setOrigin(translator.translate(getvm().getOrigin()));
              poolGeneralModel.setUsbPolicy(translator.translate(getvm().getUsbPolicy()));

              setHasDomain(AsyncDataProvider.getInstance().isWindowsOsType(getvm().getVmOsId()));

              setHasTimeZone(AsyncDataProvider.getInstance().isWindowsOsType(getvm().getVmOsId()));
              poolGeneralModel.setTimeZone(getvm().getTimeZone());

              poolGeneralModel.setIsStateless(getvm().isStateless());

              poolGeneralModel.setQuotaName(getvm().getQuotaName());

              poolGeneralModel.setHasDefaultHost(getvm().getDedicatedVmForVdsList().size() > 0);
              if (poolGeneralModel.getHasDefaultHost()) {
                AsyncQuery _asyncQuery1 = new AsyncQuery();
                _asyncQuery1.setModel(poolGeneralModel);
                _asyncQuery1.asyncCallback =
                    new INewAsyncCallback() {
                      @Override
                      public void onSuccess(Object model1, Object ReturnValue1) {
                        PoolGeneralModel poolGeneralModel1 = (PoolGeneralModel) model1;
                        String defaultHost = "";
                        ArrayList<VDS> hosts =
                            ((VdcQueryReturnValue) ReturnValue1).getReturnValue();
                        for (VDS host : hosts) {
                          if (poolGeneralModel1
                              .getvm()
                              .getDedicatedVmForVdsList()
                              .contains(host.getId())) {
                            if (defaultHost.isEmpty()) {
                              defaultHost = host.getName();
                            } else {
                              defaultHost += ", " + host.getName(); // $NON-NLS-1$
                            }
                          }
                        }
                        poolGeneralModel1.setDefaultHost(defaultHost);
                      }
                    };

                Frontend.getInstance()
                    .runQuery(
                        VdcQueryType.Search,
                        new SearchParameters(
                            "Host: cluster = " //$NON-NLS-1$
                                + getvm().getClusterName()
                                + " sortby name",
                            SearchType.VDS),
                        _asyncQuery1); //$NON-NLS-1$
              } else {
                poolGeneralModel.setDefaultHost(
                    ConstantsManager.getInstance().getConstants().anyHostInCluster());
              }
              if (getvm() != null) {
                PoolGeneralModel.super.updateProperties(getvm().getId());
              }
            } else {
              poolGeneralModel.setTemplate(null);
              poolGeneralModel.setCpuCount(0);
              poolGeneralModel.setMonitorCount(0);
              poolGeneralModel.setOS(0);
              poolGeneralModel.setDefinedMemory(null);
              poolGeneralModel.setMinAllocatedMemory(null);
              poolGeneralModel.setDefaultDisplayType(null);
              poolGeneralModel.setHasDomain(false);
              poolGeneralModel.setDomain(null);
              poolGeneralModel.setHasTimeZone(false);
              poolGeneralModel.setTimeZone(null);
              poolGeneralModel.setUsbPolicy(null);
              poolGeneralModel.setDefaultHost(null);
              poolGeneralModel.setIsStateless(false);
              poolGeneralModel.setGraphicsType(""); // $NON-NLS-1$

              poolGeneralModel.getUpdateCompleteEvent().raise(this, EventArgs.EMPTY);
            }
          }
        };
    Frontend.getInstance()
        .runQuery(
            VdcQueryType.GetVmDataByPoolId, new IdQueryParameters(pool.getVmPoolId()), _asyncQuery);
  }
  @Override
  protected boolean canDoAction() {
    if (getVdsGroup() == null) {
      return failCanDoAction(EngineMessage.VDS_CLUSTER_IS_NOT_VALID);
    }

    // A Pool cannot be added in a cluster without a defined architecture
    if (getVdsGroup().getArchitecture() == ArchitectureType.undefined) {
      return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_UNDEFINED_ARCHITECTURE);
    }

    VmPool pool = getVmPoolDao().getByName(getParameters().getVmPool().getName());
    if (pool != null
        && (getActionType() == VdcActionType.AddVmPoolWithVms
            || !pool.getVmPoolId().equals(getParameters().getVmPoolId()))) {
      return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_NAME_ALREADY_USED);
    }

    setStoragePoolId(getVdsGroup().getStoragePoolId());
    if (!validate(new StoragePoolValidator(getStoragePool()).isUp())) {
      return false;
    }

    // check if the selected template is compatible with Cluster architecture.
    if (!getVmTemplate().getId().equals(VmTemplateHandler.BLANK_VM_TEMPLATE_ID)
        && getVdsGroup().getArchitecture() != getVmTemplate().getClusterArch()) {
      return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_IS_INCOMPATIBLE);
    }

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

    if (getVmTemplate().getDiskTemplateMap().values().size() != diskInfoDestinationMap.size()) {
      log.error(
          "Can not found any default active domain for one of the disks of template with id '{}'",
          getVmTemplate().getId());
      addCanDoActionMessage(EngineMessage.ACTION_TYPE_FAILED_MISSED_STORAGES_FOR_SOME_DISKS);
      return false;
    }

    List<Guid> storageIds = new ArrayList<>();
    for (DiskImage diskImage : diskInfoDestinationMap.values()) {
      Guid storageId = diskImage.getStorageIds().get(0);
      if (!storageIds.contains(storageId) && !areTemplateImagesInStorageReady(storageId)) {
        return false;
      }
      storageIds.add(storageId);
    }

    if (getActionType() == VdcActionType.AddVmPoolWithVms && getParameters().getVmsCount() < 1) {
      return failCanDoAction(EngineMessage.VM_POOL_CANNOT_CREATE_WITH_NO_VMS);
    }

    if (getParameters().getVmStaticData().isStateless()) {
      return failCanDoAction(EngineMessage.ACTION_TYPE_FAILED_VM_FROM_POOL_CANNOT_BE_STATELESS);
    }

    if (getParameters().getVmPool().getPrestartedVms()
        > getParameters().getVmPool().getAssignedVmsCount() + getParameters().getVmsCount()) {
      return failCanDoAction(
          EngineMessage.ACTION_TYPE_FAILED_PRESTARTED_VMS_CANNOT_EXCEED_VMS_COUNT);
    }

    if (Boolean.TRUE.equals(getParameters().isVirtioScsiEnabled())
        && !FeatureSupported.virtIoScsi(getVdsGroup().getCompatibilityVersion())) {
      return failCanDoAction(
          EngineMessage.VIRTIO_SCSI_INTERFACE_IS_NOT_AVAILABLE_FOR_CLUSTER_LEVEL);
    }
    if (!setAndValidateDiskProfiles()) {
      return false;
    }
    if (!setAndValidateCpuProfile()) {
      return false;
    }
    return checkDestDomains();
  }