Moti Asayag has uploaded a new change for review. Change subject: restapi: Add Katello Errata for System level ......................................................................
restapi: Add Katello Errata for System level Katello errata are being reported also for the ovirt-engine service, represented by: /api/katelloerrata and for a specific errata: /api/katelloerrata/{katelloerratum:id} Change-Id: Id33f0ec24e779d701efb0f9be55a1cdd8be1e789 Bug-Url: https://bugzilla.redhat.com/1157377 Signed-off-by: Moti Asayag <masa...@redhat.com> --- A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/externalhostproviders/SystemKatelloErrataResource.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java M backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java M backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErrataResource.java A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErratumResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/utils/FeaturesHelper.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErrataResourceTest.java A backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErratumResourceTest.java 11 files changed, 268 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/05/37805/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/externalhostproviders/SystemKatelloErrataResource.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/externalhostproviders/SystemKatelloErrataResource.java new file mode 100644 index 0000000..25ca3e6 --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/externalhostproviders/SystemKatelloErrataResource.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2013 Red Hat, Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package org.ovirt.engine.api.resource.externalhostproviders; + +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.ovirt.engine.api.resource.ApiMediaType; + +@Path("/katelloerrata") +@Produces({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) +public interface SystemKatelloErrataResource extends KatelloErrataResource { + // This interface doesn't add any new methods, it is just a placeholder for the annotation that specifies the path + // of the resource that manages the permissions assigned to the system object. +} diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java index daa915f..7369fda 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ApiRootLinksCreator.java @@ -62,6 +62,7 @@ links.add(createLink("externalhostproviders", baseUri)); links.add(createLink("openstackimageproviders", baseUri)); links.add(createLink("openstacknetworkproviders", baseUri)); + links.add(createLink("katelloerrata", baseUri)); return links; } diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java index a1c17c1..6fd4bc6 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java @@ -247,6 +247,7 @@ import org.ovirt.engine.api.resource.externalhostproviders.ExternalHostsResource; import org.ovirt.engine.api.resource.externalhostproviders.KatelloErrataResource; import org.ovirt.engine.api.resource.externalhostproviders.KatelloErratumResource; +import org.ovirt.engine.api.resource.externalhostproviders.SystemKatelloErrataResource; import org.ovirt.engine.api.resource.gluster.GlusterBrickResource; import org.ovirt.engine.api.resource.gluster.GlusterBricksResource; import org.ovirt.engine.api.resource.gluster.GlusterHookResource; @@ -564,6 +565,7 @@ TYPES.put(Agent.class, map); map = new ParentToCollectionMap(KatelloErratumResource.class, KatelloErrataResource.class, Host.class); + map = new ParentToCollectionMap(KatelloErratumResource.class, SystemKatelloErrataResource.class, NO_PARENT); TYPES.put(KatelloErratum.class, map); } 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 d5d3cdd..fb3bd13 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 @@ -6736,3 +6736,20 @@ signatures: [] urlparams: {} headers: {} +- name: /katelloerrata|rel=get + description: get the list of errata available for the system + request: + body: + parameterType: null + signatures: [] + urlparams: + max: {context: matrix, type: 'xs:int', value: 'max results', required: false} + headers: {} +- name: /katelloerrata/{katelloerratum:id}|rel=get + description: get the details of the specific erratum available for the system + request: + body: + parameterType: null + signatures: [] + urlparams: {} + headers: {} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java index 7206160..1e8a65c 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/BackendApplication.java @@ -31,8 +31,8 @@ import org.ovirt.engine.api.restapi.resource.BackendBookmarksResource; import org.ovirt.engine.api.restapi.resource.BackendCapabilitiesResource; import org.ovirt.engine.api.restapi.resource.BackendClustersResource; -import org.ovirt.engine.api.restapi.resource.BackendDataCentersResource; import org.ovirt.engine.api.restapi.resource.BackendCpuProfilesResource; +import org.ovirt.engine.api.restapi.resource.BackendDataCentersResource; import org.ovirt.engine.api.restapi.resource.BackendDiskProfilesResource; import org.ovirt.engine.api.restapi.resource.BackendDisksResource; import org.ovirt.engine.api.restapi.resource.BackendEventsResource; @@ -58,6 +58,7 @@ import org.ovirt.engine.api.restapi.resource.aaa.BackendGroupsResource; import org.ovirt.engine.api.restapi.resource.aaa.BackendUsersResource; import org.ovirt.engine.api.restapi.resource.externalhostproviders.BackendExternalHostProvidersResource; +import org.ovirt.engine.api.restapi.resource.externalhostproviders.BackendSystemKatelloErrataResource; import org.ovirt.engine.api.restapi.resource.openstack.BackendOpenStackImageProvidersResource; import org.ovirt.engine.api.restapi.resource.openstack.BackendOpenStackNetworkProvidersResource; import org.ovirt.engine.api.restapi.resource.validation.IOExceptionMapper; @@ -154,6 +155,7 @@ addResource(new BackendExternalHostProvidersResource()); addResource(new BackendOpenStackImageProvidersResource()); addResource(new BackendOpenStackNetworkProvidersResource()); + addResource(new BackendSystemKatelloErrataResource()); final SessionProcessor processor = new SessionProcessor(); processor.setBackend(backend); diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErrataResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErrataResource.java new file mode 100644 index 0000000..7a5afa7 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErrataResource.java @@ -0,0 +1,53 @@ +package org.ovirt.engine.api.restapi.resource.externalhostproviders; + +import java.util.List; + +import javax.ws.rs.core.Response; + +import org.apache.commons.lang.NotImplementedException; +import org.ovirt.engine.api.model.KatelloErrata; +import org.ovirt.engine.api.model.KatelloErratum; +import org.ovirt.engine.api.resource.externalhostproviders.KatelloErratumResource; +import org.ovirt.engine.api.resource.externalhostproviders.SystemKatelloErrataResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResource; +import org.ovirt.engine.api.restapi.resource.SingleEntityResource; +import org.ovirt.engine.core.common.businessentities.Erratum; +import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendSystemKatelloErrataResource extends AbstractBackendCollectionResource<KatelloErratum, Erratum> implements SystemKatelloErrataResource { + + public BackendSystemKatelloErrataResource() { + super(KatelloErratum.class, Erratum.class); + } + + @Override + public KatelloErrata list() { + return mapCollection(getBackendCollection(VdcQueryType.GetErrataForSystem, new VdcQueryParametersBase())); + } + + private KatelloErrata mapCollection(List<Erratum> entities) { + KatelloErrata collection = new KatelloErrata(); + for (org.ovirt.engine.core.common.businessentities.Erratum entity : entities) { + collection.getKatelloErrata().add(addLinks(populate(map(entity), entity))); + } + + return collection; + } + + @SingleEntityResource + @Override + public KatelloErratumResource getKatelloErratumSubResource(String id) { + return inject(new BackendSystemKatelloErratumResource(id)); + } + + @Override + protected Response performRemove(String id) { + throw new NotImplementedException(); + } + + @Override + protected KatelloErratum doPopulate(KatelloErratum model, Erratum entity) { + return model; + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErratumResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErratumResource.java new file mode 100644 index 0000000..8ac1127 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErratumResource.java @@ -0,0 +1,34 @@ +package org.ovirt.engine.api.restapi.resource.externalhostproviders; + +import static org.ovirt.engine.api.restapi.utils.HexUtils.hex2string; + +import org.ovirt.engine.api.model.KatelloErratum; +import org.ovirt.engine.api.resource.externalhostproviders.KatelloErratumResource; +import org.ovirt.engine.api.restapi.resource.AbstractBackendSubResource; +import org.ovirt.engine.core.common.businessentities.Erratum; +import org.ovirt.engine.core.common.queries.NameQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.Guid; + +public class BackendSystemKatelloErratumResource extends AbstractBackendSubResource<KatelloErratum, Erratum> implements KatelloErratumResource { + + public BackendSystemKatelloErratumResource(String id) { + super(id, KatelloErratum.class, Erratum.class); + } + + @Override + public KatelloErratum get() { + return performGet(VdcQueryType.GetErratumByIdForSystem, new NameQueryParameters(hex2string(id))); + } + + @Override + protected KatelloErratum doPopulate(KatelloErratum model, Erratum entity) { + return model; + } + + @Override + protected Guid asGuidOr404(String id) { + // The identifier isn't a UUID. + return null; + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/utils/FeaturesHelper.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/utils/FeaturesHelper.java index 1287e6b..a2fbd72 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/utils/FeaturesHelper.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/utils/FeaturesHelper.java @@ -541,8 +541,8 @@ private void addErrataForHostsFeature(Features features) { Feature feature = new Feature(); - feature.setName("Katello Host Errata"); - feature.setDescription("View available Katello Errata for hosts."); + feature.setName("Katello Errata"); + feature.setDescription("View available Katello Errata for hosts and system."); features.getFeature().add(feature); } diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java index 5467fbd..dfa9850 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java @@ -131,6 +131,7 @@ "externalhostproviders", "openstackimageproviders", "openstacknetworkproviders", + "katelloerrata" }; private static final String[] relationshipsGlusterOnly = { @@ -197,6 +198,7 @@ BASE_PATH + "/externalhostproviders", BASE_PATH + "/openstackimageproviders", BASE_PATH + "/openstacknetworkproviders", + BASE_PATH + "/katelloerrata" }; private static final String[] hrefsGlusterOnly = { diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErrataResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErrataResourceTest.java new file mode 100644 index 0000000..cfa0c8a --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErrataResourceTest.java @@ -0,0 +1,60 @@ +package org.ovirt.engine.api.restapi.resource.externalhostproviders; + +import static org.easymock.EasyMock.expect; +import static org.ovirt.engine.api.restapi.utils.HexUtils.hex2string; + +import java.util.ArrayList; +import java.util.List; + +import org.ovirt.engine.api.model.KatelloErratum; +import org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest; +import org.ovirt.engine.core.common.businessentities.Erratum; +import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendSystemKatelloErrataResourceTest extends AbstractBackendCollectionResourceTest<KatelloErratum, Erratum, BackendSystemKatelloErrataResource> { + public BackendSystemKatelloErrataResourceTest() { + super(new BackendSystemKatelloErrataResource(), null, ""); + } + + @Override + protected List<KatelloErratum> getCollection() { + return collection.list().getKatelloErrata(); + } + + @Override + protected void setUpQueryExpectations(String query, Object failure) throws Exception { + setUpEntityQueryExpectations( + VdcQueryType.GetErrataForSystem, + VdcQueryParametersBase.class, + new String[] {}, + new Object[] {}, + getErrata(), + failure); + control.replay(); + } + + private List<Erratum> getErrata() { + List<Erratum> errata = new ArrayList<>(); + for (int i = 0; i < NAMES.length; i++) { + errata.add(getEntity(i)); + } + + return errata; + } + + @Override + protected Erratum getEntity(int index) { + Erratum erratum = control.createMock(Erratum.class); + expect(erratum.getId()).andReturn(NAMES[index]).anyTimes(); + expect(erratum.getDescription()).andReturn(DESCRIPTIONS[index]).anyTimes(); + return erratum; + } + + @Override + protected void verifyModel(KatelloErratum model, int index) { + assertEquals(NAMES[index], hex2string(model.getId())); + assertEquals(DESCRIPTIONS[index], model.getDescription()); + verifyLinks(model); + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErratumResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErratumResourceTest.java new file mode 100644 index 0000000..46f4c50 --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/externalhostproviders/BackendSystemKatelloErratumResourceTest.java @@ -0,0 +1,65 @@ +package org.ovirt.engine.api.restapi.resource.externalhostproviders; + +import static org.easymock.EasyMock.expect; +import static org.ovirt.engine.api.restapi.utils.HexUtils.hex2string; +import static org.ovirt.engine.api.restapi.utils.HexUtils.string2hex; + +import javax.ws.rs.WebApplicationException; + +import org.junit.Test; +import org.ovirt.engine.api.model.KatelloErratum; +import org.ovirt.engine.api.restapi.resource.AbstractBackendSubResourceTest; +import org.ovirt.engine.core.common.businessentities.Erratum; +import org.ovirt.engine.core.common.queries.NameQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryType; + +public class BackendSystemKatelloErratumResourceTest extends AbstractBackendSubResourceTest<KatelloErratum, Erratum, BackendSystemKatelloErratumResource> { + public BackendSystemKatelloErratumResourceTest() { + super(new BackendSystemKatelloErratumResource(string2hex(NAMES[1]))); + } + + @Test + public void testGetNotFound() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(true); + control.replay(); + try { + resource.get(); + fail("expected WebApplicationException"); + } catch (WebApplicationException wae) { + verifyNotFoundException(wae); + } + } + + @Test + public void testGet() throws Exception { + setUriInfo(setUpBasicUriExpectations()); + setUpGetEntityExpectations(false); + control.replay(); + verifyModel(resource.get(), 0); + } + + @Override + protected void verifyModel(KatelloErratum model, int index) { + assertEquals(GUIDS[index].toString(), hex2string(model.getId())); + assertEquals(DESCRIPTIONS[index], model.getDescription()); + verifyLinks(model); + } + + @Override + protected Erratum getEntity(int index) { + Erratum erratum = control.createMock(Erratum.class); + expect(erratum.getId()).andReturn(GUIDS[index].toString()).anyTimes(); + expect(erratum.getDescription()).andReturn(DESCRIPTIONS[index]).anyTimes(); + return erratum; + } + + private void setUpGetEntityExpectations(boolean notFound) throws Exception { + setUpGetEntityExpectations( + VdcQueryType.GetErratumByIdForSystem, + NameQueryParameters.class, + new String[] { "Name" }, + new Object[] { NAMES[1] }, + notFound ? null : getEntity(0)); + } +} -- To view, visit http://gerrit.ovirt.org/37805 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id33f0ec24e779d701efb0f9be55a1cdd8be1e789 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