Ori Liel has uploaded a new change for review. Change subject: restapi: Host Power-Management Refactor (#977674) - WIP ......................................................................
restapi: Host Power-Management Refactor (#977674) - WIP Change-Id: Id0b384347a52db8b0aa6ae684fad40a5491dd2f7 Signed-off-by: Ori Liel <[email protected]> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetFencingAgentsByVdsIdQuery.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FencingAgent.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.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/dal/dbbroker/DbFacade.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/FencingAgentDAO.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/FencingAgentDaoImpl.java M backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties M packaging/dbscripts/create_tables.sql A packaging/dbscripts/fencing_agents_sp.sql A packaging/dbscripts/upgrade/03_05_0380_create_fencing_agents_table.sql 11 files changed, 260 insertions(+), 110 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/78/27578/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetFencingAgentsByVdsIdQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetFencingAgentsByVdsIdQuery.java new file mode 100644 index 0000000..f8bc815 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetFencingAgentsByVdsIdQuery.java @@ -0,0 +1,20 @@ +package org.ovirt.engine.core.bll; + +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; + +public class GetFencingAgentsByVdsIdQuery<P extends IdQueryParameters> + extends QueriesCommandBase<P> { + + public GetFencingAgentsByVdsIdQuery(P parameters) { + super(parameters); + } + + @Override + protected void executeQueryCommand() { + getQueryReturnValue().setReturnValue(DbFacade.getInstance() + .getFencingAgentDao() + .getFencingAgentsForHost(getParameters().getId())); + } + +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FencingAgent.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FencingAgent.java new file mode 100644 index 0000000..b91974c --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FencingAgent.java @@ -0,0 +1,110 @@ +package org.ovirt.engine.core.common.businessentities; + +import javax.validation.constraints.Size; + +import org.ovirt.engine.core.common.validation.annotation.HostnameOrIp; +import org.ovirt.engine.core.common.validation.group.PowerManagementCheck; +import org.ovirt.engine.core.compat.Guid; + +public class FencingAgent { + + private Guid id; + private Guid hostId; + private int order; + + @EditableField + @Size(max = BusinessEntitiesDefinitions.HOST_IP_SIZE) + @HostnameOrIp(message = "VALIDATION.VDS.POWER_MGMT.ADDRESS.HOSTNAME_OR_IP", groups = PowerManagementCheck.class) + private String ip; + + @EditableField + @Size(max = BusinessEntitiesDefinitions.HOST_PM_TYPE_SIZE) + private String type; + + @EditableField + @Size(max = BusinessEntitiesDefinitions.HOST_PM_USER_SIZE) + private String user; + + @EditableField + @Size(max = BusinessEntitiesDefinitions.HOST_PM_PASSWD_SIZE) + private String password; + + @EditableField + private int port; + + @EditableField + @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE) + private String options; + + public Guid getId() { + return id; + } + + public void setId(Guid id) { + this.id = id; + } + + public Guid getHostId() { + return hostId; + } + + public void setHostId(Guid hostId) { + this.hostId = hostId; + } + + public int getOrder() { + return order; + } + + public void setOrder(int order) { + this.order = order; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getOptions() { + return options; + } + + public void setOptions(String options) { + this.options = options; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java index 1437a51..526a119 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VdsStatic.java @@ -84,50 +84,11 @@ private Integer vdsStrength; @EditableField - @Size(max = BusinessEntitiesDefinitions.HOST_PM_TYPE_SIZE) - private String pmType; - - @EditableField - @Size(max = BusinessEntitiesDefinitions.HOST_PM_USER_SIZE) - private String pmUser; - - @EditableField - @Size(max = BusinessEntitiesDefinitions.HOST_PM_PASSWD_SIZE) - private String pmPassword; - - @EditableField - private Integer pmPort; - - @EditableField - @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE) - private String pmOptions; - - @EditableField private boolean pmEnabled; @EditableField @Size(max = BusinessEntitiesDefinitions.GENERAL_NAME_SIZE) private String pmProxyPreferences; - - @EditableField - @HostnameOrIp(message = "VALIDATION.VDS.POWER_MGMT.ADDRESS.HOSTNAME_OR_IP", groups = PowerManagementCheck.class) - @Size(max = BusinessEntitiesDefinitions.HOST_IP_SIZE) - private String pmSecondaryIp; - - @EditableField - @Size(max = BusinessEntitiesDefinitions.HOST_PM_TYPE_SIZE) - private String pmSecondaryType; - - @EditableField - @Size(max = BusinessEntitiesDefinitions.HOST_PM_USER_SIZE) - private String pmSecondaryUser; - - @EditableField - @Size(max = BusinessEntitiesDefinitions.HOST_PM_PASSWD_SIZE) - private String pmSecondaryPassword; - - @EditableField - private Integer pmSecondaryPort; @EditableField @Size(max = BusinessEntitiesDefinitions.GENERAL_MAX_SIZE) @@ -317,38 +278,6 @@ this.vdsStrength = value < 1 ? 1 : value > 100 ? 100 : value; } - public String getPmType() { - return pmType; - } - - public void setPmType(String value) { - pmType = value; - } - - public String getPmUser() { - return pmUser; - } - - public void setPmUser(String value) { - pmUser = value; - } - - public String getPmPassword() { - return pmPassword; - } - - public void setPmPassword(String value) { - pmPassword = value; - } - - public Integer getPmPort() { - return pmPort; - } - - public void setPmPort(Integer value) { - pmPort = value; - } - public String getPmOptions() { return pmOptions; } @@ -382,45 +311,6 @@ public void setPmProxyPreferences(String pmProxyPreferences) { this.pmProxyPreferences = pmProxyPreferences; - } - public String getPmSecondaryIp() { - return this.pmSecondaryIp; - } - - public void setPmSecondaryIp(String value) { - this.pmSecondaryIp = value; - } - - public String getPmSecondaryType() { - return pmSecondaryType; - } - - public void setPmSecondaryType(String value) { - pmSecondaryType = value; - } - - public String getPmSecondaryUser() { - return pmSecondaryUser; - } - - public void setPmSecondaryUser(String value) { - pmSecondaryUser = value; - } - - public String getPmSecondaryPassword() { - return pmSecondaryPassword; - } - - public void setPmSecondaryPassword(String value) { - pmSecondaryPassword = value; - } - - public Integer getPmSecondaryPort() { - return pmSecondaryPort; - } - - public void setPmSecondaryPort(Integer value) { - pmSecondaryPort = value; } public String getPmSecondaryOptions() { 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 3b49a36..51bcebc 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 @@ -44,6 +44,7 @@ GetHostsForStorageOperation, GetServerSSHPublicKey, GetServerSSHKeyFingerprint, + GetFencingAgentsByVdsId, // VdsStatic Queries GetVdsStaticByName, 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..b8c90c6 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 @@ -14,6 +14,7 @@ import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.DiskImageDynamic; import org.ovirt.engine.core.common.businessentities.DwhHistoryTimekeeping; +import org.ovirt.engine.core.common.businessentities.FencingAgent; import org.ovirt.engine.core.common.businessentities.Image; import org.ovirt.engine.core.common.businessentities.IscsiBond; import org.ovirt.engine.core.common.businessentities.Permissions; @@ -63,6 +64,7 @@ import org.ovirt.engine.core.dao.DiskImageDynamicDAO; import org.ovirt.engine.core.dao.DiskLunMapDao; import org.ovirt.engine.core.dao.EventDAO; +import org.ovirt.engine.core.dao.FencingAgentDAO; import org.ovirt.engine.core.dao.GenericDao; import org.ovirt.engine.core.dao.ImageDao; import org.ovirt.engine.core.dao.ImageStorageDomainMapDao; @@ -177,6 +179,7 @@ put(DwhHistoryTimekeeping.class, DwhHistoryTimekeepingDao.class); put(IscsiBond.class, IscsiBondDao.class); put(VmInit.class, VmInitDAO.class); + put(FencingAgent.class, FencingAgentDAO.class); } }; @@ -1005,4 +1008,8 @@ public IscsiBondDao getIscsiBondDao() { return getDao(IscsiBondDao.class); } + + public FencingAgentDAO getFencingAgentDao() { + return getDao(FencingAgentDAO.class); + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/FencingAgentDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/FencingAgentDAO.java new file mode 100644 index 0000000..2ba6eeb --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/FencingAgentDAO.java @@ -0,0 +1,18 @@ +package org.ovirt.engine.core.dao; + +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.FencingAgent; +import org.ovirt.engine.core.compat.Guid; + +public interface FencingAgentDAO extends DAO { + + /** + * Retrieves all fencing agents for host with the give id. + * + * @param hostId + * id of host for which agents are retrieved. + * @return the list of FencingAgent instances. + */ + List<FencingAgent> getFencingAgentsForHost(Guid hostId); +} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/FencingAgentDaoImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/FencingAgentDaoImpl.java new file mode 100644 index 0000000..979fb4b --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/FencingAgentDaoImpl.java @@ -0,0 +1,39 @@ +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.FencingAgent; +import org.ovirt.engine.core.compat.Guid; +import org.springframework.jdbc.core.RowMapper; + +public class FencingAgentDaoImpl extends BaseDAODbFacade implements FencingAgentDAO { + + @Override + public List<FencingAgent> getFencingAgentsForHost(Guid hostId) { + return getCallsHandler().executeReadList("getFencingAgentsByVdsId", + FencingAgentRowMapper.instance, + getCustomMapSqlParameterSource() + .addValue("vds_id", hostId)); + } + + static final class FencingAgentRowMapper implements RowMapper<FencingAgent> { + + public final static FencingAgentRowMapper instance = new FencingAgentRowMapper(); + @Override + public FencingAgent mapRow(ResultSet rs, int rowNum) throws SQLException { + FencingAgent entity = new FencingAgent(); + entity.setId(getGuid(rs, "id")); + entity.setHostId(getGuid(rs, "vds_id")); + entity.setOrder(rs.getInt("agent_order")); + entity.setType(rs.getString("type")); + entity.setUser(rs.getString("agent_user")); + entity.setPassword(rs.getString("agent_password")); + entity.setPort(rs.getInt("port")); + entity.setOptions(rs.getString("options")); + entity.setIp(rs.getString("ip")); + 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..329e125 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 +FencingAgentDAO=org.ovirt.engine.core.dao.FencingAgentDaoImpl \ No newline at end of file diff --git a/packaging/dbscripts/create_tables.sql b/packaging/dbscripts/create_tables.sql index e525e62..20b01fb 100644 --- a/packaging/dbscripts/create_tables.sql +++ b/packaging/dbscripts/create_tables.sql @@ -1217,6 +1217,23 @@ disks_usage text ); +-- +-- Name: fencing_agents; Type: TABLE; Schema: public; Owner: engine; Tablespace: +-- + +CREATE TABLE fencing_agents +( + id UUID NOT NULL, + vds_id UUID NOT NULL, + agent_order INTEGER NOT NULL, + ip VARCHAR(255) NOT NULL, + type VARCHAR(255) NOT NULL, + agent_user VARCHAR(255) NOT NULL, + agent_password VARCHAR(255) NOT NULL, + port INTEGER NOT NULL, + options VARCHAR(255) NOT NULL, + enabled BOOLEAN DEFAULT true +); -- -- Name: disk_lun_map_pk; Type: CONSTRAINT; Schema: public; Owner: engine; Tablespace: @@ -2033,6 +2050,12 @@ CREATE INDEX ix_vdc_options ON vdc_options USING btree (option_name); -- +-- Name: idx_fencing_agents_vds_id; Type: INDEX; Schema: public; Owner: engine; Tablespace: +-- + +CREATE INDEX idx_fencing_agents_vds_id ON fencing_agents(vds_id); + +-- -- Name: disk_lun_to_disk_fk; Type: FK CONSTRAINT; Schema: public; Owner: engine -- @@ -2599,4 +2622,17 @@ ALTER TABLE ONLY vm_static ADD CONSTRAINT vm_templates_vm_static FOREIGN KEY (vmt_guid) REFERENCES vm_static(vm_guid); +-- +-- Name: fencing_agent_pk; Type: PK CONSTRAINT; Schema: public; Owner: engine +-- + +ALTER TABLE ONLY fencing_agents + ADD CONSTRAINT fencing_agent_pk PRIMARY KEY (id); + +-- +-- Name: fencing_agent_host_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: engine +-- + +ALTER TABLE ONLY fencing_agents + ADD CONSTRAINT fencing_agent_host_id_fk REFERENCES vds_static(vds_id) ON DELETE CASCADE; diff --git a/packaging/dbscripts/fencing_agents_sp.sql b/packaging/dbscripts/fencing_agents_sp.sql new file mode 100644 index 0000000..8d90171 --- /dev/null +++ b/packaging/dbscripts/fencing_agents_sp.sql @@ -0,0 +1,9 @@ +Create or replace FUNCTION GetFencingAgentsByVdsId(vds_guid UUID) RETURNS SETOF fencing_agents STABLE + AS $procedure$ +BEGIN + RETURN QUERY SELECT fencing_agents.* + FROM fencing_agents + WHERE vds_id = vds_guid; +END; $procedure$ +LANGUAGE plpgsql; + diff --git a/packaging/dbscripts/upgrade/03_05_0380_create_fencing_agents_table.sql b/packaging/dbscripts/upgrade/03_05_0380_create_fencing_agents_table.sql new file mode 100644 index 0000000..e8ccdf5 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_05_0380_create_fencing_agents_table.sql @@ -0,0 +1,19 @@ +-- create fencing_agents table +CREATE TABLE fencing_agents +( + id UUID NOT NULL CONSTRAINT fencing_agent_pk PRIMARY KEY, + vds_id UUID NOT NULL CONSTRAINT fencing_agent_host_id_fk REFERENCES vds_static(vds_id) ON DELETE CASCADE, + agent_order INTEGER NOT NULL, + ip VARCHAR(255) NOT NULL, + type VARCHAR(255) NOT NULL, + agent_user VARCHAR(255) NOT NULL, + agent_password VARCHAR(255) NOT NULL, + port INTEGER NOT NULL, + options VARCHAR(255) NOT NULL, + enabled BOOLEAN DEFAULT true +) WITH OIDS; +-- create index for vds id +CREATE INDEX idx_fencing_agents_vds_id ON fencing_agents(vds_id); + + + -- To view, visit http://gerrit.ovirt.org/27578 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id0b384347a52db8b0aa6ae684fad40a5491dd2f7 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Ori Liel <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
