Search in sources :

Example 31 with ClusterPolicy

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;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) LinkedHashMap(java.util.LinkedHashMap) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 32 with ClusterPolicy

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));
}
Also used : ClusterPolicyCRUDParameters(org.ovirt.engine.core.common.scheduling.parameters.ClusterPolicyCRUDParameters) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy)

Example 33 with ClusterPolicy

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy)

Example 34 with ClusterPolicy

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;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) ArrayList(java.util.ArrayList) List(java.util.List) ValidationError(org.ovirt.engine.core.common.utils.customprop.ValidationError) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy)

Example 35 with ClusterPolicy

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());
}
Also used : ClusterPolicyCRUDParameters(org.ovirt.engine.core.common.scheduling.parameters.ClusterPolicyCRUDParameters) Guid(org.ovirt.engine.core.compat.Guid) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Aggregations

ClusterPolicy (org.ovirt.engine.core.common.scheduling.ClusterPolicy)37 Guid (org.ovirt.engine.core.compat.Guid)20 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 ClusterPolicyCRUDParameters (org.ovirt.engine.core.common.scheduling.parameters.ClusterPolicyCRUDParameters)7 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)4 PolicyUnit (org.ovirt.engine.core.common.scheduling.PolicyUnit)4 VDS (org.ovirt.engine.core.common.businessentities.VDS)3 Pair (org.ovirt.engine.core.common.utils.Pair)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)2 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 ValidationError (org.ovirt.engine.core.common.utils.customprop.ValidationError)2 Arrays (java.util.Arrays)1