use of org.ovirt.engine.core.common.businessentities.LabelBuilder in project ovirt-engine by oVirt.
the class BackendAssignedAffinityLabelResource method remove.
@Override
public Response remove() {
QueryIdResolver<Guid> labelResolver = new QueryIdResolver<>(QueryType.GetLabelById, IdQueryParameters.class);
org.ovirt.engine.core.common.businessentities.Label entity = getEntity(labelResolver, true);
BusinessEntity<Guid> parent = constructor.create();
parent.setId(GuidUtils.asGuid(parentId));
org.ovirt.engine.core.common.businessentities.Label updatedLabel = new LabelBuilder(entity).removeEntity(parent).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 BackendAssignedAffinityLabelsResource method add.
@Override
public Response add(AffinityLabel label) {
validateParameters(label, "id");
IdQueryParameters parameters = new IdQueryParameters(GuidUtils.asGuid(label.getId()));
org.ovirt.engine.core.common.businessentities.Label entity = getEntity(org.ovirt.engine.core.common.businessentities.Label.class, QueryType.GetLabelById, parameters, label.getId(), true);
BusinessEntity<Guid> parent = constructor.create();
parent.setId(GuidUtils.asGuid(parentId));
org.ovirt.engine.core.common.businessentities.Label updatedLabel = new LabelBuilder(entity).entity(parent).build();
// Add the affinity label using the backend "update" operation. As the backend will return the added label as
// the result of the operation, we can fetch it using a simple "identity" resolver, that just returns the same
// value it is passed.
LabelActionParameters updateParams = new LabelActionParameters(updatedLabel);
return performCreate(ActionType.UpdateLabel, updateParams, (IResolver<Label, Label>) result -> result);
}
use of org.ovirt.engine.core.common.businessentities.LabelBuilder in project ovirt-engine by oVirt.
the class AddLabelCommand method executeCommand.
@Override
protected void executeCommand() {
Label label = new LabelBuilder(getParameters().getLabel()).build();
labelDao.save(label);
vmStaticDao.incrementDbGenerationForVms(new ArrayList<Guid>(label.getVms()));
setSucceeded(true);
setActionReturnValue(label.getId());
}
use of org.ovirt.engine.core.common.businessentities.LabelBuilder in project ovirt-engine by oVirt.
the class LabelFilterPolicyUnitTest method testSimple.
@Test
public void testSimple() throws Exception {
Label red = new LabelBuilder().entities(vm, host1).build();
List<Label> labels = Collections.singletonList(red);
doReturn(labels).when(labelDao).getAllByEntityIds(any());
assertThat(unit.filter(cluster, hosts, vm, new HashMap<>(), new PerHostMessages())).contains(host1).doesNotContain(host2);
}
use of org.ovirt.engine.core.common.businessentities.LabelBuilder in project ovirt-engine by oVirt.
the class LabelFilterPolicyUnitTest method testHostExtra.
@Test
public void testHostExtra() throws Exception {
Label red = new LabelBuilder().entities(vm, host1).build();
Label blue = new LabelBuilder().entities(host1, 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())).contains(host1).doesNotContain(host2);
}
Aggregations