Search in sources :

Example 26 with EngineMessage

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;
}
Also used : HostInterfaceValidator(org.ovirt.engine.core.bll.validator.HostInterfaceValidator) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Example 27 with EngineMessage

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;
}
Also used : VdsStatic(org.ovirt.engine.core.common.businessentities.VdsStatic) Guid(org.ovirt.engine.core.compat.Guid) AffinityRulesUtils(org.ovirt.engine.core.bll.scheduling.arem.AffinityRulesUtils) ArrayList(java.util.ArrayList) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) Map(java.util.Map) AffinityGroupDao(org.ovirt.engine.core.dao.scheduling.AffinityGroupDao) AffinityGroupCRUDParameters(org.ovirt.engine.core.common.scheduling.parameters.AffinityGroupCRUDParameters) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Iterator(java.util.Iterator) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Set(java.util.Set) CommandBase(org.ovirt.engine.core.bll.CommandBase) Collectors(java.util.stream.Collectors) VdsStaticDao(org.ovirt.engine.core.dao.VdsStaticDao) Objects(java.util.Objects) List(java.util.List) PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) Collections(java.util.Collections) ArrayList(java.util.ArrayList) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) AffinityRulesUtils(org.ovirt.engine.core.bll.scheduling.arem.AffinityRulesUtils)

Example 28 with EngineMessage

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())));
}
Also used : HashMap(java.util.HashMap) FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 29 with EngineMessage

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));
}
Also used : ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Guid(org.ovirt.engine.core.compat.Guid) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 30 with EngineMessage

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())));
}
Also used : FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Aggregations

EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)69 Test (org.junit.Test)31 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)27 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)17 Network (org.ovirt.engine.core.common.businessentities.network.Network)16 Guid (org.ovirt.engine.core.compat.Guid)16 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)14 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)13 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Map (java.util.Map)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)6 VM (org.ovirt.engine.core.common.businessentities.VM)6 Version (org.ovirt.engine.core.compat.Version)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 Collectors (java.util.stream.Collectors)3 VmWatchdogValidator (org.ovirt.engine.core.bll.validator.VmWatchdogValidator)3 VmBase (org.ovirt.engine.core.common.businessentities.VmBase)3