use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class HostSetupNetworksValidator method validateModifiedBondSlaves.
ValidationResult validateModifiedBondSlaves(CreateOrUpdateBond modifiedOrNewBond) {
for (String slaveName : modifiedOrNewBond.getSlaves()) {
VdsNetworkInterface potentialSlave = existingInterfacesMap.get(slaveName);
HostInterfaceValidator slaveHostInterfaceValidator = createHostInterfaceValidator(potentialSlave);
ValidationResult interfaceExists = slaveHostInterfaceValidator.interfaceExists(slaveName);
if (!interfaceExists.isValid()) {
return interfaceExists;
}
ValidationResult interfaceIsValidSlave = slaveHostInterfaceValidator.interfaceIsValidSlave();
if (!interfaceIsValidSlave.isValid()) {
return interfaceIsValidSlave;
}
/*
* definition of currently processed bond references this slave, but this slave already 'slaves' for
* another bond. This is ok only when this bond will be removed as a part of this request
* or the slave will be removed from its former bond, as a part of this request.
*/
String currentSlavesBondName = potentialSlave.getBondName();
if (potentialSlave.isPartOfBond() && /*
* we're creating new bond, and it's definition contains reference to slave already assigned
* to a different bond.
*/
(!potentialSlave.isPartOfBond(modifiedOrNewBond.getName()) && // … but this bond is also removed in this request, so it's ok.
!isBondRemoved(currentSlavesBondName) && // … or slave was removed from its former bond
!bondIsUpdatedAndDoesNotContainCertainSlave(slaveName, currentSlavesBondName))) {
EngineMessage engineMessage = EngineMessage.NETWORK_INTERFACE_ALREADY_IN_BOND;
return new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, slaveName));
}
ValidationResult slaveHasAttachedNetworksValidationResult = validateSlaveHasNoNetworks(potentialSlave.getName());
if (!slaveHasAttachedNetworksValidationResult.isValid()) {
return slaveHasAttachedNetworksValidationResult;
}
if (slaveUsedMultipleTimesInDifferentBonds(slaveName)) {
return new ValidationResult(EngineMessage.NETWORK_INTERFACE_REFERENCED_AS_A_SLAVE_MULTIPLE_TIMES, ReplacementUtils.createSetVariableString("NETWORK_INTERFACE_REFERENCED_AS_A_SLAVE_MULTIPLE_TIMES_ENTITY", slaveName));
}
ValidationResult slaveHasNoLabelsValidationResult = validateSlaveHasNoLabels(slaveName);
if (!slaveHasNoLabelsValidationResult.isValid()) {
return slaveHasNoLabelsValidationResult;
}
}
return ValidationResult.VALID;
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class AffinityGroupCRUDCommand method affinityGroupsWithoutConflict.
private boolean affinityGroupsWithoutConflict(AffinityGroup affinityGroup) {
List<AffinityGroup> affinityGroups = affinityGroupDao.getAllAffinityGroupsByClusterId(affinityGroup.getClusterId());
// Replace the existing affinity group by the updated copy
for (Iterator<AffinityGroup> it = affinityGroups.iterator(); it.hasNext(); ) {
AffinityGroup g = it.next();
if (g.getId().equals(affinityGroup.getId())) {
it.remove();
}
}
affinityGroups.add(affinityGroup);
List<AffinityRulesUtils.AffinityGroupConflicts> conflicts = AffinityRulesUtils.checkForAffinityGroupHostsConflict(affinityGroups);
for (AffinityRulesUtils.AffinityGroupConflicts conflict : conflicts) {
String affinityGroupsNames = AffinityRulesUtils.getAffinityGroupsNames(conflict.getAffinityGroups());
String hosts = conflict.getHosts().stream().map(id -> id.toString()).collect(Collectors.joining(","));
String vms = conflict.getVms().stream().map(id -> id.toString()).collect(Collectors.joining(","));
if (conflict.getType().canBeSaved()) {
addCustomValue("AffinityGroups", affinityGroupsNames);
addCustomValue("Hosts", hosts);
addCustomValue("Vms", vms);
auditLogDirector.log(this, conflict.getAuditLogType());
} else {
if (conflict.isVmToVmAffinity()) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_AFFINITY_RULES_COLLISION, String.format("$UnifiedAffinityGroups %1$s", vms), String.format("$negativeAR %1$s", affinityGroupsNames), String.format("$Vms %1$s", conflict.getNegativeVms().stream().map(id -> id.toString()).collect(Collectors.joining(","))));
} else {
List<EngineMessage> engineMessages = new ArrayList<>();
engineMessages.add(EngineMessage.ACTION_TYPE_FAILED_AFFINITY_HOSTS_RULES_COLLISION);
engineMessages.add(EngineMessage.AFFINITY_GROUPS_LIST);
engineMessages.add(EngineMessage.HOSTS_LIST);
engineMessages.add(EngineMessage.VMS_LIST);
List<String> variableReplacements = new ArrayList<>();
variableReplacements.add(String.format("$affinityGroups %1$s", affinityGroupsNames));
variableReplacements.add(String.format("$hostsList %1$s", hosts));
variableReplacements.add(String.format("$vmsList %1$s", vms));
return failValidation(engineMessages, variableReplacements);
}
}
}
return true;
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testValidateCustomPropertiesWhenCustomPropertyValidationFailed.
@Test
public void testValidateCustomPropertiesWhenCustomPropertyValidationFailed() throws Exception {
Network networkA = createNetworkWithName("networkA");
NetworkAttachment networkAttachment = createNetworkAttachment(networkA);
Map<String, String> customProperties = new HashMap<>();
customProperties.put("a", "b");
networkAttachment.setProperties(customProperties);
HostSetupNetworksValidator validator = spy(new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addNetworkAttachments(networkAttachment)).addNetworks(networkA).build());
// this was added just because of DI issues with 'Backend.getInstance().getErrorsTranslator()' is 'spyed' method
// noinspection unchecked
doReturn(Collections.emptyList()).when(validator).translateErrorMessages(any());
EngineMessage engineMessage = EngineMessage.ACTION_TYPE_FAILED_NETWORK_CUSTOM_PROPERTIES_BAD_INPUT;
assertThat(validator.validateCustomProperties(SimpleCustomPropertiesUtil.getInstance(), Collections.emptyMap(), Collections.emptyMap()), failsWith(engineMessage, ReplacementUtils.getVariableAssignmentStringWithMultipleValues(engineMessage, networkA.getName())));
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testValidRemovedBondsWhenBondIsRequired.
@Test
public void testValidRemovedBondsWhenBondIsRequired() throws Exception {
String nicName = "nicName";
bond.setName(nicName);
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addRemovedBonds(bond.getId())).addExistingInterfaces(Collections.singletonList(bond)).build();
NetworkAttachment requiredNetworkAttachment = new NetworkAttachment();
requiredNetworkAttachment.setNicName(nicName);
List<String> replacements = new ArrayList<>();
EngineMessage engineMessage = EngineMessage.BOND_USED_BY_NETWORK_ATTACHMENTS;
replacements.add(ReplacementUtils.getVariableAssignmentString(engineMessage, nicName));
// null -- new network attachment with null id.
replacements.addAll(replaceWith(HostSetupNetworksValidator.VAR_ATTACHMENT_IDS, Collections.<Guid>singletonList(null)));
assertThat(validator.validRemovedBonds(Collections.singletonList(requiredNetworkAttachment)), failsWith(engineMessage, replacements));
}
use of org.ovirt.engine.core.common.errors.EngineMessage in project ovirt-engine by oVirt.
the class HostSetupNetworksValidatorTest method testAddNetworkToNicAlongWithAddingItIntoBond.
// TODO MM: same test for vlan.
@Test
public void testAddNetworkToNicAlongWithAddingItIntoBond() {
Network networkA = createNetworkWithName("networkA");
VdsNetworkInterface nicA = createNic("nicA");
VdsNetworkInterface nicB = createNic("nicB");
NetworkAttachment networkAttachment = createNetworkAttachment(networkA, (Guid) null);
networkAttachment.setNicId(nicA.getId());
networkAttachment.setNicName(nicA.getName());
networkAttachment.setNetworkId(networkA.getId());
networkAttachment.setNetworkName(networkA.getName());
CreateOrUpdateBond createOrUpdateBond = createNewCreateOrUpdateBond(Guid.newGuid(), "bond1", nicA.getName(), nicB.getName());
addNetworkIdToNetworkDaoMock(networkA);
addNetworkToClusterDaoMock(networkA.getId());
HostSetupNetworksValidator validator = new HostSetupNetworksValidatorBuilder().setParams(new ParametersBuilder().addNetworkAttachments(networkAttachment).addBonds(createOrUpdateBond).build()).addExistingInterfaces(nicA, nicB).addNetworks(networkA).build();
ValidationResult validate = validator.validate();
assertThat(validate, not(isValid()));
EngineMessage engineMessage = EngineMessage.NETWORK_INTERFACE_ADDED_TO_BOND_AND_NETWORK_IS_ATTACHED_TO_IT_AT_THE_SAME_TIME;
assertThat(validate, failsWith(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, nicA.getName()), ReplacementUtils.createSetVariableString(HostSetupNetworksValidator.VAR_NETWORK_NAME, networkA.getName())));
}
Aggregations