use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class ExportOvaCommand method validateTargetFolder.
private ValidationResult validateTargetFolder() {
AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(getVds().getHostName()).variables(new Pair<>("target_directory", getParameters().getDirectory()), new Pair<>("validate_only", "True")).logFileDirectory(CreateOvaCommand.CREATE_OVA_LOG_DIRECTORY).logFilePrefix("ovirt-export-ova-validate-ansible").logFileName(getVds().getHostName()).logFileSuffix(getCorrelationId()).playbook(AnsibleConstants.EXPORT_OVA_PLAYBOOK);
boolean succeeded = false;
try {
succeeded = ansibleExecutor.runCommand(command).getAnsibleReturnCode() == AnsibleReturnCode.OK;
} catch (IOException | InterruptedException e) {
log.error("Invalid target for OVA (directory={}, host={}): {}", getParameters().getDirectory(), getVdsName(), e.getMessage());
log.debug("Exception", e);
}
return succeeded ? ValidationResult.VALID : new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_INVALID_OVA_DESTINATION_FOLDER, String.format("$vdsName %s", getVdsName()), String.format("$directory %s", getParameters().getDirectory()));
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class ExtractOvaCommand method runAnsibleImportOvaPlaybook.
private boolean runAnsibleImportOvaPlaybook(List<String> diskPaths) {
AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(getVds().getHostName()).variables(new Pair<>("ovirt_import_ova_path", getParameters().getOvaPath()), new Pair<>("ovirt_import_ova_disks", String.join("+", diskPaths))).logFileDirectory(IMPORT_OVA_LOG_DIRECTORY).logFilePrefix("ovirt-import-ova-ansible").logFileName(getVds().getHostName()).logFileSuffix(getCorrelationId()).playbook(AnsibleConstants.IMPORT_OVA_PLAYBOOK);
boolean succeeded = false;
AnsibleReturnValue ansibleReturnValue = null;
try {
ansibleReturnValue = ansibleExecutor.runCommand(command);
succeeded = ansibleReturnValue.getAnsibleReturnCode() == AnsibleReturnCode.OK;
} catch (IOException | InterruptedException e) {
log.debug("Failed to extract OVA", e);
}
if (!succeeded) {
log.error("Failed to extract OVA. Please check logs for more details: {}", command.logFile());
return false;
}
return true;
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class VmHandler method autoSelectDefaultDisplayType.
/**
* Automatic selection of display type based on its graphics types in parameters.
* This method preserves backward compatibility for REST API - legacy REST API doesn't allow to set display and
* graphics separately.
*/
public void autoSelectDefaultDisplayType(Guid srcEntityId, VmBase parametersStaticData, Cluster cluster, Map<GraphicsType, GraphicsDevice> graphicsDevices) {
if (parametersStaticData.getOsId() == OsRepository.AUTO_SELECT_OS) {
return;
}
List<Pair<GraphicsType, DisplayType>> graphicsAndDisplays = osRepository.getGraphicsAndDisplays(parametersStaticData.getOsId(), CompatibilityVersionUtils.getEffective(parametersStaticData, cluster));
if (parametersStaticData.getDefaultDisplayType() != null && (parametersStaticData.getDefaultDisplayType() == DisplayType.none || isDisplayTypeSupported(parametersStaticData.getDefaultDisplayType(), graphicsAndDisplays))) {
return;
}
DisplayType defaultDisplayType = null;
// map holding display type -> set of supported graphics types for this display type
Map<DisplayType, Set<GraphicsType>> displayGraphicsSupport = new LinkedHashMap<>();
for (Pair<GraphicsType, DisplayType> graphicsAndDisplay : graphicsAndDisplays) {
DisplayType display = graphicsAndDisplay.getSecond();
if (!displayGraphicsSupport.containsKey(display)) {
displayGraphicsSupport.put(display, new HashSet<>());
}
displayGraphicsSupport.get(display).add(graphicsAndDisplay.getFirst());
}
for (Map.Entry<DisplayType, Set<GraphicsType>> entry : displayGraphicsSupport.entrySet()) {
final List<GraphicsType> graphicsTypes = vmDeviceUtils.getGraphicsTypesOfEntity(srcEntityId);
final Set<GraphicsType> resultingVmGraphics = getResultingVmGraphics(graphicsTypes, graphicsDevices);
if (entry.getValue().containsAll(resultingVmGraphics)) {
defaultDisplayType = entry.getKey();
break;
}
}
if (defaultDisplayType == null) {
if (!displayGraphicsSupport.isEmpty()) {
// when not found otherwise, let's take osinfo's record as the default
Map.Entry<DisplayType, Set<GraphicsType>> entry = displayGraphicsSupport.entrySet().iterator().next();
defaultDisplayType = entry.getKey();
} else {
// no osinfo record
defaultDisplayType = DisplayType.qxl;
}
}
parametersStaticData.setDefaultDisplayType(defaultDisplayType);
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class VdsEventListener method processStorageOnVdsInactive.
private void processStorageOnVdsInactive(final VDS vds) {
// anymore.
if (!Guid.Empty.equals(vds.getStoragePoolId())) {
// when vds is being moved to maintenance, this is the part in which we disconnect it from the pool
// and the storage server. it should be synced with the host autorecovery mechanism to try to avoid
// leaving the host with storage/pool connection when it's on maintenance.
EngineLock lock = new EngineLock(Collections.singletonMap(vds.getId().toString(), new Pair<>(LockingGroup.VDS_POOL_AND_STORAGE_CONNECTIONS.toString(), EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED.toString())), null);
try {
lockManager.acquireLockWait(lock);
clearDomainCache(vds);
StoragePool storage_pool = storagePoolDao.get(vds.getStoragePoolId());
if (StoragePoolStatus.Uninitialized != storage_pool.getStatus()) {
vdsBroker.runVdsCommand(VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters(vds.getId(), vds.getStoragePoolId(), vds.getVdsSpmId()));
HostStoragePoolParametersBase params = new HostStoragePoolParametersBase(storage_pool, vds);
backend.runInternalAction(ActionType.DisconnectHostFromStoragePoolServers, params);
}
} finally {
lockManager.releaseLock(lock);
}
}
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class SchedulingManager method selectBestHost.
/**
* @param destHostIdList - used for RunAt preselection, overrides the ordering in vdsList
* @param availableVdsList - presorted list of hosts (better hosts first) that are available
*/
private Optional<Guid> selectBestHost(Cluster cluster, VM vm, List<Guid> destHostIdList, List<VDS> availableVdsList, ClusterPolicy policy, Map<String, String> parameters) {
// in case a default destination host was specified and
// it passed filters, return the first found
List<VDS> runnableHosts = new LinkedList<>();
if (destHostIdList.size() > 0) {
// intersect dedicated hosts list with available list
for (VDS vds : availableVdsList) {
for (Guid destHostId : destHostIdList) {
if (destHostId.equals(vds.getId())) {
runnableHosts.add(vds);
}
}
}
}
if (runnableHosts.isEmpty()) {
// no dedicated hosts found
runnableHosts = availableVdsList;
}
switch(runnableHosts.size()) {
case 0:
// no runnable hosts found, nothing found
return Optional.empty();
case 1:
// found single available host, in available list return it
return Optional.of(runnableHosts.get(0).getId());
default:
// select best runnable host with scoring functions (from policy)
List<Pair<Guid, Integer>> functions = policy.getFunctions();
Guid selector = Optional.of(policy).map(ClusterPolicy::getSelector).orElse(defaultSelectorGuid);
PolicyUnitImpl selectorUnit = policyUnits.get(selector);
SelectorInstance selectorInstance = selectorUnit.selector(parameters);
List<Guid> runnableGuids = runnableHosts.stream().map(VDS::getId).collect(Collectors.toList());
selectorInstance.init(functions, runnableGuids);
if (!functions.isEmpty() && shouldWeighClusterHosts(cluster, runnableHosts)) {
Optional<Guid> bestHostByFunctions = runFunctions(selectorInstance, functions, cluster, runnableHosts, vm, parameters);
if (bestHostByFunctions.isPresent()) {
return bestHostByFunctions;
}
}
}
// failed select best runnable host using scoring functions, return the first
return Optional.of(runnableHosts.get(0).getId());
}
Aggregations