use of org.ovirt.engine.core.common.utils.Pair 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.utils.Pair in project ovirt-engine by oVirt.
the class EventVmStatsRefresher method startMonitoring.
@Override
public void startMonitoring() {
allVmStatsOnlyRefresher.startMonitoring();
final String hostname = vdsManager.getVdsHostname();
resourceManager.subscribe(new EventSubscriber(hostname + "|*|VM_status|*") {
@Override
public void onSubscribe(Subscription sub) {
subscription = sub;
subscription.request(1);
}
@Override
public void onNext(Map<String, Object> map) {
try {
long fetchTime = System.nanoTime();
printEventInDebug(map);
List<Pair<VmDynamic, VdsmVm>> vms = convertEvent(map);
if (!vms.isEmpty()) {
getVmsMonitoring().perform(vms, fetchTime, vdsManager, false);
processDevices(vms.stream().map(Pair::getSecond), fetchTime);
}
} finally {
subscription.request(1);
}
}
private void printEventInDebug(Map<String, Object> map) {
if (!log.isDebugEnabled()) {
return;
}
StringBuilder sb = new StringBuilder();
ObjectDescriptor.toStringBuilder(map, sb);
log.debug("processing event for host {} data:\n{}", vdsManager.getVdsName(), sb);
}
@SuppressWarnings("unchecked")
private List<Pair<VmDynamic, VdsmVm>> convertEvent(Map<String, Object> map) {
Double notifyTime = VdsBrokerObjectsBuilder.removeNotifyTimeFromVmStatusEvent(map);
return map.entrySet().stream().map(idToMap -> toMonitoredVm(new Guid(idToMap.getKey()), (Map<String, Object>) idToMap.getValue(), notifyTime)).collect(Collectors.toList());
}
private Pair<VmDynamic, VdsmVm> toMonitoredVm(Guid vmId, Map<String, Object> vmMap, Double notifyTime) {
VmDynamic dbVm = vmDynamicDao.get(vmId);
VdsmVm vdsmVm = dbVm == null ? createVdsmVm(vmId, vmMap, notifyTime) : createVdsmVm(dbVm, vmMap, notifyTime);
return new Pair<>(dbVm, vdsmVm);
}
private VdsmVm createVdsmVm(Guid vmId, Map<String, Object> struct, Double notifyTime) {
VmDynamic fakeVm = new VmDynamic();
fakeVm.setId(vmId);
return createVdsmVm(fakeVm, struct, notifyTime);
}
private VdsmVm createVdsmVm(VmDynamic dbVmDynamic, Map<String, Object> struct, Double notifyTime) {
// send a clone of vm dynamic to be overridden with new data
VmDynamic clonedVmDynamic = new VmDynamic(dbVmDynamic);
VdsBrokerObjectsBuilder.updateVMDynamicData(clonedVmDynamic, struct, vdsManager.getCopyVds());
return new VdsmVm(notifyTime).setVmDynamic(clonedVmDynamic).setDevicesHash(VdsBrokerObjectsBuilder.getVmDevicesHash(struct));
}
@Override
public void onError(Throwable t) {
// communication issue is delivered as a message so we need to request for more
subscription.request(1);
}
@Override
public void onComplete() {
}
});
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class ImportSanStorageModel method getUnregisteredStorageDomains.
protected void getUnregisteredStorageDomains(List<StorageServerConnections> connections) {
VDS vds = getContainer().getHost().getSelectedItem();
Frontend.getInstance().runQuery(QueryType.GetUnregisteredBlockStorageDomains, new GetUnregisteredBlockStorageDomainsParameters(vds.getId(), getType(), connections), new AsyncQuery<QueryReturnValue>(returnValue -> {
Pair<List<StorageDomain>, List<StorageServerConnections>> returnValuePair = returnValue.getReturnValue();
ArrayList<StorageDomain> storageDomains = (ArrayList<StorageDomain>) returnValuePair.getFirst();
ArrayList<StorageServerConnections> connections1 = (ArrayList<StorageServerConnections>) returnValuePair.getSecond();
if (storageDomains != null) {
addStorageDomains(storageDomains);
}
postGetUnregisteredStorageDomains(storageDomains, connections1);
}));
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class GlusterVolumeGeoRepCreateSessionPopupView method initEditors.
private void initEditors() {
showEligibleVolumes = new EntityModelCheckBoxEditor(Align.RIGHT);
startSessionEditor = new EntityModelCheckBoxEditor(Align.RIGHT);
slaveClusterEditor = new ListModelTypeAheadListBoxEditor<>(new ListModelTypeAheadListBoxEditor.NullSafeSuggestBoxRenderer<String>() {
@Override
public String getReplacementStringNullSafe(String data) {
return data;
}
@Override
public String getDisplayStringNullSafe(String data) {
return templates.typeAheadNameDescription(data == null ? constants.empty() : data, constants.empty()).asString();
}
});
slaveHostIpEditor = new ListModelTypeAheadListBoxEditor<>(new ListModelTypeAheadListBoxEditor.NullSafeSuggestBoxRenderer<Pair<String, Guid>>() {
@Override
public String getReplacementStringNullSafe(Pair<String, Guid> data) {
return data.getFirst();
}
@Override
public String getDisplayStringNullSafe(Pair<String, Guid> data) {
return templates.typeAheadNameDescription(data == null ? constants.empty() : data.getFirst(), constants.empty()).asString();
}
});
slaveVolumeEditor = new ListModelTypeAheadListBoxEditor<>(new ListModelTypeAheadListBoxEditor.NullSafeSuggestBoxRenderer<GlusterVolumeEntity>() {
@Override
public String getReplacementStringNullSafe(GlusterVolumeEntity data) {
return data.getName();
}
@Override
public String getDisplayStringNullSafe(GlusterVolumeEntity data) {
return templates.typeAheadNameDescription(data.getName() == null ? constants.empty() : data.getName(), data.getClusterName() == null ? constants.empty() : data.getClusterName()).asString();
}
});
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class AddVmCommand method getSharedLocks.
@Override
protected Map<String, Pair<String, String>> getSharedLocks() {
Map<String, Pair<String, String>> locks = new HashMap<>();
locks.put(getVmTemplateId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.TEMPLATE, new LockMessage(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_IS_USED_FOR_CREATE_VM).with("VmName", getVmName())));
for (DiskImage image : getImagesToCheckDestinationStorageDomains()) {
locks.put(image.getId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.DISK, getDiskSharedLockMessage()));
}
if (getParameters().getPoolId() != null) {
locks.put(getParameters().getPoolId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.VM_POOL, new LockMessage(EngineMessage.ACTION_TYPE_FAILED_VM_POOL_IS_USED_FOR_CREATE_VM).with("VmName", getVmName())));
}
return locks;
}
Aggregations