Maor Lipchuk has uploaded a new change for review. Change subject: core: adding DAO support for unregistered VMs. ......................................................................
core: adding DAO support for unregistered VMs. * Add new BE OvfEntityData * Adding new table unregistered_ovf_of_entities * Add stored procedured * Adding UnregisteredOVFDataDAO [WIP] Tests should be added. Change-Id: I385fac757f46131ae0c0048b6cf39b78f037e852 Signed-off-by: Maor Lipchuk <[email protected]> --- A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/OvfEntityData.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UnregisteredOVFDataDAO.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UnregisteredOVFDataDAODbFacadeImpl.java M backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties A packaging/dbscripts/unregistered_OVF_data_sp.sql A packaging/dbscripts/upgrade/03_05_0170_unregistered_ovf_of_entities.sql 7 files changed, 257 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/80/26480/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/OvfEntityData.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/OvfEntityData.java new file mode 100644 index 0000000..f48e9a3 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/OvfEntityData.java @@ -0,0 +1,106 @@ +package org.ovirt.engine.core.common.businessentities; + +import java.io.Serializable; + +import org.ovirt.engine.core.compat.Guid; + +public class OvfEntityData extends IVdcQueryable implements Serializable { + private static final long serialVersionUID = 3376648147702972152L; + private Guid vmId; + private String vmName; + private String entityType; + private Guid storageDomainId; + private String ovfData; + private String ovfExtraData; + + public Guid getVmId() { + return vmId; + } + public void setVmId(Guid vmId) { + this.vmId = vmId; + } + public String getVmName() { + return vmName; + } + public void setVmName(String vmName) { + this.vmName = vmName; + } + public String getEntityType() { + return entityType; + } + public void setEntityType(String entityType) { + this.entityType = entityType; + } + public Guid getStorageDomainId() { + return storageDomainId; + } + public void setStorageDomainId(Guid storageDomainId) { + this.storageDomainId = storageDomainId; + } + public String getOvfData() { + return ovfData; + } + public void setOvfData(String ovfData) { + this.ovfData = ovfData; + } + public String getOvfExtraData() { + return ovfExtraData; + } + public void setOvfExtraData(String ovfExtraData) { + this.ovfExtraData = ovfExtraData; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((entityType == null) ? 0 : entityType.hashCode()); + result = prime * result + ((ovfData == null) ? 0 : ovfData.hashCode()); + result = prime * result + ((ovfExtraData == null) ? 0 : ovfExtraData.hashCode()); + result = prime * result + ((storageDomainId == null) ? 0 : storageDomainId.hashCode()); + result = prime * result + ((vmId == null) ? 0 : vmId.hashCode()); + result = prime * result + ((vmName == null) ? 0 : vmName.hashCode()); + return result; + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + OvfEntityData other = (OvfEntityData) obj; + if (entityType == null) { + if (other.entityType != null) + return false; + } else if (!entityType.equals(other.entityType)) + return false; + if (ovfData == null) { + if (other.ovfData != null) + return false; + } else if (!ovfData.equals(other.ovfData)) + return false; + if (ovfExtraData == null) { + if (other.ovfExtraData != null) + return false; + } else if (!ovfExtraData.equals(other.ovfExtraData)) + return false; + if (storageDomainId == null) { + if (other.storageDomainId != null) + return false; + } else if (!storageDomainId.equals(other.storageDomainId)) + return false; + if (vmId == null) { + if (other.vmId != null) + return false; + } else if (!vmId.equals(other.vmId)) + return false; + if (vmName == null) { + if (other.vmName != null) + return false; + } else if (!vmName.equals(other.vmName)) + return false; + return true; + } +} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java index b8d519e..37e3b69 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java @@ -16,6 +16,7 @@ import org.ovirt.engine.core.common.businessentities.DwhHistoryTimekeeping; import org.ovirt.engine.core.common.businessentities.Image; import org.ovirt.engine.core.common.businessentities.IscsiBond; +import org.ovirt.engine.core.common.businessentities.OvfEntityData; import org.ovirt.engine.core.common.businessentities.Permissions; import org.ovirt.engine.core.common.businessentities.Provider; import org.ovirt.engine.core.common.businessentities.Role; @@ -86,6 +87,7 @@ import org.ovirt.engine.core.dao.StorageServerConnectionDAO; import org.ovirt.engine.core.dao.StorageServerConnectionLunMapDAO; import org.ovirt.engine.core.dao.TagDAO; +import org.ovirt.engine.core.dao.UnregisteredOVFDataDAO; import org.ovirt.engine.core.dao.VdcOptionDAO; import org.ovirt.engine.core.dao.VdsDAO; import org.ovirt.engine.core.dao.VdsDynamicDAO; @@ -177,6 +179,7 @@ put(DwhHistoryTimekeeping.class, DwhHistoryTimekeepingDao.class); put(IscsiBond.class, IscsiBondDao.class); put(VmInit.class, VmInitDAO.class); + put(OvfEntityData.class, UnregisteredOVFDataDAO.class); } }; @@ -347,6 +350,15 @@ } /** + * Returns the singleton instance of {@link UnregisteredOVFDataDAO}. + * + * @return the dao + */ + public UnregisteredOVFDataDAO getUnregisteredOVFDataDao() { + return getDao(UnregisteredOVFDataDAO.class); + } + + /** * Returns the singleton instance of {@link VmAndTemplatesGenerationsDAO}. * * @return the dao diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UnregisteredOVFDataDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UnregisteredOVFDataDAO.java new file mode 100644 index 0000000..2771df7 --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UnregisteredOVFDataDAO.java @@ -0,0 +1,37 @@ +package org.ovirt.engine.core.dao; + +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.OvfEntityData; +import org.ovirt.engine.core.compat.Guid; + +public interface UnregisteredOVFDataDAO extends DAO { + + /** + * Retrieves the entity with the given VM id. + * + * @param id + * The VM Id. + * @return The entity instance, or <code>null</code> if not found. + */ + public OvfEntityData getByVmId(Guid vmId); + + /** + * Retrieves all the entities of type OvfEntityData related to the storage Domain Id. + * + * @param storageDomainId + * The Storage Domain Id + * @param entityType + * The entity type (VM/Template) + * @return List of all the OvfEntityData related to the storage Domain Id, or an empty list if none is found. + */ + public List<OvfEntityData> getAllForStorageDomain(Guid storageDomainId, String entityType); + + /** + * + * @param vmId + * @param storageDomainId + * @param ovfExtraData + */ + public void insertOVFDataForEntities(Guid vmId, Guid storageDomainId, String ovfExtraData); +} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UnregisteredOVFDataDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UnregisteredOVFDataDAODbFacadeImpl.java new file mode 100644 index 0000000..dc8c7ac --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UnregisteredOVFDataDAODbFacadeImpl.java @@ -0,0 +1,52 @@ +package org.ovirt.engine.core.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import org.ovirt.engine.core.common.businessentities.OvfEntityData; +import org.ovirt.engine.core.compat.Guid; +import org.springframework.jdbc.core.RowMapper; + +public class UnregisteredOVFDataDAODbFacadeImpl extends BaseDAODbFacade implements UnregisteredOVFDataDAO { + + @Override + public List<OvfEntityData> getAllForStorageDomain(Guid storageDomainId, String entityType) { + return getCallsHandler().executeReadList("getAllOVFEntitiesForStorageDomain", + OvfEntityDataRowMapper.instance, + getCustomMapSqlParameterSource() + .addValue("storage_domain_id", storageDomainId) + .addValue("entity_type", entityType)); + } + + @Override + public OvfEntityData getByVmId(Guid vmId) { + return getCallsHandler().executeRead("getOVFDataByVmId", + OvfEntityDataRowMapper.instance, + getCustomMapSqlParameterSource() + .addValue("vm_guid", vmId)); + } + + @Override + public void insertOVFDataForEntities(Guid vmId, Guid storageDomainId, String ovfExtraData) { + getCallsHandler().executeModification("InsertOVFDataForEntities", getCustomMapSqlParameterSource() + .addValue("vm_guid", vmId) + .addValue("storage_domain_id", storageDomainId) + .addValue("ovf_extra_data", ovfExtraData)); + } + + private static class OvfEntityDataRowMapper implements RowMapper<OvfEntityData> { + public static final OvfEntityDataRowMapper instance = new OvfEntityDataRowMapper(); + + @Override + public OvfEntityData mapRow(ResultSet rs, int rowNum) throws SQLException { + OvfEntityData entity = new OvfEntityData(); + entity.setVmId(getGuid(rs, "vm_guid")); + entity.setVmName(rs.getString("vm_name")); + entity.setEntityType(rs.getString("entity_type")); + entity.setStorageDomainId(getGuid(rs, "storage_domain_id")); + entity.setOvfData(rs.getString("ovf_data")); + entity.setOvfExtraData(rs.getString("ovf_extra_data")); + return entity; + } + } +} diff --git a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties index 19273d7..e6d1502 100644 --- a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties +++ b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties @@ -74,3 +74,4 @@ IscsiBondDao=org.ovirt.engine.core.dao.IscsiBondDaoDbFacadeImpl VmInitDAO=org.ovirt.engine.core.dao.VmInitDAODbFacadeImpl StorageDomainOvfInfoDao=org.ovirt.engine.core.dao.StorageDomainOvfInfoDbFacadeImpl +UnregisteredOVFDataDAO=org.ovirt.engine.core.dao.UnregisteredOVFDataDAODbFacadeImpl diff --git a/packaging/dbscripts/unregistered_OVF_data_sp.sql b/packaging/dbscripts/unregistered_OVF_data_sp.sql new file mode 100644 index 0000000..0502c0f --- /dev/null +++ b/packaging/dbscripts/unregistered_OVF_data_sp.sql @@ -0,0 +1,40 @@ +---------------------------------------------------------------- +-- [unregistered_ovf_of_entities] Table + +Create or replace FUNCTION InsertOVFDataForEntities(v_vm_guid UUID, + v_storage_domain_id UUID, + v_ovf_extra_data UUID) +RETURNS VOID + AS $procedure$ +BEGIN + INSERT INTO unregistered_ovf_of_entities(vm_guid, storage_domain_id, entity_type, vm_name, ovf_data, ovf_extra_data) + SELECT v_vm_guid, v_storage_domain_id, entity_type, vm_name, ovf_data, v_ovf_extra_data + FROM vm_static vs,vm_ovf_generations vog + WHERE vs.vm_guid = vog.vm_guid + AND vs.vm_guid = v_vm_guid; +END; $procedure$ +LANGUAGE plpgsql; + + +Create or replace FUNCTION getAllOVFEntitiesForStorageDomain(v_storage_domain_id UUID, v_entity_type VARCHAR(20)) +RETURNS SETOF unregistered_ovf_of_entities STABLE + AS $procedure$ +BEGIN + RETURN QUERY SELECT unregistered_ovf_of_entities.* + FROM unregistered_ovf_of_entities + WHERE storage_domain_id = v_storage_domain_id + AND entity_type = v_entity_type; +END; $procedure$ +LANGUAGE plpgsql; + + +Create or replace FUNCTION getOVFDataByVmId(v_vm_guid UUID) +RETURNS SETOF unregistered_ovf_of_entities STABLE + AS $procedure$ +BEGIN + RETURN QUERY SELECT unregistered_ovf_of_entities.* + FROM unregistered_ovf_of_entities + WHERE vm_guid = v_vm_guid; +END; $procedure$ +LANGUAGE plpgsql; + diff --git a/packaging/dbscripts/upgrade/03_05_0170_unregistered_ovf_of_entities.sql b/packaging/dbscripts/upgrade/03_05_0170_unregistered_ovf_of_entities.sql new file mode 100644 index 0000000..bbba962 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_05_0170_unregistered_ovf_of_entities.sql @@ -0,0 +1,9 @@ +CREATE TABLE unregistered_ovf_of_entities +( + vm_guid UUID PRIMARY KEY, + vm_name character varying(255) NOT NULL, + entity_type character varying(32) NOT NULL, + storage_domain_id UUID, + ovf_data text, + ovf_extra_data text +); -- To view, visit http://gerrit.ovirt.org/26480 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I385fac757f46131ae0c0048b6cf39b78f037e852 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Maor Lipchuk <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
