Search in sources :

Example 1 with LabelBuilder

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

the class BackendAffinityLabelHostResource method remove.

public Response remove() {
    // First we need to check if the label contains the host:
    Label label = BackendAffinityLabelHelper.getLabel(this, labelId);
    if (!label.getHosts().contains(guid)) {
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    // Remove the host from the label:
    VDS entity = new VDS();
    entity.setId(guid);
    Label updatedLabel = new LabelBuilder(label).removeEntity(entity).build();
    return performAction(ActionType.UpdateLabel, new LabelActionParameters(updatedLabel));
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) VDS(org.ovirt.engine.core.common.businessentities.VDS) LabelActionParameters(org.ovirt.engine.core.common.action.LabelActionParameters) Label(org.ovirt.engine.core.common.businessentities.Label) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder)

Example 2 with LabelBuilder

use of org.ovirt.engine.core.common.businessentities.LabelBuilder 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 3 with LabelBuilder

use of org.ovirt.engine.core.common.businessentities.LabelBuilder 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 4 with LabelBuilder

use of org.ovirt.engine.core.common.businessentities.LabelBuilder 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)

Example 5 with LabelBuilder

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

the class LabelDaoTest method testCreateAndGetByReferencedId.

@Test
public void testCreateAndGetByReferencedId() {
    Label label = new LabelBuilder().name("test label").id(Guid.newGuid()).entity(host).build();
    labelDao.save(label);
    VmStatic vm = createAndSaveVm();
    label = new LabelBuilder().name("test label 2").id(Guid.newGuid()).entity(vm).build();
    labelDao.save(label);
    VmStatic vm2 = createAndSaveVm();
    label = new LabelBuilder().name("test label not in result").id(Guid.newGuid()).entity(vm2).build();
    labelDao.save(label);
    List<Label> read = labelDao.getAllByEntityIds(Lists.newArrayList(host.getId(), vm.getId(), Guid.newGuid()));
    assertNotNull(read);
    assertEquals(2, read.size());
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Test(org.junit.Test)

Aggregations

LabelBuilder (org.ovirt.engine.core.common.businessentities.LabelBuilder)20 Label (org.ovirt.engine.core.common.businessentities.Label)19 Test (org.junit.Test)11 Guid (org.ovirt.engine.core.compat.Guid)8 LabelActionParameters (org.ovirt.engine.core.common.action.LabelActionParameters)6 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)4 PerHostMessages (org.ovirt.engine.core.common.scheduling.PerHostMessages)3 HashMap (java.util.HashMap)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 VM (org.ovirt.engine.core.common.businessentities.VM)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PathParam (javax.ws.rs.PathParam)1 Response (javax.ws.rs.core.Response)1 AffinityLabel (org.ovirt.engine.api.model.AffinityLabel)1 AffinityLabels (org.ovirt.engine.api.model.AffinityLabels)1 Host (org.ovirt.engine.api.model.Host)1 Vm (org.ovirt.engine.api.model.Vm)1 AssignedAffinityLabelResource (org.ovirt.engine.api.resource.AssignedAffinityLabelResource)1