Martin Betak has uploaded a new change for review. Change subject: restapi: Support ;current on cdroms collection ......................................................................
restapi: Support ;current on cdroms collection Add support for displaying current CDs (as opposed the configured) using the ;current matrix parameter on the BackendCdRomsResource. So far it was possible to get current CD only per individual VM (using BackendCdRomResource) Change-Id: Iaa14b3ceb09ab8d824fa9fae0ef3eb7d4df7f855 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1092070 Signed-off-by: Martin Betak <[email protected]> --- M backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/QueryHelper.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCdRomResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCdRomsResource.java 3 files changed, 28 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/74/27974/1 diff --git a/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/QueryHelper.java b/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/QueryHelper.java index e457f04..4e4f04e 100644 --- a/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/QueryHelper.java +++ b/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/QueryHelper.java @@ -46,6 +46,8 @@ public static final String CONSTRAINT_PARAMETER = "search"; private static final String RETURN_TYPE_SEPARTOR = " : "; + public static final String CURRENT_CONSTRAINT_PARAMETER = "current"; + private QueryHelper() {} /** @@ -192,4 +194,12 @@ HashMap<String, String> constraints = getMatrixConstraints(uriInfo, constraint); return constraints.containsKey(constraint) ? constraints.get(constraint) : null; } + + public static boolean hasCurrentConstraint(UriInfo uriInfo) { + // TODO: CURRENT_CONSTRAINT_PARAMETER as query parameter is depreciated and supported + // for backward compatibility only - should be dropped at 4.0. + return QueryHelper.hasConstraint(uriInfo.getQueryParameters(), CURRENT_CONSTRAINT_PARAMETER) || + (hasMatrixParam(uriInfo, CURRENT_CONSTRAINT_PARAMETER) && + !"false".equalsIgnoreCase(QueryHelper.getMatrixConstraint(uriInfo, CURRENT_CONSTRAINT_PARAMETER))); + } } diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCdRomResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCdRomResource.java index 3d17a40..b655055 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCdRomResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCdRomResource.java @@ -27,10 +27,8 @@ @Override public CdRom update(CdRom resource) { - // TODO: CURRENT_CONSTRAINT_PARAMETER as query parameter is depreciated and supported - // for backward compatibility only - should be dropped at 4.0. - if (QueryHelper.hasConstraint(getUriInfo().getQueryParameters(), CURRENT_CONSTRAINT_PARAMETER) || - QueryHelper.hasMatrixParam(getUriInfo(), CURRENT_CONSTRAINT_PARAMETER)) { + + if (QueryHelper.hasCurrentConstraint(getUriInfo())) { validateParameters(resource, requiredUpdateFields); performAction(VdcActionType.ChangeDisk, new ChangeDiskCommandParameters(getEntity(entityResolver, true).getId(), @@ -43,9 +41,7 @@ @Override public CdRom get() { - final boolean getCurrent = QueryHelper.hasMatrixParam(getUriInfo(), CURRENT_CONSTRAINT_PARAMETER) && - !"false".equalsIgnoreCase(QueryHelper.getMatrixConstraint(getUriInfo(), CURRENT_CONSTRAINT_PARAMETER)); - if (getCurrent) { + if (QueryHelper.hasCurrentConstraint(getUriInfo())) { VM vm = collection.lookupEntity(guid); if (vm == null) { return notFound(); diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCdRomsResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCdRomsResource.java index 2a602bb..03112eb 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCdRomsResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendCdRomsResource.java @@ -1,5 +1,6 @@ package org.ovirt.engine.api.restapi.resource; +import org.ovirt.engine.api.common.util.QueryHelper; import org.ovirt.engine.api.model.CdRom; import org.ovirt.engine.api.model.CdRoms; import org.ovirt.engine.api.resource.DeviceResource; @@ -14,6 +15,8 @@ import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.api.restapi.resource.AbstractBackendSubResource.ParametersProvider; + +import java.util.List; import static org.ovirt.engine.api.restapi.types.CdRomMapper.CDROM_ID; @@ -65,6 +68,18 @@ return new VmManagementParametersBase(getUpdatable(null)); } + @Override + protected CdRoms mapCollection(List<VM> entities) { + if (QueryHelper.hasCurrentConstraint(getUriInfo())) { + for (VM entity : entities) { + // change the iso path so the result of 'map' will contain current cd instead of the + // persistent configuration + entity.setIsoPath(entity.getCurrentCd()); + } + } + return super.mapCollection(entities); + } + protected VmStatic getUpdatable(String isoPath) { VmStatic updatable = getEntity(VM.class, VdcQueryType.GetVmByVmId, -- To view, visit http://gerrit.ovirt.org/27974 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iaa14b3ceb09ab8d824fa9fae0ef3eb7d4df7f855 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Betak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
