use of org.ovirt.engine.core.common.businessentities.StoragePool in project ovirt-engine by oVirt.
the class ExistingPoolModelBehavior method postInitStorageDomains.
@Override
protected void postInitStorageDomains() {
ArrayList<DiskModel> disks = (ArrayList<DiskModel>) getModel().getDisks();
if (disks == null) {
return;
}
ActionGroup actionGroup = getModel().isCreateInstanceOnly() ? ActionGroup.CREATE_INSTANCE : ActionGroup.CREATE_VM;
StoragePool dataCenter = getModel().getSelectedDataCenter();
AsyncDataProvider.getInstance().getPermittedStorageDomainsByStoragePoolId(asyncQuery(storageDomains -> {
ArrayList<DiskModel> disks1 = (ArrayList<DiskModel>) getModel().getDisks();
ArrayList<StorageDomain> activeStorageDomains = filterStorageDomains(storageDomains);
DisksAllocationModel disksAllocationModel = getModel().getDisksAllocationModel();
disksAllocationModel.setActiveStorageDomains(activeStorageDomains);
getModel().getStorageDomain().setItems(activeStorageDomains);
for (DiskModel diskModel : disks1) {
// Setting Quota
diskModel.getQuota().setItems(getModel().getQuota().getItems());
diskModel.getQuota().setIsChangeable(false);
List<Guid> storageIds = ((DiskImage) diskModel.getDisk()).getStorageIds();
for (DiskImage disk : pool.getDiskList()) {
if (diskModel.getDisk() instanceof DiskImage && ((DiskImage) diskModel.getDisk()).getImageId().equals(disk.getImageTemplateId())) {
storageIds = new ArrayList<>(disk.getStorageIds());
break;
}
}
if (storageIds == null || storageIds.size() == 0) {
continue;
}
Guid storageId = storageIds.get(0);
StorageDomain storageDomain = activeStorageDomains.stream().filter(new Linq.IdPredicate<>(storageId)).findFirst().orElse(null);
List<StorageDomain> diskStorageDomains = new ArrayList<>();
diskStorageDomains.add(storageDomain);
diskModel.getStorageDomain().setItems(diskStorageDomains);
diskModel.getStorageDomain().setIsChangeable(false);
}
}), dataCenter.getId(), actionGroup);
getModel().getDisksAllocationModel().initializeAutoSelectTarget(false, actualPool.isAutoStorageSelect());
}
use of org.ovirt.engine.core.common.businessentities.StoragePool in project ovirt-engine by oVirt.
the class ExistingVmModelBehavior method loadDataCenter.
private void loadDataCenter() {
// Preinitialize the VM compatibility version because it's needed during init
Version newCustomCompatibilityVersion = ((ExistingVmModelBehavior) getModel().getBehavior()).getVm().getStaticData().getCustomCompatibilityVersion();
if (newCustomCompatibilityVersion != null) {
getModel().getCustomCompatibilityVersion().setItems(Collections.singletonList(newCustomCompatibilityVersion), newCustomCompatibilityVersion);
}
AsyncDataProvider.getInstance().getDataCenterById(asyncQuery(dataCenter -> {
if (dataCenter != null) {
final List<StoragePool> dataCenters = new ArrayList<>(Arrays.asList(new StoragePool[] { dataCenter }));
initClusters(dataCenters);
} else {
ExistingVmModelBehavior behavior = (ExistingVmModelBehavior) getModel().getBehavior();
VM currentVm = behavior.vm;
Cluster cluster = new Cluster();
cluster.setId(currentVm.getClusterId());
cluster.setName(currentVm.getClusterName());
cluster.setCompatibilityVersion(currentVm.getClusterCompatibilityVersion());
cluster.setStoragePoolId(currentVm.getStoragePoolId());
DataCenterWithCluster dataCenterWithCluster = new DataCenterWithCluster(null, cluster);
getModel().getDataCenterWithClustersList().setItems(Arrays.asList(dataCenterWithCluster));
getModel().getDataCenterWithClustersList().setSelectedItem(dataCenterWithCluster);
behavior.initTemplate();
behavior.updateCdImage();
}
}), vm.getStoragePoolId());
}
use of org.ovirt.engine.core.common.businessentities.StoragePool in project ovirt-engine by oVirt.
the class TemplateVmModelBehavior method initialize.
@Override
public void initialize() {
super.initialize();
getModel().getTemplateWithVersion().setIsChangeable(false);
getModel().getBaseTemplate().setIsChangeable(false);
getModel().getTemplateWithVersion().setIsChangeable(false);
getModel().getProvisioning().setIsChangeable(false);
getModel().getStorageDomain().setIsChangeable(false);
getModel().getIsSoundcardEnabled().setIsChangeable(true);
getModel().getVmType().setIsChangeable(true);
getModel().getTemplateVersionName().setIsChangeable(!template.isBaseTemplate());
getModel().getName().setIsChangeable(template.isBaseTemplate());
if (template.getStoragePoolId() != null && !template.getStoragePoolId().equals(Guid.Empty)) {
AsyncDataProvider.getInstance().getDataCenterById(new AsyncQuery<>(dataCenter -> AsyncDataProvider.getInstance().getClusterListByService(new AsyncQuery<>(clusters -> {
ArrayList<Cluster> clustersSupportingVirt = new ArrayList<>();
// filter clusters supporting virt service only
for (Cluster cluster : clusters) {
if (cluster.supportsVirtService()) {
clustersSupportingVirt.add(cluster);
}
}
List<Cluster> filteredClusters = AsyncDataProvider.getInstance().filterByArchitecture(clustersSupportingVirt, template.getClusterArch());
getModel().setDataCentersAndClusters(getModel(), new ArrayList<>(Arrays.asList(new StoragePool[] { dataCenter })), filteredClusters, template.getClusterId());
updateRngDevice(template.getId());
AsyncDataProvider.getInstance().isSoundcardEnabled(new AsyncQuery<>(returnValue -> {
getModel().getIsSoundcardEnabled().setEntity(returnValue);
initTemplate();
initCdImage();
}), template.getId());
Frontend.getInstance().runQuery(QueryType.IsBalloonEnabled, new IdQueryParameters(template.getId()), new AsyncQuery<>((QueryReturnValue returnValue) -> getModel().getMemoryBalloonDeviceEnabled().setEntity((Boolean) returnValue.getReturnValue())));
AsyncDataProvider.getInstance().isVirtioScsiEnabledForVm(new AsyncQuery<>(returnValue -> getModel().getIsVirtioScsiEnabled().setEntity(returnValue)), template.getId());
}), true, false)), template.getStoragePoolId());
}
AsyncDataProvider.getInstance().getWatchdogByVmId(new AsyncQuery<>((AsyncCallback<QueryReturnValue>) returnValue -> {
UnitVmModel model = getModel();
@SuppressWarnings("unchecked") Collection<VmWatchdog> watchdogs = returnValue.getReturnValue();
for (VmWatchdog watchdog : watchdogs) {
model.getWatchdogAction().setSelectedItem(watchdog.getAction());
model.getWatchdogModel().setSelectedItem(watchdog.getModel());
}
}), template.getId());
getModel().getMigrationMode().setSelectedItem(template.getMigrationSupport());
setupBaseTemplate(template.getBaseTemplateId());
}
use of org.ovirt.engine.core.common.businessentities.StoragePool in project ovirt-engine by oVirt.
the class UpdateClusterCommand method validate.
@Override
protected boolean validate() {
boolean result = true;
boolean hasVms = false;
boolean hasVmOrHost = false;
boolean sameCpuNames = false;
boolean allVdssInMaintenance = false;
List<VM> vmList = null;
if (oldCluster == null) {
addValidationMessage(EngineMessage.VDS_CLUSTER_IS_NOT_VALID);
result = false;
}
// if the name was changed then make sure the new name is unique
if (result && !StringUtils.equals(oldCluster.getName(), getCluster().getName())) {
if (!isClusterUnique(getCluster().getName())) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_DO_ACTION_NAME_IN_USE);
result = false;
}
}
if (result && !VersionSupport.checkVersionSupported(getCluster().getCompatibilityVersion())) {
addValidationMessage(VersionSupport.getUnsupportedVersionMessage());
result = false;
}
if (result) {
allForCluster = vdsDao.getAllForCluster(oldCluster.getId());
}
// decreasing of compatibility version is only allowed when no hosts exists, and not beneath the DC version
if (result && getCluster().getCompatibilityVersion().compareTo(oldCluster.getCompatibilityVersion()) < 0) {
if (!allForCluster.isEmpty()) {
result = false;
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_CANNOT_DECREASE_CLUSTER_WITH_HOSTS_COMPATIBILITY_VERSION);
}
if (oldCluster.getStoragePoolId() != null) {
ClusterValidator validator = new ClusterValidator(dbFacade, oldCluster, getCpuFlagsManagerHandler());
if (!validate(validator.dataCenterVersionMismatch())) {
result = false;
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_CANNOT_DECREASE_COMPATIBILITY_VERSION_UNDER_DC);
}
}
}
if (result && oldCluster.getStoragePoolId() != null && !oldCluster.getStoragePoolId().equals(getCluster().getStoragePoolId())) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_CHANGE_STORAGE_POOL);
result = false;
}
// If both original Cpu and new Cpu are null, don't check Cpu validity
if (result) {
allVdssInMaintenance = areAllVdssInMaintenance(allForCluster);
}
// Validate the cpu only if the cluster supports Virt
if (result && getCluster().supportsVirtService() && (oldCluster.getCpuName() != null || getCluster().getCpuName() != null)) {
// Check that cpu exist
if (!checkIfCpusExist()) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_CPU_NOT_FOUND);
addValidationMessage(EngineMessage.VAR__TYPE__CLUSTER);
result = false;
} else {
// vds in this cluster, cannot update
if (!StringUtils.isEmpty(oldCluster.getCpuName()) && !checkIfCpusSameManufacture(oldCluster) && !allVdssInMaintenance) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_CPU_ILLEGAL);
result = false;
}
}
}
if (result) {
vmList = vmDao.getAllForCluster(oldCluster.getId());
hasVmOrHost = !vmList.isEmpty() || !allForCluster.isEmpty();
}
// cannot change the processor architecture while there are attached hosts or VMs to the cluster
if (result && getCluster().supportsVirtService() && !isArchitectureUpdatable() && hasVmOrHost) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_CPU_ARCHITECTURE_ILLEGAL);
result = false;
}
if (result) {
sameCpuNames = StringUtils.equals(oldCluster.getCpuName(), getCluster().getCpuName());
}
if (result) {
boolean isOldCPUEmpty = StringUtils.isEmpty(oldCluster.getCpuName());
if (!isOldCPUEmpty && !sameCpuNames && !isCpuUpdatable(oldCluster) && hasVmOrHost) {
addValidationMessage(EngineMessage.CLUSTER_CPU_IS_NOT_UPDATABLE);
result = false;
}
}
if (result && !oldCluster.getCompatibilityVersion().equals(getCluster().getCompatibilityVersion())) {
for (VM vm : vmList) {
if (vm.isPreviewSnapshot()) {
// can't change cluster version when a VM is in preview
if (result) {
addValidationMessage(EngineMessage.CLUSTER_VERSION_CHANGE_VM_PREVIEW);
// and continue with adding validation messages
result = false;
}
addValidationMessage(vm.getName());
}
}
}
if (result) {
List<VDS> vdss = new ArrayList<>();
isAddedToStoragePool = oldCluster.getStoragePoolId() == null && getCluster().getStoragePoolId() != null;
if (isAddedToStoragePool && !validateManagementNetwork()) {
return false;
}
for (VDS vds : allForCluster) {
if (vds.getStatus() == VDSStatus.Up) {
if (isAddedToStoragePool) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_VDS_UP);
return false;
} else {
vdss.add(vds);
}
}
}
for (VDS vds : vdss) {
if (!VersionSupport.checkClusterVersionSupported(getCluster().getCompatibilityVersion(), vds)) {
result = false;
addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_COMPATIBILITY_VERSION_WITH_LOWER_HOSTS);
break;
} else if (getCluster().supportsVirtService() && missingServerCpuFlags(vds) != null) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_CPU_WITH_LOWER_HOSTS);
result = false;
break;
}
if (!isSupportedEmulatedMachinesMatchClusterLevel(vds)) {
return failValidation(EngineMessage.CLUSTER_CANNOT_UPDATE_COMPATIBILITY_VERSION_WITH_INCOMPATIBLE_EMULATED_MACHINE);
}
}
if (result) {
Set<SupportedAdditionalClusterFeature> additionalClusterFeaturesAdded = getAdditionalClusterFeaturesAdded();
// New Features cannot be enabled if all up hosts are not supporting the selected feature
if (CollectionUtils.isNotEmpty(additionalClusterFeaturesAdded) && !checkClusterFeaturesSupported(vdss, additionalClusterFeaturesAdded)) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_SUPPORTED_FEATURES_WITH_LOWER_HOSTS);
result = false;
}
}
if (result) {
boolean notDownVms = false;
boolean suspendedVms = false;
hasVms = vmList.size() > 0;
if (!sameCpuNames) {
for (VM vm : vmList) {
if (vm.getStatus() == VMStatus.Suspended) {
suspendedVms = true;
break;
} else if (vm.getStatus() != VMStatus.Down) {
notDownVms = true;
break;
}
}
if (suspendedVms) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_CPU_WITH_SUSPENDED_VMS);
result = false;
} else if (notDownVms) {
int compareResult = compareCpuLevels(oldCluster);
if (compareResult > 0) {
// Upgrade of CPU in same compability level is allowed if
// there
// are running VMs - but we should warn they
// cannot not be hibernated
addCustomValue("Cluster", getParameters().getCluster().getName());
auditLogDirector.log(this, AuditLogType.CANNOT_HIBERNATE_RUNNING_VMS_AFTER_CLUSTER_CPU_UPGRADE);
}
}
}
}
}
if (result && getCluster().getStoragePoolId() != null) {
StoragePool storagePool = storagePoolDao.get(getCluster().getStoragePoolId());
if (oldCluster.getStoragePoolId() == null && storagePool.isLocal()) {
// we allow only one cluster in localfs data center
if (!clusterDao.getAllForStoragePool(getCluster().getStoragePoolId()).isEmpty()) {
getReturnValue().getValidationMessages().add(EngineMessage.CLUSTER_CANNOT_ADD_MORE_THEN_ONE_HOST_TO_LOCAL_STORAGE.toString());
result = false;
} else if (Config.getValue(ConfigValues.AutoRegistrationDefaultClusterID).equals(getCluster().getId())) {
addValidationMessage(EngineMessage.DEFAULT_CLUSTER_CANNOT_BE_ON_LOCALFS);
result = false;
}
}
}
if (result) {
if (!(getCluster().supportsGlusterService() || getCluster().supportsVirtService())) {
addValidationMessage(EngineMessage.CLUSTER_AT_LEAST_ONE_SERVICE_MUST_BE_ENABLED);
result = false;
} else if (getCluster().supportsGlusterService() && getCluster().supportsVirtService() && !isAllowClusterWithVirtGluster()) {
addValidationMessage(EngineMessage.CLUSTER_ENABLING_BOTH_VIRT_AND_GLUSTER_SERVICES_NOT_ALLOWED);
result = false;
}
}
if (result && hasVms && !getCluster().supportsVirtService()) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_DISABLE_VIRT_WHEN_CLUSTER_CONTAINS_VMS);
result = false;
}
if (result && !getCluster().supportsGlusterService()) {
List<GlusterVolumeEntity> volumes = glusterVolumeDao.getByClusterId(getCluster().getId());
if (volumes != null && volumes.size() > 0) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_DISABLE_GLUSTER_WHEN_CLUSTER_CONTAINS_VOLUMES);
result = false;
}
}
if (result && getCluster().supportsTrustedService() && Config.<String>getValue(ConfigValues.AttestationServer).equals("")) {
addValidationMessage(EngineMessage.CLUSTER_CANNOT_SET_TRUSTED_ATTESTATION_SERVER_NOT_CONFIGURED);
result = false;
}
if (result && !FeatureSupported.isMigrationSupported(getArchitecture(), getCluster().getCompatibilityVersion()) && getCluster().getMigrateOnError() != MigrateOnErrorOptions.NO) {
return failValidation(EngineMessage.MIGRATION_ON_ERROR_IS_NOT_SUPPORTED);
}
if (result) {
result = validateClusterPolicy(oldCluster);
}
if (result && getParameters().isForceResetEmulatedMachine()) {
for (VDS vds : allForCluster) {
if (vds.getStatus() == VDSStatus.Up) {
addValidationMessage(EngineMessage.CLUSTER_HOSTS_MUST_BE_DOWN);
result = false;
break;
}
}
}
ClusterValidator clusterValidator = new ClusterValidator(dbFacade, getCluster(), cpuFlagsManagerHandler);
result = result && validate(clusterValidator.rngSourcesAllowed()) && validate(clusterValidator.memoryOptimizationConfiguration()) && validate(moveMacs.canMigrateMacsToAnotherMacPool(oldCluster, getNewMacPoolId())) && validateDefaultNetworkProvider() && validate(clusterValidator.supportedFirewallTypeForClusterVersion());
return result;
}
use of org.ovirt.engine.core.common.businessentities.StoragePool in project ovirt-engine by oVirt.
the class RemoveVdsCommand method validate.
@Override
protected boolean validate() {
boolean returnValue = canRemoveVds(getVdsId(), getReturnValue().getValidationMessages());
StoragePool storagePool = storagePoolDao.getForVds(getParameters().getVdsId());
if (returnValue && storagePool != null && storagePool.isLocal()) {
if (!storageDomainDao.getAllForStoragePool(storagePool.getId()).isEmpty()) {
returnValue = failValidation(EngineMessage.VDS_CANNOT_REMOVE_HOST_WITH_LOCAL_STORAGE);
}
}
// Perform volume bricks on server and up server null check
if (returnValue && isGlusterEnabled()) {
upServer = glusterUtil.getUpServer(getClusterId());
if (!getParameters().isForceAction()) {
// fail if host has bricks on a volume
if (hasVolumeBricksOnServer()) {
returnValue = failValidation(EngineMessage.VDS_CANNOT_REMOVE_HOST_HAVING_GLUSTER_VOLUME);
} else if (upServer == null && clusterHasMultipleHosts()) {
// fail if there is no up server in cluster, and if host being removed is not
// the last server in cluster
addValidationMessageVariable("clusterName", getCluster().getName());
returnValue = failValidation(EngineMessage.ACTION_TYPE_FAILED_NO_UP_SERVER_FOUND);
}
} else {
// if force, cannot remove only if there are bricks on server and there is an up server.
if (hasVolumeBricksOnServer() && upServer != null) {
returnValue = failValidation(EngineMessage.VDS_CANNOT_REMOVE_HOST_HAVING_GLUSTER_VOLUME);
}
}
}
return returnValue;
}
Aggregations