Search in sources :

Example 11 with Label

use of org.ovirt.engine.core.common.businessentities.Label in project ovirt-engine by oVirt.

the class UpdateLabelCommand method validate.

@Override
protected boolean validate() {
    if (getLabelId() == null) {
        addValidationMessage(EngineMessage.AFFINITY_LABEL_NOT_EXISTS);
        return false;
    }
    Label label = labelDao.get(getLabelId());
    if (label == null) {
        addValidationMessage(EngineMessage.AFFINITY_LABEL_NOT_EXISTS);
        return false;
    }
    if (label.isReadOnly() && !isInternalExecution()) {
        addValidationMessage(EngineMessage.AFFINITY_LABEL_READ_ONLY);
        return false;
    }
    label = getParameters().getLabel();
    if (label.getName() == null || label.getName().isEmpty()) {
        addValidationMessage(EngineMessage.AFFINITY_LABEL_BAD_NAME);
        return false;
    }
    Label existing = labelDao.getByName(label.getName());
    if (existing != null && !existing.getId().equals(label.getId())) {
        addValidationMessage(EngineMessage.AFFINITY_LABEL_NAME_ALREADY_EXISTS);
        return false;
    }
    return super.validate();
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label)

Example 12 with Label

use of org.ovirt.engine.core.common.businessentities.Label in project ovirt-engine by oVirt.

the class RemoveLabelCommand method executeCommand.

@Override
protected void executeCommand() {
    if (getLabelId() != null) {
        Label label = labelDao.get(getLabelId());
        vmStaticDao.incrementDbGenerationForVms(new ArrayList<Guid>(label.getVms()));
        labelDao.remove(getLabelId());
        setSucceeded(true);
    }
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label) Guid(org.ovirt.engine.core.compat.Guid)

Example 13 with Label

use of org.ovirt.engine.core.common.businessentities.Label in project ovirt-engine by oVirt.

the class OvfVmReader method readAffinityLabelsSection.

@Override
protected void readAffinityLabelsSection(XmlNode section) {
    XmlNodeList list = selectNodes(section, OvfProperties.AFFINITY_LABEL);
    List<Label> affinityLabels = new ArrayList<>();
    for (XmlNode node : list) {
        String affinityLabelName = node.attributes.get("ovf:name").innerText;
        LabelBuilder builder = new LabelBuilder();
        Label label = builder.name(affinityLabelName).build();
        affinityLabels.add(label);
    }
    fullEntityOvfData.setAffinityLabels(affinityLabels);
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) Label(org.ovirt.engine.core.common.businessentities.Label) ArrayList(java.util.ArrayList) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)

Example 14 with Label

use of org.ovirt.engine.core.common.businessentities.Label in project ovirt-engine by oVirt.

the class LabelFilterPolicyUnitTest method testEmpty.

@Test
public void testEmpty() throws Exception {
    Label red = new LabelBuilder().entities(vm, host1).build();
    Label blue = new LabelBuilder().entities(vm, host2).build();
    List<Label> labels = Arrays.asList(red, blue);
    doReturn(labels).when(labelDao).getAllByEntityIds(any());
    assertThat(unit.filter(cluster, hosts, vm, new HashMap<>(), new PerHostMessages())).isEmpty();
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) PerHostMessages(org.ovirt.engine.core.common.scheduling.PerHostMessages) Test(org.junit.Test)

Example 15 with Label

use of org.ovirt.engine.core.common.businessentities.Label in project ovirt-engine by oVirt.

the class LabelDaoTest method testCreateAndGetWithVM.

@Test
public void testCreateAndGetWithVM() {
    Guid guid = Guid.newGuid();
    VmStatic vm = createAndSaveVm();
    Label label = new LabelBuilder().name("test label").id(guid).vm(vm.getId()).build();
    labelDao.save(label);
    Label read = labelDao.get(guid);
    assertNotNull(read);
    assertEquals(guid, read.getId());
    assertEquals(label.getName(), read.getName());
    assertNotNull(read.getVms());
    assertEquals(1, read.getVms().size());
    assertEquals(0, read.getHosts().size());
    assertEquals(vm.getId(), read.getVms().iterator().next());
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Aggregations

Label (org.ovirt.engine.core.common.businessentities.Label)47 Test (org.junit.Test)19 LabelBuilder (org.ovirt.engine.core.common.businessentities.LabelBuilder)19 Guid (org.ovirt.engine.core.compat.Guid)14 LabelActionParameters (org.ovirt.engine.core.common.action.LabelActionParameters)7 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)3 VM (org.ovirt.engine.core.common.businessentities.VM)3 PerHostMessages (org.ovirt.engine.core.common.scheduling.PerHostMessages)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 AffinityLabel (org.ovirt.engine.api.model.AffinityLabel)2 Host (org.ovirt.engine.api.model.Host)2 Vm (org.ovirt.engine.api.model.Vm)2 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 FullEntityOvfData (org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)2 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)2