use of org.ovirt.engine.core.common.businessentities.StoragePool in project ovirt-engine by oVirt.
the class IrsProxy method hostsStorageConnectionsAndPoolMetadataRefresh.
@OnTimerMethodAnnotation("hostsStorageConnectionsAndPoolMetadataRefresh")
public void hostsStorageConnectionsAndPoolMetadataRefresh() {
Map<Guid, Guid> reportsToHandle = procceedReportsThreatmenet();
if (reportsToHandle.isEmpty()) {
return;
}
List<Callable<Void>> connectStorageTasks = new ArrayList<>();
final List<Callable<Void>> refreshStoragePoolTasks = new ArrayList<>();
final StoragePool storagePool = storagePoolDao.get(storagePoolId);
final Guid masterDomainId = storageDomainDao.getMasterStorageDomainIdForPool(storagePoolId);
final List<StoragePoolIsoMap> storagePoolIsoMap = storagePoolIsoMapDao.getAllForStoragePool(storagePoolId);
Map<String, Pair<String, String>> acquiredLocks = new HashMap<>();
try {
for (Map.Entry<Guid, Guid> entry : reportsToHandle.entrySet()) {
Guid vdsId = entry.getKey();
Guid currentReportId = entry.getValue();
vdsHandeledReportsOnUnseenDomains.put(vdsId, currentReportId);
Map<String, Pair<String, String>> lockMap = Collections.singletonMap(vdsId.toString(), new Pair<>(LockingGroup.VDS_POOL_AND_STORAGE_CONNECTIONS.toString(), EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED.toString()));
EngineLock engineLock = new EngineLock(lockMap, null);
if (!lockManager.acquireLock(engineLock).getFirst()) {
log.info("Failed to acquire lock to refresh storage connection and pool metadata for host '{}', skipping it", vdsId);
continue;
}
final VDS vds = vdsDao.get(entry.getKey());
if (vds.getStatus() != VDSStatus.Up) {
log.info("Skipping storage connection and pool metadata information for host '{}' as it's no longer in status UP", vdsId);
lockManager.releaseLock(engineLock);
continue;
}
acquiredLocks.putAll(lockMap);
connectStorageTasks.add(() -> {
getEventListener().connectHostToDomainsInActiveOrUnknownStatus(vds);
return null;
});
refreshStoragePoolTasks.add(() -> {
storagePoolDomainHelper.refreshHostPoolMetadata(vds, storagePool, masterDomainId, storagePoolIsoMap);
return null;
});
}
final Set<String> handledHosts = acquiredLocks.keySet();
log.info("Running storage connections refresh for hosts '{}'", handledHosts);
ThreadPoolUtil.invokeAll(connectStorageTasks);
log.info("Submitting to the event queue pool refresh for hosts '{}'", handledHosts);
getEventQueue().submitEventSync(new Event(storagePoolId, null, null, EventType.POOLREFRESH, ""), () -> {
log.info("Running storage pool metadata refresh for hosts '{}'", handledHosts);
ThreadPoolUtil.invokeAll(refreshStoragePoolTasks);
return new EventResult(true, EventType.POOLREFRESH);
});
} finally {
if (!acquiredLocks.isEmpty()) {
lockManager.releaseLock(new EngineLock(acquiredLocks, null));
}
}
}
use of org.ovirt.engine.core.common.businessentities.StoragePool 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.StoragePool in project ovirt-engine by oVirt.
the class IrsProxy method startSpm.
private SpmStatusResult startSpm(final StoragePool storagePool, VDS selectedVds, int prevId, String lver, int vdsSpmIdToFence) {
storagePool.setStatus(StoragePoolStatus.Contend);
storagePool.setSpmVdsId(selectedVds.getId());
TransactionSupport.executeInNewTransaction(() -> {
storagePoolDao.update(storagePool);
return null;
});
log.info("starting spm on vds '{}', storage pool '{}', prevId '{}', LVER '{}'", selectedVds.getName(), storagePool.getName(), prevId, lver);
SpmStatusResult spmStatus = (SpmStatusResult) resourceManager.runVdsCommand(VDSCommandType.SpmStart, new SpmStartVDSCommandParameters(selectedVds.getId(), storagePoolId, prevId, lver, storagePool.getRecoveryMode(), vdsSpmIdToFence != -1, storagePool.getStoragePoolFormatType())).getReturnValue();
if (spmStatus == null || spmStatus.getSpmStatus() != SpmStatus.SPM) {
getEventListener().storagePoolStatusChange(storagePool.getId(), StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC, EngineError.ENGINE, TransactionScopeOption.RequiresNew);
if (spmStatus != null) {
TransactionSupport.executeInNewTransaction(() -> {
StoragePool pool = storagePoolDao.get(storagePool.getId());
pool.setSpmVdsId(null);
storagePoolDao.update(pool);
return null;
});
}
throw new IrsSpmStartFailedException();
}
return spmStatus;
}
use of org.ovirt.engine.core.common.businessentities.StoragePool in project ovirt-engine by oVirt.
the class IrsProxy method proceedStoragePoolStats.
@SuppressWarnings("unchecked")
private void proceedStoragePoolStats(StoragePool storagePool) {
// ugly patch because vdsm doesnt check if host is spm on spm
// operations
VDSReturnValue result = null;
Guid curVdsId = currentVdsId;
if (curVdsId != null) {
result = resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(curVdsId, storagePoolId));
}
if (result == null || !result.getSucceeded() || (result.getSucceeded() && ((SpmStatusResult) result.getReturnValue()).getSpmStatus() != SpmStatus.SPM)) {
// update pool status to problematic until fence will happen
if (storagePool.getStatus() != StoragePoolStatus.NonResponsive && storagePool.getStatus() != StoragePoolStatus.NotOperational) {
if (result != null && result.getVdsError() != null) {
updateStoragePoolStatus(storagePoolId, StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC_WITH_ERROR, result.getVdsError().getCode());
} else {
updateStoragePoolStatus(storagePoolId, StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC, EngineError.ENGINE);
}
}
// then cause failover with attempts
if (result != null && !(result.getExceptionObject() instanceof VDSNetworkException)) {
HashMap<Guid, AsyncTaskStatus> tasksList = (HashMap<Guid, AsyncTaskStatus>) resourceManager.runVdsCommand(VDSCommandType.HSMGetAllTasksStatuses, new VdsIdVDSCommandParametersBase(curVdsId)).getReturnValue();
boolean allTasksFinished = true;
if (tasksList != null) {
for (AsyncTaskStatus taskStatus : tasksList.values()) {
if (AsyncTaskStatusEnum.finished != taskStatus.getStatus()) {
allTasksFinished = false;
break;
}
}
}
if ((tasksList == null) || allTasksFinished) {
nullifyInternalProxies();
} else {
if (_errorAttempts < Config.<Integer>getValue(ConfigValues.SPMFailOverAttempts)) {
_errorAttempts++;
log.warn("failed getting spm status for pool '{}' ({}), attempt number: {}", storagePoolId, storagePool.getName(), _errorAttempts);
} else {
nullifyInternalProxies();
_errorAttempts = 0;
}
}
}
} else if (result.getSucceeded() && ((SpmStatusResult) result.getReturnValue()).getSpmStatus() == SpmStatus.SPM && (storagePool.getStatus() == StoragePoolStatus.NonResponsive || storagePool.getStatus() == StoragePoolStatus.Contend)) {
// if recovered from network exception set back to up
storagePoolDao.updateStatus(storagePool.getId(), StoragePoolStatus.Up);
storagePool.setStatus(StoragePoolStatus.Up);
getEventListener().storagePoolStatusChanged(storagePool.getId(), storagePool.getStatus());
}
List<StorageDomain> domainsInDb = storageDomainDao.getAllForStoragePool(storagePoolId);
GetStoragePoolInfoVDSCommandParameters tempVar = new GetStoragePoolInfoVDSCommandParameters(storagePoolId);
tempVar.setIgnoreFailoverLimit(true);
VDSReturnValue storagePoolInfoResult = resourceManager.runVdsCommand(VDSCommandType.GetStoragePoolInfo, tempVar);
if (storagePoolInfoResult.getSucceeded()) {
KeyValuePairCompat<StoragePool, List<StorageDomain>> data = (KeyValuePairCompat<StoragePool, List<StorageDomain>>) storagePoolInfoResult.getReturnValue();
int masterVersion = data.getKey().getMasterDomainVersion();
HashSet<Guid> domainsInVds = new HashSet<>();
List<StorageDomain> storageDomainsToSync = data.getValue().stream().peek(storageDomain -> domainsInVds.add(storageDomain.getId())).filter(storageDomain -> proceedStorageDomain(storageDomain, masterVersion, storagePool)).collect(Collectors.toList());
if (!storageDomainsToSync.isEmpty()) {
getEventListener().syncStorageDomainsLuns(getCurrentVdsId(), storageDomainsToSync.stream().map(StorageDomain::getId).collect(Collectors.toList()));
}
for (final StorageDomain domainInDb : domainsInDb) {
if (domainInDb.getStorageDomainType() != StorageDomainType.Master && domainInDb.getStatus() != StorageDomainStatus.Locked && !domainInDb.getStorageType().isCinderDomain() && !domainsInVds.contains(domainInDb.getId())) {
// domain not attached to pool anymore
storagePoolIsoMapDao.remove(new StoragePoolIsoMapId(domainInDb.getId(), storagePoolId));
}
}
}
domainsInMaintenanceCheck(domainsInDb, storagePool);
}
use of org.ovirt.engine.core.common.businessentities.StoragePool in project ovirt-engine by oVirt.
the class IrsProxy method getIrsProxy.
public IIrsServer getIrsProxy() {
if (getmIrsProxy() == null) {
final StoragePool storagePool = storagePoolDao.get(storagePoolId);
// don't try to start spm on uninitialized pool
if (storagePool.getStatus() != StoragePoolStatus.Uninitialized) {
String host = TransactionSupport.executeInScope(TransactionScopeOption.Suppress, () -> getHostFromVds());
if (host != null) {
// Get the values of the timeouts:
int clientTimeOut = Config.<Integer>getValue(ConfigValues.vdsTimeout) * 1000;
int connectionTimeOut = Config.<Integer>getValue(ConfigValues.vdsConnectionTimeout) * 1000;
int heartbeat = Config.<Integer>getValue(ConfigValues.vdsHeartbeatInSeconds) * 1000;
int clientRetries = Config.<Integer>getValue(ConfigValues.vdsRetries);
irsProxy = TransportFactory.createIrsServer(host, getmIrsPort(), clientTimeOut, connectionTimeOut, clientRetries, heartbeat, resourceManager.getExecutor());
runStoragePoolUpEvent(storagePool);
}
}
}
return getmIrsProxy();
}
Aggregations