use of org.ovirt.engine.core.compat.KeyValuePairCompat 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.compat.KeyValuePairCompat in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommand method updateOvfForVmsOfStoragePool.
/**
* Update ovfs for updated/newly vms since last run for the given storage pool
*/
protected void updateOvfForVmsOfStoragePool(StoragePool pool) {
Guid poolId = pool.getId();
List<Guid> vmsIdsForUpdate = vmAndTemplatesGenerationsDao.getVmsIdsForOvfUpdate(poolId);
int i = 0;
while (i < vmsIdsForUpdate.size()) {
int size = Math.min(itemsCountPerUpdate, vmsIdsForUpdate.size() - i);
List<Guid> idsToProcess = vmsIdsForUpdate.subList(i, i + size);
i += size;
Map<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndTemplateMetadata = populateVmsMetadataForOvfUpdate(idsToProcess);
if (!vmsAndTemplateMetadata.isEmpty()) {
performOvfUpdate(vmsAndTemplateMetadata);
}
}
}
use of org.ovirt.engine.core.compat.KeyValuePairCompat in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommand method populateVmsMetadataForOvfUpdate.
/**
* Create and returns map contains valid vms metadata
*/
protected Map<Guid, KeyValuePairCompat<String, List<Guid>>> populateVmsMetadataForOvfUpdate(List<Guid> idsToProcess) {
Map<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndTemplateMetadata = new HashMap<>();
List<VM> vms = vmDao.getVmsByIds(idsToProcess);
for (VM vm : vms) {
if (VMStatus.ImageLocked != vm.getStatus()) {
updateVmDisksFromDb(vm);
if (!verifyImagesStatus(vm.getDiskList())) {
continue;
}
ArrayList<DiskImage> vmImages = ovfUpdateProcessHelper.getVmImagesFromDb(vm);
if (!verifyImagesStatus(vmImages)) {
continue;
}
vm.setSnapshots(snapshotDao.getAllWithConfiguration(vm.getId()));
if (!verifySnapshotsStatus(vm.getSnapshots())) {
continue;
}
ovfUpdateProcessHelper.loadVmData(vm);
Long currentDbGeneration = vmStaticDao.getDbGeneration(vm.getId());
if (currentDbGeneration == null) {
log.warn("currentDbGeneration of VM (name: '{}', id: '{}') is null, probably because the VM was deleted during the run of OvfDataUpdater.", vm.getName(), vm.getId());
continue;
}
if (vm.getStaticData().getDbGeneration() == currentDbGeneration) {
List<LunDisk> lunDisks = DisksFilter.filterLunDisks(vm.getDiskMap().values());
for (LunDisk lun : lunDisks) {
lun.getLun().setLunConnections(new ArrayList<>(storageServerConnectionDao.getAllForLun(lun.getLun().getId())));
}
List<AffinityGroup> affinityGroups = affinityGroupDao.getAllAffinityGroupsByVmId(vm.getId());
List<Label> affinityLabels = labelDao.getAllByEntityIds(Collections.singletonList(vm.getId()));
Set<DbUser> dbUsers = new HashSet<>(dbUserDao.getAllForVm(vm.getId()));
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
fullEntityOvfData.setDiskImages(vmImages);
fullEntityOvfData.setLunDisks(lunDisks);
fullEntityOvfData.setAffinityGroups(affinityGroups);
fullEntityOvfData.setAffinityLabels(affinityLabels);
fullEntityOvfData.setDbUsers(dbUsers);
ovfHelper.populateUserToRoles(fullEntityOvfData, vm.getId());
proccessedOvfConfigurationsInfo.add(ovfUpdateProcessHelper.buildMetadataDictionaryForVm(vm, vmsAndTemplateMetadata, fullEntityOvfData));
proccessedIdsInfo.add(vm.getId());
proccessedOvfGenerationsInfo.add(vm.getStaticData().getDbGeneration());
proccessDisksDomains(vm.getDiskList());
}
}
}
return vmsAndTemplateMetadata;
}
use of org.ovirt.engine.core.compat.KeyValuePairCompat in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommand method updateOvfForTemplatesOfStoragePool.
/**
* Update ovfs for updated/added templates since last for the given storage pool
*/
protected void updateOvfForTemplatesOfStoragePool(StoragePool pool) {
Guid poolId = pool.getId();
List<Guid> templateIdsForUpdate = vmAndTemplatesGenerationsDao.getVmTemplatesIdsForOvfUpdate(poolId);
int i = 0;
while (i < templateIdsForUpdate.size()) {
int size = Math.min(templateIdsForUpdate.size() - i, itemsCountPerUpdate);
List<Guid> idsToProcess = templateIdsForUpdate.subList(i, i + size);
i += size;
Map<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndTemplateMetadata = populateTemplatesMetadataForOvfUpdate(idsToProcess);
if (!vmsAndTemplateMetadata.isEmpty()) {
performOvfUpdate(vmsAndTemplateMetadata);
}
}
}
use of org.ovirt.engine.core.compat.KeyValuePairCompat in project ovirt-engine by oVirt.
the class UpdateVMVDSCommand method buildVmsStuctListFromParameters.
private Map[] buildVmsStuctListFromParameters() {
// ("vm":vmGUID, "ovf":metaOVF, "imglist":imgList)
Map[] result = new Map[getParameters().getInfoDictionary().entrySet().size()];
int counter = 0;
for (Map.Entry<Guid, KeyValuePairCompat<String, List<Guid>>> data : getParameters().getInfoDictionary().entrySet()) {
Map vmToSend = new HashMap();
vmToSend.put("vm", data.getKey().toString());
vmToSend.put("ovf", data.getValue().getKey());
List<Guid> imagesGuidList = data.getValue().getValue();
String[] imageList = new String[imagesGuidList.size()];
for (int i = 0; i < imagesGuidList.size(); i++) {
imageList[i] = imagesGuidList.get(i).toString();
}
vmToSend.put("imglist", StringUtils.join(imageList, ','));
result[counter] = vmToSend;
counter++;
}
return result;
}
Aggregations