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);
}
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());
}
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();
}
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));
}
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();
}
Aggregations