use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class VmCommand method validateLeaseStorageDomain.
protected boolean validateLeaseStorageDomain(Guid leaseStorageDomainId) {
StorageDomain domain = storageDomainDao.getForStoragePool(leaseStorageDomainId, getStoragePoolId());
StorageDomainValidator validator = new StorageDomainValidator(domain);
return validate(validator.isDomainExistAndActive()) && validate(validator.isDataDomain());
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class VmPoolHandler method isNonPrestartedVmFree.
/**
* Check if a specific VM is free. A VM is considered free if it isn't attached to a user and not during preview
* @param vmId The VM ID
* @param errorProcessor the error messages processor object or lambda expression (may be <code>null</code>)
* @return True if the VM is free, false otherwise
*/
public boolean isNonPrestartedVmFree(Guid vmId, ErrorProcessor errorProcessor) {
List<String> messages = new ArrayList<>();
// check that there is no user already attached to this VM
if (vmAssignedToUser(vmId, messages)) {
return failVmFree(errorProcessor, vmId, messages);
}
// check that VN can be run
if (!canRunPoolVm(vmId, messages)) {
return failVmFree(errorProcessor, vmId, messages);
}
// check VM images
ValidationResult vmDuringSnapshotResult = snapshotsValidator.vmNotDuringSnapshot(vmId);
if (!vmDuringSnapshotResult.isValid()) {
return failVmFree(errorProcessor, vmId, vmDuringSnapshotResult.getMessagesAsStrings());
}
ValidationResult vmInPreviewResult = snapshotsValidator.vmNotInPreview(vmId);
if (!vmInPreviewResult.isValid()) {
return failVmFree(errorProcessor, vmId, vmInPreviewResult.getMessagesAsStrings());
}
List<Disk> disks = diskDao.getAllForVm(vmId);
List<DiskImage> vmImages = DisksFilter.filterImageDisks(disks, ONLY_NOT_SHAREABLE, ONLY_SNAPABLE);
VM vm = vmDao.get(vmId);
StoragePool sp = storagePoolDao.get(vm.getStoragePoolId());
ValidationResult spUpResult = new StoragePoolValidator(sp).existsAndUp();
if (!spUpResult.isValid()) {
return failVmFree(errorProcessor, vmId, spUpResult.getMessagesAsStrings());
}
Guid storageDomainId = vmImages.size() > 0 ? vmImages.get(0).getStorageIds().get(0) : Guid.Empty;
if (!Guid.Empty.equals(storageDomainId)) {
StorageDomainValidator storageDomainValidator = new StorageDomainValidator(storageDomainDao.getForStoragePool(storageDomainId, sp.getId()));
ValidationResult domainActiveResult = storageDomainValidator.isDomainExistAndActive();
if (!domainActiveResult.isValid()) {
return failVmFree(errorProcessor, vmId, domainActiveResult.getMessagesAsStrings());
}
}
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(vmImages);
ValidationResult disksNotLockedResult = diskImagesValidator.diskImagesNotLocked();
if (!disksNotLockedResult.isValid()) {
messages.addAll(disksNotLockedResult.getMessagesAsStrings());
messages.addAll(disksNotLockedResult.getVariableReplacements());
return failVmFree(errorProcessor, vmId, messages);
}
ValidationResult vmNotLockResult = new VmValidator(vm).vmNotLocked();
if (!vmNotLockResult.isValid()) {
return failVmFree(errorProcessor, vmId, vmNotLockResult.getMessagesAsStrings());
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class VmTemplateHandler method isVmTemplateImagesReady.
public ValidationResult isVmTemplateImagesReady(VmTemplate vmTemplate, Guid storageDomainId, boolean checkImagesExists, boolean checkLocked, boolean checkIllegal, boolean checkStorageDomain, List<DiskImage> providedVmtImages) {
List<DiskImage> vmtImages = providedVmtImages;
if (checkStorageDomain) {
StorageDomainValidator storageDomainValidator = new StorageDomainValidator(storageDomainDao.getForStoragePool(storageDomainId, vmTemplate.getStoragePoolId()));
ValidationResult returnValue = storageDomainValidator.isDomainExistAndActive();
if (!returnValue.isValid()) {
return returnValue;
}
}
if (checkImagesExists) {
if (vmtImages == null) {
vmtImages = DisksFilter.filterImageDisks(diskDao.getAllForVm(vmTemplate.getId()), ONLY_ACTIVE);
}
if (vmtImages.size() > 0 && !imagesHandler.isImagesExists(vmtImages, vmtImages.get(0).getStoragePoolId())) {
return new ValidationResult(EngineMessage.TEMPLATE_IMAGE_NOT_EXIST);
}
}
if (checkLocked) {
if (vmTemplate.getStatus() == VmTemplateStatus.Locked) {
return new ValidationResult(EngineMessage.VM_TEMPLATE_IMAGE_IS_LOCKED);
}
if (vmtImages != null) {
for (DiskImage image : vmtImages) {
if (image.getImageStatus() == ImageStatus.LOCKED) {
return new ValidationResult(EngineMessage.VM_TEMPLATE_IMAGE_IS_LOCKED);
}
}
}
}
if (checkIllegal && (vmTemplate.getStatus() == VmTemplateStatus.Illegal)) {
return new ValidationResult(EngineMessage.VM_TEMPLATE_IMAGE_IS_ILLEGAL);
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class AddVmCommand method validateProvidedDestinations.
private boolean validateProvidedDestinations() {
for (DiskImage diskImage : diskInfoDestinationMap.values()) {
if (diskImage.getStorageIds() == null || diskImage.getStorageIds().isEmpty()) {
diskImage.setStorageIds(new ArrayList<>());
diskImage.getStorageIds().add(getParameters().getStorageDomainId());
}
Guid storageDomainId = diskImage.getStorageIds().get(0);
if (destStorages.get(storageDomainId) == null) {
StorageDomain storage = storageDomainDao.getForStoragePool(storageDomainId, getStoragePoolId());
StorageDomainValidator validator = new StorageDomainValidator(storage);
if (!validate(validator.isDomainExistAndActive()) || !validate(validator.domainIsValidDestination())) {
return false;
}
destStorages.put(storage.getId(), storage);
}
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator in project ovirt-engine by oVirt.
the class RunVmValidator method validateVmLease.
public ValidationResult validateVmLease() {
if (vm.getLeaseStorageDomainId() == null) {
return ValidationResult.VALID;
}
if (vm.getLeaseInfo() == null) {
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_INVALID_VM_LEASE);
}
StorageDomain leaseStorageDomain = storageDomainDao.getForStoragePool(vm.getLeaseStorageDomainId(), vm.getStoragePoolId());
StorageDomainValidator storageDomainValidator = new StorageDomainValidator(leaseStorageDomain);
ValidationResult validationResult = storageDomainValidator.isDomainExistAndActive();
if (!validationResult.isValid()) {
return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_INVALID_VM_LEASE_STORAGE_DOMAIN_STATUS, String.format("$LeaseStorageDomainName %1$s", leaseStorageDomain.getName()));
}
return ValidationResult.VALID;
}
Aggregations