use of org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters 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.vdscommands.SpmStatusVDSCommandParameters in project ovirt-engine by oVirt.
the class SpmStartVDSCommand method executeVdsBrokerCommand.
@Override
protected void executeVdsBrokerCommand() {
result = getBroker().spmStart(getParameters().getStoragePoolId().toString(), getParameters().getPrevId(), getParameters().getPrevLVER(), getParameters().getRecoveryMode().getValue(), String.valueOf(getParameters().getSCSIFencing()).toLowerCase(), Config.getValue(ConfigValues.MaxNumberOfHostsInStoragePool), getParameters().getStoragePoolFormatType().getValue());
proceedProxyReturnValue();
Guid taskId = new Guid(result.uuid);
AsyncTaskStatus taskStatus;
log.info("spmStart polling started: taskId '{}'", taskId);
do {
// TODO: make configurable
ThreadUtils.sleep(1000L);
taskStatus = (AsyncTaskStatus) resourceManager.runVdsCommand(VDSCommandType.HSMGetTaskStatus, new HSMTaskGuidBaseVDSCommandParameters(vdsId, taskId)).getReturnValue();
log.debug("spmStart polling - task status: '{}'", taskStatus.getStatus());
} while (taskStatus.getStatus() != AsyncTaskStatusEnum.finished && taskStatus.getStatus() != AsyncTaskStatusEnum.unknown);
log.info("spmStart polling ended: taskId '{}' task status '{}'", taskId, taskStatus.getStatus());
if (!taskStatus.getTaskEndedSuccessfully()) {
log.error("Start SPM Task failed - result: '{}', message: {}", taskStatus.getResult(), taskStatus.getMessage());
}
SpmStatusResult spmStatus = (SpmStatusResult) resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(vdsId, getParameters().getStoragePoolId())).getReturnValue();
if (spmStatus != null) {
log.info("spmStart polling ended, spm status: {}", spmStatus.getSpmStatus());
} else {
log.error("spmStart polling ended, failed to get the spm status");
}
try {
resourceManager.runVdsCommand(VDSCommandType.HSMClearTask, new HSMTaskGuidBaseVDSCommandParameters(vdsId, taskId));
} catch (Exception e) {
log.error("Could not clear spmStart task '{}', continuing with SPM selection: {}", taskId, e.getMessage());
log.debug("Exception", e);
}
setReturnValue(spmStatus);
}
use of org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters in project ovirt-engine by oVirt.
the class IrsProxy method failover.
public boolean failover() {
Guid vdsId = currentVdsId;
nullifyInternalProxies();
boolean performFailover = false;
if (vdsId != null) {
try {
VDSReturnValue statusResult = resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(vdsId, storagePoolId));
if (statusResult != null && statusResult.getSucceeded() && (((SpmStatusResult) statusResult.getReturnValue()).getSpmStatus() == SpmStatus.SPM || ((SpmStatusResult) statusResult.getReturnValue()).getSpmStatus() == SpmStatus.Contend)) {
performFailover = resourceManager.runVdsCommand(VDSCommandType.SpmStop, new SpmStopVDSCommandParameters(vdsId, storagePoolId)).getSucceeded();
} else {
performFailover = true;
}
} catch (Exception ex) {
// try to failover to another host if failed to get spm
// status or stop spm
// (in case currentVdsId has wrong id for some reason)
log.error("Could not get spm status on host '{}' for spmStop: {}", vdsId, ex.getMessage());
log.debug("Exception", ex);
performFailover = true;
}
}
if (performFailover) {
log.info("Irs placed on server '{}' failed. Proceed Failover", vdsId);
triedVdssList.add(vdsId);
return true;
} else {
log.error("IRS failover failed - can't allocate vds server");
return false;
}
}
use of org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters in project ovirt-engine by oVirt.
the class IrsProxy method getHostFromVds.
private String getHostFromVds() {
String returnValue = null;
Guid curVdsId = (currentVdsId != null) ? currentVdsId : Guid.Empty;
StoragePool storagePool = storagePoolDao.get(storagePoolId);
if (storagePool == null) {
log.info("hostFromVds::Finished elect spm, storage pool '{}' was removed", storagePoolId);
return null;
}
List<VDS> prioritizedVdsInPool = getPrioritizedVdsInPool();
currentVdsId = null;
// If VDS is in initialize status, wait for it to be up (or until
// configurable timeout is reached)
waitForVdsIfIsInitializing(curVdsId);
// update pool status to problematic while selecting spm
StoragePoolStatus prevStatus = storagePool.getStatus();
if (prevStatus != StoragePoolStatus.NonResponsive) {
try {
getEventListener().storagePoolStatusChange(storagePoolId, StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC_SEARCHING_NEW_SPM, EngineError.ENGINE, TransactionScopeOption.RequiresNew);
} catch (RuntimeException ex) {
throw new IRSStoragePoolStatusException(ex);
}
}
VDS selectedVds = null;
SpmStatusResult spmStatus = null;
if (prioritizedVdsInPool != null && prioritizedVdsInPool.size() > 0) {
selectedVds = prioritizedVdsInPool.get(0);
} else if (!Guid.Empty.equals(curVdsId) && !getTriedVdssList().contains(curVdsId)) {
selectedVds = vdsDao.get(curVdsId);
if (selectedVds.getStatus() != VDSStatus.Up || selectedVds.getVdsSpmPriority() == BusinessEntitiesDefinitions.HOST_MIN_SPM_PRIORITY) {
selectedVds = null;
}
}
if (selectedVds != null) {
// Stores origin host id in case and will be needed to disconnect from storage pool
Guid selectedVdsId = selectedVds.getId();
Integer selectedVdsSpmId = selectedVds.getVdsSpmId();
triedVdssList.add(selectedVdsId);
currentVdsId = selectedVds.getId();
connectStoragePool(selectedVds, storagePool);
VDSReturnValue returnValueFromVds = resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(selectedVds.getId(), storagePoolId));
spmStatus = (SpmStatusResult) returnValueFromVds.getReturnValue();
boolean ignoreSpmStatusResult = returnValueFromVds.getVdsError() != null && returnValueFromVds.getVdsError().getCode() == EngineError.InquireNotSupportedError;
if (spmStatus != null || ignoreSpmStatusResult) {
boolean performedPoolConnect = false;
log.info("hostFromVds::selectedVds - '{}', spmStatus '{}', storage pool '{}', storage pool version '{}'", selectedVds.getName(), spmStatus != null ? spmStatus.getSpmStatus() : "unknown", storagePool.getName(), storagePool.getCompatibilityVersion());
if (ignoreSpmStatusResult) {
spmStatus = startSpm(storagePool, selectedVds, DEFAULT_PREV_ID, DEFAULT_LVER, DEFAULT_PREV_ID);
} else {
if (spmStatus.getSpmStatus() == SpmStatus.Unknown_Pool) {
connectStoragePool(selectedVds, storagePool);
performedPoolConnect = true;
// refresh spmStatus result
spmStatus = (SpmStatusResult) resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(selectedVds.getId(), storagePoolId)).getReturnValue();
log.info("hostFromVds::Connected host to pool - selectedVds - {}, spmStatus {}, storage pool {}", selectedVds.getName(), spmStatus.getSpmStatus(), storagePool.getName());
}
RefObject<VDS> tempRefObject = new RefObject<>(selectedVds);
spmStatus = handleSpmStatusResult(curVdsId, prioritizedVdsInPool, storagePool, tempRefObject, spmStatus);
selectedVds = tempRefObject.argvalue;
}
if (selectedVds != null) {
RefObject<VDS> tempRefObject2 = new RefObject<>(selectedVds);
RefObject<SpmStatusResult> tempRefObject3 = new RefObject<>(spmStatus);
returnValue = handleSelectedVdsForSPM(storagePool, tempRefObject2, tempRefObject3, prevStatus);
selectedVds = tempRefObject2.argvalue;
spmStatus = tempRefObject3.argvalue;
} else {
currentVdsId = null;
}
if (performedPoolConnect && selectedVds == null) {
// if could not start spm on this host and connected to
// pool here
// then disconnect
resourceManager.runVdsCommand(VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters(selectedVdsId, storagePoolId, selectedVdsSpmId));
}
} else {
log.info("hostFromVds::selectedVds - '{}', spmStatus returned null!", selectedVds.getName());
if (returnValueFromVds.getExceptionObject() instanceof IRSNoMasterDomainException) {
throw returnValueFromVds.getExceptionObject();
}
}
}
return returnValue;
}
use of org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters in project ovirt-engine by oVirt.
the class IrsProxy method handleSpmStatusResult.
private SpmStatusResult handleSpmStatusResult(Guid curVdsId, List<VDS> vdsByPool, final StoragePool storagePool, RefObject<VDS> selectedVds, SpmStatusResult spmStatus) {
if (spmStatus.getSpmStatus() == SpmStatus.Free) {
int vdsSpmIdToFence = -1;
boolean startSpm = true;
if (spmStatus.getSpmId() != -1 && !wasVdsManuallyFenced(spmStatus.getSpmId())) {
int spmId = spmStatus.getSpmId();
Guid spmVdsId = Guid.Empty;
VDS spmVds = null;
if (selectedVds.argvalue.getVdsSpmId() == spmId) {
spmVdsId = selectedVds.argvalue.getId();
} else {
for (VDS tempVds : vdsByPool) {
if (tempVds.getVdsSpmId() == spmId) {
log.info("Found spm host '{}', host name: '{}', according to spmId: '{}'.", tempVds.getId(), tempVds.getName(), spmId);
spmVds = tempVds;
break;
}
}
// non operational we want to find it as well
if (spmVds == null) {
List<VDS> nonOperationalVds = vdsDao.getAllForStoragePoolAndStatus(storagePoolId, VDSStatus.NonOperational);
for (VDS tempVds : nonOperationalVds) {
if (tempVds.getVdsSpmId() == spmId) {
spmVds = tempVds;
break;
}
}
}
if (spmVds != null) {
spmVdsId = spmVds.getId();
} else if (!curVdsId.equals(Guid.Empty)) {
VDS currentVds = vdsDao.get(curVdsId);
if (currentVds != null && currentVds.getStatus() == VDSStatus.Up && currentVds.getVdsSpmId() != null && currentVds.getVdsSpmId().equals(spmId)) {
spmVdsId = curVdsId;
spmVds = currentVds;
}
}
}
try {
if (!spmVdsId.equals(Guid.Empty)) {
SpmStatusResult destSpmStatus = (SpmStatusResult) resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(spmVdsId, storagePoolId)).getReturnValue();
log.info("SpmStatus on vds '{}': '{}'", spmVdsId, destSpmStatus == null ? "NULL" : destSpmStatus.getSpmStatus());
// intentionally unreachable code
if (destSpmStatus != null && destSpmStatus.getSpmStatus() == SpmStatus.SPM) {
if (!spmVdsId.equals(selectedVds.argvalue.getId()) && spmVds != null && spmVds.getStatus() == VDSStatus.Up) {
selectedVds.argvalue = spmVds;
startSpm = false;
log.info("Using old spm server: '{}', no start needed", spmVds.getName());
return destSpmStatus;
} else // VDS is non-operational and SPM
{
log.warn("Host reports to be SPM '{}', but is not up.", spmVdsId);
vdsSpmIdToFence = spmStatus.getSpmId();
}
} else // it is not SPM and continue.
if (destSpmStatus == null || (destSpmStatus.getSpmStatus() != SpmStatus.Free && destSpmStatus.getSpmStatus() != SpmStatus.Unknown_Pool)) {
vdsSpmIdToFence = spmStatus.getSpmId();
}
} else {
log.error("SPM Init: could not find reported vds or not up - pool: '{}' vds_spm_id: '{}'", storagePool.getName(), spmStatus.getSpmId());
vdsSpmIdToFence = spmStatus.getSpmId();
}
} catch (Exception ex) {
vdsSpmIdToFence = spmStatus.getSpmId();
}
}
if (startSpm) {
VdsSpmIdMap map = vdsSpmIdMapDao.get(storagePoolId, vdsSpmIdToFence);
if (map != null) {
VDS vdsToFenceObject = vdsDao.get(map.getId());
if (vdsToFenceObject != null) {
log.info("SPM selection - vds seems as spm '{}'", vdsToFenceObject.getName());
if (vdsToFenceObject.getStatus() == VDSStatus.NonResponsive) {
log.warn("spm vds is non responsive, stopping spm selection.");
selectedVds.argvalue = null;
return spmStatus;
} else {
// try to stop spm
VDSReturnValue spmStopReturnValue = resourceManager.runVdsCommand(VDSCommandType.SpmStop, new SpmStopVDSCommandParameters(vdsToFenceObject.getId(), storagePoolId));
// continue with spm selection
if (spmStopReturnValue != null && spmStopReturnValue.getSucceeded()) {
log.info("spm stop succeeded, continuing with spm selection");
} else // if spm stop failed for any reason we stop spm
// selection
{
log.warn("spm stop on spm failed, stopping spm selection!");
selectedVds.argvalue = null;
return spmStatus;
}
}
}
}
spmStatus = startSpm(storagePool, selectedVds.argvalue, spmStatus.getSpmId(), spmStatus.getSpmLVER(), vdsSpmIdToFence);
}
}
return spmStatus;
}
Aggregations