Search in sources :

Example 6 with LabelActionParameters

use of org.ovirt.engine.core.common.action.LabelActionParameters 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 7 with LabelActionParameters

use of org.ovirt.engine.core.common.action.LabelActionParameters 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 8 with LabelActionParameters

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

Example 9 with LabelActionParameters

use of org.ovirt.engine.core.common.action.LabelActionParameters 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));
}
Also used : LabelActionParameters(org.ovirt.engine.core.common.action.LabelActionParameters) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) Guid(org.ovirt.engine.core.compat.Guid)

Example 10 with LabelActionParameters

use of org.ovirt.engine.core.common.action.LabelActionParameters 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);
}
Also used : AffinityLabels(org.ovirt.engine.api.model.AffinityLabels) QueryType(org.ovirt.engine.core.common.queries.QueryType) PathParam(javax.ws.rs.PathParam) Guid(org.ovirt.engine.core.compat.Guid) BusinessEntity(org.ovirt.engine.core.common.businessentities.BusinessEntity) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) LabelActionParameters(org.ovirt.engine.core.common.action.LabelActionParameters) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) GuidUtils(org.ovirt.engine.api.restapi.utils.GuidUtils) AssignedAffinityLabelsResource(org.ovirt.engine.api.resource.AssignedAffinityLabelsResource) ActionType(org.ovirt.engine.core.common.action.ActionType) List(java.util.List) AssignedAffinityLabelResource(org.ovirt.engine.api.resource.AssignedAffinityLabelResource) Response(javax.ws.rs.core.Response) Label(org.ovirt.engine.core.common.businessentities.Label) AffinityLabel(org.ovirt.engine.api.model.AffinityLabel) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) LabelActionParameters(org.ovirt.engine.core.common.action.LabelActionParameters) Label(org.ovirt.engine.core.common.businessentities.Label) AffinityLabel(org.ovirt.engine.api.model.AffinityLabel) Label(org.ovirt.engine.core.common.businessentities.Label) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

LabelActionParameters (org.ovirt.engine.core.common.action.LabelActionParameters)10 Label (org.ovirt.engine.core.common.businessentities.Label)7 LabelBuilder (org.ovirt.engine.core.common.businessentities.LabelBuilder)6 Guid (org.ovirt.engine.core.compat.Guid)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 VM (org.ovirt.engine.core.common.businessentities.VM)2 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)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 AssignedAffinityLabelsResource (org.ovirt.engine.api.resource.AssignedAffinityLabelsResource)1 GuidUtils (org.ovirt.engine.api.restapi.utils.GuidUtils)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1