use of org.ovirt.engine.core.common.businessentities.StorageDomainStatic in project ovirt-engine by oVirt.
the class IrsBrokerCommand method startReconstruct.
private void startReconstruct() {
StorageDomainStatic masterDomain = null;
List<StorageDomainStatic> storageDomainStaticList = DbFacade.getInstance().getStorageDomainStaticDao().getAllForStoragePool(getParameters().getStoragePoolId());
for (StorageDomainStatic storageDomainStatic : storageDomainStaticList) {
if (storageDomainStatic.getStorageDomainType() == StorageDomainType.Master) {
masterDomain = storageDomainStatic;
break;
}
}
if (masterDomain != null) {
final Guid masterDomainId = masterDomain.getId();
eventQueue.submitEventAsync(new Event(getParameters().getStoragePoolId(), masterDomainId, null, EventType.RECONSTRUCT, "IrsBrokerCommand.startReconstruct()"), () -> eventListener.masterDomainNotOperational(masterDomainId, getParameters().getStoragePoolId(), true, getVDSReturnValue().getVdsError() != null && getVDSReturnValue().getVdsError().getCode() == EngineError.StoragePoolWrongMaster));
} else {
log.error("IrsBroker::IRSNoMasterDomainException:: Could not find master domain for pool '{}'", getParameters().getStoragePoolId());
}
}
use of org.ovirt.engine.core.common.businessentities.StorageDomainStatic in project ovirt-engine by oVirt.
the class IrsProxy method proceedStorageDomain.
private boolean proceedStorageDomain(StorageDomain domainFromVdsm, int dataMasterVersion, StoragePool storagePool) {
StorageDomain storage_domain = storageDomainDao.getForStoragePool(domainFromVdsm.getId(), storagePoolId);
if (storage_domain != null) {
StorageDomainStatic domainFromDb = storage_domain.getStorageStaticData();
StoragePoolIsoMap domainPoolMapFromDb = storage_domain.getStoragePoolIsoMapData();
// If the domain is master in the DB
if (domainFromDb.getStorageDomainType() == StorageDomainType.Master && domainPoolMapFromDb != null && domainPoolMapFromDb.getStatus() != StorageDomainStatus.Locked) {
// and the domain is not master in the VDSM
if (!((domainFromVdsm.getStorageDomainType() == StorageDomainType.Master) || (domainFromVdsm.getStorageDomainType() == StorageDomainType.Unknown))) {
reconstructMasterDomainNotInSync(domainFromVdsm.getStoragePoolId(), domainFromDb, "Mismatch between master in DB and VDSM", MessageFormat.format("Master domain is not in sync between DB and VDSM. " + "Domain {0} marked as master in DB and not in the storage", domainFromDb.getStorageName()));
} else // mismatch
if (dataMasterVersion != storagePool.getMasterDomainVersion()) {
reconstructMasterDomainNotInSync(domainFromVdsm.getStoragePoolId(), domainFromDb, "Mismatch between master version in DB and VDSM", MessageFormat.format("Master domain version is not in sync between DB and VDSM. " + "Domain {0} marked as master, but the version in DB: {1} and in VDSM: {2}", domainFromDb.getStorageName(), storagePool.getMasterDomainVersion(), dataMasterVersion));
}
}
boolean statusChanged = false;
if (domainPoolMapFromDb == null) {
domainFromVdsm.setStoragePoolId(storagePoolId);
storagePoolIsoMapDao.save(domainFromVdsm.getStoragePoolIsoMapData());
statusChanged = true;
} else if (!domainPoolMapFromDb.getStatus().isStorageDomainInProcess() && domainPoolMapFromDb.getStatus() != domainFromVdsm.getStatus()) {
if (domainPoolMapFromDb.getStatus() != StorageDomainStatus.Inactive && domainFromVdsm.getStatus() != StorageDomainStatus.Inactive) {
storagePoolIsoMapDao.update(domainFromVdsm.getStoragePoolIsoMapData());
statusChanged = true;
}
if (domainFromVdsm.getStatus() != null && domainFromVdsm.getStatus() == StorageDomainStatus.Inactive && domainFromDb.getStorageDomainType() == StorageDomainType.Master) {
StoragePool pool = storagePoolDao.get(domainPoolMapFromDb.getStoragePoolId());
if (pool != null) {
storagePoolDao.updateStatus(pool.getId(), StoragePoolStatus.Maintenance);
pool.setStatus(StoragePoolStatus.Maintenance);
getEventListener().storagePoolStatusChanged(pool.getId(), StoragePoolStatus.Maintenance);
}
}
}
// update dynamic data
if (statusChanged || (domainPoolMapFromDb.getStatus() != StorageDomainStatus.Inactive && domainFromVdsm.getStatus() == StorageDomainStatus.Active)) {
storageDomainDynamicDao.update(domainFromVdsm.getStorageDynamicData());
if (domainFromVdsm.getAvailableDiskSize() != null && domainFromVdsm.getUsedDiskSize() != null) {
double freePercent = domainFromVdsm.getStorageDynamicData().getfreeDiskPercent();
AuditLogType type = AuditLogType.UNASSIGNED;
Integer freeDiskInGB = domainFromVdsm.getStorageDynamicData().getAvailableDiskSize();
if (freeDiskInGB != null) {
if (freePercent < domainFromDb.getWarningLowSpaceIndicator()) {
type = AuditLogType.IRS_DISK_SPACE_LOW;
}
if (freeDiskInGB < domainFromDb.getCriticalSpaceActionBlocker()) {
// Note, if both conditions are met, only IRS_DISK_SPACE_LOW_ERROR will be shown
type = AuditLogType.IRS_DISK_SPACE_LOW_ERROR;
}
}
if (type != AuditLogType.UNASSIGNED) {
AuditLogable logable = new AuditLogableImpl();
logable.setStorageDomainName(domainFromDb.getStorageName());
logable.addCustomValue("DiskSpace", domainFromVdsm.getAvailableDiskSize().toString());
domainFromVdsm.setStorageName(domainFromDb.getStorageName());
auditLogDirector.log(logable, type);
}
}
Set<EngineError> alerts = domainFromVdsm.getAlerts();
if (alerts != null && !alerts.isEmpty()) {
AuditLogable logable = new AuditLogableImpl();
logable.setStorageDomainName(domainFromDb.getStorageName());
domainFromVdsm.setStorageName(domainFromDb.getStorageName());
for (EngineError alert : alerts) {
switch(alert) {
case VG_METADATA_CRITICALLY_FULL:
auditLogDirector.log(logable, AuditLogType.STORAGE_ALERT_VG_METADATA_CRITICALLY_FULL);
break;
case SMALL_VG_METADATA:
auditLogDirector.log(logable, AuditLogType.STORAGE_ALERT_SMALL_VG_METADATA);
break;
default:
log.error("Unrecognized alert for domain {}(id = {}): {}", domainFromVdsm.getStorageName(), domainFromVdsm.getId(), alert);
break;
}
}
}
}
// Block domains should have their LUNs synchronized and updated in the DB.
if (statusChanged && domainFromVdsm.getStatus() == StorageDomainStatus.Active && storage_domain.getStorageType().isBlockDomain()) {
return true;
}
} else {
log.debug("The domain with id '{}' was not found in DB", domainFromVdsm.getId());
}
return false;
}
use of org.ovirt.engine.core.common.businessentities.StorageDomainStatic in project ovirt-engine by oVirt.
the class StorageDomainHelper method checkNumberOfLVsForBlockDomain.
/**
* If the storage domain given in the parameter is a block domain, the number of LVs on this domain will be fetched
* and if it exceeds the maximum number of LVs defined in the AlertOnNumberOfLVs config value, an audit log will
* be logged to indicate that the number of LVs on this domain exceeded the allowed number of LVs
*/
public void checkNumberOfLVsForBlockDomain(Guid storageDomainId) {
StorageDomainStatic domain = storageDomainStaticDao.get(storageDomainId);
if (domain.getStorageType().isBlockDomain()) {
long numOfLVs = storageDomainDao.getNumberOfImagesInStorageDomain(storageDomainId);
Integer maxNumOfLVs = Config.getValue(ConfigValues.AlertOnNumberOfLVs);
if (numOfLVs >= maxNumOfLVs) {
AuditLogable logable = new AuditLogableImpl();
logable.setStorageDomainName(domain.getName());
logable.addCustomValue("maxNumOfLVs", maxNumOfLVs.toString());
logable.setStorageDomainId(storageDomainId);
auditLogDirector.log(logable, AuditLogType.NUMBER_OF_LVS_ON_STORAGE_DOMAIN_EXCEEDED_THRESHOLD);
}
}
}
use of org.ovirt.engine.core.common.businessentities.StorageDomainStatic in project ovirt-engine by oVirt.
the class ImportVmTemplateCommand method validate.
@Override
protected boolean validate() {
if (getVmTemplate() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
if (getCluster() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_CAN_NOT_BE_EMPTY);
}
if (!getCluster().getStoragePoolId().equals(getStoragePoolId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_IS_NOT_VALID);
}
setDescription(getVmTemplateName());
// check that the storage pool is valid
if (!validate(createStoragePoolValidator().existsAndUp()) || !validateTemplateArchitecture() || !isClusterCompatible()) {
return false;
}
// set the source domain and check that it is ImportExport type and active
setSourceDomainId(getParameters().getSourceDomainId());
StorageDomainValidator sourceDomainValidator = new StorageDomainValidator(getSourceDomain());
if (!validate(sourceDomainValidator.isDomainExistAndActive())) {
return false;
}
if ((getSourceDomain().getStorageDomainType() != StorageDomainType.ImportExport) && !getParameters().isImagesExistOnTargetStorageDomain()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
}
if (!getParameters().isImagesExistOnTargetStorageDomain()) {
// Set the template images from the Export domain and change each image id storage is to the import domain
GetAllFromExportDomainQueryParameters tempVar = new GetAllFromExportDomainQueryParameters(getParameters().getStoragePoolId(), getParameters().getSourceDomainId());
QueryReturnValue qretVal = runInternalQuery(QueryType.GetTemplatesFromExportDomain, tempVar);
if (!qretVal.getSucceeded()) {
return false;
}
Map<VmTemplate, List<DiskImage>> templates = qretVal.getReturnValue();
ArrayList<DiskImage> images = new ArrayList<>();
for (Map.Entry<VmTemplate, List<DiskImage>> entry : templates.entrySet()) {
if (entry.getKey().getId().equals(getVmTemplate().getId())) {
images = new ArrayList<>(entry.getValue());
getVmTemplate().setInterfaces(entry.getKey().getInterfaces());
getVmTemplate().setOvfVersion(entry.getKey().getOvfVersion());
break;
}
}
getParameters().setImages(images);
getVmTemplate().setImages(images);
ensureDomainMap(getImages(), getParameters().getDestDomainId());
HashMap<Guid, DiskImage> imageMap = new HashMap<>();
for (DiskImage image : images) {
if (Guid.Empty.equals(image.getVmSnapshotId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
}
StorageDomain storageDomain = getStorageDomain(imageToDestinationDomainMap.get(image.getId()));
StorageDomainValidator validator = new StorageDomainValidator(storageDomain);
if (!validate(validator.isDomainExistAndActive()) || !validate(validator.domainIsValidDestination())) {
return false;
}
StorageDomainStatic targetDomain = storageDomain.getStorageStaticData();
changeRawToCowIfSparseOnBlockDevice(targetDomain.getStorageType(), image);
if (!ImagesHandler.checkImageConfiguration(targetDomain, image, getReturnValue().getValidationMessages())) {
return false;
}
image.setStoragePoolId(getParameters().getStoragePoolId());
image.setStorageIds(new ArrayList<>(Collections.singletonList(storageDomain.getId())));
imageMap.put(image.getImageId(), image);
}
getVmTemplate().setDiskImageMap(imageMap);
}
sourceTemplateId = getVmTemplateId();
if (getParameters().isImportAsNewEntity()) {
initImportClonedTemplate();
}
VmTemplate duplicateTemplate = vmTemplateDao.get(getParameters().getVmTemplate().getId());
// check that the template does not exists in the target domain
if (duplicateTemplate != null) {
return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_EXISTS, String.format("$TemplateName %1$s", duplicateTemplate.getName()));
}
if (getVmTemplate().isBaseTemplate() && isVmTemplateWithSameNameExist()) {
return failValidation(EngineMessage.VM_CANNOT_IMPORT_TEMPLATE_NAME_EXISTS);
}
if (!validateNoDuplicateDiskImages(getImages())) {
return false;
}
if (getImages() != null && !getImages().isEmpty() && !getParameters().isImagesExistOnTargetStorageDomain()) {
if (!validateSpaceRequirements(getImages())) {
return false;
}
}
List<VmNetworkInterface> vmNetworkInterfaces = getVmTemplate().getInterfaces();
vmNicMacsUtils.replaceInvalidEmptyStringMacAddressesWithNull(vmNetworkInterfaces);
if (!validate(vmNicMacsUtils.validateMacAddress(vmNetworkInterfaces))) {
return false;
}
// if this is a template version, check base template exist
if (!getVmTemplate().isBaseTemplate()) {
VmTemplate baseTemplate = vmTemplateDao.get(getVmTemplate().getBaseTemplateId());
if (baseTemplate == null) {
return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_VERSION_MISSING_BASE);
}
}
if (!setAndValidateDiskProfiles()) {
return false;
}
if (!setAndValidateCpuProfile()) {
return false;
}
if (!validate(vmHandler.validateMaxMemorySize(getVmTemplate(), getEffectiveCompatibilityVersion()))) {
return false;
}
List<EngineMessage> msgs = openStackMetadataAdapter.validate(getVmTemplate().getVmInit());
if (!CollectionUtils.isEmpty(msgs)) {
return failValidation(msgs);
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.StorageDomainStatic in project ovirt-engine by oVirt.
the class GlusterGeoRepSyncJob method removeDeletedSessions.
private void removeDeletedSessions(Cluster cluster, final Map<String, GlusterGeoRepSession> sessionsMap, GlusterVolumeEntity volume) {
List<GlusterGeoRepSession> sessionsInDb;
if (volume != null) {
// syncing for a specific volume, so retrieve only that volume's sessions
sessionsInDb = geoRepDao.getGeoRepSessions(volume.getId());
} else {
sessionsInDb = geoRepDao.getGeoRepSessionsInCluster(cluster.getId());
}
if (CollectionUtils.isEmpty(sessionsInDb)) {
return;
}
List<GlusterGeoRepSession> sessionsToDelete = new ArrayList<>();
for (GlusterGeoRepSession grepSession : sessionsInDb) {
if (sessionsMap.get(grepSession.getSessionKey()) == null) {
sessionsToDelete.add(grepSession);
}
}
for (final GlusterGeoRepSession session : sessionsToDelete) {
log.info("geo-rep session '{}' detected removed for volume '{}'", session.getSessionKey(), session.getMasterVolumeName());
// check if geo-rep session is reference by a DR schedule
List<StorageDomainDR> storageDRs = storageDomainDRDao.getWithGeoRepSession(session.getId());
for (StorageDomainDR storageDR : storageDRs) {
// delete and log deletion of storage DR - the schedule needs to be deleted as well
log.info("Geo-rep session '{}'- for volume '{}' that has been deleted from CLI " + "has associated DR sync schedules which will be removed", session.getSessionKey(), session.getMasterVolumeName());
if (storageDR.getJobId() != null) {
schedulerUtil.deleteJob(storageDR.getJobId());
}
storageDomainDRDao.remove(storageDR.getStorageDomainId(), storageDR.getGeoRepSessionId());
StorageDomainStatic storageDomain = storageDomainStaticDao.get(storageDR.getStorageDomainId());
Map<String, String> customValues = new HashMap<>();
customValues.put("storageDomainName", storageDomain.getName());
customValues.put("geoRepSessionKey", session.getSessionKey());
logGeoRepMessage(AuditLogType.STORAGE_DOMAIN_DR_DELETED, cluster, customValues);
}
geoRepDao.remove(session.getId());
logGeoRepMessage(AuditLogType.GLUSTER_GEOREP_SESSION_DELETED_FROM_CLI, cluster, session);
}
}
Aggregations