use of org.ovirt.engine.core.common.businessentities.ServerCpu in project ovirt-engine by oVirt.
the class CpuLevelFilterPolicyUnit method filter.
@Override
public List<VDS> filter(Cluster cluster, List<VDS> hosts, VM vm, Map<String, String> parameters, PerHostMessages messages) {
List<VDS> hostsToRunOn = new ArrayList<>();
// full name of the vm cpu
String customCpu;
Version latestVer = cpuFlagsManagerHandler.getLatestDictionaryVersion();
/* get required cpu name */
if (StringUtils.isNotEmpty(vm.getCpuName())) {
// dynamic check - used for 1.migrating vms 2.run-once 3.after dynamic field is updated with current static-field\cluster
customCpu = vm.getCpuName();
} else if (StringUtils.isNotEmpty(vm.getCustomCpuName())) {
// static check - used only for cases where the dynamic value hasn't been updated yet(validate)
customCpu = vm.getCustomCpuName();
} else {
// use cluster default - all hosts are valid
return hosts;
}
// translate vdsVerb to full cpu name
customCpu = cpuFlagsManagerHandler.getCpuNameByCpuId(customCpu, latestVer);
if (StringUtils.isNotEmpty(customCpu)) {
/* find compatible hosts */
for (VDS host : hosts) {
ServerCpu cpu = cpuFlagsManagerHandler.findMaxServerCpuByFlags(host.getCpuFlags(), latestVer);
String hostCpuName = cpu == null ? null : cpu.getCpuName();
if (StringUtils.isNotEmpty(hostCpuName)) {
if (cpuFlagsManagerHandler.checkIfCpusSameManufacture(customCpu, hostCpuName, latestVer)) {
// verify comparison uses only one cpu-level scale
int compareResult = cpuFlagsManagerHandler.compareCpuLevels(customCpu, hostCpuName, latestVer);
if (compareResult <= 0) {
hostsToRunOn.add(host);
log.debug("Host '{}' wasn't filtered out as it has a CPU level ({}) which is higher or equal than the CPU level the VM was run with ({})", host.getName(), hostCpuName, customCpu);
} else {
log.debug("Host '{}' was filtered out as it has a CPU level ({}) which is lower than the CPU level the VM was run with ({})", host.getName(), hostCpuName, customCpu);
messages.addMessage(host.getId(), String.format("$hostCPULevel %1$s", hostCpuName));
messages.addMessage(host.getId(), String.format("$vmCPULevel %1$s", customCpu));
messages.addMessage(host.getId(), EngineMessage.VAR__DETAIL__LOW_CPU_LEVEL.toString());
}
}
}
}
}
return hostsToRunOn;
}
use of org.ovirt.engine.core.common.businessentities.ServerCpu in project ovirt-engine by oVirt.
the class BackendClusterLevelsResource method makeClusterLevel.
public ClusterLevel makeClusterLevel(String version) {
ClusterLevel level = new ClusterLevel();
level.setId(version);
// Not exposing CPU list filtered queries:
if (!isFiltered()) {
CpuTypes cpuTypes = new CpuTypes();
for (ServerCpu serverCpu : getServerCpuList(version)) {
CpuType cpuType = new CpuType();
cpuType.setName(serverCpu.getCpuName());
cpuType.setLevel(serverCpu.getLevel());
cpuType.setArchitecture(CPUMapper.map(serverCpu.getArchitecture(), null));
cpuTypes.getCpuTypes().add(cpuType);
}
level.setCpuTypes(cpuTypes);
}
// Add permits:
Permits permits = new Permits();
for (ActionGroup actionGroup : getActionGroups()) {
Permit permit = PermitMapper.map(actionGroup, null);
permits.getPermits().add(permit);
}
level.setPermits(permits);
return LinkHelper.addLinks(level);
}
use of org.ovirt.engine.core.common.businessentities.ServerCpu in project ovirt-engine by oVirt.
the class AsyncDataProvider method initCpuMap.
private void initCpuMap() {
cpuMap = new HashMap<>();
final List<QueryType> queryTypes = new ArrayList<>();
final List<QueryParametersBase> queryParams = new ArrayList<>();
for (Version version : Version.ALL) {
queryTypes.add(QueryType.GetAllServerCpuList);
queryParams.add(new GetAllServerCpuListParameters(version));
}
final IFrontendMultipleQueryAsyncCallback callback = result -> {
for (int i = 0; i < result.getReturnValues().size(); i++) {
final List<ServerCpu> cpus = result.getReturnValues().get(i).getReturnValue();
final Version version = ((GetAllServerCpuListParameters) result.getParameters().get(i)).getVersion();
initCpuMapForVersion(version, cpus);
}
};
Frontend.getInstance().runMultipleQueries(queryTypes, queryParams, callback);
}
use of org.ovirt.engine.core.common.businessentities.ServerCpu in project ovirt-engine by oVirt.
the class SearchQueryTest method mockCpuFlagsManagerHandler.
@Before
public void mockCpuFlagsManagerHandler() {
ServerCpu resultCpu = new ServerCpu();
resultCpu.setCpuName("cpu");
when(cpuFlagsManagerHandler.findMaxServerCpuByFlags("flag", Version.getLast())).thenReturn(resultCpu);
}
use of org.ovirt.engine.core.common.businessentities.ServerCpu in project ovirt-engine by oVirt.
the class GetHostArchitectureQuery method executeQueryCommand.
@Override
protected void executeQueryCommand() {
VDS host = vdsDao.get(getParameters().getId());
ServerCpu sc = cpuFlagsManagerHandler.findMaxServerCpuByFlags(host.getCpuFlags(), host.getClusterCompatibilityVersion());
getQueryReturnValue().setReturnValue(sc == null ? ArchitectureType.undefined : sc.getArchitecture());
}
Aggregations