Moti Asayag has uploaded a new change for review. Change subject: restapi: Support labels on host nics ......................................................................
restapi: Support labels on host nics Adding support for labels on host nic level. The support actions for labels are GET, POST and DELETE done via: /api/hosts/{host:id}/nics/{nic:id}/labels /api/hosts/{host:id}/nics/{nic:id}/labels/{label:id} See: http://www.ovirt.org/Features/NetworkLabels#REST Change-Id: I127c77382f0a4790d7c9ba40d77577e941e51919 Bug-Url: https://bugzilla.redhat.com/1040586 Signed-off-by: Moti Asayag <masa...@redhat.com> --- M backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/LinkHelper.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java M backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd M backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java 8 files changed, 210 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/78/22878/1 diff --git a/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/LinkHelper.java b/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/LinkHelper.java index cec137c..662626a 100644 --- a/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/LinkHelper.java +++ b/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/LinkHelper.java @@ -369,6 +369,7 @@ map = new ParentToCollectionMap(LabelResource.class, LabelsResource.class); map.add(LabelResource.class, LabelsResource.class, Network.class); + map.add(LabelResource.class, LabelsResource.class, HostNIC.class); TYPES.put(Label.class, map); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java index edc090c..8f19a86 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/HostNicResource.java @@ -18,15 +18,15 @@ import javax.ws.rs.Consumes; import javax.ws.rs.GET; -import javax.ws.rs.Path; import javax.ws.rs.POST; +import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import org.jboss.resteasy.annotations.providers.jaxb.Formatted; import javax.ws.rs.core.Response; -import org.ovirt.engine.api.model.Actionable; +import org.jboss.resteasy.annotations.providers.jaxb.Formatted; import org.ovirt.engine.api.model.Action; +import org.ovirt.engine.api.model.Actionable; import org.ovirt.engine.api.model.HostNIC; @@ -53,4 +53,7 @@ @Actionable @Path("detach") public Response detach(Action action); + + @Path("labels") + public LabelsResource getLabelsResource(); } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd index 46a754a..a5934e4 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd @@ -1992,6 +1992,7 @@ <xs:extension base="BaseResource"> <xs:sequence> <xs:element ref="network" minOccurs="0" maxOccurs="1"/> + <xs:element ref="host_nic" minOccurs="0" maxOccurs="1"/> </xs:sequence> </xs:extension> </xs:complexContent> diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml index cabf0be..50f066f 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml @@ -2633,6 +2633,45 @@ signatures: [] urlparams: {} headers: {} +- name: /hosts/{host:id}/nics/{nic:id}/labels|rel=get + description: get the labels of an interface + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} +- name: /hosts/{host:id}/nics/{nic:id}/labels/|rel=add + description: add a new label to the interface + request: + body: + parameterType: Label + signatures: + - mandatoryArguments: {label.id: 'xs:string'} + description: add a new label to the interface + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} + Expect: {value: 201-created, required: false} + Correlation-Id: {value: 'any string', required: false} +- name: /hosts/{host:id}/nics/{nic:id}/labels/{label:id}|rel=get + description: get a specific label of an interface + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} +- name: /hosts/{host:id}/nics/{nic:id}/labels/{label:id}|rel=delete + description: delete the specified label of an interface + request: + body: + parameterType: null + signatures: [] + urlparams: + async: {context: matrix, type: 'xs:boolean', value: true|false, required: false} + headers: + Correlation-Id: {value: 'any string', required: false} - name: /hosts/{host:id}/permissions|rel=get description: get the list of permissions for the host request: diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResource.java new file mode 100644 index 0000000..4d8b5cd --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelResource.java @@ -0,0 +1,40 @@ +package org.ovirt.engine.api.restapi.resource; + +import org.ovirt.engine.api.model.HostNIC; +import org.ovirt.engine.api.model.Label; +import org.ovirt.engine.api.model.Labels; +import org.ovirt.engine.api.resource.LabelResource; +import org.ovirt.engine.core.common.businessentities.network.NetworkLabel; + +public class BackendHostNicLabelResource extends AbstractBackendResource<Label, NetworkLabel> implements LabelResource { + + private String id; + private BackendHostNicLabelsResource parent; + + protected BackendHostNicLabelResource(String id, BackendHostNicLabelsResource parent) { + super(Label.class, NetworkLabel.class); + this.id = id; + this.parent = parent; + } + + @Override + public Label get() { + Labels labels = parent.list(); + if (labels != null) { + for (Label label : labels.getLabels()) { + if (label.getId().equals(id)) { + label.setHostNic(new HostNIC()); + label.getNetwork().setId(parent.getHostNicId().toString()); + return addLinks(label); + } + } + } + + return notFound(); + } + + @Override + protected Label doPopulate(Label model, NetworkLabel entity) { + return model; + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResource.java new file mode 100644 index 0000000..60b1369 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicLabelsResource.java @@ -0,0 +1,116 @@ +package org.ovirt.engine.api.restapi.resource; + +import java.util.List; +import java.util.Objects; + +import javax.ws.rs.core.Response; + +import org.ovirt.engine.api.model.BaseResource; +import org.ovirt.engine.api.model.HostNIC; +import org.ovirt.engine.api.model.Label; +import org.ovirt.engine.api.model.Labels; +import org.ovirt.engine.api.resource.LabelResource; +import org.ovirt.engine.api.resource.LabelsResource; +import org.ovirt.engine.core.common.action.LabelNicParameters; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.businessentities.network.NetworkLabel; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.Guid; + +public class BackendHostNicLabelsResource extends AbstractBackendCollectionResource<Label, NetworkLabel> implements LabelsResource { + + private Guid nicId; + + protected BackendHostNicLabelsResource(Guid nicId) { + super(Label.class, NetworkLabel.class); + this.nicId = nicId; + } + + @Override + public Labels list() { + return mapCollection(getHostNicLabels(nicId)); + } + + private List<NetworkLabel> getHostNicLabels(Guid hostNicId) { + return getBackendCollection(VdcQueryType.GetNetworkLabelsByHostNicId, new IdQueryParameters(hostNicId)); + } + + private Labels mapCollection(List<NetworkLabel> networkLabels) { + Labels labels = new Labels(); + for (NetworkLabel networkLabel : networkLabels) { + Label label = new Label(); + label.setId(networkLabel.getId()); + labels.getLabels().add(label); + addLinks(label, HostNIC.class); + } + + return labels; + } + + @Override + public Response add(Label label) { + validateParameters(label, "id"); + return performCreate(VdcActionType.LabelNic, + new LabelNicParameters(nicId, label.getId()), + new NetworkLabelIdResolver(nicId, label.getId())); + } + + @SingleEntityResource + @Override + public LabelResource getLabelSubResource(String id) { + return inject(new BackendHostNicLabelResource(id, this)); + } + + @Override + protected Response performRemove(String id) { + return performAction(VdcActionType.UnlabelNic, new LabelNicParameters(nicId, id)); + } + + @Override + protected Label doPopulate(Label model, NetworkLabel entity) { + return model; + } + + @Override + protected Label addParents(Label model) { + model.setHostNic(new HostNIC()); + model.getHostNic().setId(nicId.toString()); + return model; + }; + + @Override + protected Label addLinks(Label model, + Class<? extends BaseResource> suggestedParent, + String... excludeSubCollectionMembers) { + return super.addLinks(model, HostNIC.class); + } + + public Guid getHostNicId() { + return nicId; + } + + protected class NetworkLabelIdResolver extends EntityIdResolver<String> { + + private Guid nicId; + + NetworkLabelIdResolver() { + } + + NetworkLabelIdResolver(Guid nicId, String label) { + this.nicId = nicId; + } + + @Override + public NetworkLabel lookupEntity(String id) throws BackendFailureException { + List<NetworkLabel> labels = getHostNicLabels(nicId); + for (NetworkLabel label : labels) { + if (Objects.equals(label.getId(), id)) { + return label; + } + } + + return null; + } + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java index f0de06e..d856c01 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicResource.java @@ -14,6 +14,7 @@ import org.ovirt.engine.api.model.Network; import org.ovirt.engine.api.model.Option; import org.ovirt.engine.api.resource.HostNicResource; +import org.ovirt.engine.api.resource.LabelsResource; import org.ovirt.engine.api.resource.StatisticsResource; import org.ovirt.engine.core.common.action.AttachNetworkToVdsParameters; import org.ovirt.engine.core.common.action.UpdateNetworkToVdsParameters; @@ -197,4 +198,9 @@ private org.ovirt.engine.core.common.businessentities.network.Network map(Network network, org.ovirt.engine.core.common.businessentities.network.Network template) { return getMapper(Network.class, org.ovirt.engine.core.common.businessentities.network.Network.class).map(network, template); } + + @Override + public LabelsResource getLabelsResource() { + return inject(new BackendHostNicLabelsResource(asGuid(id))); + } } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java index 6fce594..8b4ba84 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostNicsResource.java @@ -40,7 +40,7 @@ extends AbstractBackendCollectionResource<HostNIC, VdsNetworkInterface> implements HostNicsResource { - static final String SUB_COLLECTIONS = "statistics"; + static final String[] SUB_COLLECTIONS = { "statistics", "labels" }; private String hostId; -- To view, visit http://gerrit.ovirt.org/22878 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I127c77382f0a4790d7c9ba40d77577e941e51919 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <masa...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches