Gilad Chaplik has uploaded a new change for review. Change subject: engine: set QoS href under profile ......................................................................
engine: set QoS href under profile * Add a qurey to fetch all qos entities by type * For disk, cpu and vnic profile, fetch all qos objects (if needed), and set the DataCenter, inorder to map it to correct path (/DataCenter/<dc_id>/qoss/<qos_id>/) Change-Id: Ib345485d9d64d3adf28c2ea61a17c0cc0c828abb Bug-Url: https://bugzilla.redhat.com/1078863 Signed-off-by: Gilad Chaplik <gchap...@redhat.com> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllQosByTypeQuery.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/QosBaseDaoFacadeImpl.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendVnicProfilesResource.java M packaging/dbscripts/qos_sp.sql 7 files changed, 145 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/30/31930/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllQosByTypeQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllQosByTypeQuery.java new file mode 100644 index 0000000..eadc976 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllQosByTypeQuery.java @@ -0,0 +1,17 @@ +package org.ovirt.engine.core.bll; + +import org.ovirt.engine.core.common.queries.QosQueryParameterBase; + +public class GetAllQosByTypeQuery extends QosQueryBase { + + public GetAllQosByTypeQuery(QosQueryParameterBase parameters) { + super(parameters); + } + + @Override + protected void executeQueryCommand() { + getQueryReturnValue().setReturnValue(getQosDao() + .getAll()); + } + +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java index faa779d..132859e 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java @@ -344,6 +344,7 @@ GetQosById, GetAllQosByStoragePoolId, GetAllQosByStoragePoolIdAndType, + GetAllQosByType, GetWatchdog(VdcQueryAuthType.User), GetConsoleDevices(VdcQueryAuthType.User), diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/QosBaseDaoFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/QosBaseDaoFacadeImpl.java index b10c3ed..5460d20 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/QosBaseDaoFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/qos/QosBaseDaoFacadeImpl.java @@ -31,6 +31,15 @@ } @Override + public List<T> getAll() { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("qos_type", getQosType()); + return getCallsHandler().executeReadList("GetAllQosByQosType", + createEntityRowMapper(), + parameterSource); + } + + @Override public List<T> getAllForStoragePoolId(Guid storagePoolId) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("storage_pool_id", storagePoolId.getUuid()) diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResource.java index f661846..b99f80f 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCpuProfilesResource.java @@ -1,14 +1,21 @@ package org.ovirt.engine.api.restapi.resource; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.ws.rs.core.Response; import org.ovirt.engine.api.model.CpuProfile; import org.ovirt.engine.api.model.CpuProfiles; +import org.ovirt.engine.api.model.DataCenter; +import org.ovirt.engine.api.model.QoS; import org.ovirt.engine.core.common.action.CpuProfileParameters; import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.businessentities.qos.CpuQos; +import org.ovirt.engine.core.common.businessentities.qos.QosType; import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.QosQueryParameterBase; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.compat.Guid; @@ -23,13 +30,41 @@ protected CpuProfiles mapCollection(List<org.ovirt.engine.core.common.businessentities.profiles.CpuProfile> entities) { CpuProfiles collection = new CpuProfiles(); + Map<Guid, QoS> qosMap = new HashMap<>(); for (org.ovirt.engine.core.common.businessentities.profiles.CpuProfile entity : entities) { - collection.getCpuProfiles().add(addLinks(populate(map(entity), entity))); + CpuProfile profile = populate(map(entity), entity); + collection.getCpuProfiles().add(profile); + if (entity.getQosId() != null) { + qosMap.put(entity.getQosId(), profile.getQos()); + } } + handleQosDataCenterLinks(qosMap); + for (CpuProfile cpuProfile : collection.getCpuProfiles()) { + addLinks(cpuProfile); + } return collection; } + /** + * used to set qos's href (requires dc id). + */ + private void handleQosDataCenterLinks(Map<Guid, QoS> qosMap) { + if (!qosMap.isEmpty()) { + List<CpuQos> list = getBackendCollection( + CpuQos.class, + VdcQueryType.GetAllQosByType, + new QosQueryParameterBase(null, QosType.CPU)); + for (CpuQos cpuQos : list) { + QoS qos = qosMap.get(cpuQos.getId()); + if (qos != null) { + qos.setDataCenter(new DataCenter()); + qos.getDataCenter().setId(cpuQos.getStoragePoolId().toString()); + } + } + } + } + protected Response add(CpuProfile cpuProfile) { validateParameters(cpuProfile); CpuProfileParameters parameters = diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResource.java index 1391261..219fd4a 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDiskProfilesResource.java @@ -1,14 +1,21 @@ package org.ovirt.engine.api.restapi.resource; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.ws.rs.core.Response; +import org.ovirt.engine.api.model.DataCenter; import org.ovirt.engine.api.model.DiskProfile; import org.ovirt.engine.api.model.DiskProfiles; +import org.ovirt.engine.api.model.QoS; import org.ovirt.engine.core.common.action.DiskProfileParameters; import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.businessentities.qos.QosType; +import org.ovirt.engine.core.common.businessentities.qos.StorageQos; import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.QosQueryParameterBase; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.compat.Guid; @@ -23,13 +30,41 @@ protected DiskProfiles mapCollection(List<org.ovirt.engine.core.common.businessentities.profiles.DiskProfile> entities) { DiskProfiles collection = new DiskProfiles(); + Map<Guid, QoS> qosMap = new HashMap<>(); for (org.ovirt.engine.core.common.businessentities.profiles.DiskProfile entity : entities) { - collection.getDiskProfiles().add(addLinks(populate(map(entity), entity))); + DiskProfile profile = populate(map(entity), entity); + collection.getDiskProfiles().add(profile); + if (entity.getQosId() != null) { + qosMap.put(entity.getQosId(), profile.getQos()); + } } + handleQosDataCenterLinks(qosMap); + for (DiskProfile diskProfile : collection.getDiskProfiles()) { + addLinks(diskProfile); + } return collection; } + /** + * used to set qos's href (requires dc id). + */ + private void handleQosDataCenterLinks(Map<Guid, QoS> qosMap) { + if (!qosMap.isEmpty()) { + List<StorageQos> list = getBackendCollection( + StorageQos.class, + VdcQueryType.GetAllQosByType, + new QosQueryParameterBase(null, QosType.STORAGE)); + for (StorageQos storageQos : list) { + QoS qos = qosMap.get(storageQos.getId()); + if (qos != null) { + qos.setDataCenter(new DataCenter()); + qos.getDataCenter().setId(storageQos.getStoragePoolId().toString()); + } + } + } + } + protected Response add(DiskProfile diskProfile) { validateParameters(diskProfile); DiskProfileParameters parameters = diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendVnicProfilesResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendVnicProfilesResource.java index c0cda15..f2042a5 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendVnicProfilesResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendVnicProfilesResource.java @@ -1,14 +1,21 @@ package org.ovirt.engine.api.restapi.resource; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.ws.rs.core.Response; +import org.ovirt.engine.api.model.DataCenter; +import org.ovirt.engine.api.model.QoS; import org.ovirt.engine.api.model.VnicProfile; import org.ovirt.engine.api.model.VnicProfiles; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VnicProfileParameters; +import org.ovirt.engine.core.common.businessentities.network.NetworkQoS; +import org.ovirt.engine.core.common.businessentities.qos.QosType; import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.QosQueryParameterBase; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.compat.Guid; @@ -25,13 +32,41 @@ protected VnicProfiles mapCollection(List<org.ovirt.engine.core.common.businessentities.network.VnicProfile> entities) { VnicProfiles collection = new VnicProfiles(); + Map<Guid, QoS> qosMap = new HashMap<>(); for (org.ovirt.engine.core.common.businessentities.network.VnicProfile entity : entities) { - collection.getVnicProfiles().add(addLinks(populate(map(entity), entity))); + VnicProfile profile = populate(map(entity), entity); + collection.getVnicProfiles().add(profile); + if (entity.getNetworkQosId() != null) { + qosMap.put(entity.getNetworkQosId(), profile.getQos()); + } } + handleQosDataCenterLinks(qosMap); + for (VnicProfile vnicProfile : collection.getVnicProfiles()) { + addLinks(vnicProfile); + } return collection; } + /** + * used to set qos's href (requires dc id). + */ + private void handleQosDataCenterLinks(Map<Guid, QoS> qosMap) { + if (!qosMap.isEmpty()) { + List<NetworkQoS> list = getBackendCollection( + NetworkQoS.class, + VdcQueryType.GetAllQosByType, + new QosQueryParameterBase(null, QosType.NETWORK)); + for (NetworkQoS networkQoS : list) { + QoS qos = qosMap.get(networkQoS.getId()); + if (qos != null) { + qos.setDataCenter(new DataCenter()); + qos.getDataCenter().setId(networkQoS.getStoragePoolId().toString()); + } + } + } + } + protected Response add(VnicProfile vnicProfile) { validateParameters(vnicProfile); return performCreate(VdcActionType.AddVnicProfile, diff --git a/packaging/dbscripts/qos_sp.sql b/packaging/dbscripts/qos_sp.sql index 2c849fb..01230bc 100644 --- a/packaging/dbscripts/qos_sp.sql +++ b/packaging/dbscripts/qos_sp.sql @@ -150,6 +150,16 @@ LANGUAGE plpgsql; +Create or replace FUNCTION GetAllQosByQosType(v_qos_type SMALLINT) RETURNS SETOF qos STABLE + AS $procedure$ +BEGIN +RETURN QUERY SELECT * + FROM qos + WHERE qos_type = v_qos_type; +END; $procedure$ +LANGUAGE plpgsql; + + Create or replace FUNCTION GetQosByDiskProfile(v_disk_profile_id UUID) RETURNS SETOF qos STABLE AS $procedure$ BEGIN -- To view, visit http://gerrit.ovirt.org/31930 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib345485d9d64d3adf28c2ea61a17c0cc0c828abb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Gilad Chaplik <gchap...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches