Search in sources :

Example 11 with LabelBuilder

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

the class LabelDaoTest method testCreateAndDeleteById.

@Test
public void testCreateAndDeleteById() {
    Guid guid = Guid.newGuid();
    Label label = new LabelBuilder().name("test label").id(guid).host(host.getId()).build();
    labelDao.save(label);
    labelDao.remove(label.getId());
    Label read = labelDao.get(guid);
    assertNull(read);
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 12 with LabelBuilder

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

the class LabelDaoTest method testCreateAndGetAll.

@Test
public void testCreateAndGetAll() {
    Guid guid = Guid.newGuid();
    Label label = new LabelBuilder().name("test label").id(guid).build();
    labelDao.save(label);
    List<Label> readList = labelDao.getAll();
    assertNotNull(readList);
    Label read = readList.get(0);
    assertNotNull(read);
    assertEquals(guid, read.getId());
    assertEquals(label.getName(), read.getName());
}
Also used : Label(org.ovirt.engine.core.common.businessentities.Label) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 13 with LabelBuilder

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

the class BackendAffinityLabelHostsResource method add.

@Override
public Response add(Host model) {
    validateParameters(model, "id");
    Label label = BackendAffinityLabelHelper.getLabel(this, labelId);
    VDS entity = new VDS();
    entity.setId(GuidUtils.asGuid(model.getId()));
    Label updatedLabel = new LabelBuilder(label).entity(entity).build();
    // The command used to add the host to the label returns the label, but we need to return the virtual machine,
    // so we ignore the result and return a link to the added host:
    LabelActionParameters updateParams = new LabelActionParameters(updatedLabel);
    try {
        doAction(ActionType.UpdateLabel, updateParams);
    } catch (BackendFailureException exception) {
        handleError(exception, false);
    }
    Host result = BackendAffinityLabelHelper.makeHostLink(entity.getId());
    return Response.ok(Response.Status.CREATED).entity(result).build();
}
Also used : 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) Host(org.ovirt.engine.api.model.Host)

Example 14 with LabelBuilder

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

the class BackendAffinityLabelVmResource method remove.

public Response remove() {
    // First we need to check if the affinity label does contain the virtual machine:
    Label label = BackendAffinityLabelHelper.getLabel(this, labelId);
    if (!label.getVms().contains(guid)) {
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    // Remove the virtual machine from the label:
    VM entity = new VM();
    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) LabelActionParameters(org.ovirt.engine.core.common.action.LabelActionParameters) VM(org.ovirt.engine.core.common.businessentities.VM) Label(org.ovirt.engine.core.common.businessentities.Label) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder)

Example 15 with LabelBuilder

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

the class BackendAffinityLabelVmsResource method add.

@Override
public Response add(Vm model) {
    validateParameters(model, "id");
    Label label = BackendAffinityLabelHelper.getLabel(this, labelId);
    VM entity = new VM();
    entity.setId(GuidUtils.asGuid(model.getId()));
    Label updatedLabel = new LabelBuilder(label).entity(entity).build();
    // The command used to add the virtual machine to the label returns the label, but we need to return the virtual
    // machine, so we ignore the result and return a link to the added virtual machine:
    LabelActionParameters updateParams = new LabelActionParameters(updatedLabel);
    try {
        doAction(ActionType.UpdateLabel, updateParams);
    } catch (BackendFailureException exception) {
        handleError(exception, false);
    }
    Vm result = BackendAffinityLabelHelper.makeVmLink(entity.getId());
    return Response.ok(Response.Status.CREATED).entity(result).build();
}
Also used : LabelActionParameters(org.ovirt.engine.core.common.action.LabelActionParameters) VM(org.ovirt.engine.core.common.businessentities.VM) Vm(org.ovirt.engine.api.model.Vm) Label(org.ovirt.engine.core.common.businessentities.Label) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder)

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