use of org.ovirt.engine.core.common.scheduling.ClusterPolicy in project ovirt-engine by oVirt.
the class Cloner method cloneClusterPolicy.
private static Object cloneClusterPolicy(ClusterPolicy clusterPolicy) {
ClusterPolicy obj = new ClusterPolicy();
if (clusterPolicy.getId() != null) {
obj.setId(clusterPolicy.getId());
}
obj.setName(clusterPolicy.getName());
obj.setDescription(clusterPolicy.getDescription());
obj.setLocked(clusterPolicy.isLocked());
obj.setDefaultPolicy(clusterPolicy.isDefaultPolicy());
if (clusterPolicy.getFilters() != null) {
obj.setFilters(new ArrayList<Guid>());
for (Guid policyUnitId : clusterPolicy.getFilters()) {
obj.getFilters().add(policyUnitId);
}
}
if (clusterPolicy.getFilterPositionMap() != null) {
obj.setFilterPositionMap(new HashMap<Guid, Integer>());
for (Entry<Guid, Integer> entry : clusterPolicy.getFilterPositionMap().entrySet()) {
obj.getFilterPositionMap().put(entry.getKey(), entry.getValue());
}
}
if (clusterPolicy.getFunctions() != null) {
obj.setFunctions(new ArrayList<Pair<Guid, Integer>>());
for (Pair<Guid, Integer> pair : clusterPolicy.getFunctions()) {
obj.getFunctions().add(new Pair<>(pair.getFirst(), pair.getSecond()));
}
}
if (clusterPolicy.getBalance() != null) {
obj.setBalance(clusterPolicy.getBalance());
}
if (clusterPolicy.getParameterMap() != null) {
obj.setParameterMap(new LinkedHashMap());
for (Entry<String, String> entry : clusterPolicy.getParameterMap().entrySet()) {
obj.getParameterMap().put(entry.getKey(), entry.getValue());
}
}
return obj;
}
use of org.ovirt.engine.core.common.scheduling.ClusterPolicy in project ovirt-engine by oVirt.
the class BackendWeightResource method remove.
@Override
public Response remove() {
ClusterPolicy entity = parent.getClusterPolicy();
updateEntityForRemove(entity, guid);
return performAction(ActionType.EditClusterPolicy, new ClusterPolicyCRUDParameters(entity.getId(), entity));
}
use of org.ovirt.engine.core.common.scheduling.ClusterPolicy in project ovirt-engine by oVirt.
the class UpdateClusterCommandTest method createCommand.
private void createCommand(final Cluster group) {
cmd.getParameters().setManagementNetworkId(managementNetworkId);
cmd.getParameters().setCluster(group);
cmd.setClusterId(group.getId());
doReturn(clusterDao).when(dbFacadeMock).getClusterDao();
doReturn(storagePoolDao).when(dbFacadeMock).getStoragePoolDao();
doReturn(true).when(cmd).isSupportedEmulatedMachinesMatchClusterLevel(any());
// cluster upgrade
doReturn(new ClusterPolicy()).when(schedulingManager).getClusterPolicy(any(Guid.class));
final ClusterPolicy clusterPolicy = new ClusterPolicy();
clusterPolicy.setId(ClusterPolicy.UPGRADE_POLICY_GUID);
doReturn(clusterPolicy).when(schedulingManager).getClusterPolicy(eq(ClusterPolicy.UPGRADE_POLICY_GUID));
if (StringUtils.isEmpty(group.getCpuName())) {
doReturn(ArchitectureType.undefined).when(cmd).getArchitecture();
} else {
doReturn(ArchitectureType.x86_64).when(cmd).getArchitecture();
}
when(clusterDao.get(any())).thenReturn(createDefaultCluster());
when(clusterDao.getByName(any())).thenReturn(createDefaultCluster());
List<Cluster> clusterList = new ArrayList<>();
clusterList.add(createDefaultCluster());
when(clusterDao.getByName(any(), anyBoolean())).thenReturn(clusterList);
Map<String, String> migrationMap = new HashMap<>();
migrationMap.put("undefined", "true");
migrationMap.put("x86", "true");
migrationMap.put("ppc", "true");
mcr.mockConfigValue(ConfigValues.IsMigrationSupported, cmd.getCluster().getCompatibilityVersion(), migrationMap);
}
use of org.ovirt.engine.core.common.scheduling.ClusterPolicy in project ovirt-engine by oVirt.
the class ClusterOperationCommandBase method validateClusterPolicy.
protected boolean validateClusterPolicy(Cluster oldCluster) {
Cluster newCluster = getCluster();
boolean alreadyInUpgradeMode = oldCluster != null && oldCluster.isInUpgradeMode();
ClusterPolicy clusterPolicy = getClusterPolicy(newCluster);
if (clusterPolicy == null) {
return false;
}
newCluster.setClusterPolicyId(clusterPolicy.getId());
if (alreadyInUpgradeMode && !newCluster.isInUpgradeMode()) {
// Check if we can safely stop the cluster upgrade
final List<VDS> hosts = vdsDao.getAllForCluster(getClusterId());
if (!validate(getUpgradeValidator().isUpgradeDone(hosts))) {
return false;
}
} else if (!alreadyInUpgradeMode && newCluster.isInUpgradeMode()) {
final List<VDS> hosts = vdsDao.getAllForCluster(getClusterId());
final List<VM> vms = vmDao.getAllForCluster(getClusterId());
populateVMNUMAInfo(vms);
if (!validate(getUpgradeValidator().isUpgradePossible(hosts, vms))) {
return false;
}
}
Map<String, String> customPropertiesRegexMap = getSchedulingManager().getCustomPropertiesRegexMap(clusterPolicy);
updateClusterPolicyProperties(getCluster(), clusterPolicy, customPropertiesRegexMap);
List<ValidationError> validationErrors = SimpleCustomPropertiesUtil.getInstance().validateProperties(customPropertiesRegexMap, getCluster().getClusterPolicyProperties());
if (!validationErrors.isEmpty()) {
SimpleCustomPropertiesUtil.getInstance().handleCustomPropertiesError(validationErrors, getReturnValue().getValidationMessages());
return false;
}
return true;
}
use of org.ovirt.engine.core.common.scheduling.ClusterPolicy in project ovirt-engine by oVirt.
the class ClusterPolicyCRUDCommandTest method testCheckAddEditValidations.
@Test
public void testCheckAddEditValidations() {
Guid clusterPolicyId = new Guid("e754440b-76a6-4099-8235-4565ab4b5521");
ClusterPolicy clusterPolicy = new ClusterPolicy();
clusterPolicy.setId(clusterPolicyId);
ClusterPolicyCRUDCommand command = new ClusterPolicyCRUDCommand(new ClusterPolicyCRUDParameters(clusterPolicyId, clusterPolicy), null) {
@Override
protected void executeCommand() {
}
};
command.schedulingManager = schedulingManager;
assertTrue(command.checkAddEditValidations());
}
Aggregations