コード例 #1
0
 // TODO asynch event handler - design infra code to allow async events in segregated thread
 public void onMomPolicyChange(@Observes @MomPolicyUpdate final VDSGroup cluster) {
   if (cluster == null || cluster.getCompatibilityVersion().compareTo(Version.v3_4) < 0) return;
   List<VDS> activeHostsInCluster =
       vdsDao.getAllForVdsGroupWithStatus(cluster.getId(), VDSStatus.Up);
   // collect all Active hosts into a callable list
   List<Callable<Object>> callables = new LinkedList<>();
   for (final VDS vds : activeHostsInCluster) {
     callables.add(
         new Callable<Object>() {
           @Override
           public Object call() {
             try {
               resourceManagerProvider
                   .get()
                   .runVdsCommand(
                       VDSCommandType.SetMOMPolicyParameters,
                       new MomPolicyVDSParameters(
                           vds,
                           cluster.isEnableBallooning(),
                           cluster.isEnableKsm(),
                           cluster.isKsmMergeAcrossNumaNodes()));
             } catch (EngineException e) {
               log.error("Could not update MoM policy on host '{}'", vds.getName());
             }
             return null;
           }
         });
   }
   // run all VDSCommands concurrently with executor
   if (callables.size() > 0) ThreadPoolUtil.invokeAll(callables);
 }
コード例 #2
0
  private VDSGroup getVdsGroup(Version ver) {
    VDSGroup vdsGroup = new VDSGroup();
    vdsGroup.setId(CLUSTER_ID);
    vdsGroup.setCompatibilityVersion(ver);

    return vdsGroup;
  }
コード例 #3
0
 protected void updateCustomPropertySheet() {
   if (getModel().getSelectedCluster() == null) {
     return;
   }
   VDSGroup cluster = getModel().getSelectedCluster();
   updateCustomPropertySheet(cluster.getcompatibility_version());
 }
コード例 #4
0
  private void setupCommonMock(boolean glusterEnabled) throws Exception {
    mockHostValidator();
    when(commandMock.canDoAction()).thenCallRealMethod();
    when(commandMock.canConnect(any(VDS.class))).thenCallRealMethod();
    when(commandMock.getParameters()).thenReturn(parameters);

    when(commandMock.isGlusterSupportEnabled()).thenReturn(glusterEnabled);
    when(commandMock.getVdsGroupDao()).thenReturn(groupDaoMock);
    when(commandMock.getClusterUtils()).thenReturn(clusterUtils);

    when(vdsDaoMock.get(vdsId)).thenReturn(null);
    when(commandMock.getVdsDao()).thenReturn(vdsDaoMock);
    when(commandMock.validateVdsGroup()).thenReturn(true);
    when(commandMock.isPowerManagementLegal(
            any(Boolean.class), anyListOf(FenceAgent.class), any(String.class)))
        .thenReturn(true);
    when(commandMock.getSSHClient()).thenReturn(sshClient);
    Version version = new Version("1.2.3");
    VDSGroup vdsGroup = new VDSGroup();
    vdsGroup.setCompatibilityVersion(version);
    when(commandMock.getVdsGroup()).thenReturn(vdsGroup);
    when(commandMock.isPowerManagementLegal(
            parameters.getVdsStaticData().isPmEnabled(),
            parameters.getFenceAgents(),
            new Version("1.2.3").toString()))
        .thenReturn(true);
    doNothing().when(sshClient).connect();
    doNothing().when(sshClient).authenticate();
  }
コード例 #5
0
  @Override
  protected boolean canDoAction() {
    if (!super.canDoAction()) {
      return false;
    }

    VDSGroup cluster = getVdsGroup();
    if (cluster == null) {
      addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_IS_NOT_VALID);
      return false;
    }

    if (!cluster.supportsGlusterService()) {
      addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_DOES_NOT_SUPPORT_GLUSTER);
      return false;
    }

    if (volumeNameExists(volume.getName())) {
      addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_GLUSTER_VOLUME_NAME_ALREADY_EXISTS);
      addCanDoActionMessage(String.format("$volumeName %1$s", volume.getName()));
      return false;
    }

    return validateBricks(volume);
  }
コード例 #6
0
  protected Version getClusterCompatibilityVersion() {
    VDSGroup cluster = getModel().getSelectedCluster();
    if (cluster == null) {
      return null;
    }

    return cluster.getcompatibility_version();
  }
コード例 #7
0
ファイル: Linq.java プロジェクト: derekhiggins/ovirt-engine
 /**
  * Check if VDSGroup item with specified id exist in List
  *
  * @param items
  * @param id
  * @return
  */
 public static boolean IsClusterItemExistInList(List<VDSGroup> items, Guid id) {
   for (VDSGroup a : items) {
     if (id.equals(a.getId())) {
       return true;
     }
   }
   return false;
 }
コード例 #8
0
 protected void updateCpuSharesAvailability() {
   if (getModel().getSelectedCluster() != null) {
     VDSGroup cluster = getModel().getSelectedCluster();
     boolean availableCpuShares = cluster.getcompatibility_version().compareTo(Version.v3_3) >= 0;
     getModel().getCpuSharesAmountSelection().setIsAvailable(availableCpuShares);
     getModel().getCpuSharesAmount().setIsAvailable(availableCpuShares);
   }
 }
コード例 #9
0
 private VDSGroup getVDsGroup() {
   VDSGroup vdsGroup = new VDSGroup();
   vdsGroup.setId(clusterId);
   vdsGroup.setVirtService(false);
   vdsGroup.setGlusterService(true);
   vdsGroup.setcompatibility_version(Version.v3_1);
   return vdsGroup;
 }
コード例 #10
0
ファイル: Linq.java プロジェクト: derekhiggins/ovirt-engine
  public static boolean IsHostBelongsToAnyOfClusters(ArrayList<VDSGroup> clusters, VDS host) {
    for (VDSGroup cluster : clusters) {
      if (cluster.getId().equals(host.getvds_group_id())) {
        return true;
      }
    }

    return false;
  }
コード例 #11
0
 @Override
 public void setMainTabSelectedItem(VDSGroup selectedItem) {
   driver.edit(getDetailModel());
   form.update();
   glusterSwiftPanel.setVisible(
       selectedItem.supportsGlusterService()
           && GlusterFeaturesUtil.isGlusterSwiftSupported(
               selectedItem.getcompatibility_version()));
 }
コード例 #12
0
  private Version clusterVersionOrNull(UnitVmModel model) {
    VDSGroup vdsGroup = model.getSelectedCluster();

    if (vdsGroup == null || vdsGroup.getcompatibility_version() == null) {
      return null;
    }

    return vdsGroup.getcompatibility_version();
  }
コード例 #13
0
 protected void updateVirtioScsiAvailability() {
   VDSGroup cluster = getModel().getSelectedCluster();
   boolean isVirtioScsiEnabled =
       (Boolean)
           AsyncDataProvider.getInstance()
               .getConfigValuePreConverted(
                   ConfigurationValues.VirtIoScsiEnabled,
                   cluster.getcompatibility_version().getValue());
   getModel().getIsVirtioScsiEnabled().setIsAvailable(isVirtioScsiEnabled);
 }
  protected VDSGroup setUpVDSGroupExpectations(Guid id) {
    VDSGroup group = control.createMock(VDSGroup.class);
    expect(group.getID()).andReturn(id).anyTimes();

    setUpEntityQueryExpectations(
        VdcQueryType.GetVdsGroupByVdsGroupId,
        GetVdsGroupByVdsGroupIdParameters.class,
        new String[] {"VdsGroupId"},
        new Object[] {id},
        group);
    return group;
  }
コード例 #15
0
 @Override
 protected VdsGroupDAO getVdsGroupDAO() {
   VdsGroupDAO d = mock(VdsGroupDAO.class);
   List<VDSGroup> list = new ArrayList<VDSGroup>();
   VDSGroup g = new VDSGroup();
   g.setID(getParameters().getVdsGroupId());
   Version v = new Version("2.2");
   g.setcompatibility_version(v);
   list.add(g);
   when(d.getAllForStoragePool(any(Guid.class))).thenReturn(list);
   when(d.get(any(Guid.class))).thenReturn(g);
   return d;
 }
コード例 #16
0
ファイル: Linq.java プロジェクト: derekhiggins/ovirt-engine
  /**
   * Finds min Version by clusters list.
   *
   * @param source IList to look in
   * @return Version MinVersion
   */
  public static Version GetMinVersionByClusters(List<VDSGroup> source) {
    Version minVersion =
        source != null && source.size() > 0 ? source.get(0).getcompatibility_version() : null;

    if (minVersion != null) {
      for (VDSGroup cluster : source) {
        minVersion =
            cluster.getcompatibility_version().compareTo(minVersion) < 0
                ? (Version) cluster.getcompatibility_version()
                : minVersion;
      }
    }

    return minVersion;
  }
コード例 #17
0
  protected void updateOSValues() {

    List<Integer> vmOsValues;
    VDSGroup cluster = getModel().getSelectedCluster();

    if (cluster != null) {
      vmOsValues = AsyncDataProvider.getInstance().getOsIds(cluster.getArchitecture());
      Integer selectedOsId = getModel().getOSType().getSelectedItem();
      getModel().getOSType().setItems(vmOsValues);
      if (selectedOsId != null && vmOsValues.contains(selectedOsId)) {
        getModel().getOSType().setSelectedItem(selectedOsId);
      }

      postOsItemChanged();
    }
  }
コード例 #18
0
  protected void updateQuotaByCluster(final Guid defaultQuota, final String quotaName) {
    if (getModel().getQuota().getIsAvailable()) {
      VDSGroup cluster = getModel().getSelectedCluster();
      if (cluster == null) {
        return;
      }
      Frontend.getInstance()
          .runQuery(
              VdcQueryType.GetAllRelevantQuotasForVdsGroup,
              new IdQueryParameters(cluster.getId()),
              new AsyncQuery(
                  getModel(),
                  new INewAsyncCallback() {

                    @Override
                    public void onSuccess(Object model, Object returnValue) {
                      UnitVmModel vmModel = (UnitVmModel) model;
                      ArrayList<Quota> quotaList =
                          ((VdcQueryReturnValue) returnValue).getReturnValue();
                      if (quotaList != null && !quotaList.isEmpty()) {
                        vmModel.getQuota().setItems(quotaList);
                      }
                      if (quotaList != null
                          && defaultQuota != null
                          && !Guid.Empty.equals(defaultQuota)) {
                        boolean hasQuotaInList = false;
                        for (Quota quota : quotaList) {
                          if (quota.getId().equals(defaultQuota)) {
                            vmModel.getQuota().setSelectedItem(quota);
                            hasQuotaInList = true;
                            break;
                          }
                        }
                        // Add the quota to the list only in edit mode
                        if (!hasQuotaInList && !getModel().getIsNew()) {
                          Quota quota = new Quota();
                          quota.setId(defaultQuota);
                          quota.setQuotaName(quotaName);
                          quotaList.add(quota);
                          vmModel.getQuota().setItems(quotaList);
                          vmModel.getQuota().setSelectedItem(quota);
                        }
                      }
                    }
                  }));
    }
  }
コード例 #19
0
  protected void updateCpuPinningVisibility() {
    if (getModel().getSelectedCluster() != null) {
      VDSGroup cluster = getModel().getSelectedCluster();
      String compatibilityVersion = cluster.getcompatibility_version().toString();
      boolean isLocalSD =
          getModel().getSelectedDataCenter() != null
              && getModel().getSelectedDataCenter().isLocal();

      // cpu pinning is available on Local SD with no consideration for auto assign value
      boolean hasCpuPinning =
          Boolean.FALSE.equals(getModel().getIsAutoAssign().getEntity()) || isLocalSD;

      if (Boolean.FALSE.equals(
          AsyncDataProvider.getInstance()
              .getConfigValuePreConverted(
                  ConfigurationValues.CpuPinningEnabled, compatibilityVersion))) {
        hasCpuPinning = false;
      } else if (Boolean.FALSE.equals(
              AsyncDataProvider.getInstance()
                  .getConfigValuePreConverted(
                      ConfigurationValues.CpuPinMigrationEnabled,
                      AsyncDataProvider.getInstance().getDefaultConfigurationVersion()))
          && isVmMigratable()
          && !isLocalSD) {
        hasCpuPinning = false;
      }

      if (!hasCpuPinning) {
        if (isLocalSD) {
          getModel()
              .getCpuPinning()
              .setChangeProhibitionReason(constants.cpuPinningUnavailableLocalStorage());
        } else {
          getModel().getCpuPinning().setChangeProhibitionReason(constants.cpuPinningUnavailable());
        }
        getModel().getCpuPinning().setEntity("");
      }
      getModel().getCpuPinning().setIsChangable(hasCpuPinning);
    }
  }
コード例 #20
0
  public void OnSelectHost() {
    MoveHost model = (MoveHost) getWindow();

    if (model.getProgress() != null) {
      return;
    }

    if (!model.Validate()) {
      return;
    }

    model.setSelectedHosts(new java.util.ArrayList<VDS>());
    for (EntityModel a : Linq.<EntityModel>Cast(model.getItems())) {
      if (a.getIsSelected()) {
        model.getSelectedHosts().add((VDS) a.getEntity());
      }
    }

    VDSGroup cluster = (VDSGroup) model.getCluster().getSelectedItem();

    java.util.ArrayList<VdcActionParametersBase> paramerterList =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (VDS host : model.getSelectedHosts()) {
      // Try to change host's cluster as neccessary.
      if (host.getvds_group_id() != null && !host.getvds_group_id().equals(cluster.getId())) {
        paramerterList.add(new ChangeVDSClusterParameters(cluster.getId(), host.getId()));
      }
    }
    model.StartProgress(null);
    Frontend.RunMultipleAction(
        VdcActionType.ChangeVDSCluster,
        paramerterList,
        new IFrontendMultipleActionAsyncCallback() {
          @Override
          public void Executed(FrontendMultipleActionAsyncResult result) {

            ClusterGuideModel clusterGuideModel = (ClusterGuideModel) result.getState();
            java.util.ArrayList<VDS> hosts =
                ((MoveHost) clusterGuideModel.getWindow()).getSelectedHosts();
            java.util.ArrayList<VdcReturnValueBase> retVals =
                (java.util.ArrayList<VdcReturnValueBase>) result.getReturnValue();
            if (retVals != null && hosts.size() == retVals.size()) {
              int i = 0;
              for (VDS selectedHost : hosts) {
                if (selectedHost.getstatus() == VDSStatus.PendingApproval
                    && retVals.get(i) != null
                    && retVals.get(i).getSucceeded()) {
                  Frontend.RunAction(
                      VdcActionType.ApproveVds, new ApproveVdsParameters(selectedHost.getId()));
                }
              }
              i++;
            }
            clusterGuideModel.getWindow().StopProgress();
            clusterGuideModel.Cancel();
            clusterGuideModel.PostAction();
          }
        },
        this);
  }
コード例 #21
0
  /**
   * Update the given VM with the (static) data that is contained in the configuration. The {@link
   * VM#getImages()} will contain the images that were read from the configuration.
   *
   * @param vm The VM to update.
   * @param configuration The configuration to update from.
   * @return In case of a problem reading the configuration, <code>false</code>. Otherwise, <code>
   *     true</code>.
   */
  public boolean updateVmFromConfiguration(VM vm, String configuration) {

    try {
      VmStatic oldVmStatic = vm.getStaticData();
      RefObject<VM> vmRef = new RefObject<VM>();
      RefObject<ArrayList<DiskImage>> imagesRef = new RefObject<ArrayList<DiskImage>>();
      RefObject<ArrayList<VmNetworkInterface>> interfacesRef =
          new RefObject<ArrayList<VmNetworkInterface>>();
      new OvfManager().ImportVm(configuration, vmRef, imagesRef, interfacesRef);
      new VMStaticOvfLogHandler(vmRef.argvalue.getStaticData()).resetDefaults(oldVmStatic);

      vm.setStaticData(vmRef.argvalue.getStaticData());
      vm.setImages(imagesRef.argvalue);
      vm.setInterfaces(interfacesRef.argvalue);

      // These fields are not saved in the OVF, so get them from the current VM.
      vm.setdedicated_vm_for_vds(oldVmStatic.getdedicated_vm_for_vds());
      vm.setiso_path(oldVmStatic.getiso_path());
      vm.setvds_group_id(oldVmStatic.getvds_group_id());
      // The VM configuration does not hold the vds group Id.
      // It is necessary to fetch the vm static from the Db, in order to get this information
      VmStatic vmStaticFromDb = getVmStaticDao().get(vm.getId());
      if (vmStaticFromDb != null) {
        VDSGroup vdsGroup = getVdsGroupDao().get(vmStaticFromDb.getvds_group_id());
        if (vdsGroup != null) {
          vm.setvds_group_compatibility_version(vdsGroup.getcompatibility_version());
          vm.setvds_group_name(vdsGroup.getname());
          vm.setvds_group_cpu_name(vdsGroup.getcpu_name());
        }
      }
      return true;
    } catch (OvfReaderException e) {
      log.errorFormat("Failed to update VM from the configuration: {0}).", configuration, e);
      return false;
    }
  }
コード例 #22
0
  public void SetDefaultNames(VDS host, RefObject<String> message) {
    message.argvalue = null;
    setCommonName(StringFormat.format("%1$s-Local", host.getvds_name().replace('.', '-')));
    storage_pool candidate = null;

    // selecet all possible DCs
    VdcQueryReturnValue returnValue =
        Frontend.RunQuery(
            VdcQueryType.Search,
            new SearchParameters(
                StringFormat.format("DataCenter: name=%1$s", getCommonName() + "*"),
                SearchType.StoragePool));

    java.util.ArrayList<storage_pool> dataCenterList = new java.util.ArrayList<storage_pool>();
    java.util.ArrayList<VDSGroup> clusterList = null;
    if (returnValue != null && returnValue.getSucceeded() && returnValue.getReturnValue() != null) {
      dataCenterList =
          Linq.<storage_pool>Cast(
              (java.util.ArrayList<IVdcQueryable>) returnValue.getReturnValue());
    }
    // check if current settings suitable for local setup (in case just SD creation failed -
    // re-using the same setup)
    boolean useCurrentSettings = false;
    if (host.getstorage_pool_id() != null) {
      storage_pool tempCandidate = DataProvider.GetDataCenterById(host.getstorage_pool_id());
      if (IsLocalDataCenterEmpty(tempCandidate)) {
        candidate = tempCandidate;
        useCurrentSettings = true;
      } else {
        if (tempCandidate != null && tempCandidate.getstorage_pool_type() == StorageType.LOCALFS) {
          message.argvalue =
              "Note: Local Storage is already configured for this Host. The Host belongs to "
                  + host.getstorage_pool_name()
                  + " with local Storage Domain. If OK is clicked - this Host will be moved to a new Data Center, and a new Local Storage Domain will be created. Hit Cancel to abort the operation.";
        }
      }
    }
    // check if there is other DC suitable for re-use
    if (candidate == null) {
      for (storage_pool dataCenter : dataCenterList) {
        // need to check if the new DC is without host.
        if (IsLocalDataCenterEmpty(dataCenter)
            && DataProvider.GetLocalStorageHost(dataCenter.getname()) == null) {
          candidate = dataCenter;
          break;
        }
      }
    }
    java.util.ArrayList<String> listNames = new java.util.ArrayList<String>();
    // in case we found a suitable candidte for re-use:
    if (candidate != null) {
      getDataCenter().setDataCenterId(candidate.getId());
      getDataCenter().getName().setEntity(candidate.getname());
      getDataCenter().getDescription().setEntity(candidate.getdescription());
      Version compVersion = candidate.getcompatibility_version();
      getDataCenter().getVersion().setSelectedItem(compVersion);
      getCluster().getVersion().setSelectedItem(compVersion);
      setDontCreateDataCenter(true);
      // if we use current settings there is no need to create cluster.
      if (useCurrentSettings) {
        getCluster().setClusterId(host.getvds_group_id().getValue());
        getCluster().getName().setEntity(host.getvds_group_name());
        VDSGroup cluster = DataProvider.GetClusterById(host.getvds_group_id().getValue());
        if (cluster != null) {
          getCluster().getDescription().setEntity(cluster.getdescription());
          ServerCpu tempVar = new ServerCpu();
          tempVar.setCpuName(cluster.getcpu_name());
          getCluster().getCPU().setSelectedItem(tempVar);
        }
        setDontCreateCluster(true);
        setDontChangeHostCluster(true);
      }
      // use differnt cluster
      else {
        // check the DC cluster list (for re-use)
        clusterList = DataProvider.GetClusterList(candidate.getId());
        // no clusters avilable - pick up new name.
        if (clusterList.isEmpty()) {
          java.util.ArrayList<VDSGroup> listClusters = DataProvider.GetClusterList();
          listNames = new java.util.ArrayList<String>();
          for (VDSGroup cluster : listClusters) {
            listNames.add(cluster.getname());
          }
          getCluster().getName().setEntity(AvailableName(listNames));
        } else {
          // use the DC cluster.
          getCluster().setClusterId(clusterList.get(0).getId());
          getCluster().getName().setEntity(clusterList.get(0).getname());
          getCluster().getDescription().setEntity(clusterList.get(0).getdescription());
          VDSGroup cluster = DataProvider.GetClusterById(getCluster().getClusterId().getValue());
          if (cluster != null) {
            ServerCpu tempVar2 = new ServerCpu();
            tempVar2.setCpuName(cluster.getcpu_name());
            getCluster().getCPU().setSelectedItem(tempVar2);
          }
          setDontCreateCluster(true);
          if (host.getvds_group_id().getValue().equals(getCluster().getClusterId())) {
            setDontChangeHostCluster(true);
          }
        }
      }
    } else {
      // didn't found DC to re-use, so we select new names:
      listNames = new java.util.ArrayList<String>();
      for (storage_pool storagePool : dataCenterList) {
        listNames.add(storagePool.getname());
      }
      getDataCenter().getName().setEntity(AvailableName(listNames));

      // Choose a Data Center version corresponding to the host.
      if (!StringHelper.isNullOrEmpty(host.getsupported_cluster_levels())) {
        // the supported_cluster_levels are sorted.
        String[] array = host.getsupported_cluster_levels().split("[,]", -1);
        Version maxCombindVersion = null;

        for (int i = 0; i < array.length; i++) {
          Version vdsVersion = new Version(array[i]);
          for (Version version :
              (java.util.List<Version>) getDataCenter().getVersion().getItems()) {
            if (version.equals(vdsVersion) && version.compareTo(maxCombindVersion) > 0) {
              maxCombindVersion = version;
            }
          }
        }
        if (maxCombindVersion != null) {
          getDataCenter().getVersion().setSelectedItem(maxCombindVersion);
          getCluster().getVersion().setSelectedItem(maxCombindVersion);
        }
      }

      listNames = new java.util.ArrayList<String>();
      if (clusterList == null) {
        clusterList = DataProvider.GetClusterList();
      }

      for (VDSGroup cluster : clusterList) {
        listNames.add(cluster.getname());
      }
      getCluster().getName().setEntity(AvailableName(listNames));
    }

    // Choose default CPU name to match host.
    if (host.getCpuName() != null && getCluster().getCPU().getSelectedItem() != null) {
      getCluster()
          .getCPU()
          .setSelectedItem(
              Linq.FirstOrDefault(
                  (java.util.List<ServerCpu>) getCluster().getCPU().getItems(),
                  new Linq.ServerCpuPredicate(host.getCpuName().getCpuName())));
    }
    // always choose a avialable storage name.
    java.util.ArrayList<storage_domains> listStorageDomains = DataProvider.GetStorageDomainList();
    listNames = new java.util.ArrayList<String>();
    for (storage_domains storageDomain : listStorageDomains) {
      listNames.add(storageDomain.getstorage_name());
    }
    getFormattedStorageName().setEntity(AvailableName(listNames));
  }
コード例 #23
0
 /** By default admin query is fired, UserPortal overrides it to fire user query */
 protected void getHostListByCluster(VDSGroup cluster, AsyncQuery query) {
   AsyncDataProvider.getInstance().getHostListByCluster(query, cluster.getName());
 }
コード例 #24
0
ファイル: Linq.java プロジェクト: derekhiggins/ovirt-engine
 @Override
 public int compare(VDSGroup x, VDSGroup y) {
   return x.getname().compareTo(y.getname());
 }
コード例 #25
0
ファイル: Linq.java プロジェクト: derekhiggins/ovirt-engine
 @Override
 public boolean Match(VDSGroup source) {
   return id.equals(source.getId());
 }
コード例 #26
0
  protected boolean validate() {
    VM vm = parentCommand.getVm();
    if (vm == null) {
      parentCommand.addCanDoActionMessage(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
      return false;
    } else {
      targetCluster = DbFacade.getInstance().getVdsGroupDao().get(targetClusterId);
      if (targetCluster == null) {
        parentCommand.addCanDoActionMessage(EngineMessage.VM_CLUSTER_IS_NOT_VALID);
        return false;
      }

      // Check that the target cluster is in the same data center.
      if (!targetCluster.getStoragePoolId().equals(vm.getStoragePoolId())) {
        parentCommand.addCanDoActionMessage(
            EngineMessage.VM_CANNOT_MOVE_TO_CLUSTER_IN_OTHER_STORAGE_POOL);
        return false;
      }

      List<VmNic> interfaces = DbFacade.getInstance().getVmNicDao().getAllForVm(vm.getId());

      Version clusterCompatibilityVersion = targetCluster.getCompatibilityVersion();
      if (!validateDestinationClusterContainsNetworks(interfaces)
          || !validateNics(interfaces, clusterCompatibilityVersion)) {
        return false;
      }

      // Check if VM static parameters are compatible for new cluster.
      boolean isCpuSocketsValid =
          AddVmCommand.checkCpuSockets(
              vm.getStaticData().getNumOfSockets(),
              vm.getStaticData().getCpuPerSocket(),
              vm.getStaticData().getThreadsPerCpu(),
              clusterCompatibilityVersion.getValue(),
              parentCommand.getReturnValue().getCanDoActionMessages());
      if (!isCpuSocketsValid) {
        return false;
      }

      // Check that the USB policy is legal
      if (!VmHandler.isUsbPolicyLegal(
          vm.getUsbPolicy(),
          vm.getOs(),
          targetCluster,
          parentCommand.getReturnValue().getCanDoActionMessages())) {
        return false;
      }

      // Check if the display type is supported
      if (!VmHandler.isGraphicsAndDisplaySupported(
          vm.getOs(),
          VmDeviceUtils.getGraphicsTypesOfEntity(vm.getId()),
          vm.getDefaultDisplayType(),
          parentCommand.getReturnValue().getCanDoActionMessages(),
          clusterCompatibilityVersion)) {
        return false;
      }

      if (VmDeviceUtils.hasVirtioScsiController(vm.getId())) {
        // Verify cluster compatibility
        if (!FeatureSupported.virtIoScsi(targetCluster.getCompatibilityVersion())) {
          return parentCommand.failCanDoAction(
              EngineMessage.VIRTIO_SCSI_INTERFACE_IS_NOT_AVAILABLE_FOR_CLUSTER_LEVEL);
        }

        // Verify OS compatibility
        if (!VmHandler.isOsTypeSupportedForVirtioScsi(
            vm.getOs(),
            targetCluster.getCompatibilityVersion(),
            parentCommand.getReturnValue().getCanDoActionMessages())) {
          return false;
        }
      }

      // A existing VM cannot be changed into a cluster without a defined architecture
      if (targetCluster.getArchitecture() == ArchitectureType.undefined) {
        return parentCommand.failCanDoAction(
            EngineMessage.ACTION_TYPE_FAILED_CLUSTER_UNDEFINED_ARCHITECTURE);
      } else if (targetCluster.getArchitecture() != vm.getClusterArch()) {
        return parentCommand.failCanDoAction(
            EngineMessage.ACTION_TYPE_FAILED_VM_CLUSTER_DIFFERENT_ARCHITECTURES);
      }
    }
    return true;
  }
コード例 #27
0
 @Override
 protected void EntityChanging(Object newValue, Object oldValue) {
   VDSGroup vdsGroup = (VDSGroup) newValue;
   getNewNetworkCommand()
       .setIsExecutionAllowed(vdsGroup != null && vdsGroup.getstorage_pool_id() != null);
 }