Liran Zelkha has uploaded a new change for review. Change subject: core: Make VDSGroup a JPA entity ......................................................................
core: Make VDSGroup a JPA entity Make the VDSGroup entity a JPA entity. Change-Id: Ic65c113fbc9c673dd814c83e03323ee7eca15ec8 Signed-off-by: lzel...@redhat.com <lzel...@redhat.com> --- M backend/manager/modules/bll/src/main/resources/META-INF/persistence.xml M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/SerialNumberPolicy.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDSGroup.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/OptimizationType.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAO.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAODbFacadeImpl.java M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsGroupDAOTest.java M packaging/dbscripts/vds_groups_sp.sql 8 files changed, 263 insertions(+), 590 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/71/41471/1 diff --git a/backend/manager/modules/bll/src/main/resources/META-INF/persistence.xml b/backend/manager/modules/bll/src/main/resources/META-INF/persistence.xml index 605b5fe..d993b82 100644 --- a/backend/manager/modules/bll/src/main/resources/META-INF/persistence.xml +++ b/backend/manager/modules/bll/src/main/resources/META-INF/persistence.xml @@ -18,6 +18,7 @@ <class>org.ovirt.engine.core.common.businessentities.VmNumaNode</class> <class>org.ovirt.engine.core.common.businessentities.NumaNodeCPUMap</class> <class>org.ovirt.engine.core.common.businessentities.NumaNodeVmVds</class> + <class>org.ovirt.engine.core.common.businessentities.VDSGroup</class> <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/SerialNumberPolicy.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/SerialNumberPolicy.java index 69007fb..bb2694b 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/SerialNumberPolicy.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/SerialNumberPolicy.java @@ -32,7 +32,7 @@ * @param value * @return If {@code value} is null returns null specifying unset policy. */ - public static SerialNumberPolicy forValue(Integer value) { + public static SerialNumberPolicy forValue(int value) { return mappings.get(value); } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDSGroup.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDSGroup.java index e44b2a6..37a4064 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDSGroup.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDSGroup.java @@ -3,13 +3,27 @@ import java.io.Serializable; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; +import javax.persistence.Cacheable; +import javax.persistence.Column; +import javax.persistence.ColumnResult; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.NamedNativeQueries; +import javax.persistence.NamedNativeQuery; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.SqlResultSetMapping; +import javax.persistence.SqlResultSetMappings; +import javax.persistence.Table; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; +import org.hibernate.annotations.Parameter; +import org.hibernate.annotations.Type; import org.ovirt.engine.core.common.scheduling.OptimizationType; -import org.ovirt.engine.core.common.utils.ObjectUtils; import org.ovirt.engine.core.common.validation.annotation.ValidI18NName; import org.ovirt.engine.core.common.validation.annotation.ValidSerialNumberPolicy; import org.ovirt.engine.core.common.validation.annotation.ValidUri; @@ -21,11 +35,68 @@ @ValidVdsGroup(groups = { CreateEntity.class }) @ValidSerialNumberPolicy(groups = {CreateEntity.class, UpdateEntity.class}) +@Entity +@Table(name = "vds_groups") +@Cacheable(true) +@NamedQueries({ + @NamedQuery(name = "VDSGroup.getByNameSensitive", query = "select v from VDSGroup v where v.name = :name"), + @NamedQuery(name = "VDSGroup.getByNameInSensitive", + query = "select v from VDSGroup v where UPPER(v.name) = UPPER(:name)"), + @NamedQuery(name = "VDSGroup.getClustersByServiceAndCompatibilityVersion", + query = "select v from VDSGroup v where " + + "v.virtService = :virtService and v.glusterService = :glusterService and v.compatibilityVersion = :compatibilityVersion"), + @NamedQuery(name = "VDSGroup.getClustersByClusterPolicyId", + query = "select v from VDSGroup v where v.clusterPolicyId = :clusterPolicyId"), + @NamedQuery(name = "VDSGroup.getClustersHavingHosts", + query = "select v from VDSGroup v where v.id in (select static.vdsGroupId from VdsStatic static)"), + @NamedQuery(name = "VDSGroup.getTrustedClusters", + query = "select v from VDSGroup v where v.trustedService = true") +}) +@SqlResultSetMappings({ + @SqlResultSetMapping(name = "VDSGroup.getVmsCountByClusterId.Mapping", columns = { + @ColumnResult(name = "getnumberofvmsincluster") }), + @SqlResultSetMapping(name = "VDSGroup.getHostsAndVmsForClusters.Mapping", columns = { + @ColumnResult(name = "vds_group_id"), + @ColumnResult(name = "hosts"), + @ColumnResult(name = "vms") }) +}) +@NamedNativeQueries({ + @NamedNativeQuery(name = "VDSGroup.getWithRunningVms", + query = "select * from GetVdsGroupWithRunningVms(CAST( CAST (? AS text) AS uuid))", + resultClass = VDSGroup.class), + @NamedNativeQuery(name = "VDSGroup.getIsEmpty", + query = "select * from GetIsVdsGroupEmpty(CAST( CAST (? AS text) AS uuid))", + resultClass = VDSGroup.class), + @NamedNativeQuery(name = "VDSGroup.getHostsAndVmsForClusters", + query = "select * from GetHostsAndVmsForClusters(?)", + resultSetMapping = "VDSGroup.getHostsAndVmsForClusters.Mapping"), + @NamedNativeQuery(name = "VDSGroup.getVmsCountByClusterId", + query = "select * from GetNumberOfVmsInCluster(CAST( CAST (? AS text) AS uuid))", + resultSetMapping = "VDSGroup.getVmsCountByClusterId.Mapping"), + @NamedNativeQuery(name = "VDSGroup.get", + query = "select * from GetVdsGroupByVdsGroupId(CAST( CAST (? AS text) AS uuid),CAST( CAST (? AS text) AS uuid), ?)", + resultClass = VDSGroup.class), + @NamedNativeQuery(name = "VDSGroup.getByName", + query = "select * from GetVdsGroupForUserByVdsGroupName(?,CAST( CAST (? AS text) AS uuid), ?)", + resultClass = VDSGroup.class), + @NamedNativeQuery(name = "VDSGroup.getAll", + query = "select * from GetAllFromVdsGroups(CAST( CAST (? AS text) AS uuid), ?)", + resultClass = VDSGroup.class), + @NamedNativeQuery(name = "VDSGroup.getAllForStoragePool", + query = "select * from GetVdsGroupsByStoragePoolId(CAST( CAST (? AS text) AS uuid), CAST( CAST (? AS text) AS uuid), ?)", + resultClass = VDSGroup.class), + @NamedNativeQuery(name = "VDSGroup.getClustersWithPermittedAction", + query = "select * from fn_perms_get_vds_groups_with_permitted_action(CAST( CAST (? AS text) AS uuid), ?)", + resultClass = VDSGroup.class) +}) public class VDSGroup extends IVdcQueryable implements Serializable, BusinessEntity<Guid>, HasStoragePool<Guid>, Nameable, Commented, HasSerialNumberPolicy, HasMigrationOptions { private static final long serialVersionUID = 5659359762655478095L; + @Id + @Column(name = "vds_group_id") + @Type(type = "org.ovirt.engine.core.dao.jpa.GuidUserType") private Guid id; @NotNull(message = "VALIDATION.VDS_GROUP.NAME.NOT_NULL", groups = { CreateEntity.class, UpdateEntity.class }) @@ -33,85 +104,141 @@ groups = { CreateEntity.class, UpdateEntity.class }) @ValidI18NName(message = "VALIDATION.VDS_GROUP.NAME.INVALID", groups = { CreateEntity.class, UpdateEntity.class }) + @Column(name = "name") private String name; @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE) + @Column(name = "description") private String description; + @Column(name = "free_text_comment") private String comment; @Size(max = BusinessEntitiesDefinitions.CLUSTER_CPU_NAME_SIZE) + @Column(name = "cpu_name") private String cpuName; + @Column(name = "storage_pool_id") + @Type(type = "org.ovirt.engine.core.dao.jpa.GuidUserType") private Guid storagePoolId; @Size(max = BusinessEntitiesDefinitions.DATACENTER_NAME_SIZE) - private String storagePoolName; + // @Column(name = "storage_pool_name") + // TODO + private transient String storagePoolName; + @Column(name = "max_vds_memory_over_commit") private int maxVdsMemoryOverCommit; + @Column(name = "enable_balloon") private boolean enableBallooning; + @Column(name = "enable_ksm") private boolean enableKsm; + @Column(name = "count_threads_as_cores") private boolean countThreadsAsCores; @Size(max = BusinessEntitiesDefinitions.GENERAL_VERSION_SIZE) + @Column(name = "compatibility_version") private String compatibilityVersion; - private Version compatVersion; + // TODO + private transient Version compatVersion; + @Column(name = "transparent_hugepages") private boolean transparentHugepages; - private MigrateOnErrorOptions migrateOnError; + // TODO + private transient MigrateOnErrorOptions migrateOnError; + @Column(name = "virt_service") private boolean virtService; + @Column(name = "gluster_service") private boolean glusterService; + @Column(name = "tunnel_migration") private boolean tunnelMigration; + @Column(name = "emulated_machine") private String emulatedMachine; + @Column(name = "trusted_service") private boolean trustedService; + @Column(name = "ha_reservation") private boolean haReservation; + @Column(name = "optional_reason") private boolean optionalReasonRequired; + @Column(name = "maintenance_reason_required") private boolean maintenanceReasonRequired; + @Column(name = "cluster_policy_id") + @Type(type = "org.ovirt.engine.core.dao.jpa.GuidUserType") private Guid clusterPolicyId; - private String clusterPolicyName; + // @Column(name = "cluster_policy_name") + // TODO + private transient String clusterPolicyName; - private Set<SupportedAdditionalClusterFeature> addtionalFeaturesSupported; + // TODO + private transient Set<SupportedAdditionalClusterFeature> addtionalFeaturesSupported; @ValidUri(message = "VALIDATION.VDS_GROUP.SPICE_PROXY.HOSTNAME_OR_IP", groups = { CreateEntity.class, UpdateEntity.class }) @Size(max = BusinessEntitiesDefinitions.SPICE_PROXY_ADDR_SIZE) + @Column(name = "spice_proxy") private String spiceProxy; - private Map<String, String> clusterPolicyProperties; + // TODO + private transient Map<String, String> clusterPolicyProperties; + + @Column(name = "detect_emulated_machine") private boolean detectEmulatedMachine; + @Column(name = "architecture") + @Type( + type = "org.ovirt.engine.core.dao.jpa.EnumUserType", + parameters = { @Parameter(name = "type", + value = "org.ovirt.engine.core.common.businessentities.ArchitectureType") }) private ArchitectureType architecture; + + @Column(name = "optimization_type") + @Type( + type = "org.ovirt.engine.core.dao.jpa.EnumUserType", + parameters = { @Parameter(name = "type", + value = "org.ovirt.engine.core.common.scheduling.OptimizationType") }) private OptimizationType optimizationType; + @Column(name = "serial_number_policy") + @Type( + type = "org.ovirt.engine.core.dao.jpa.EnumUserType", + parameters = { @Parameter(name = "type", + value = "org.ovirt.engine.core.common.businessentities.SerialNumberPolicy") }) private SerialNumberPolicy serialNumberPolicy; - private VDSGroupHostsAndVMs groupHostsAndVms; + + private transient VDSGroupHostsAndVMs groupHostsAndVms; @Size(max = BusinessEntitiesDefinitions.VM_SERIAL_NUMBER_SIZE) + @Column(name = "custom_serial_number") private String customSerialNumber; - private Set<VmRngDevice.Source> requiredRngSources; + // TODO + private transient Set<VmRngDevice.Source> requiredRngSources; - private FencingPolicy fencingPolicy; + // TODO + private transient FencingPolicy fencingPolicy; + @Column(name = "is_auto_converge") private Boolean autoConverge; + @Column(name = "is_migrate_compressed") private Boolean migrateCompressed; + @Column(name = "gluster_tuned_profile") private String glusterTunedProfile; public VDSGroup() { @@ -447,41 +574,7 @@ @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (id == null ? 0 : id.hashCode()); - result = prime * result + (compatVersion == null ? 0 : compatVersion.hashCode()); - result = prime * result + (compatibilityVersion == null ? 0 : compatibilityVersion.hashCode()); - result = prime * result + (cpuName == null ? 0 : cpuName.hashCode()); - result = prime * result + (description == null ? 0 : description.hashCode()); - result = prime * result + maxVdsMemoryOverCommit; - result = prime * result + (countThreadsAsCores ? 1231 : 1237); - result = prime * result + (migrateOnError == null ? 0 : migrateOnError.hashCode()); - result = prime * result + (name == null ? 0 : name.hashCode()); - result = prime * result + (storagePoolId == null ? 0 : storagePoolId.hashCode()); - result = prime * result + (storagePoolName == null ? 0 : storagePoolName.hashCode()); - result = prime * result + (transparentHugepages ? 1231 : 1237); - result = prime * result + (virtService ? 1231 : 1237); - result = prime * result + (glusterService ? 1231 : 1237); - result = prime * result + (tunnelMigration ? 1231 : 1237); - result = prime * result + (emulatedMachine == null ? 0 : emulatedMachine.hashCode()); - result = prime * result + (trustedService ? 1231 : 1237); - result = prime * result + (haReservation ? 1231 : 1237); - result = prime * result + (clusterPolicyName == null ? 0 : clusterPolicyName.hashCode()); - result = prime * result + (clusterPolicyProperties == null ? 0 : clusterPolicyProperties.hashCode()); - result = prime * result + (requiredRngSources == null ? 0 : requiredRngSources.hashCode()); - result = prime * result + (enableKsm ? 1231 : 1237); - result = prime * result + (enableBallooning ? 1231 : 1237); - result = prime * result + (optimizationType == null ? 0 : optimizationType.hashCode()); - result = prime * result + (serialNumberPolicy == null ? 0 : serialNumberPolicy.hashCode()); - result = prime * result + (customSerialNumber == null ? 0 : customSerialNumber.hashCode()); - result = prime * result + (fencingPolicy == null ? 0 : fencingPolicy.hashCode()); - result = prime * result + (autoConverge == null ? 0 : autoConverge.hashCode()); - result = prime * result + (migrateCompressed == null ? 0 : migrateCompressed.hashCode()); - result = prime * result + (glusterTunedProfile == null ? 0 : glusterTunedProfile.hashCode()); - result = prime * result + (addtionalFeaturesSupported == null ? 0 : addtionalFeaturesSupported.hashCode()); - result = prime * result + (maintenanceReasonRequired ? 1231 : 1237); - return result; + return Objects.hash(id); } @Override @@ -493,42 +586,7 @@ return false; } VDSGroup other = (VDSGroup) obj; - // *ATTENTION* when adding fields to this, please make sure that equals still works, if not this will - // cause all kinds of havoc in the UI when clusters are refreshed. - return (ObjectUtils.objectsEqual(id, other.id) - && ObjectUtils.objectsEqual(compatVersion, other.compatVersion) - && ObjectUtils.objectsEqual(compatibilityVersion, other.compatibilityVersion) - && ObjectUtils.objectsEqual(cpuName, other.cpuName) - && ObjectUtils.objectsEqual(description, other.description) - && maxVdsMemoryOverCommit == other.maxVdsMemoryOverCommit - && countThreadsAsCores == other.countThreadsAsCores - && migrateOnError == other.migrateOnError - && ObjectUtils.objectsEqual(name, other.name) - && ObjectUtils.objectsEqual(storagePoolId, other.storagePoolId) - && ObjectUtils.objectsEqual(storagePoolName, other.storagePoolName) - && transparentHugepages == other.transparentHugepages - && virtService == other.virtService - && glusterService == other.glusterService - && tunnelMigration == other.tunnelMigration - && ObjectUtils.objectsEqual(emulatedMachine, other.emulatedMachine) - && trustedService == other.trustedService - && haReservation == other.haReservation - && ObjectUtils.objectsEqual(clusterPolicyId, other.clusterPolicyId) - && ObjectUtils.objectsEqual(clusterPolicyName, other.clusterPolicyName) - && ObjectUtils.objectsEqual(clusterPolicyProperties, other.clusterPolicyProperties) - && enableKsm == other.enableKsm - && enableBallooning == other.enableBallooning - && detectEmulatedMachine == other.detectEmulatedMachine - && optimizationType == other.optimizationType) - && serialNumberPolicy == other.serialNumberPolicy - && ObjectUtils.objectsEqual(customSerialNumber, other.customSerialNumber) - && ObjectUtils.objectsEqual(requiredRngSources, other.requiredRngSources) - && ObjectUtils.objectsEqual(fencingPolicy, other.fencingPolicy) - && ObjectUtils.objectsEqual(autoConverge, other.autoConverge) - && ObjectUtils.objectsEqual(migrateCompressed, other.migrateCompressed) - && ObjectUtils.objectsEqual(glusterTunedProfile, other.glusterTunedProfile) - && ObjectUtils.objectsEqual(maintenanceReasonRequired, other.maintenanceReasonRequired) - && ObjectUtils.objectsEqual(addtionalFeaturesSupported, other.addtionalFeaturesSupported); + return Objects.equals(id, other.id); } } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/OptimizationType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/OptimizationType.java index 2dd5d3d..a069305 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/OptimizationType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/OptimizationType.java @@ -1,6 +1,7 @@ package org.ovirt.engine.core.common.scheduling; + /** * cluster's optimization method, * <p> @@ -31,4 +32,13 @@ public int getValue() { return value; } + + /** + * Maps Integer value to OptimizationType. + * @param value + * @return If {@code value} is null returns null specifying unset OptimizationType. + */ + public static OptimizationType forValue(int value) { + return from(value); + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAO.java index 221c573..ee3fed6 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAO.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAO.java @@ -10,7 +10,7 @@ * <code>VdsGroupDAO</code> defines a type that performs CRUD operations on instances of {@link VDSGroup}. * */ -public interface VdsGroupDAO extends DAO, SearchDAO<VDSGroup> { +public interface VdsGroupDAO extends GenericDao<VDSGroup, Guid>, SearchDAO<VDSGroup> { /** * Gets the group with the specified id. * diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAODbFacadeImpl.java index 0bab488..76c1424 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsGroupDAODbFacadeImpl.java @@ -1,69 +1,56 @@ package org.ovirt.engine.core.dao; -import java.sql.Array; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import javax.inject.Named; -import javax.inject.Singleton; +import javax.enterprise.context.ApplicationScoped; +import javax.interceptor.Interceptors; import org.ovirt.engine.core.common.businessentities.ActionGroup; -import org.ovirt.engine.core.common.businessentities.ArchitectureType; -import org.ovirt.engine.core.common.businessentities.MigrateOnErrorOptions; -import org.ovirt.engine.core.common.businessentities.SerialNumberPolicy; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VDSGroupHostsAndVMs; -import org.ovirt.engine.core.common.businessentities.VmRngDevice; -import org.ovirt.engine.core.common.scheduling.OptimizationType; import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.dal.dbbroker.DbFacadeUtils; -import org.ovirt.engine.core.utils.SerializationFactory; +import org.ovirt.engine.core.dao.jpa.AbstractJpaDao; +import org.ovirt.engine.core.utils.transaction.TransactionalInterceptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.stereotype.Component; /** * <code>VdsGroupDAODbFacadeImpl</code> provides an implementation of {@link VdsGroupDAO} that uses code previously * found in {@link org.ovirt.engine.core.dal.dbbroker.DbFacade}. * */ -@Named -@Singleton -public class VdsGroupDAODbFacadeImpl extends BaseDAODbFacade implements VdsGroupDAO { +@Interceptors({ TransactionalInterceptor.class }) +@ApplicationScoped +@Component +public class VdsGroupDAODbFacadeImpl extends AbstractJpaDao<VDSGroup, Guid> implements VdsGroupDAO { private static final Logger log = LoggerFactory.getLogger(VdsGroupDAODbFacadeImpl.class); - @Override - public VDSGroup get(Guid id) { - return get(id, null, false); + public VdsGroupDAODbFacadeImpl() { + super(VDSGroup.class); } @Override public VDSGroup get(Guid id, Guid userID, boolean isFiltered) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("vds_group_id", id).addValue("user_id", userID).addValue("is_filtered", isFiltered); - - return getCallsHandler().executeRead("GetVdsGroupByVdsGroupId", VdsGroupRowMapper.instance, parameterSource); + return singleResult(entityManager.createNamedQuery("VDSGroup.get", VDSGroup.class) + .setParameter(1, id.toString()) + .setParameter(2, userID.toString()) + .setParameter(3, isFiltered)); } @Override public VDSGroup getWithRunningVms(Guid id) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("vds_group_id", id); - return getCallsHandler().executeRead("GetVdsGroupWithRunningVms", VdsGroupRowMapper.instance, parameterSource); + return singleResult(entityManager.createNamedQuery("VDSGroup.getWithRunningVms", VDSGroup.class) + .setParameter(1, id.toString())); } @Override public Boolean getIsEmpty(Guid id) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("vds_group_id", id); - return getCallsHandler().executeRead("GetIsVdsGroupEmpty", BooleanRowMapper.instance, parameterSource); + return (Boolean) entityManager.createNamedQuery("VDSGroup.getIsEmpty") + .setParameter("vdsGroupId", id).getSingleResult(); } @Override @@ -73,24 +60,22 @@ @Override public List<VDSGroup> getByName(String name, boolean isCaseSensitive) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("vds_group_name", name) - .addValue("is_case_sensitive", isCaseSensitive); + String queryName; - return getCallsHandler().executeReadList("GetVdsGroupByVdsGroupName", - VdsGroupRowMapper.instance, - parameterSource); + if (isCaseSensitive) { + queryName = "VDSGroup.getByNameSensitive"; + } else { + queryName = "VDSGroup.getByNameInSensitive"; + } + return multipleResults(entityManager.createNamedQuery(queryName, VDSGroup.class).setParameter("name", name)); } @Override public VDSGroup getByName(String name, Guid userID, boolean isFiltered) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("vds_group_name", name).addValue("user_id", userID).addValue("is_filtered", isFiltered); - - return (VDSGroup) DbFacadeUtils.asSingleResult( - getCallsHandler().executeReadList("GetVdsGroupForUserByVdsGroupName", - VdsGroupRowMapper.instance, - parameterSource)); + return singleResult(entityManager.createNamedQuery("VDSGroup.getByName", VDSGroup.class) + .setParameter(1, name) + .setParameter(2, userID.toString()) + .setParameter(3, isFiltered)); } @Override @@ -100,17 +85,15 @@ @Override public List<VDSGroup> getAllForStoragePool(Guid id, Guid userID, boolean isFiltered) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("storage_pool_id", id).addValue("user_id", userID).addValue("is_filtered", isFiltered); - - return getCallsHandler().executeReadList("GetVdsGroupsByStoragePoolId", - VdsGroupRowMapper.instance, - parameterSource); + return multipleResults(entityManager.createNamedQuery("VDSGroup.getAllForStoragePool", VDSGroup.class) + .setParameter(1, id.toString()) + .setParameter(2, (userID == null) ? null : userID.toString()) + .setParameter(3, isFiltered)); } @Override public List<VDSGroup> getAllWithQuery(String query) { - List<VDSGroup> groups = getJdbcTemplate().query(query, VdsGroupRowMapper.instance); + List<VDSGroup> groups = multipleResults(entityManager.createNativeQuery(query)); try { // The UI requires the host and vm count @@ -123,233 +106,76 @@ } @Override - public List<VDSGroup> getAll() { - return getAll(null, false); - } - - @Override public List<VDSGroup> getAll(Guid userID, boolean isFiltered) { - MapSqlParameterSource parameterSource = - getCustomMapSqlParameterSource().addValue("user_id", userID).addValue("is_filtered", isFiltered); - return getCallsHandler().executeReadList("GetAllFromVdsGroups", VdsGroupRowMapper.instance, parameterSource); + return multipleResults(entityManager.createNamedQuery("VDSGroup.getAll", VDSGroup.class) + .setParameter(1, userID.toString()) + .setParameter(2, isFiltered)); } @Override public void save(VDSGroup group) { - Guid id = group.getId(); - if (Guid.isNullOrEmpty(id)) { - id = Guid.newGuid(); - group.setId(id); + if (Guid.isNullOrEmpty(group.getId())) { + group.setId(Guid.newGuid()); } - getCallsHandler().executeModification("InsertVdsGroups", getVdsGroupParamSource(group)); - } - - @Override - public void update(VDSGroup group) { - getCallsHandler().executeModification("UpdateVdsGroup", getVdsGroupParamSource(group)); - } - - @Override - public void remove(Guid id) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("vds_group_id", id); - - getCallsHandler().executeModification("DeleteVdsGroup", parameterSource); + super.save(group); } @Override public List<VDSGroup> getClustersWithPermittedAction(Guid userId, ActionGroup actionGroup) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("user_id", userId).addValue("action_group_id", actionGroup.getId()); - - return getCallsHandler().executeReadList("fn_perms_get_vds_groups_with_permitted_action", - VdsGroupRowMapper.instance, - parameterSource); + return multipleResults(entityManager.createNamedQuery("VDSGroup.getClustersWithPermittedAction", VDSGroup.class) + .setParameter("userId", userId) + .setParameter("actionGroupId", actionGroup.getId())); } @Override public List<VDSGroup> getClustersHavingHosts() { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource(); - - return getCallsHandler().executeReadList("GetClustersHavingHosts", - VdsGroupRowMapper.instance, - parameterSource); + return multipleResults(entityManager.createNamedQuery("VDSGroup.getClustersHavingHosts", VDSGroup.class)); } @Override public void setEmulatedMachine(Guid vdsGroupId, String emulatedMachine, boolean detectEmulatedMachine) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("vds_group_id", vdsGroupId) - .addValue("emulated_machine", emulatedMachine) - .addValue("detect_emulated_machine", detectEmulatedMachine); - - getCallsHandler().executeModification("UpdateVdsGroupEmulatedMachine", parameterSource); + VDSGroup group = get(vdsGroupId); + group.setEmulatedMachine(emulatedMachine); + group.setDetectEmulatedMachine(detectEmulatedMachine); + update(group); } @Override public int getVmsCountByClusterId(Guid vdsGroupId) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("vds_group_id", vdsGroupId); - return getCallsHandler().executeRead("GetNumberOfVmsInCluster", - getIntegerMapper(), - parameterSource); + return ((Number) entityManager.createNamedQuery("VDSGroup.getVmsCountByClusterId") + .setParameter(1, vdsGroupId.toString()).getSingleResult()).intValue(); } @Override public List<VDSGroup> getTrustedClusters() { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("trusted_service", true); - return getCallsHandler().executeReadList("GetTrustedVdsGroups", VdsGroupRowMapper.instance, parameterSource); - } - - private MapSqlParameterSource getVdsGroupParamSource(VDSGroup group) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("description", group.getDescription()) - .addValue("name", group.getName()) - .addValue("free_text_comment", group.getComment()) - .addValue("vds_group_id", group.getId()) - .addValue("cpu_name", group.getCpuName()) - .addValue("storage_pool_id", group.getStoragePoolId()) - .addValue("max_vds_memory_over_commit", - group.getMaxVdsMemoryOverCommit()) - .addValue("count_threads_as_cores", - group.getCountThreadsAsCores()) - .addValue("transparent_hugepages", - group.getTransparentHugepages()) - .addValue("compatibility_version", - group.getCompatibilityVersion()) - .addValue("migrate_on_error", group.getMigrateOnError()) - .addValue("virt_service", group.supportsVirtService()) - .addValue("gluster_service", group.supportsGlusterService()) - .addValue("tunnel_migration", group.isTunnelMigration()) - .addValue("required_rng_sources", VmRngDevice.sourcesToCsv(group.getRequiredRngSources())) - .addValue("emulated_machine", group.getEmulatedMachine()) - .addValue("detect_emulated_machine", group.isDetectEmulatedMachine()) - .addValue("trusted_service", group.supportsTrustedService()) - .addValue("ha_reservation", group.supportsHaReservation()) - .addValue("optional_reason", group.isOptionalReasonRequired()) - .addValue("maintenance_reason_required", group.isMaintenanceReasonRequired()) - .addValue("cluster_policy_id", group.getClusterPolicyId()) - .addValue("cluster_policy_custom_properties", - SerializationFactory.getSerializer().serialize(group.getClusterPolicyProperties())) - .addValue("architecture", group.getArchitecture()) - .addValue("enable_balloon", group.isEnableBallooning()) - .addValue("optimization_type", group.getOptimizationType()) - .addValue("enable_ksm", group.isEnableKsm()) - .addValue("spice_proxy", group.getSpiceProxy()) - .addValue("serial_number_policy", group.getSerialNumberPolicy() == null ? null : group.getSerialNumberPolicy().getValue()) - .addValue("custom_serial_number", group.getCustomSerialNumber()) - .addValue("skip_fencing_if_sd_active", group.getFencingPolicy().isSkipFencingIfSDActive()) - .addValue("skip_fencing_if_connectivity_broken", group.getFencingPolicy().isSkipFencingIfConnectivityBroken()) - .addValue("hosts_with_broken_connectivity_threshold", group.getFencingPolicy().getHostsWithBrokenConnectivityThreshold()) - .addValue("fencing_enabled", group.getFencingPolicy().isFencingEnabled()) - .addValue("is_auto_converge", group.getAutoConverge()) - .addValue("is_migrate_compressed", group.getMigrateCompressed()) - .addValue("gluster_tuned_profile", group.getGlusterTunedProfile()); - - return parameterSource; - } - - private final static class VDSGroupHostsAndVMsRowMapper implements RowMapper<VDSGroupHostsAndVMs> { - public static final RowMapper<VDSGroupHostsAndVMs> instance = new VDSGroupHostsAndVMsRowMapper(); - - @Override - public VDSGroupHostsAndVMs mapRow(ResultSet rs, int rowNum) throws SQLException { - VDSGroupHostsAndVMs entity = new VDSGroupHostsAndVMs(); - entity.setHosts(rs.getInt("hosts")); - entity.setVms(rs.getInt("vms")); - entity.setVdsGroupId(getGuid(rs, "vds_group_id")); - return entity; - } - - } - private final static class VdsGroupRowMapper implements RowMapper<VDSGroup> { - public static final RowMapper<VDSGroup> instance = new VdsGroupRowMapper(); - @Override - public VDSGroup mapRow(ResultSet rs, int rowNum) - throws SQLException { - VDSGroup entity = new VDSGroup(); - entity.setDescription(rs.getString("description")); - entity.setName(rs.getString("name")); - entity.setId(getGuidDefaultEmpty(rs, "vds_group_id")); - entity.setComment(rs.getString("free_text_comment")); - entity.setCpuName(rs.getString("cpu_name")); - entity.setStoragePoolId(getGuid(rs, "storage_pool_id")); - entity.setStoragePoolName(rs - .getString("storage_pool_name")); - entity.setMaxVdsMemoryOverCommit(rs - .getInt("max_vds_memory_over_commit")); - entity.setCountThreadsAsCores(rs - .getBoolean("count_threads_as_cores")); - entity.setTransparentHugepages(rs - .getBoolean("transparent_hugepages")); - entity.setCompatibilityVersion(new Version(rs - .getString("compatibility_version"))); - entity.setMigrateOnError(MigrateOnErrorOptions.forValue(rs.getInt("migrate_on_error"))); - entity.setVirtService(rs.getBoolean("virt_service")); - entity.setGlusterService(rs.getBoolean("gluster_service")); - entity.setTunnelMigration(rs.getBoolean("tunnel_migration")); - entity.getRequiredRngSources().addAll(VmRngDevice.csvToSourcesSet(rs.getString("required_rng_sources"))); - entity.setEmulatedMachine(rs.getString("emulated_machine")); - entity.setDetectEmulatedMachine(rs.getBoolean("detect_emulated_machine")); - entity.setTrustedService(rs.getBoolean("trusted_service")); - entity.setHaReservation(rs.getBoolean("ha_reservation")); - entity.setOptionalReasonRequired(rs.getBoolean("optional_reason")); - entity.setMaintenanceReasonRequired(rs.getBoolean("maintenance_reason_required")); - entity.setClusterPolicyId(Guid.createGuidFromString(rs.getString("cluster_policy_id"))); - entity.setClusterPolicyName(rs.getString("cluster_policy_name")); - entity.setClusterPolicyProperties(SerializationFactory.getDeserializer() - .deserializeOrCreateNew(rs.getString("cluster_policy_custom_properties"), LinkedHashMap.class)); - entity.setEnableBallooning(rs.getBoolean("enable_balloon")); - entity.setEnableKsm(rs.getBoolean("enable_ksm")); - entity.setArchitecture(ArchitectureType.forValue(rs.getInt("architecture"))); - entity.setOptimizationType(OptimizationType.from(rs.getInt("optimization_type"))); - entity.setSpiceProxy(rs.getString("spice_proxy")); - entity.setSerialNumberPolicy(SerialNumberPolicy.forValue((Integer) rs.getObject("serial_number_policy"))); - entity.setCustomSerialNumber(rs.getString("custom_serial_number")); - entity.getFencingPolicy().setSkipFencingIfSDActive(rs.getBoolean("skip_fencing_if_sd_active")); - entity.getFencingPolicy().setSkipFencingIfConnectivityBroken(rs.getBoolean("skip_fencing_if_connectivity_broken")); - entity.getFencingPolicy().setHostsWithBrokenConnectivityThreshold(rs.getInt("hosts_with_broken_connectivity_threshold")); - entity.getFencingPolicy().setFencingEnabled(rs.getBoolean("fencing_enabled")); - entity.setAutoConverge((Boolean) rs.getObject("is_auto_converge")); - entity.setMigrateCompressed((Boolean) rs.getObject("is_migrate_compressed")); - entity.setGlusterTunedProfile(rs.getString("gluster_tuned_profile")); - - return entity; - } - } - - private final static class BooleanRowMapper implements RowMapper<Boolean> { - public static final RowMapper<Boolean> instance = new BooleanRowMapper(); - - @Override - public Boolean mapRow(ResultSet rs, int rowNum) throws SQLException { - return Boolean.valueOf(rs.getBoolean(1)); - } + return multipleResults(entityManager.createNamedQuery("VDSGroup.getTrustedClusters", VDSGroup.class)); } @Override public List<VDSGroup> getClustersByClusterPolicyId(Guid clusterPolicyId) { - return getCallsHandler().executeReadList("GetVdsGroupsByClusterPolicyId", - VdsGroupRowMapper.instance, - getCustomMapSqlParameterSource() - .addValue("cluster_policy_id", clusterPolicyId)); + return multipleResults(entityManager.createNamedQuery("VDSGroup.getClustersByClusterPolicyId", VDSGroup.class) + .setParameter("clusterPolicyId", clusterPolicyId)); } protected List<VDSGroup> getHostsAndVmsForClusters(List<VDSGroup> vdsGroups) throws Exception { Map<Guid, VDSGroup> groupsById = new HashMap<>(); + StringBuilder sb = new StringBuilder(); for (VDSGroup vdsGroup : vdsGroups) { + sb.append(vdsGroup.getId()).append(","); groupsById.put(vdsGroup.getId(), vdsGroup); } - Connection c = getJdbcTemplate().getDataSource().getConnection(); - Array groups = c.createArrayOf("uuid", groupsById.keySet().toArray()); - List<VDSGroupHostsAndVMs> dataList = getCallsHandler().executeReadList("GetHostsAndVmsForClusters", - VDSGroupHostsAndVMsRowMapper.instance, - getCustomMapSqlParameterSource() - .addValue("vds_group_ids", groups)); - - c.close(); - for (VDSGroupHostsAndVMs groupDetail : dataList) { - groupsById.get(groupDetail.getVdsGroupId()).setGroupHostsAndVms(groupDetail); + if (sb.length() > 0) { + sb.deleteCharAt(sb.length() - 1); + } + List<Object[]> dataList = + multipleResults(entityManager.createNamedQuery("VDSGroup.getHostsAndVmsForClusters") + .setParameter(1, sb.toString())); + for (Object[] groupDetail : dataList) { + VDSGroupHostsAndVMs groupHostAndVm = new VDSGroupHostsAndVMs(); + groupHostAndVm.setVdsGroupId(Guid.createGuidFromString(groupDetail[0].toString())); + groupHostAndVm.setHosts(((Number) groupDetail[1]).intValue()); + groupHostAndVm.setVms(((Number) groupDetail[2]).intValue()); + groupsById.get(groupHostAndVm.getVdsGroupId()).setGroupHostsAndVms(groupHostAndVm); } //The VDS groups have been updated, but we want to keep the order, so return the original list which is //in the right order. @@ -359,10 +185,10 @@ @Override public List<VDSGroup> getClustersByServiceAndCompatibilityVersion(boolean glusterService, boolean virtService, String compatibilityVersion) { - return getCallsHandler().executeReadList("GetVdsGroupsByServiceAndCompatibilityVersion", - VdsGroupRowMapper.instance, - getCustomMapSqlParameterSource().addValue("gluster_service", glusterService) - .addValue("virt_service", virtService) - .addValue("compatibility_version", compatibilityVersion)); + return multipleResults(entityManager.createNamedQuery("VDSGroup.getClustersByServiceAndCompatibilityVersion", + VDSGroup.class) + .setParameter("glusterService", glusterService) + .setParameter("virtService", virtService) + .setParameter("compatibilityVersion", compatibilityVersion)); } } diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsGroupDAOTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsGroupDAOTest.java index e21deb1..7295cd4 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsGroupDAOTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VdsGroupDAOTest.java @@ -22,7 +22,8 @@ import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.dao.scheduling.ClusterPolicyDao; -public class VdsGroupDAOTest extends BaseDAOTestCase { +public class VdsGroupDAOTest extends BaseHibernateDaoTestCase<VdsGroupDAO, VDSGroup, Guid> { + private static final String NEW_FIELD_VALUE = "test comment"; private static final int NUMBER_OF_GROUPS = 9; private static final int NUMBER_OF_TRUSTED_GROUPS = 4; private static final int NUMBER_OF_GROUPS_FOR_PRIVELEGED_USER = 2; @@ -65,6 +66,7 @@ newGroup.setDetectEmulatedMachine(true); newGroup.setEmulatedMachine("rhel6.4.0"); newGroup.setArchitecture(ArchitectureType.x86_64); + newGroup.setId(Guid.newGuid()); } @@ -96,16 +98,6 @@ VDSGroup result = dao.getWithRunningVms(existingVdsGroup.getId()); assertNotNull(result); - } - - /** - * Ensures that retrieving a group works as expected. - */ - @Test - public void testGet() { - VDSGroup result = dao.get(existingVdsGroup.getId()); - - assertCorrectVDSGroup(result); } /** @@ -307,53 +299,6 @@ } /** - * Ensures saving a group works as expected. - */ - @Test - public void testSave() { - dao.save(newGroup); - - VDSGroup result = dao.getByName(newGroup.getName()); - - assertNotNull(result); - assertEquals(newGroup, result); - } - - /** - * Ensures that updating a group works as expected. - */ - @Test - public void testUpdate() { - String oldName = existingVdsGroup.getName(); - - existingVdsGroup.setName("This is the new name"); - existingVdsGroup.setVirtService(false); - existingVdsGroup.setGlusterService(true); - - dao.update(existingVdsGroup); - - VDSGroup result = dao.get(existingVdsGroup.getId()); - - assertCorrectVDSGroup(result); - - result = dao.getByName(oldName); - - assertNull(result); - } - - /** - * Ensures that removing a group works as expected. - */ - @Test - public void testRemove() { - dao.remove(groupWithNoRunningVms.getId()); - - VDSGroup result = dao.get(groupWithNoRunningVms.getId()); - - assertNull(result); - } - - /** * Test the use of the special procedure to update emulated_machine */ @Test @@ -488,4 +433,35 @@ assertNotNull(clusters); assertThat(clusters, hasSize(4)); } + + @Override + protected VdsGroupDAO getDao() { + return dao; + } + + @Override + protected VDSGroup getExistingEntity() { + return existingVdsGroup; + } + + @Override + protected VDSGroup getNonExistentEntity() { + return newGroup; + } + + @Override + protected int getAllEntitiesCount() { + return NUMBER_OF_GROUPS; + } + + @Override + protected VDSGroup modifyEntity(VDSGroup entity) { + entity.setComment(NEW_FIELD_VALUE); + return entity; + } + + @Override + protected void verifyEntityModification(VDSGroup result) { + assertEquals(NEW_FIELD_VALUE, result.getComment()); + } } diff --git a/packaging/dbscripts/vds_groups_sp.sql b/packaging/dbscripts/vds_groups_sp.sql index 586c6c7..bca159d 100644 --- a/packaging/dbscripts/vds_groups_sp.sql +++ b/packaging/dbscripts/vds_groups_sp.sql @@ -7,152 +7,6 @@ -Create or replace FUNCTION InsertVdsGroups( - v_vds_group_id UUID, - v_description VARCHAR(4000), - v_free_text_comment text, - v_name VARCHAR(40), - v_cpu_name VARCHAR(255), - v_storage_pool_id UUID , - v_max_vds_memory_over_commit INTEGER, - v_count_threads_as_cores BOOLEAN, - v_compatibility_version VARCHAR(40), - v_transparent_hugepages BOOLEAN, - v_migrate_on_error INTEGER, - v_virt_service BOOLEAN, - v_gluster_service BOOLEAN, - v_tunnel_migration BOOLEAN, - v_emulated_machine VARCHAR(40), - v_detect_emulated_machine BOOLEAN, - v_trusted_service BOOLEAN, - v_ha_reservation BOOLEAN, - v_optional_reason BOOLEAN, - v_maintenance_reason_required BOOLEAN, - v_cluster_policy_id UUID, - v_cluster_policy_custom_properties text, - v_enable_balloon BOOLEAN, - v_architecture INTEGER, - v_optimization_type SMALLINT, - v_spice_proxy VARCHAR(255), - v_enable_ksm BOOLEAN, - v_serial_number_policy SMALLINT, - v_custom_serial_number VARCHAR(255), - v_required_rng_sources varchar(255), - v_skip_fencing_if_sd_active BOOLEAN, - v_skip_fencing_if_connectivity_broken BOOLEAN, - v_hosts_with_broken_connectivity_threshold SMALLINT, - v_fencing_enabled BOOLEAN, - v_is_auto_converge BOOLEAN, - v_is_migrate_compressed BOOLEAN, - v_gluster_tuned_profile VARCHAR(50) -) -RETURNS VOID - AS $procedure$ -BEGIN - INSERT INTO vds_groups(vds_group_id,description, name, free_text_comment, cpu_name, storage_pool_id, max_vds_memory_over_commit, count_threads_as_cores, compatibility_version, - transparent_hugepages, migrate_on_error, virt_service, gluster_service, tunnel_migration, emulated_machine, detect_emulated_machine, trusted_service, ha_reservation, optional_reason, maintenance_reason_required, cluster_policy_id, - cluster_policy_custom_properties, enable_balloon, architecture, optimization_type, spice_proxy, enable_ksm, serial_number_policy, custom_serial_number, required_rng_sources, skip_fencing_if_sd_active, skip_fencing_if_connectivity_broken, hosts_with_broken_connectivity_threshold, fencing_enabled, - is_auto_converge, is_migrate_compressed, gluster_tuned_profile) - VALUES(v_vds_group_id,v_description, v_name, v_free_text_comment, v_cpu_name, v_storage_pool_id, v_max_vds_memory_over_commit, v_count_threads_as_cores, v_compatibility_version, - v_transparent_hugepages, v_migrate_on_error, v_virt_service, v_gluster_service, v_tunnel_migration, v_emulated_machine, v_detect_emulated_machine, v_trusted_service, v_ha_reservation, v_optional_reason, v_maintenance_reason_required, v_cluster_policy_id, v_cluster_policy_custom_properties, v_enable_balloon, - v_architecture, v_optimization_type, v_spice_proxy, v_enable_ksm, v_serial_number_policy, v_custom_serial_number, v_required_rng_sources, v_skip_fencing_if_sd_active, v_skip_fencing_if_connectivity_broken, v_hosts_with_broken_connectivity_threshold, v_fencing_enabled, - v_is_auto_converge, v_is_migrate_compressed, v_gluster_tuned_profile); -END; $procedure$ -LANGUAGE plpgsql; - - - - - -Create or replace FUNCTION UpdateVdsGroup(v_description VARCHAR(4000) , - v_free_text_comment text, - v_name VARCHAR(40), - v_vds_group_id UUID, - v_cpu_name VARCHAR(255) , - v_storage_pool_id UUID , - v_max_vds_memory_over_commit INTEGER, - v_count_threads_as_cores BOOLEAN, - v_compatibility_version VARCHAR(40), - v_transparent_hugepages BOOLEAN , - v_migrate_on_error INTEGER, - v_virt_service BOOLEAN, - v_gluster_service BOOLEAN, - v_tunnel_migration BOOLEAN, - v_emulated_machine VARCHAR(40), - v_detect_emulated_machine BOOLEAN, - v_trusted_service BOOLEAN, - v_ha_reservation BOOLEAN, - v_optional_reason BOOLEAN, - v_maintenance_reason_required BOOLEAN, - v_cluster_policy_id UUID, - v_cluster_policy_custom_properties text, - v_enable_balloon BOOLEAN, - v_architecture INTEGER, - v_optimization_type SMALLINT, - v_spice_proxy VARCHAR(255), - v_enable_ksm BOOLEAN, - v_serial_number_policy SMALLINT, - v_custom_serial_number VARCHAR(255), - v_required_rng_sources varchar(255), - v_skip_fencing_if_sd_active BOOLEAN, - v_skip_fencing_if_connectivity_broken BOOLEAN, - v_hosts_with_broken_connectivity_threshold SMALLINT, - v_fencing_enabled BOOLEAN, - v_is_auto_converge BOOLEAN, - v_is_migrate_compressed BOOLEAN, - v_gluster_tuned_profile VARCHAR(50) -) -RETURNS VOID - - --The [vds_groups] table doesn't have a timestamp column. Optimistic concurrency logic cannot be generated - AS $procedure$ -BEGIN - UPDATE vds_groups - SET description = v_description, free_text_comment = v_free_text_comment, name = v_name,cpu_name = v_cpu_name, - storage_pool_id = v_storage_pool_id,_update_date = LOCALTIMESTAMP, - max_vds_memory_over_commit = v_max_vds_memory_over_commit, - count_threads_as_cores = v_count_threads_as_cores, - compatibility_version = v_compatibility_version,transparent_hugepages = v_transparent_hugepages, - migrate_on_error = v_migrate_on_error, - virt_service = v_virt_service, gluster_service = v_gluster_service, tunnel_migration = v_tunnel_migration, - emulated_machine = v_emulated_machine, detect_emulated_machine = v_detect_emulated_machine, trusted_service = v_trusted_service, ha_reservation = v_ha_reservation , optional_reason = v_optional_reason, maintenance_reason_required = v_maintenance_reason_required, cluster_policy_id = v_cluster_policy_id, - cluster_policy_custom_properties = v_cluster_policy_custom_properties, enable_balloon = v_enable_balloon, architecture = v_architecture, - optimization_type = v_optimization_type, spice_proxy = v_spice_proxy, enable_ksm = v_enable_ksm, - serial_number_policy = v_serial_number_policy, custom_serial_number = v_custom_serial_number, - required_rng_sources = v_required_rng_sources, - skip_fencing_if_sd_active = v_skip_fencing_if_sd_active, - skip_fencing_if_connectivity_broken = v_skip_fencing_if_connectivity_broken, - hosts_with_broken_connectivity_threshold = v_hosts_with_broken_connectivity_threshold, - fencing_enabled = v_fencing_enabled, - is_auto_converge = v_is_auto_converge, - is_migrate_compressed = v_is_migrate_compressed, - gluster_tuned_profile = v_gluster_tuned_profile - WHERE vds_group_id = v_vds_group_id; -END; $procedure$ -LANGUAGE plpgsql; - - - - - -Create or replace FUNCTION DeleteVdsGroup(v_vds_group_id UUID) -RETURNS VOID - AS $procedure$ - DECLARE - v_val UUID; -BEGIN - -- Get (and keep) a shared lock with "right to upgrade to exclusive" - -- in order to force locking parent before children - select vds_group_id INTO v_val FROM vds_groups WHERE vds_group_id = v_vds_group_id FOR UPDATE; - DELETE FROM vds_groups - WHERE vds_group_id = v_vds_group_id; - -- delete VDS group permissions -- - DELETE FROM permissions where object_id = v_vds_group_id; -END; $procedure$ -LANGUAGE plpgsql; - - - Create or replace FUNCTION GetAllFromVdsGroups(v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF vds_groups_view STABLE AS $procedure$ BEGIN @@ -179,19 +33,6 @@ END; $procedure$ LANGUAGE plpgsql; - - - - -Create or replace FUNCTION GetVdsGroupByVdsGroupName(v_vds_group_name VARCHAR(40), v_is_case_sensitive BOOLEAN) RETURNS SETOF vds_groups_view STABLE - AS $procedure$ -BEGIN - RETURN QUERY SELECT vds_groups_view.* - FROM vds_groups_view - WHERE name = v_vds_group_name OR (NOT v_is_case_sensitive AND name ilike v_vds_group_name); -END; $procedure$ -LANGUAGE plpgsql; - @@ -258,42 +99,12 @@ END; $procedure$ LANGUAGE plpgsql; --- This SP returns all clusters which have valid hosts attached to them -Create or replace FUNCTION GetClustersHavingHosts() RETURNS SETOF vds_groups_view STABLE - AS $procedure$ -BEGIN - RETURN QUERY SELECT vds_groups_view.* - FROM vds_groups_view - WHERE EXISTS (SELECT 1 from vds_static WHERE vds_group_id = vds_groups_view.vds_group_id); -END; $procedure$ -LANGUAGE plpgsql; - ---This SP updates the vds_group emulated machine and the detection mode -Create or replace FUNCTION UpdateVdsGroupEmulatedMachine(v_vds_group_id UUID, v_emulated_machine varchar(40), v_detect_emulated_machine BOOLEAN) RETURNS VOID - AS $procedure$ -BEGIN - UPDATE vds_groups - SET emulated_machine = v_emulated_machine, detect_emulated_machine = v_detect_emulated_machine - WHERE vds_group_id = v_vds_group_id; -END; $procedure$ -LANGUAGE plpgsql; - Create or replace FUNCTION GetTrustedVdsGroups() RETURNS SETOF vds_groups_view STABLE AS $procedure$ BEGIN RETURN QUERY SELECT vds_groups_view.* FROM vds_groups_view WHERE trusted_service; -END; $procedure$ -LANGUAGE plpgsql; - --- returns all clusters attached to a specific cluster policy (given as a parameter to the SP) -Create or replace FUNCTION GetVdsGroupsByClusterPolicyId(v_cluster_policy_id UUID) RETURNS SETOF vds_groups_view STABLE - AS $procedure$ -BEGIN - RETURN QUERY SELECT vds_groups_view.* - FROM vds_groups_view - WHERE cluster_policy_id = v_cluster_policy_id; END; $procedure$ LANGUAGE plpgsql; @@ -307,23 +118,14 @@ LANGUAGE plpgsql; DROP TYPE IF EXISTS host_vm_cluster_rs CASCADE; -CREATE TYPE host_vm_cluster_rs AS (vds_group_id UUID,hosts bigint,vms bigint); +CREATE TYPE host_vm_cluster_rs AS (vds_group_id TEXT,hosts bigint,vms bigint); -Create or replace FUNCTION GetHostsAndVmsForClusters(v_vds_group_ids UUID[]) RETURNS SETOF host_vm_cluster_rs STABLE +Create or replace FUNCTION GetHostsAndVmsForClusters(v_vds_group_ids VARCHAR) RETURNS SETOF host_vm_cluster_rs STABLE AS $procedure$ BEGIN - RETURN QUERY SELECT groups.vds_group_id,(select COUNT(DISTINCT vds.vds_id) from vds_static vds where vds.vds_group_id = groups.vds_group_id) as host_count,(select COUNT(DISTINCT vms.vm_guid) from vm_static vms where vms.vds_group_id = groups.vds_group_id and vms.entity_type::text = 'VM'::text) as vm_count + RETURN QUERY SELECT CAST(groups.vds_group_id AS TEXT),(select COUNT(DISTINCT vds.vds_id) from vds_static vds where vds.vds_group_id = groups.vds_group_id) as host_count,(select COUNT(DISTINCT vms.vm_guid) from vm_static vms where vms.vds_group_id = groups.vds_group_id and vms.entity_type::text = 'VM'::text) as vm_count FROM vds_groups groups - WHERE groups.vds_group_id = any(v_vds_group_ids) + WHERE groups.vds_group_id in (select * from fnSplitterUuid(v_vds_group_ids)) GROUP BY groups.vds_group_id; -END; $procedure$ -LANGUAGE plpgsql; - -Create or replace FUNCTION GetVdsGroupsByServiceAndCompatibilityVersion(v_gluster_service BOOLEAN, v_virt_service BOOLEAN, v_compatibility_version VARCHAR(40)) RETURNS SETOF vds_groups_view STABLE - AS $procedure$ -BEGIN - RETURN QUERY SELECT vds_groups_view.* - FROM vds_groups_view - WHERE virt_service = v_virt_service AND gluster_service = v_gluster_service AND compatibility_version = v_compatibility_version; END; $procedure$ LANGUAGE plpgsql; -- To view, visit https://gerrit.ovirt.org/41471 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic65c113fbc9c673dd814c83e03323ee7eca15ec8 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liran Zelkha <lzel...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches