use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class StorageHandlingCommandBase method getLatestOVFDisk.
/**
* Returns the best match for OVF disk from all the disks. If no OVF disk was found, it returns null for disk and
* size 0. If there are OVF disks, we first match the updated ones, and from them we retrieve the one which was last
* updated.
*
* @param ovfStoreDiskImages
* - A list of OVF_STORE disks
* @return A Pair which contains the best OVF disk to retrieve data from and its size.
*/
private Pair<DiskImage, Long> getLatestOVFDisk(List<DiskImage> ovfStoreDiskImages) {
Date foundOvfDiskUpdateDate = new Date();
boolean isFoundOvfDiskUpdated = false;
Long size = 0L;
Disk ovfDisk = null;
for (DiskImage ovfStoreDisk : ovfStoreDiskImages) {
boolean isBetterOvfDiskFound = false;
Map<String, Object> diskDescriptionMap;
try {
diskDescriptionMap = JsonHelper.jsonToMap(ovfStoreDisk.getDescription());
} catch (IOException e) {
log.warn("Exception while generating json containing ovf store info: {}", e.getMessage());
log.debug("Exception", e);
continue;
}
boolean isUpdated = Boolean.valueOf(diskDescriptionMap.get(OvfInfoFileConstants.IsUpdated).toString());
Date date = getDateFromDiskDescription(diskDescriptionMap);
if (date == null) {
continue;
}
if (isFoundOvfDiskUpdated && !isUpdated) {
continue;
}
if ((isUpdated && !isFoundOvfDiskUpdated) || date.after(foundOvfDiskUpdateDate)) {
isBetterOvfDiskFound = true;
}
if (isBetterOvfDiskFound) {
isFoundOvfDiskUpdated = isUpdated;
foundOvfDiskUpdateDate = date;
ovfDisk = ovfStoreDisk;
size = Long.valueOf(diskDescriptionMap.get(OvfInfoFileConstants.Size).toString());
}
}
return new Pair<>((DiskImage) ovfDisk, size);
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class CINDERStorageHelper method registerLibvirtSecrets.
public Pair<Boolean, EngineFault> registerLibvirtSecrets(StorageDomain storageDomain, VDS vds, List<LibvirtSecret> libvirtSecrets) {
VDSReturnValue returnValue;
if (!libvirtSecrets.isEmpty()) {
try {
returnValue = backend.getResourceManager().runVdsCommand(VDSCommandType.RegisterLibvirtSecrets, new RegisterLibvirtSecretsVDSParameters(vds.getId(), libvirtSecrets));
} catch (RuntimeException e) {
log.error("Failed to register libvirt secret for storage domain {} on vds {}. Error: {}", storageDomain.getName(), vds.getName(), e.getMessage());
log.debug("Exception", e);
return new Pair<>(false, null);
}
if (!returnValue.getSucceeded()) {
addMessageToAuditLog(AuditLogType.FAILED_TO_REGISTER_LIBVIRT_SECRET, storageDomain, vds);
log.error("Failed to register libvirt secret for storage domain {} on vds {}.", storageDomain.getName(), vds.getName());
EngineFault engineFault = new EngineFault();
engineFault.setError(returnValue.getVdsError().getCode());
return new Pair<>(false, engineFault);
}
}
return new Pair<>(true, null);
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class CINDERStorageHelper method runConnectionStorageToDomain.
@Override
protected Pair<Boolean, EngineFault> runConnectionStorageToDomain(StorageDomain storageDomain, Guid vdsId, int type) {
Provider<?> provider = providerDao.get(Guid.createGuidFromString(storageDomain.getStorage()));
List<LibvirtSecret> libvirtSecrets = libvirtSecretDao.getAllByProviderId(provider.getId());
VDS vds = vdsDao.get(vdsId);
if (!isLibrbdAvailable(vds)) {
log.error("Couldn't found librbd1 package on vds {} (needed for storage domain {}).", vds.getName(), storageDomain.getName());
addMessageToAuditLog(AuditLogType.NO_LIBRBD_PACKAGE_AVAILABLE_ON_VDS, null, vds);
return new Pair<>(false, null);
}
return registerLibvirtSecrets(storageDomain, vds, libvirtSecrets);
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class ConnectAllHostsToLunCommand method connectVdsToLun.
/**
* The following method will connect all provided lund to all running host in pool
*
* @param luns
* - the luns which should be connected
* @return the map where the key is true/false value which means if connection successes/not successes and value is
* map of luns Ids -> connected hosts
*/
private Pair<Boolean, Map<String, List<Guid>>> connectVdsToLun(List<LUNs> luns) {
Map<String, List<Guid>> resultMap = new HashMap<>();
for (VDS vds : getAllRunningVdssInPool()) {
// try to connect vds to luns and getDeviceList in order to refresh them
for (LUNs lun : luns) {
if (!connectStorageToLunByVdsId(vds, lun)) {
log.error("Could not connect host '{}' to lun '{}'", vds.getName(), lun.getLUNId());
setVds(vds);
handleFailure(vds, lun);
return new Pair<>(Boolean.FALSE, resultMap);
} else {
List<Guid> hosts = resultMap.get(lun.getLUNId());
if (hosts == null) {
hosts = new ArrayList<>();
resultMap.put(lun.getLUNId(), hosts);
}
hosts.add(vds.getId());
}
}
// Refresh all connected luns to host
if (!validateConnectedLuns(vds, getParameters().getLunIds())) {
return new Pair<>(Boolean.FALSE, resultMap);
}
}
return new Pair<>(Boolean.TRUE, resultMap);
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class SyncMacsOfDbNicsWithSnapshot method auditLogPerformedReplacements.
private void auditLogPerformedReplacements(List<Pair<String, String>> macReplacements) {
AuditLogable event = new AuditLogableImpl();
List<String> replacementsString = macReplacements.stream().map(e -> e.getFirst() + "->" + e.getSecond()).collect(Collectors.toList());
String auditLogMessage = "Following MACs had to be reallocated: " + replacementsString;
auditLogDirector.log(event, AuditLogType.MAC_ADDRESS_HAD_TO_BE_REALLOCATED, auditLogMessage);
}
Aggregations