Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4B2B218E7B for ; Wed, 2 Dec 2015 21:08:04 +0000 (UTC) Received: (qmail 71437 invoked by uid 500); 2 Dec 2015 21:08:04 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 71402 invoked by uid 500); 2 Dec 2015 21:08:04 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 71387 invoked by uid 99); 2 Dec 2015 21:08:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Dec 2015 21:08:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EAD23DFFB6; Wed, 2 Dec 2015 21:08:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: remi@apache.org To: commits@cloudstack.apache.org Date: Wed, 02 Dec 2015 21:08:03 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: updated refs/heads/master to df63434 Repository: cloudstack Updated Branches: refs/heads/master cd15c66c0 -> df6343452 Removed unused code from the EngineHostDao Implementation. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4a34901f Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4a34901f Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4a34901f Branch: refs/heads/master Commit: 4a34901ff6701a56abc33eaaed25433242d9a5fa Parents: a323434 Author: cirstofolini Authored: Thu Nov 26 22:46:55 2015 -0200 Committer: cirstofolini Committed: Thu Nov 26 22:46:55 2015 -0200 ---------------------------------------------------------------------- .../entity/api/db/dao/EngineHostDao.java | 43 --- .../entity/api/db/dao/EngineHostDaoImpl.java | 386 +++---------------- 2 files changed, 47 insertions(+), 382 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4a34901f/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDao.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDao.java index a332a4c..26721d5 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDao.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDao.java @@ -16,16 +16,12 @@ // under the License. package org.apache.cloudstack.engine.datacenter.entity.api.db.dao; -import java.util.Date; import java.util.List; import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity; import org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO; import com.cloud.host.Host; -import com.cloud.host.Host.Type; -import com.cloud.info.RunningHostCountInfo; -import com.cloud.resource.ResourceState; import com.cloud.utils.db.GenericDao; import com.cloud.utils.fsm.StateDao; @@ -35,23 +31,6 @@ import com.cloud.utils.fsm.StateDao; */ public interface EngineHostDao extends GenericDao, StateDao { - long countBy(long clusterId, ResourceState... states); - - /** - * Mark all hosts associated with a certain management server - * as disconnected. - * - * @param msId management server id. - */ - void markHostsAsDisconnected(long msId, long lastPing); - - List findLostHosts(long timeout); - - List findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId); - - List getRunningHostCounts(Date cutTime); - - long getNextSequence(long hostId); void loadDetails(EngineHostVO host); @@ -60,26 +39,4 @@ public interface EngineHostDao extends GenericDao, void loadHostTags(EngineHostVO host); List listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag); - - long countRoutingHostsByDataCenter(long dcId); - - List findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId); - - boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo); - - EngineHostVO findByGuid(String guid); - - EngineHostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type); - - List findHypervisorHostInCluster(long clusterId); - - /** - * @param type - * @param clusterId - * @param podId - * @param dcId - * @param haTag TODO - * @return - */ - List listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4a34901f/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java index 3a45976..80d6274 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java @@ -17,13 +17,10 @@ package org.apache.cloudstack.engine.datacenter.entity.api.db.dao; import java.sql.PreparedStatement; -import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.TimeZone; import javax.ejb.Local; import javax.inject.Inject; @@ -37,13 +34,9 @@ import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEnti import org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO; import com.cloud.host.Host; -import com.cloud.host.Host.Type; import com.cloud.host.HostTagVO; import com.cloud.host.Status; -import com.cloud.info.RunningHostCountInfo; -import com.cloud.org.Managed; import com.cloud.resource.ResourceState; -import com.cloud.utils.DateUtil; import com.cloud.utils.db.Attribute; import com.cloud.utils.db.DB; import com.cloud.utils.db.Filter; @@ -64,59 +57,57 @@ import com.cloud.utils.exception.CloudRuntimeException; @TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1) public class EngineHostDaoImpl extends GenericDaoBase implements EngineHostDao { private static final Logger s_logger = Logger.getLogger(EngineHostDaoImpl.class); - private static final Logger status_logger = Logger.getLogger(Status.class); - private static final Logger state_logger = Logger.getLogger(ResourceState.class); - - protected final SearchBuilder TypePodDcStatusSearch; - - protected final SearchBuilder IdStatusSearch; - protected final SearchBuilder TypeDcSearch; - protected final SearchBuilder TypeDcStatusSearch; - protected final SearchBuilder TypeClusterStatusSearch; - protected final SearchBuilder MsStatusSearch; - protected final SearchBuilder DcPrivateIpAddressSearch; - protected final SearchBuilder DcStorageIpAddressSearch; - - protected final SearchBuilder GuidSearch; - protected final SearchBuilder DcSearch; - protected final SearchBuilder PodSearch; - protected final SearchBuilder TypeSearch; - protected final SearchBuilder StatusSearch; - protected final SearchBuilder ResourceStateSearch; - protected final SearchBuilder NameLikeSearch; - protected final SearchBuilder NameSearch; - protected final SearchBuilder SequenceSearch; - protected final SearchBuilder DirectlyConnectedSearch; - protected final SearchBuilder UnmanagedDirectConnectSearch; - protected final SearchBuilder UnmanagedApplianceSearch; - protected final SearchBuilder MaintenanceCountSearch; - protected final SearchBuilder ClusterStatusSearch; - protected final SearchBuilder TypeNameZoneSearch; - protected final SearchBuilder AvailHypevisorInZone; - - protected final SearchBuilder DirectConnectSearch; - protected final SearchBuilder ManagedDirectConnectSearch; - protected final SearchBuilder ManagedRoutingServersSearch; - protected final SearchBuilder SecondaryStorageVMSearch; - protected SearchBuilder StateChangeSearch; - - protected SearchBuilder UUIDSearch; - - protected final GenericSearchBuilder HostsInStatusSearch; - protected final GenericSearchBuilder CountRoutingByDc; - protected final SearchBuilder RoutingSearch; - - protected final Attribute _statusAttr; - protected final Attribute _resourceStateAttr; - protected final Attribute _msIdAttr; - protected final Attribute _pingTimeAttr; + + private final SearchBuilder TypePodDcStatusSearch; + + private final SearchBuilder IdStatusSearch; + private final SearchBuilder TypeDcSearch; + private final SearchBuilder TypeDcStatusSearch; + private final SearchBuilder TypeClusterStatusSearch; + private final SearchBuilder MsStatusSearch; + private final SearchBuilder DcPrivateIpAddressSearch; + private final SearchBuilder DcStorageIpAddressSearch; + + private final SearchBuilder GuidSearch; + private final SearchBuilder DcSearch; + private final SearchBuilder PodSearch; + private final SearchBuilder TypeSearch; + private final SearchBuilder StatusSearch; + private final SearchBuilder ResourceStateSearch; + private final SearchBuilder NameLikeSearch; + private final SearchBuilder NameSearch; + private final SearchBuilder SequenceSearch; + private final SearchBuilder DirectlyConnectedSearch; + private final SearchBuilder UnmanagedDirectConnectSearch; + private final SearchBuilder UnmanagedApplianceSearch; + private final SearchBuilder MaintenanceCountSearch; + private final SearchBuilder ClusterStatusSearch; + private final SearchBuilder TypeNameZoneSearch; + private final SearchBuilder AvailHypevisorInZone; + + private final SearchBuilder DirectConnectSearch; + private final SearchBuilder ManagedDirectConnectSearch; + private final SearchBuilder ManagedRoutingServersSearch; + private final SearchBuilder SecondaryStorageVMSearch; + private SearchBuilder StateChangeSearch; + + private SearchBuilder UUIDSearch; + + private final GenericSearchBuilder HostsInStatusSearch; + private final GenericSearchBuilder CountRoutingByDc; + private final SearchBuilder RoutingSearch; + + private final Attribute _statusAttr; + private final Attribute _resourceStateAttr; + private final Attribute _msIdAttr; + private final Attribute _pingTimeAttr; @Inject - protected HostDetailsDao _detailsDao; + private HostDetailsDao _detailsDao; @Inject - protected HostTagsDao _hostTagsDao; + private HostTagsDao _hostTagsDao; @Inject - protected EngineClusterDao _clusterDao; + private EngineClusterDao _clusterDao; public EngineHostDaoImpl() { @@ -319,89 +310,6 @@ public class EngineHostDaoImpl extends GenericDaoBase implem } @Override - public long countBy(long clusterId, ResourceState... states) { - SearchCriteria sc = MaintenanceCountSearch.create(); - - sc.setParameters("resourceState", (Object[])states); - sc.setParameters("cluster", clusterId); - - List hosts = listBy(sc); - return hosts.size(); - } - - @Override - public EngineHostVO findByGuid(String guid) { - SearchCriteria sc = GuidSearch.create("guid", guid); - return findOneBy(sc); - } - - @Override - @DB - public List findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId) { - TransactionLegacy txn = TransactionLegacy.currentTxn(); - txn.start(); - SearchCriteria sc = UnmanagedDirectConnectSearch.create(); - sc.setParameters("lastPinged", lastPingSecondsAfter); - //sc.setParameters("resourceStates", ResourceState.ErrorInMaintenance, ResourceState.Maintenance, ResourceState.PrepareForMaintenance, ResourceState.Disabled); - sc.setJoinParameters("ClusterManagedSearch", "managed", Managed.ManagedState.Managed); - List hosts = lockRows(sc, new Filter(EngineHostVO.class, "clusterId", true, 0L, limit), true); - - for (EngineHostVO host : hosts) { - host.setManagementServerId(managementServerId); - update(host.getId(), host); - } - - txn.commit(); - - return hosts; - } - - @Override - @DB - public List findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId) { - TransactionLegacy txn = TransactionLegacy.currentTxn(); - - txn.start(); - SearchCriteria sc = UnmanagedApplianceSearch.create(); - sc.setParameters("lastPinged", lastPingSecondsAfter); - sc.setParameters("types", Type.ExternalDhcp, Type.ExternalFirewall, Type.ExternalLoadBalancer, Type.PxeServer, Type.TrafficMonitor, Type.L2Networking); - List hosts = lockRows(sc, null, true); - - for (EngineHostVO host : hosts) { - host.setManagementServerId(managementServerId); - update(host.getId(), host); - } - - txn.commit(); - - return hosts; - } - - @Override - public void markHostsAsDisconnected(long msId, long lastPing) { - SearchCriteria sc = MsStatusSearch.create(); - sc.setParameters("ms", msId); - - EngineHostVO host = createForUpdate(); - host.setLastPinged(lastPing); - host.setDisconnectedOn(new Date()); - UpdateBuilder ub = getUpdateBuilder(host); - ub.set(host, "status", Status.Disconnected); - - update(ub, sc, null); - - sc = MsStatusSearch.create(); - sc.setParameters("ms", msId); - - host = createForUpdate(); - host.setManagementServerId(null); - host.setLastPinged((System.currentTimeMillis() >> 10) - (10 * 60)); - host.setDisconnectedOn(new Date()); - ub = getUpdateBuilder(host); - update(ub, sc, null); - } - - @Override public List listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag) { SearchBuilder hostTagSearch = _hostTagsDao.createSearchBuilder(); @@ -435,54 +343,6 @@ public class EngineHostDaoImpl extends GenericDaoBase implem } @Override - public List listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag) { - SearchBuilder hostTagSearch = null; - if (haTag != null && !haTag.isEmpty()) { - hostTagSearch = _hostTagsDao.createSearchBuilder(); - hostTagSearch.and().op("tag", hostTagSearch.entity().getTag(), SearchCriteria.Op.NEQ); - hostTagSearch.or("tagNull", hostTagSearch.entity().getTag(), SearchCriteria.Op.NULL); - hostTagSearch.cp(); - } - - SearchBuilder hostSearch = createSearchBuilder(); - - hostSearch.and("type", hostSearch.entity().getType(), SearchCriteria.Op.EQ); - hostSearch.and("clusterId", hostSearch.entity().getClusterId(), SearchCriteria.Op.EQ); - hostSearch.and("podId", hostSearch.entity().getPodId(), SearchCriteria.Op.EQ); - hostSearch.and("zoneId", hostSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); - hostSearch.and("status", hostSearch.entity().getStatus(), SearchCriteria.Op.EQ); - hostSearch.and("resourceState", hostSearch.entity().getResourceState(), SearchCriteria.Op.EQ); - - if (haTag != null && !haTag.isEmpty()) { - hostSearch.join("hostTagSearch", hostTagSearch, hostSearch.entity().getId(), hostTagSearch.entity().getHostId(), JoinBuilder.JoinType.LEFTOUTER); - } - - SearchCriteria sc = hostSearch.create(); - - if (haTag != null && !haTag.isEmpty()) { - sc.setJoinParameters("hostTagSearch", "tag", haTag); - } - - if (type != null) { - sc.setParameters("type", type); - } - - if (clusterId != null) { - sc.setParameters("clusterId", clusterId); - } - - if (podId != null) { - sc.setParameters("podId", podId); - } - - sc.setParameters("zoneId", dcId); - sc.setParameters("status", Status.Up); - sc.setParameters("resourceState", ResourceState.Enabled); - - return listBy(sc); - } - - @Override public void loadDetails(EngineHostVO host) { Map details = _detailsDao.findDetails(host.getId()); host.setDetails(details); @@ -494,29 +354,6 @@ public class EngineHostDaoImpl extends GenericDaoBase implem host.setHostTags(hostTags); } - @DB - @Override - public List findLostHosts(long timeout) { - TransactionLegacy txn = TransactionLegacy.currentTxn(); - List result = new ArrayList(); - String sql = - "select h.id from host h left join cluster c on h.cluster_id=c.id where h.mgmt_server_id is not null and h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage', 'L2Networking') and (h.cluster_id is null or c.managed_state = 'Managed') ;"; - try(PreparedStatement pstmt = txn.prepareStatement(sql);) { - pstmt.setLong(1, timeout); - try(ResultSet rs = pstmt.executeQuery();) { - while (rs.next()) { - long id = rs.getLong(1); //ID column - result.add(findById(id)); - } - }catch (Exception e) { - s_logger.warn("Exception: ", e); - } - } catch (Exception e) { - s_logger.warn("Exception: ", e); - } - return result; - } - @Override public void saveDetails(EngineHostVO host) { Map details = host.getDetails(); @@ -582,66 +419,6 @@ public class EngineHostDaoImpl extends GenericDaoBase implem } @Override - @DB - public List getRunningHostCounts(Date cutTime) { - String sql = - "select * from (" + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid " - + "where h.status='Up' and h.type='SecondaryStorage' and m.last_update > ? " + "group by h.data_center_id, h.type " + "UNION ALL " - + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid " - + "where h.status='Up' and h.type='Routing' and m.last_update > ? " + "group by h.data_center_id, h.type) as t " + "ORDER by t.data_center_id, t.type"; - - ArrayList l = new ArrayList(); - - TransactionLegacy txn = TransactionLegacy.currentTxn(); - ; - PreparedStatement pstmt = null; - try { - pstmt = txn.prepareAutoCloseStatement(sql); - String gmtCutTime = DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutTime); - pstmt.setString(1, gmtCutTime); - pstmt.setString(2, gmtCutTime); - - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - RunningHostCountInfo info = new RunningHostCountInfo(); - info.setDcId(rs.getLong(1)); - info.setHostType(rs.getString(2)); - info.setCount(rs.getInt(3)); - - l.add(info); - } - } catch (SQLException e) { - s_logger.error("sql exception while getting running hosts: " + e.getLocalizedMessage()); - } catch (Throwable e) { - s_logger.info("[ignored]" - + "caught something while getting running hosts: " + e.getLocalizedMessage()); - } - return l; - } - - @Override - public long getNextSequence(long hostId) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("getNextSequence(), hostId: " + hostId); - } - - TableGenerator tg = _tgs.get("host_req_sq"); - assert tg != null : "how can this be wrong!"; - - return s_seqFetcher.getNextSequence(Long.class, tg, hostId); - } - - /*TODO: this is used by mycloud, check if it needs resource state Enabled */ - @Override - public long countRoutingHostsByDataCenter(long dcId) { - SearchCriteria sc = CountRoutingByDc.create(); - sc.setParameters("dc", dcId); - sc.setParameters("type", Host.Type.Routing); - sc.setParameters("status", Status.Up.toString()); - return customSearch(sc, null).get(0); - } - - @Override public boolean updateState(State currentState, DataCenterResourceEntity.State.Event event, State nextState, DataCenterResourceEntity hostEntity, Object data) { EngineHostVO vo = findById(hostEntity.getId()); Date oldUpdatedTime = vo.getLastUpdated(); @@ -685,68 +462,6 @@ public class EngineHostDaoImpl extends GenericDaoBase implem } @Override - public boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo) { - EngineHostVO host = (EngineHostVO)vo; - SearchBuilder sb = createSearchBuilder(); - sb.and("resource_state", sb.entity().getResourceState(), SearchCriteria.Op.EQ); - sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); - sb.done(); - - SearchCriteria sc = sb.create(); - - sc.setParameters("resource_state", oldState); - sc.setParameters("id", host.getId()); - - UpdateBuilder ub = getUpdateBuilder(host); - ub.set(host, _resourceStateAttr, newState); - int result = update(ub, sc, null); - assert result <= 1 : "How can this update " + result + " rows? "; - - if (state_logger.isDebugEnabled() && result == 0) { - EngineHostVO ho = findById(host.getId()); - assert ho != null : "How how how? : " + host.getId(); - - StringBuilder str = new StringBuilder("Unable to update resource state: ["); - str.append("m = " + host.getId()); - str.append("; name = " + host.getName()); - str.append("; old state = " + oldState); - str.append("; event = " + event); - str.append("; new state = " + newState + "]"); - state_logger.debug(str.toString()); - } else { - StringBuilder msg = new StringBuilder("Resource state update: ["); - msg.append("id = " + host.getId()); - msg.append("; name = " + host.getName()); - msg.append("; old state = " + oldState); - msg.append("; event = " + event); - msg.append("; new state = " + newState + "]"); - state_logger.debug(msg.toString()); - } - - return result > 0; - } - - @Override - public EngineHostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type) { - SearchCriteria sc = TypeNameZoneSearch.create(); - sc.setParameters("type", type); - sc.setParameters("name", name); - sc.setParameters("zoneId", zoneId); - return findOneBy(sc); - } - - @Override - public List findHypervisorHostInCluster(long clusterId) { - SearchCriteria sc = TypeClusterStatusSearch.create(); - sc.setParameters("type", Host.Type.Routing); - sc.setParameters("cluster", clusterId); - sc.setParameters("status", Status.Up); - sc.setParameters("resourceState", ResourceState.Enabled); - - return listBy(sc); - } - - @Override public List lockRows( SearchCriteria sc, Filter filter, boolean exclusive) { // TODO Auto-generated method stub @@ -754,13 +469,6 @@ public class EngineHostDaoImpl extends GenericDaoBase implem } @Override - public org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO lockOneRandomRow( - SearchCriteria sc, boolean exclusive) { - // TODO Auto-generated method stub - return null; - } - - @Override public List search( SearchCriteria sc, Filter filter) { // TODO Auto-generated method stub