use of org.ovirt.engine.core.common.utils.customprop.ValidationError in project ovirt-engine by oVirt.
the class HostSetupNetworksValidator method validateCustomProperties.
ValidationResult validateCustomProperties(SimpleCustomPropertiesUtil util, Map<String, String> validPropertiesForVm, Map<String, String> validPropertiesForNonVm) {
for (NetworkAttachment attachment : params.getNetworkAttachments()) {
Network network = existingNetworkRelatedToAttachment(attachment);
if (attachment.hasProperties()) {
List<ValidationError> errors = util.validateProperties(network.isVmNetwork() ? validPropertiesForVm : validPropertiesForNonVm, attachment.getProperties());
if (!errors.isEmpty()) {
handleCustomPropertiesError(util, errors);
EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_NETWORK_CUSTOM_PROPERTIES_BAD_INPUT;
return new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentStringWithMultipleValues(engineMessage, network.getName()));
}
}
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.utils.customprop.ValidationError in project ovirt-engine by oVirt.
the class ClusterPolicyCRUDCommand method checkAddEditValidations.
protected boolean checkAddEditValidations() {
List<ClusterPolicy> clusterPolicies = schedulingManager.getClusterPolicies();
if (getClusterPolicy() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID);
}
for (ClusterPolicy clusterPolicy : clusterPolicies) {
if (!clusterPolicy.getId().equals(getClusterPolicy().getId()) && clusterPolicy.getName().equals(getClusterPolicy().getName())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_NAME_INUSE);
}
}
Map<Guid, PolicyUnitImpl> map = schedulingManager.getPolicyUnitsMap();
Set<Guid> existingPolicyUnits = new HashSet<>();
// check filter policy units
if (getClusterPolicy().getFilters() != null) {
for (Guid filterId : getClusterPolicy().getFilters()) {
if (isPolicyUnitExists(filterId, existingPolicyUnits)) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT);
}
PolicyUnitImpl policyUnitImpl = map.get(filterId);
if (policyUnitImpl == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
}
if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.FILTER) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_FILTER_NOT_IMPLEMENTED);
}
}
}
// check filters positions (there could be only one filter attached to first (-1) and last (-1)
if (getClusterPolicy().getFilterPositionMap() != null) {
boolean hasFirst = false;
boolean hasLast = false;
for (Integer position : getClusterPolicy().getFilterPositionMap().values()) {
if (position == -1) {
if (!hasFirst) {
hasFirst = true;
} else {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_ONLY_ONE_FILTER_CAN_BE_FIRST);
}
} else if (position == 1) {
if (!hasLast) {
hasLast = true;
} else {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_ONLY_ONE_FILTER_CAN_BE_LAST);
}
}
}
}
// check function policy units
if (getClusterPolicy().getFunctions() != null) {
for (Pair<Guid, Integer> functionPair : getClusterPolicy().getFunctions()) {
if (isPolicyUnitExists(functionPair.getFirst(), existingPolicyUnits)) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT);
}
PolicyUnitImpl policyUnitImpl = map.get(functionPair.getFirst());
if (policyUnitImpl == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
}
if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.WEIGHT) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_FUNCTION_NOT_IMPLEMENTED);
}
if (functionPair.getSecond() < 0) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_FUNCTION_FACTOR_NEGATIVE);
}
}
}
// check balance policy unit
if (getClusterPolicy().getBalance() != null) {
PolicyUnitImpl policyUnitImpl = map.get(getClusterPolicy().getBalance());
if (policyUnitImpl == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
}
if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.LOAD_BALANCING) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_BALANCE_NOT_IMPLEMENTED);
}
}
// check selector policy unit
if (getClusterPolicy().getSelector() != null) {
PolicyUnitImpl policyUnitImpl = map.get(getClusterPolicy().getSelector());
if (policyUnitImpl == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
}
if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.SELECTOR) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_SELECTOR_NOT_IMPLEMENTED);
}
}
List<ValidationError> validationErrors = SimpleCustomPropertiesUtil.getInstance().validateProperties(schedulingManager.getCustomPropertiesRegexMap(getClusterPolicy()), getClusterPolicy().getParameterMap());
if (!validationErrors.isEmpty()) {
SimpleCustomPropertiesUtil.getInstance().handleCustomPropertiesError(validationErrors, getReturnValue().getValidationMessages());
return false;
}
return true;
}
use of org.ovirt.engine.core.common.utils.customprop.ValidationError in project ovirt-engine by oVirt.
the class DevicePropertiesUtils method validateProperties.
/**
* Validates the custom properties of a device. These errors are checked during validation:
* <ol>
* <li>Device custom properties are supported in version</li>
* <li>Device custom properties can be assigned to specified type</li>
* <li>Device custom properties syntax is ok</li>
* <li>Device custom property is defined for specified version and type</li>
* <li>Device custom property value matches its value constrains</li>
* </ol>
*
* @param version
* version of the cluster that the VM containing the device is in
* @param type
* type of a device
* @param properties
* device custom properties
* @return list of errors appeared during validation
*/
public List<ValidationError> validateProperties(Version version, VmDeviceGeneralType type, Map<String, String> properties) {
if (properties == null || properties.isEmpty()) {
// No errors in case of empty value
return Collections.emptyList();
}
if (!supportedDeviceTypes.contains(type)) {
return invalidDeviceTypeValidationError;
}
if (syntaxErrorInProperties(properties)) {
return invalidSyntaxValidationError;
}
List<ValidationError> results = new ArrayList<>();
Set<ValidationError> errorsSet = new HashSet<>();
for (Map.Entry<String, String> e : properties.entrySet()) {
String key = e.getKey();
if (key == null || !deviceProperties.get(version).get(type).containsKey(key)) {
errorsSet.add(new ValidationError(ValidationFailureReason.KEY_DOES_NOT_EXIST, key));
continue;
}
String value = StringUtils.defaultString(e.getValue());
if (!value.matches(deviceProperties.get(version).get(type).get(key))) {
errorsSet.add(new ValidationError(ValidationFailureReason.INCORRECT_VALUE, key));
continue;
}
}
results.addAll(errorsSet);
return results;
}
use of org.ovirt.engine.core.common.utils.customprop.ValidationError 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.utils.customprop.ValidationError in project ovirt-engine by oVirt.
the class VnicProfileValidator method validateCustomProperties.
public boolean validateCustomProperties(List<String> messages) {
StoragePool dataCenter = dcDao.get(getNetwork().getDataCenterId());
List<ValidationError> errors = DevicePropertiesUtils.getInstance().validateProperties(dataCenter.getCompatibilityVersion(), VmDeviceGeneralType.INTERFACE, vnicProfile.getCustomProperties());
if (!errors.isEmpty()) {
DevicePropertiesUtils.getInstance().handleCustomPropertiesError(errors, messages);
return false;
}
return true;
}
Aggregations