cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From muralire...@apache.org
Subject [14/93] [abbrv] [partial] merge master
Date Mon, 13 May 2013 15:53:34 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
new file mode 100755
index 0000000..07a4232
--- /dev/null
+++ b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
@@ -0,0 +1,920 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.host.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.annotation.PostConstruct;
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.persistence.TableGenerator;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.cluster.agentlb.HostTransferMapVO;
+import com.cloud.cluster.agentlb.dao.HostTransferMapDao;
+import com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl;
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.dc.dao.ClusterDaoImpl;
+import com.cloud.host.Host;
+import com.cloud.host.Host.Type;
+import com.cloud.host.HostTagVO;
+import com.cloud.host.HostVO;
+import com.cloud.host.Status;
+import com.cloud.host.Status.Event;
+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;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.JoinBuilder;
+import com.cloud.utils.db.JoinBuilder.JoinType;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.UpdateBuilder;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Component
+@Local(value = { HostDao.class })
+@DB(txn = false)
+@TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1)
+public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao { //FIXME: , ExternalIdDao {
+    private static final Logger s_logger = Logger.getLogger(HostDaoImpl.class);
+    private static final Logger status_logger = Logger.getLogger(Status.class);
+    private static final Logger state_logger = Logger.getLogger(ResourceState.class);
+
+    protected SearchBuilder<HostVO> TypePodDcStatusSearch;
+
+    protected SearchBuilder<HostVO> IdStatusSearch;
+    protected SearchBuilder<HostVO> TypeDcSearch;
+    protected SearchBuilder<HostVO> TypeDcStatusSearch;
+    protected SearchBuilder<HostVO> TypeClusterStatusSearch;
+    protected SearchBuilder<HostVO> MsStatusSearch;
+    protected SearchBuilder<HostVO> DcPrivateIpAddressSearch;
+    protected SearchBuilder<HostVO> DcStorageIpAddressSearch;
+
+    protected SearchBuilder<HostVO> GuidSearch;
+    protected SearchBuilder<HostVO> DcSearch;
+    protected SearchBuilder<HostVO> PodSearch;
+    protected SearchBuilder<HostVO> TypeSearch;
+    protected SearchBuilder<HostVO> StatusSearch;
+    protected SearchBuilder<HostVO> ResourceStateSearch;
+    protected SearchBuilder<HostVO> NameLikeSearch;
+    protected SearchBuilder<HostVO> NameSearch;
+    protected SearchBuilder<HostVO> SequenceSearch;
+    protected SearchBuilder<HostVO> DirectlyConnectedSearch;
+    protected SearchBuilder<HostVO> UnmanagedDirectConnectSearch;
+    protected SearchBuilder<HostVO> UnmanagedApplianceSearch;
+    protected SearchBuilder<HostVO> MaintenanceCountSearch;
+    protected SearchBuilder<HostVO> ClusterStatusSearch;
+    protected SearchBuilder<HostVO> TypeNameZoneSearch;
+    protected SearchBuilder<HostVO> AvailHypevisorInZone;
+
+    protected SearchBuilder<HostVO> DirectConnectSearch;
+    protected SearchBuilder<HostVO> ManagedDirectConnectSearch;
+    protected SearchBuilder<HostVO> ManagedRoutingServersSearch;
+    protected SearchBuilder<HostVO> SecondaryStorageVMSearch;
+
+
+    protected GenericSearchBuilder<HostVO, Long> HostsInStatusSearch;
+    protected GenericSearchBuilder<HostVO, Long> CountRoutingByDc;
+    protected SearchBuilder<HostTransferMapVO> HostTransferSearch;
+    protected SearchBuilder<ClusterVO> ClusterManagedSearch;
+    protected SearchBuilder<HostVO> RoutingSearch;
+
+    protected SearchBuilder<HostVO> HostsForReconnectSearch;
+    protected GenericSearchBuilder<HostVO, Long> ClustersOwnedByMSSearch;
+    protected GenericSearchBuilder<ClusterVO, Long> AllClustersSearch;
+    protected SearchBuilder<HostVO> HostsInClusterSearch;
+    
+    protected Attribute _statusAttr;
+    protected Attribute _resourceStateAttr;
+    protected Attribute _msIdAttr;
+    protected Attribute _pingTimeAttr;
+    
+    @Inject protected HostDetailsDao _detailsDao;
+    @Inject protected HostTagsDao _hostTagsDao;
+    @Inject protected HostTransferMapDao _hostTransferDao;
+    @Inject protected ClusterDao _clusterDao;
+
+    public HostDaoImpl() {
+    	super();
+    }
+
+    @PostConstruct
+    public void init() {
+
+        MaintenanceCountSearch = createSearchBuilder();
+        MaintenanceCountSearch.and("cluster", MaintenanceCountSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
+        MaintenanceCountSearch.and("resourceState", MaintenanceCountSearch.entity().getResourceState(), SearchCriteria.Op.IN);
+        MaintenanceCountSearch.done();
+
+        TypePodDcStatusSearch = createSearchBuilder();
+        HostVO entity = TypePodDcStatusSearch.entity();
+        TypePodDcStatusSearch.and("type", entity.getType(), SearchCriteria.Op.EQ);
+        TypePodDcStatusSearch.and("pod", entity.getPodId(), SearchCriteria.Op.EQ);
+        TypePodDcStatusSearch.and("dc", entity.getDataCenterId(), SearchCriteria.Op.EQ);
+        TypePodDcStatusSearch.and("cluster", entity.getClusterId(), SearchCriteria.Op.EQ);
+        TypePodDcStatusSearch.and("status", entity.getStatus(), SearchCriteria.Op.EQ);
+        TypePodDcStatusSearch.and("resourceState", entity.getResourceState(), SearchCriteria.Op.EQ);
+        TypePodDcStatusSearch.done();
+
+        MsStatusSearch = createSearchBuilder();
+        MsStatusSearch.and("ms", MsStatusSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
+        MsStatusSearch.and("type", MsStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
+        MsStatusSearch.and("resourceState", MsStatusSearch.entity().getResourceState(), SearchCriteria.Op.NIN);
+        MsStatusSearch.done();
+
+        TypeDcSearch = createSearchBuilder();
+        TypeDcSearch.and("type", TypeDcSearch.entity().getType(), SearchCriteria.Op.EQ);
+        TypeDcSearch.and("dc", TypeDcSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        TypeDcSearch.done();
+        
+        SecondaryStorageVMSearch = createSearchBuilder();
+        SecondaryStorageVMSearch.and("type", SecondaryStorageVMSearch.entity().getType(), SearchCriteria.Op.EQ);
+        SecondaryStorageVMSearch.and("dc", SecondaryStorageVMSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        SecondaryStorageVMSearch.and("status", SecondaryStorageVMSearch.entity().getStatus(), SearchCriteria.Op.EQ);
+        SecondaryStorageVMSearch.done();
+
+        TypeDcStatusSearch = createSearchBuilder();
+        TypeDcStatusSearch.and("type", TypeDcStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
+        TypeDcStatusSearch.and("dc", TypeDcStatusSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        TypeDcStatusSearch.and("status", TypeDcStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
+        TypeDcStatusSearch.and("resourceState", TypeDcStatusSearch.entity().getResourceState(), SearchCriteria.Op.EQ);
+        TypeDcStatusSearch.done();
+
+        TypeClusterStatusSearch = createSearchBuilder();
+        TypeClusterStatusSearch.and("type", TypeClusterStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
+        TypeClusterStatusSearch.and("cluster", TypeClusterStatusSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
+        TypeClusterStatusSearch.and("status", TypeClusterStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
+        TypeClusterStatusSearch.and("resourceState", TypeClusterStatusSearch.entity().getResourceState(), SearchCriteria.Op.EQ);
+        TypeClusterStatusSearch.done();
+
+        IdStatusSearch = createSearchBuilder();
+        IdStatusSearch.and("id", IdStatusSearch.entity().getId(), SearchCriteria.Op.EQ);
+        IdStatusSearch.and("states", IdStatusSearch.entity().getStatus(), SearchCriteria.Op.IN);
+        IdStatusSearch.done();
+
+        DcPrivateIpAddressSearch = createSearchBuilder();
+        DcPrivateIpAddressSearch.and("privateIpAddress", DcPrivateIpAddressSearch.entity().getPrivateIpAddress(), SearchCriteria.Op.EQ);
+        DcPrivateIpAddressSearch.and("dc", DcPrivateIpAddressSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        DcPrivateIpAddressSearch.done();
+
+        DcStorageIpAddressSearch = createSearchBuilder();
+        DcStorageIpAddressSearch.and("storageIpAddress", DcStorageIpAddressSearch.entity().getStorageIpAddress(), SearchCriteria.Op.EQ);
+        DcStorageIpAddressSearch.and("dc", DcStorageIpAddressSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        DcStorageIpAddressSearch.done();
+
+        GuidSearch = createSearchBuilder();
+        GuidSearch.and("guid", GuidSearch.entity().getGuid(), SearchCriteria.Op.EQ);
+        GuidSearch.done();
+
+        DcSearch = createSearchBuilder();
+        DcSearch.and("dc", DcSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        DcSearch.done();
+
+        ClusterStatusSearch = createSearchBuilder();
+        ClusterStatusSearch.and("cluster", ClusterStatusSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
+        ClusterStatusSearch.and("status", ClusterStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
+        ClusterStatusSearch.done();
+
+        TypeNameZoneSearch = createSearchBuilder();
+        TypeNameZoneSearch.and("name", TypeNameZoneSearch.entity().getName(), SearchCriteria.Op.EQ);
+        TypeNameZoneSearch.and("type", TypeNameZoneSearch.entity().getType(), SearchCriteria.Op.EQ);
+        TypeNameZoneSearch.and("zoneId", TypeNameZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        TypeNameZoneSearch.done();
+
+        PodSearch = createSearchBuilder();
+        PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
+        PodSearch.done();
+
+        TypeSearch = createSearchBuilder();
+        TypeSearch.and("type", TypeSearch.entity().getType(), SearchCriteria.Op.EQ);
+        TypeSearch.done();
+
+        StatusSearch = createSearchBuilder();
+        StatusSearch.and("status", StatusSearch.entity().getStatus(), SearchCriteria.Op.IN);
+        StatusSearch.done();
+        
+        ResourceStateSearch = createSearchBuilder();
+        ResourceStateSearch.and("resourceState", ResourceStateSearch.entity().getResourceState(), SearchCriteria.Op.IN);
+        ResourceStateSearch.done();
+
+        NameLikeSearch = createSearchBuilder();
+        NameLikeSearch.and("name", NameLikeSearch.entity().getName(), SearchCriteria.Op.LIKE);
+        NameLikeSearch.done();
+
+        NameSearch = createSearchBuilder();
+        NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
+        NameSearch.done();
+
+        SequenceSearch = createSearchBuilder();
+        SequenceSearch.and("id", SequenceSearch.entity().getId(), SearchCriteria.Op.EQ);
+        // SequenceSearch.addRetrieve("sequence", SequenceSearch.entity().getSequence());
+        SequenceSearch.done();
+
+        DirectlyConnectedSearch = createSearchBuilder();
+        DirectlyConnectedSearch.and("resource", DirectlyConnectedSearch.entity().getResource(), SearchCriteria.Op.NNULL);
+        DirectlyConnectedSearch.and("ms", DirectlyConnectedSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
+        DirectlyConnectedSearch.and("statuses", DirectlyConnectedSearch.entity().getStatus(), SearchCriteria.Op.EQ);
+        DirectlyConnectedSearch.and("resourceState", DirectlyConnectedSearch.entity().getResourceState(), SearchCriteria.Op.NOTIN);
+        DirectlyConnectedSearch.done();
+
+        UnmanagedDirectConnectSearch = createSearchBuilder();
+        UnmanagedDirectConnectSearch.and("resource", UnmanagedDirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
+        UnmanagedDirectConnectSearch.and("server", UnmanagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
+        UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
+        UnmanagedDirectConnectSearch.and("resourceStates", UnmanagedDirectConnectSearch.entity().getResourceState(), SearchCriteria.Op.NIN);
+        UnmanagedDirectConnectSearch.and("cluster", UnmanagedDirectConnectSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
+        /*
+         * UnmanagedDirectConnectSearch.op(SearchCriteria.Op.OR, "managementServerId",
+         * UnmanagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
+         * UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(),
+         * SearchCriteria.Op.LTEQ); UnmanagedDirectConnectSearch.cp(); UnmanagedDirectConnectSearch.cp();
+         */
+        try {
+        HostTransferSearch = _hostTransferDao.createSearchBuilder();
+        } catch (Throwable e) {
+        	s_logger.debug("error", e);
+        }
+        HostTransferSearch.and("id", HostTransferSearch.entity().getId(), SearchCriteria.Op.NULL);
+        UnmanagedDirectConnectSearch.join("hostTransferSearch", HostTransferSearch, HostTransferSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getId(), JoinType.LEFTOUTER);
+        ClusterManagedSearch = _clusterDao.createSearchBuilder();
+        ClusterManagedSearch.and("managed", ClusterManagedSearch.entity().getManagedState(), SearchCriteria.Op.EQ);
+        UnmanagedDirectConnectSearch.join("ClusterManagedSearch", ClusterManagedSearch, ClusterManagedSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getClusterId(), JoinType.INNER);
+        UnmanagedDirectConnectSearch.done();
+        
+
+        DirectConnectSearch = createSearchBuilder();
+        DirectConnectSearch.and("resource", DirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
+        DirectConnectSearch.and("id", DirectConnectSearch.entity().getId(), SearchCriteria.Op.EQ);
+        DirectConnectSearch.and().op("nullserver", DirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
+        DirectConnectSearch.or("server", DirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
+        DirectConnectSearch.cp();
+        DirectConnectSearch.done();
+
+        UnmanagedApplianceSearch = createSearchBuilder();
+        UnmanagedApplianceSearch.and("resource", UnmanagedApplianceSearch.entity().getResource(), SearchCriteria.Op.NNULL);
+        UnmanagedApplianceSearch.and("server", UnmanagedApplianceSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
+        UnmanagedApplianceSearch.and("types", UnmanagedApplianceSearch.entity().getType(), SearchCriteria.Op.IN);
+        UnmanagedApplianceSearch.and("lastPinged", UnmanagedApplianceSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
+        UnmanagedApplianceSearch.done();
+
+        AvailHypevisorInZone = createSearchBuilder();
+        AvailHypevisorInZone.and("zoneId", AvailHypevisorInZone.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        AvailHypevisorInZone.and("hostId", AvailHypevisorInZone.entity().getId(), SearchCriteria.Op.NEQ);
+        AvailHypevisorInZone.and("type", AvailHypevisorInZone.entity().getType(), SearchCriteria.Op.EQ);
+        AvailHypevisorInZone.groupBy(AvailHypevisorInZone.entity().getHypervisorType());
+        AvailHypevisorInZone.done();
+
+        HostsInStatusSearch = createSearchBuilder(Long.class);
+        HostsInStatusSearch.selectField(HostsInStatusSearch.entity().getId());
+        HostsInStatusSearch.and("dc", HostsInStatusSearch.entity().getDataCenterId(), Op.EQ);
+        HostsInStatusSearch.and("pod", HostsInStatusSearch.entity().getPodId(), Op.EQ);
+        HostsInStatusSearch.and("cluster", HostsInStatusSearch.entity().getClusterId(), Op.EQ);
+        HostsInStatusSearch.and("type", HostsInStatusSearch.entity().getType(), Op.EQ);
+        HostsInStatusSearch.and("statuses", HostsInStatusSearch.entity().getStatus(), Op.IN);
+        HostsInStatusSearch.done();
+
+        CountRoutingByDc = createSearchBuilder(Long.class);
+        CountRoutingByDc.select(null, Func.COUNT, null);
+        CountRoutingByDc.and("dc", CountRoutingByDc.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        CountRoutingByDc.and("type", CountRoutingByDc.entity().getType(), SearchCriteria.Op.EQ);
+        CountRoutingByDc.and("status", CountRoutingByDc.entity().getStatus(), SearchCriteria.Op.EQ);
+
+        CountRoutingByDc.done();
+
+        ManagedDirectConnectSearch = createSearchBuilder();
+        ManagedDirectConnectSearch.and("resource", ManagedDirectConnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
+        ManagedDirectConnectSearch.and("server", ManagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
+        ManagedDirectConnectSearch.done();
+
+        ManagedRoutingServersSearch = createSearchBuilder();
+        ManagedRoutingServersSearch.and("server", ManagedRoutingServersSearch.entity().getManagementServerId(), SearchCriteria.Op.NNULL);
+        ManagedRoutingServersSearch.and("type", ManagedRoutingServersSearch.entity().getType(), SearchCriteria.Op.EQ);
+        ManagedRoutingServersSearch.done();
+        
+        RoutingSearch = createSearchBuilder();
+        RoutingSearch.and("type", RoutingSearch.entity().getType(), SearchCriteria.Op.EQ);
+        RoutingSearch.done();
+
+        HostsForReconnectSearch = createSearchBuilder();
+        HostsForReconnectSearch.and("resource", HostsForReconnectSearch.entity().getResource(), SearchCriteria.Op.NNULL);
+        HostsForReconnectSearch.and("server", HostsForReconnectSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
+        HostsForReconnectSearch.and("lastPinged", HostsForReconnectSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
+        HostsForReconnectSearch.and("resourceStates", HostsForReconnectSearch.entity().getResourceState(), SearchCriteria.Op.NIN);
+        HostsForReconnectSearch.and("cluster", HostsForReconnectSearch.entity().getClusterId(), SearchCriteria.Op.NNULL);
+        HostsForReconnectSearch.and("status", HostsForReconnectSearch.entity().getStatus(), SearchCriteria.Op.IN);
+        HostsForReconnectSearch.done();
+
+        ClustersOwnedByMSSearch = createSearchBuilder(Long.class);
+        ClustersOwnedByMSSearch.select(null, Func.DISTINCT, ClustersOwnedByMSSearch.entity().getClusterId());
+        ClustersOwnedByMSSearch.and("resource", ClustersOwnedByMSSearch.entity().getResource(), SearchCriteria.Op.NNULL);
+        ClustersOwnedByMSSearch.and("cluster", ClustersOwnedByMSSearch.entity().getClusterId(), SearchCriteria.Op.NNULL);
+        ClustersOwnedByMSSearch.and("server", ClustersOwnedByMSSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
+        ClustersOwnedByMSSearch.done();
+
+        AllClustersSearch = _clusterDao.createSearchBuilder(Long.class);
+        AllClustersSearch.select(null, Func.NATIVE, AllClustersSearch.entity().getId());
+        AllClustersSearch.and("managed", AllClustersSearch.entity().getManagedState(), SearchCriteria.Op.EQ);
+        AllClustersSearch.done();
+
+        HostsInClusterSearch = createSearchBuilder();
+        HostsInClusterSearch.and("resource", HostsInClusterSearch.entity().getResource(), SearchCriteria.Op.NNULL);
+        HostsInClusterSearch.and("cluster", HostsInClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
+        HostsInClusterSearch.and("server", HostsInClusterSearch.entity().getManagementServerId(), SearchCriteria.Op.NNULL);
+        HostsInClusterSearch.done();
+
+        _statusAttr = _allAttributes.get("status");
+        _msIdAttr = _allAttributes.get("managementServerId");
+        _pingTimeAttr = _allAttributes.get("lastPinged");
+        _resourceStateAttr = _allAttributes.get("resourceState");
+
+        assert (_statusAttr != null && _msIdAttr != null && _pingTimeAttr != null) : "Couldn't find one of these attributes";
+    }
+
+    @Override
+    public long countBy(long clusterId, ResourceState... states) {
+        SearchCriteria<HostVO> sc = MaintenanceCountSearch.create();
+
+        sc.setParameters("resourceState", (Object[]) states);
+        sc.setParameters("cluster", clusterId);
+
+        List<HostVO> hosts = listBy(sc);
+        return hosts.size();
+    }
+    
+
+    @Override
+    public HostVO findByGuid(String guid) {
+        SearchCriteria<HostVO> sc = GuidSearch.create("guid", guid);
+        return findOneBy(sc);
+    }
+
+    /*
+     * Find hosts which is in Disconnected, Down, Alert and ping timeout and server is not null, set server to null
+     */
+    private void resetHosts(long managementServerId, long lastPingSecondsAfter) {
+        SearchCriteria<HostVO> sc = HostsForReconnectSearch.create();
+        sc.setParameters("server", managementServerId);
+        sc.setParameters("lastPinged", lastPingSecondsAfter);
+        sc.setParameters("status", Status.Disconnected, Status.Down, Status.Alert);
+
+        List<HostVO> hosts = lockRows(sc, null, true); // exclusive lock
+        for (HostVO host : hosts) {
+            host.setManagementServerId(null);
+            update(host.getId(), host);
+        }
+    }
+
+    /*
+     * Returns a list of cluster owned by @managementServerId
+     */
+    private List<Long> findClustersOwnedByManagementServer(long managementServerId) {
+        SearchCriteria<Long> sc = ClustersOwnedByMSSearch.create();
+        sc.setParameters("server", managementServerId);
+
+        List<Long> clusters = customSearch(sc, null);
+        return clusters;
+    }
+
+    /*
+     * Returns a list of all cluster Ids
+     */
+    private List<Long> listAllClusters() {
+        SearchCriteria<Long> sc = AllClustersSearch.create();
+        sc.setParameters("managed", Managed.ManagedState.Managed);
+
+        List<Long> clusters = _clusterDao.customSearch(sc, null);
+        return clusters;
+    }
+
+    /*
+     * This determines if hosts belonging to cluster(@clusterId) are up for grabs
+     *
+     * This is used for handling following cases:
+     * 1. First host added in cluster
+     * 2. During MS restart all hosts in a cluster are without any MS
+     */
+    private boolean canOwnCluster(long clusterId) {
+        SearchCriteria<HostVO> sc = HostsInClusterSearch.create();
+        sc.setParameters("cluster", clusterId);
+
+        List<HostVO> hosts = search(sc, null);
+        boolean ownCluster = (hosts == null || hosts.size() == 0);
+
+        return ownCluster;
+    }
+
+    @Override @DB
+    public List<HostVO> findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId) {
+        Transaction txn = Transaction.currentTxn();
+
+        // reset hosts that are suitable candidates for reconnect
+        txn.start();
+        resetHosts(managementServerId, lastPingSecondsAfter);
+        txn.commit();
+
+        List<Long> clusters = findClustersOwnedByManagementServer(managementServerId);
+        List<Long> allClusters = listAllClusters();
+
+        SearchCriteria<HostVO> sc = UnmanagedDirectConnectSearch.create();
+        sc.setParameters("lastPinged", lastPingSecondsAfter);
+        sc.setJoinParameters("ClusterManagedSearch", "managed", Managed.ManagedState.Managed);
+        List<HostVO> assignedHosts = new ArrayList<HostVO>();
+        List<Long> remainingClusters = new ArrayList<Long>();
+
+        // handle clusters already owned by @managementServerId
+        txn.start();
+        for (Long clusterId : allClusters) {
+            if (clusters.contains(clusterId)) { // host belongs to clusters owned by @managementServerId
+                sc.setParameters("cluster", clusterId);
+                List<HostVO> unmanagedHosts = lockRows(sc, null, true);
+                for (HostVO host : unmanagedHosts) {
+                    host.setManagementServerId(managementServerId);
+                    update(host.getId(), host);
+                    assignedHosts.add(host);
+                }
+            } else {
+                remainingClusters.add(clusterId);
+            }
+        }
+        txn.commit();
+
+        // for remaining clusters check if they can be owned
+        for (Long clusterId : remainingClusters) {
+            txn.start();
+            sc.setParameters("cluster", clusterId);
+            List<HostVO> unmanagedHosts = lockRows(sc, null, true);
+            if (canOwnCluster(clusterId)) { // cluster is not owned by any other MS, so @managementServerId can own it
+                for (HostVO host : unmanagedHosts) {
+                    host.setManagementServerId(managementServerId);
+                    update(host.getId(), host);
+                    assignedHosts.add(host);
+                }
+            }
+            txn.commit();
+        }
+
+        return assignedHosts;
+    }
+    
+    @Override @DB
+    public List<HostVO> findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId) {
+    	Transaction txn = Transaction.currentTxn();
+    	
+    	txn.start();
+    	SearchCriteria<HostVO> sc = UnmanagedApplianceSearch.create();
+    	sc.setParameters("lastPinged", lastPingSecondsAfter);
+        sc.setParameters("types", Type.ExternalDhcp, Type.ExternalFirewall, Type.ExternalLoadBalancer, Type.BaremetalDhcp, Type.BaremetalPxe, Type.TrafficMonitor, Type.L2Networking);
+    	List<HostVO> hosts = lockRows(sc, null, true);
+    	
+    	for (HostVO host : hosts) {
+    		host.setManagementServerId(managementServerId);
+    		update(host.getId(), host);
+    	}
+    	
+    	txn.commit();
+    	
+    	return hosts;
+    }
+
+    @Override
+    public void markHostsAsDisconnected(long msId, long lastPing) {
+        SearchCriteria<HostVO> sc = MsStatusSearch.create();
+        sc.setParameters("ms", msId);
+
+        HostVO 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<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag) {
+
+        SearchBuilder<HostTagVO> hostTagSearch = _hostTagsDao.createSearchBuilder();
+        HostTagVO tagEntity = hostTagSearch.entity();
+        hostTagSearch.and("tag", tagEntity.getTag(), SearchCriteria.Op.EQ);
+
+        SearchBuilder<HostVO> hostSearch = createSearchBuilder();
+        HostVO entity = hostSearch.entity();
+        hostSearch.and("type", entity.getType(), SearchCriteria.Op.EQ);
+        hostSearch.and("pod", entity.getPodId(), SearchCriteria.Op.EQ);
+        hostSearch.and("dc", entity.getDataCenterId(), SearchCriteria.Op.EQ);
+        hostSearch.and("cluster", entity.getClusterId(), SearchCriteria.Op.EQ);
+        hostSearch.and("status", entity.getStatus(), SearchCriteria.Op.EQ);
+        hostSearch.and("resourceState", entity.getResourceState(), SearchCriteria.Op.EQ);
+        hostSearch.join("hostTagSearch", hostTagSearch, entity.getId(), tagEntity.getHostId(), JoinBuilder.JoinType.INNER);
+
+        SearchCriteria<HostVO> sc = hostSearch.create();
+        sc.setJoinParameters("hostTagSearch", "tag", hostTag);
+        sc.setParameters("type", type.toString());
+        if (podId != null) {
+            sc.setParameters("pod", podId);
+        }
+        if (clusterId != null) {
+            sc.setParameters("cluster", clusterId);
+        }
+        sc.setParameters("dc", dcId);
+        sc.setParameters("status", Status.Up.toString());
+        sc.setParameters("resourceState", ResourceState.Enabled.toString());
+
+        return listBy(sc);
+    }
+    
+    
+    @Override
+    public List<HostVO> listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag) {
+        SearchBuilder<HostTagVO> 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<HostVO> 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<HostVO> 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(HostVO host) {
+        Map<String, String> details = _detailsDao.findDetails(host.getId());
+        host.setDetails(details);
+    }
+
+    @Override
+    public void loadHostTags(HostVO host) {
+        List<String> hostTags = _hostTagsDao.gethostTags(host.getId());
+        host.setHostTags(hostTags);
+    }
+
+    @DB
+    @Override
+    public List<HostVO> findLostHosts(long timeout) {
+        Transaction txn = Transaction.currentTxn();
+        PreparedStatement pstmt = null;
+        List<HostVO> result = new ArrayList<HostVO>();
+        ResultSet rs = null;
+        try {
+            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') ;" ;
+            pstmt = txn.prepareStatement(sql);
+            pstmt.setLong(1, timeout);
+            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);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+        return result;
+    }
+   
+    @Override
+    public void saveDetails(HostVO host) {
+        Map<String, String> details = host.getDetails();
+        if (details == null) {
+            return;
+        }
+        _detailsDao.persist(host.getId(), details);
+    }
+
+    protected void saveHostTags(HostVO host) {
+        List<String> hostTags = host.getHostTags();
+        if (hostTags == null || (hostTags != null && hostTags.isEmpty())) {
+            return;
+        }
+        _hostTagsDao.persist(host.getId(), hostTags);
+    }
+
+    @Override
+    @DB
+    public HostVO persist(HostVO host) {
+        final String InsertSequenceSql = "INSERT INTO op_host(id) VALUES(?)";
+
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+
+        HostVO dbHost = super.persist(host);
+
+        try {
+            PreparedStatement pstmt = txn.prepareAutoCloseStatement(InsertSequenceSql);
+            pstmt.setLong(1, dbHost.getId());
+            pstmt.executeUpdate();
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to persist the sequence number for this host");
+        }
+
+        saveDetails(host);
+        loadDetails(dbHost);
+        saveHostTags(host);
+        loadHostTags(dbHost);
+
+        txn.commit();
+
+        return dbHost;
+    }
+
+    @Override
+    @DB
+    public boolean update(Long hostId, HostVO host) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+
+        boolean persisted = super.update(hostId, host);
+        if (!persisted) {
+            return persisted;
+        }
+
+        saveDetails(host);
+        saveHostTags(host);
+
+        txn.commit();
+
+        return persisted;
+    }
+
+    @Override
+    @DB
+    public List<RunningHostCountInfo> 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<RunningHostCountInfo> l = new ArrayList<RunningHostCountInfo>();
+
+        Transaction txn = Transaction.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) {
+        } catch (Throwable e) {
+        }
+        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<Long> 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(Status oldStatus, Event event, Status newStatus, Host vo, Object data) {
+		HostVO host = findById(vo.getId());
+		long oldPingTime = host.getLastPinged();
+
+		SearchBuilder<HostVO> sb = createSearchBuilder();
+		sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
+		sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
+		sb.and("update", sb.entity().getUpdated(), SearchCriteria.Op.EQ);
+		if (newStatus.checkManagementServer()) {
+			sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ);
+			sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL);
+			sb.or("msid", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ);
+			sb.closeParen();
+		}
+		sb.done();
+
+		SearchCriteria<HostVO> sc = sb.create();
+
+		sc.setParameters("status", oldStatus);
+		sc.setParameters("id", host.getId());
+		sc.setParameters("update", host.getUpdated());
+		long oldUpdateCount = host.getUpdated();
+		if (newStatus.checkManagementServer()) {
+			sc.setParameters("ping", oldPingTime);
+			sc.setParameters("msid", host.getManagementServerId());
+		}
+
+		long newUpdateCount = host.incrUpdated();
+		UpdateBuilder ub = getUpdateBuilder(host);
+		ub.set(host, _statusAttr, newStatus);
+		if (newStatus.updateManagementServer()) {
+			if (newStatus.lostConnection()) {
+				ub.set(host, _msIdAttr, null);
+			} else {
+				ub.set(host, _msIdAttr, host.getManagementServerId());
+			}
+			if (event.equals(Event.Ping) || event.equals(Event.AgentConnected)) {
+				ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10);
+			}
+		}
+		if (event.equals(Event.ManagementServerDown)) {
+			ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60)));
+		}
+		int result = update(ub, sc, null);
+		assert result <= 1 : "How can this update " + result + " rows? ";
+
+		if (status_logger.isDebugEnabled() && result == 0) {
+			HostVO ho = findById(host.getId());
+			assert ho != null : "How how how? : " + host.getId();
+
+			StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString());
+			str.append(". Name=").append(host.getName());
+			str.append("; New=[status=").append(newStatus.toString()).append(":msid=")
+			        .append(newStatus.lostConnection() ? "null" : host.getManagementServerId()).append(":lastpinged=").append(host.getLastPinged()).append("]");
+			str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=")
+			        .append(oldPingTime).append("]");
+			str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=")
+			        .append(vo.getLastPinged()).append(":old update count=").append(oldUpdateCount).append("]");
+			status_logger.debug(str.toString());
+		} else {
+			StringBuilder msg = new StringBuilder("Agent status update: [");
+			msg.append("id = " + host.getId());
+			msg.append("; name = " + host.getName());
+			msg.append("; old status = " + oldStatus);
+			msg.append("; event = " + event);
+			msg.append("; new status = " + newStatus);
+			msg.append("; old update count = " + oldUpdateCount);
+			msg.append("; new update count = " + newUpdateCount + "]");
+			status_logger.debug(msg.toString());
+		}
+		
+		return result > 0;
+	}
+	
+    @Override
+    public boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo) {
+        HostVO host = (HostVO)vo;
+        SearchBuilder<HostVO> sb = createSearchBuilder();
+        sb.and("resource_state", sb.entity().getResourceState(), SearchCriteria.Op.EQ);
+        sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
+        sb.done();
+        
+        SearchCriteria<HostVO> 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) {
+            HostVO 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 HostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type) {
+        SearchCriteria<HostVO> sc = TypeNameZoneSearch.create();
+        sc.setParameters("type", type);
+        sc.setParameters("name", name);
+        sc.setParameters("zoneId", zoneId);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public List<HostVO> findHypervisorHostInCluster(long clusterId) {
+        SearchCriteria<HostVO> 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);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/host/dao/HostDetailsDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostDetailsDao.java b/engine/schema/src/com/cloud/host/dao/HostDetailsDao.java
new file mode 100644
index 0000000..5babcad
--- /dev/null
+++ b/engine/schema/src/com/cloud/host/dao/HostDetailsDao.java
@@ -0,0 +1,32 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.host.dao;
+
+import java.util.Map;
+
+import com.cloud.host.DetailVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface HostDetailsDao extends GenericDao<DetailVO, Long> {
+    Map<String, String> findDetails(long hostId);
+    
+    void persist(long hostId, Map<String, String> details);
+    
+    DetailVO findDetail(long hostId, String name);
+
+	void deleteDetails(long hostId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/host/dao/HostDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostDetailsDaoImpl.java b/engine/schema/src/com/cloud/host/dao/HostDetailsDaoImpl.java
new file mode 100644
index 0000000..b6a9cef
--- /dev/null
+++ b/engine/schema/src/com/cloud/host/dao/HostDetailsDaoImpl.java
@@ -0,0 +1,110 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.host.dao;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.host.DetailVO;
+import com.cloud.utils.crypt.DBEncryptionUtil;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value=HostDetailsDao.class)
+public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements HostDetailsDao {
+    protected final SearchBuilder<DetailVO> HostSearch;
+    protected final SearchBuilder<DetailVO> DetailSearch;
+    
+    public HostDetailsDaoImpl() {
+        HostSearch = createSearchBuilder();
+        HostSearch.and("hostId", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
+        HostSearch.done();
+        
+        DetailSearch = createSearchBuilder();
+        DetailSearch.and("hostId", DetailSearch.entity().getHostId(), SearchCriteria.Op.EQ);
+        DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
+        DetailSearch.done();
+    }
+
+    @Override
+    public DetailVO findDetail(long hostId, String name) {
+        SearchCriteria<DetailVO> sc = DetailSearch.create();
+        sc.setParameters("hostId", hostId);
+        sc.setParameters("name", name);
+        
+        DetailVO detail = findOneIncludingRemovedBy(sc);
+        if("password".equals(name) && detail != null){
+        	detail.setValue(DBEncryptionUtil.decrypt(detail.getValue()));
+        }
+        return detail;
+    }
+
+    @Override
+    public Map<String, String> findDetails(long hostId) {
+        SearchCriteria<DetailVO> sc = HostSearch.create();
+        sc.setParameters("hostId", hostId);
+        
+        List<DetailVO> results = search(sc, null);
+        Map<String, String> details = new HashMap<String, String>(results.size());
+        for (DetailVO result : results) {
+        	if("password".equals(result.getName())){
+        		details.put(result.getName(), DBEncryptionUtil.decrypt(result.getValue()));
+        	} else {
+        		details.put(result.getName(), result.getValue());
+        	}
+        }
+        return details;
+    }
+    
+    @Override
+    public void deleteDetails(long hostId) {
+        SearchCriteria sc = HostSearch.create();
+        sc.setParameters("hostId", hostId);
+        
+        List<DetailVO> results = search(sc, null);
+        for (DetailVO result : results) {
+        	remove(result.getId());
+        }
+    }
+
+    @Override
+    public void persist(long hostId, Map<String, String> details) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        SearchCriteria<DetailVO> sc = HostSearch.create();
+        sc.setParameters("hostId", hostId);
+        expunge(sc);
+        
+        for (Map.Entry<String, String> detail : details.entrySet()) {
+        	String value = detail.getValue();
+        	if("password".equals(detail.getKey())){
+        		value = DBEncryptionUtil.encrypt(value);
+        	}
+            DetailVO vo = new DetailVO(hostId, detail.getKey(), value);
+            persist(vo);
+        }
+        txn.commit();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/host/dao/HostTagsDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostTagsDao.java b/engine/schema/src/com/cloud/host/dao/HostTagsDao.java
new file mode 100644
index 0000000..ddda882
--- /dev/null
+++ b/engine/schema/src/com/cloud/host/dao/HostTagsDao.java
@@ -0,0 +1,30 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.host.dao;
+
+import java.util.List;
+import com.cloud.host.HostTagVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface HostTagsDao extends GenericDao<HostTagVO, Long> {
+    
+    void persist(long hostId, List<String> hostTags);
+    
+    List<String> gethostTags(long hostId);
+	
+}
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/host/dao/HostTagsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostTagsDaoImpl.java b/engine/schema/src/com/cloud/host/dao/HostTagsDaoImpl.java
new file mode 100644
index 0000000..0e93275
--- /dev/null
+++ b/engine/schema/src/com/cloud/host/dao/HostTagsDaoImpl.java
@@ -0,0 +1,75 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.host.dao;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.host.HostTagVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value=HostTagsDao.class)
+public class HostTagsDaoImpl extends GenericDaoBase<HostTagVO, Long> implements HostTagsDao {
+    protected final SearchBuilder<HostTagVO> HostSearch;
+    
+    public HostTagsDaoImpl() {
+        HostSearch = createSearchBuilder();
+        HostSearch.and("hostId", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
+        HostSearch.done();        
+    }
+
+    @Override
+    public List<String> gethostTags(long hostId) {
+        SearchCriteria<HostTagVO> sc = HostSearch.create();
+        sc.setParameters("hostId", hostId);
+        
+        List<HostTagVO> results = search(sc, null);
+        List<String> hostTags = new ArrayList<String>(results.size());
+        for (HostTagVO result : results) {
+        	hostTags.add(result.getTag());
+        }
+
+        return hostTags;
+    }
+    
+    @Override
+    public void persist(long hostId, List<String> hostTags) {
+        Transaction txn = Transaction.currentTxn();
+
+        txn.start();
+        SearchCriteria<HostTagVO> sc = HostSearch.create();
+        sc.setParameters("hostId", hostId);
+        expunge(sc);
+        
+        for (String tag : hostTags) {
+            tag = tag.trim();
+            if(tag.length() > 0) {
+                HostTagVO vo = new HostTagVO(hostId, tag);
+                persist(vo);
+            }
+        }
+        txn.commit();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/hypervisor/HypervisorCapabilitiesVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/hypervisor/HypervisorCapabilitiesVO.java b/engine/schema/src/com/cloud/hypervisor/HypervisorCapabilitiesVO.java
new file mode 100644
index 0000000..6689066
--- /dev/null
+++ b/engine/schema/src/com/cloud/hypervisor/HypervisorCapabilitiesVO.java
@@ -0,0 +1,212 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor;
+
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.api.Identity;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.utils.NumbersUtil;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="hypervisor_capabilities")
+public class HypervisorCapabilitiesVO implements HypervisorCapabilities {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private long id;
+
+    @Column(name="hypervisor_type")
+    @Enumerated(value=EnumType.STRING)
+    private HypervisorType hypervisorType;
+
+    @Column(name="hypervisor_version")
+    private String hypervisorVersion;
+
+    @Column(name="max_guests_limit")
+    private Long maxGuestsLimit;
+
+    @Column(name="security_group_enabled")
+    private boolean securityGroupEnabled;
+
+    @Column(name="uuid")
+    private String uuid;
+
+    @Column(name="max_data_volumes_limit")
+    private Integer maxDataVolumesLimit;
+
+    @Column(name="max_hosts_per_cluster")
+    private Integer maxHostsPerCluster;
+
+    @Column(name="vm_snapshot_enabled")
+    private Boolean vmSnapshotEnabled;
+
+    @Column(name="storage_motion_supported")
+    private boolean storageMotionSupported;
+
+    protected HypervisorCapabilitiesVO() {
+    	this.uuid = UUID.randomUUID().toString();
+    }
+
+    public HypervisorCapabilitiesVO(HypervisorType hypervisorType, String hypervisorVersion, Long maxGuestsLimit,
+            boolean securityGroupEnabled, boolean storageMotionSupported) {
+        this.hypervisorType = hypervisorType;
+        this.hypervisorVersion = hypervisorVersion;
+        this.maxGuestsLimit = maxGuestsLimit;
+        this.securityGroupEnabled = securityGroupEnabled;
+        this.storageMotionSupported = storageMotionSupported;
+    	this.uuid = UUID.randomUUID().toString();
+    }
+
+    /**
+     * @param hypervisorType the hypervisorType to set
+     */
+    public void setHypervisorType(HypervisorType hypervisorType) {
+        this.hypervisorType = hypervisorType;
+    }
+
+
+    /**
+     * @return the hypervisorType
+     */
+    @Override
+    public HypervisorType getHypervisorType() {
+        return hypervisorType;
+    }
+
+    /**
+     * @param hypervisorVersion the hypervisorVersion to set
+     */
+    public void setHypervisorVersion(String hypervisorVersion) {
+        this.hypervisorVersion = hypervisorVersion;
+    }
+
+    /**
+     * @return the hypervisorVersion
+     */
+    @Override
+    public String getHypervisorVersion() {
+        return hypervisorVersion;
+    }
+
+    public void setSecurityGroupEnabled(Boolean securityGroupEnabled) {
+        this.securityGroupEnabled = securityGroupEnabled;
+    }
+
+    /**
+     * @return the securityGroupSupport
+     */
+    @Override
+    public boolean isSecurityGroupEnabled() {
+        return securityGroupEnabled;
+    }
+
+    /**
+     * @param maxGuests the maxGuests to set
+     */
+    public void setMaxGuestsLimit(Long maxGuestsLimit) {
+        this.maxGuestsLimit = maxGuestsLimit;
+    }
+
+    /**
+     * @return the maxGuests
+     */
+    @Override
+    public Long getMaxGuestsLimit() {
+        return maxGuestsLimit;
+    }
+
+    /**
+     * @param storageMotionSupported
+     */
+    public void setStorageMotionSupported(boolean storageMotionSupported) {
+        this.storageMotionSupported = storageMotionSupported;
+    }
+
+    /**
+     * @return if storage motion is supported
+     */
+    @Override
+    public boolean isStorageMotionSupported() {
+        return storageMotionSupported;
+    }
+
+
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public int hashCode() {
+        return NumbersUtil.hash(id);
+    }
+    
+    @Override
+    public String getUuid() {
+    	return this.uuid;
+    }
+    
+    public void setUuid(String uuid) {
+    	this.uuid = uuid;
+    }
+
+    @Override
+    public Integer getMaxDataVolumesLimit() {
+        return maxDataVolumesLimit;
+    }
+
+    public void setMaxDataVolumesLimit(Integer maxDataVolumesLimit) {
+        this.maxDataVolumesLimit = maxDataVolumesLimit;
+    }
+
+    @Override
+    public Integer getMaxHostsPerCluster() {
+        return maxHostsPerCluster;
+    }
+
+    public void setMaxHostsPerCluster(Integer maxHostsPerCluster) {
+        this.maxHostsPerCluster = maxHostsPerCluster;
+    }
+
+	public Boolean getVmSnapshotEnabled() {
+		return vmSnapshotEnabled;
+	}
+
+	public void setVmSnapshotEnabled(Boolean vmSnapshotEnabled) {
+		this.vmSnapshotEnabled = vmSnapshotEnabled;
+	}
+
+	@Override
+    public boolean equals(Object obj) {
+        if (obj instanceof HypervisorCapabilitiesVO) {
+            return ((HypervisorCapabilitiesVO)obj).getId() == this.getId();
+        } else {
+            return false;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/hypervisor/dao/HypervisorCapabilitiesDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/hypervisor/dao/HypervisorCapabilitiesDao.java b/engine/schema/src/com/cloud/hypervisor/dao/HypervisorCapabilitiesDao.java
new file mode 100644
index 0000000..1fdc03a
--- /dev/null
+++ b/engine/schema/src/com/cloud/hypervisor/dao/HypervisorCapabilitiesDao.java
@@ -0,0 +1,38 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.dao;
+
+import java.util.List;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.hypervisor.HypervisorCapabilitiesVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface HypervisorCapabilitiesDao extends GenericDao<HypervisorCapabilitiesVO, Long> {
+    
+    List<HypervisorCapabilitiesVO> listAllByHypervisorType(HypervisorType hypervisorType);
+    
+    HypervisorCapabilitiesVO findByHypervisorTypeAndVersion(HypervisorType hypervisorType, String hypervisorVersion);
+    
+    Long getMaxGuestsLimit(HypervisorType hypervisorType, String hypervisorVersion);
+
+    Integer getMaxDataVolumesLimit(HypervisorType hypervisorType, String hypervisorVersion);
+
+    Integer getMaxHostsPerCluster(HypervisorType hypervisorType, String hypervisorVersion);
+    
+    Boolean isVmSnapshotEnabled(HypervisorType hypervisorType, String hypervisorVersion);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java b/engine/schema/src/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java
new file mode 100644
index 0000000..b5e17ee
--- /dev/null
+++ b/engine/schema/src/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java
@@ -0,0 +1,105 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.hypervisor.dao;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.hypervisor.HypervisorCapabilitiesVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import java.util.List;
+
+@Component
+@Local(value=HypervisorCapabilitiesDao.class)
+public class HypervisorCapabilitiesDaoImpl extends GenericDaoBase<HypervisorCapabilitiesVO, Long> implements HypervisorCapabilitiesDao {
+    
+    private static final Logger s_logger = Logger.getLogger(HypervisorCapabilitiesDaoImpl.class);
+
+    protected final SearchBuilder<HypervisorCapabilitiesVO> HypervisorTypeSearch;
+    protected final SearchBuilder<HypervisorCapabilitiesVO> HypervisorTypeAndVersionSearch;
+
+    private static final String DEFAULT_VERSION = "default";
+    
+    protected HypervisorCapabilitiesDaoImpl() {
+        HypervisorTypeSearch = createSearchBuilder();
+        HypervisorTypeSearch.and("hypervisorType", HypervisorTypeSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ);
+        HypervisorTypeSearch.done();
+        
+        HypervisorTypeAndVersionSearch = createSearchBuilder();
+        HypervisorTypeAndVersionSearch.and("hypervisorType", HypervisorTypeAndVersionSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ);
+        HypervisorTypeAndVersionSearch.and("hypervisorVersion", HypervisorTypeAndVersionSearch.entity().getHypervisorVersion(), SearchCriteria.Op.EQ);
+        HypervisorTypeAndVersionSearch.done();
+    }
+
+    HypervisorCapabilitiesVO getCapabilities(HypervisorType hypervisorType, String hypervisorVersion) {
+        HypervisorCapabilitiesVO result = findByHypervisorTypeAndVersion(hypervisorType, hypervisorVersion);
+        if (result == null) { // if data is not available for a specific version then use 'default' as version
+            result = findByHypervisorTypeAndVersion(hypervisorType, DEFAULT_VERSION);
+        }
+        return result;
+    }
+
+    @Override
+    public List<HypervisorCapabilitiesVO> listAllByHypervisorType(HypervisorType hypervisorType){
+        SearchCriteria<HypervisorCapabilitiesVO> sc = HypervisorTypeSearch.create();
+        sc.setParameters("hypervisorType", hypervisorType);
+        return search(sc, null);
+    }
+    
+    @Override
+    public HypervisorCapabilitiesVO findByHypervisorTypeAndVersion(HypervisorType hypervisorType, String hypervisorVersion){
+        SearchCriteria<HypervisorCapabilitiesVO> sc = HypervisorTypeAndVersionSearch.create();
+        sc.setParameters("hypervisorType", hypervisorType);
+        sc.setParameters("hypervisorVersion", hypervisorVersion);
+        return findOneBy(sc);
+    }
+    
+    @Override
+    public Long getMaxGuestsLimit(HypervisorType hypervisorType, String hypervisorVersion){
+        Long defaultLimit = new Long(50);
+        HypervisorCapabilitiesVO result = getCapabilities(hypervisorType, hypervisorVersion);
+        if (result == null)
+            return defaultLimit;
+        Long limit = result.getMaxGuestsLimit();
+        if (limit == null)
+            return defaultLimit;
+        return limit;
+    }
+
+    @Override
+    public Integer getMaxDataVolumesLimit(HypervisorType hypervisorType, String hypervisorVersion) {
+        HypervisorCapabilitiesVO result = getCapabilities(hypervisorType, hypervisorVersion);
+        return result.getMaxDataVolumesLimit();
+    }
+
+    @Override
+    public Integer getMaxHostsPerCluster(HypervisorType hypervisorType, String hypervisorVersion) {
+        HypervisorCapabilitiesVO result = getCapabilities(hypervisorType, hypervisorVersion);
+        return result.getMaxHostsPerCluster();
+    }
+
+	@Override
+	public Boolean isVmSnapshotEnabled(HypervisorType hypervisorType,
+			String hypervisorVersion) {
+		HypervisorCapabilitiesVO result = getCapabilities(hypervisorType, hypervisorVersion);
+		return result.getVmSnapshotEnabled();
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/keystore/KeystoreDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/keystore/KeystoreDao.java b/engine/schema/src/com/cloud/keystore/KeystoreDao.java
new file mode 100644
index 0000000..291f16e
--- /dev/null
+++ b/engine/schema/src/com/cloud/keystore/KeystoreDao.java
@@ -0,0 +1,29 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.keystore;
+
+import java.util.List;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface KeystoreDao extends GenericDao<KeystoreVO, Long> {
+	KeystoreVO findByName(String name);
+	void save(String name, String certificate, String key, String domainSuffix);
+	void save(String alias, String certificate, Integer index,
+			String domainSuffix);
+	List<KeystoreVO> findCertChain();
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/keystore/KeystoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/keystore/KeystoreDaoImpl.java b/engine/schema/src/com/cloud/keystore/KeystoreDaoImpl.java
new file mode 100644
index 0000000..0ea97c7
--- /dev/null
+++ b/engine/schema/src/com/cloud/keystore/KeystoreDaoImpl.java
@@ -0,0 +1,118 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.keystore;
+
+import java.sql.PreparedStatement;
+import java.util.Comparator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+import edu.emory.mathcs.backport.java.util.Collections;
+
+@Component
+@Local(value={KeystoreDao.class})
+public class KeystoreDaoImpl extends GenericDaoBase<KeystoreVO, Long> implements KeystoreDao {
+    protected final SearchBuilder<KeystoreVO> FindByNameSearch;
+    protected final SearchBuilder<KeystoreVO> CertChainSearch;
+
+	public KeystoreDaoImpl() {
+		FindByNameSearch = createSearchBuilder();
+		FindByNameSearch.and("name", FindByNameSearch.entity().getName(), Op.EQ);
+		FindByNameSearch.done();
+		
+		CertChainSearch = createSearchBuilder();
+		CertChainSearch.and("key", CertChainSearch.entity().getKey(), Op.NULL);
+		CertChainSearch.done();
+	}
+	
+	@Override
+	public List<KeystoreVO> findCertChain() {
+		SearchCriteria<KeystoreVO> sc =  CertChainSearch.create();
+		List<KeystoreVO> ks = listBy(sc);
+		Collections.sort(ks, new Comparator() { public int compare(Object o1, Object o2) {
+			Integer seq1 = ((KeystoreVO)o1).getIndex();
+			Integer seq2 = ((KeystoreVO)o2).getIndex();
+			return seq1.compareTo(seq2);
+		}});
+		return ks;
+	}
+	
+	@Override
+	public KeystoreVO findByName(String name) {
+		assert(name != null);
+		
+		SearchCriteria<KeystoreVO> sc =  FindByNameSearch.create();
+		sc.setParameters("name", name);
+		return findOneBy(sc);
+	}
+	
+	@Override
+	@DB
+	public void save(String name, String certificate, String key, String domainSuffix) {
+		Transaction txn = Transaction.currentTxn();
+		try {
+			txn.start();
+			
+			String sql = "INSERT INTO keystore (`name`, `certificate`, `key`, `domain_suffix`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE `certificate`=?, `key`=?, `domain_suffix`=?";
+			PreparedStatement pstmt = txn.prepareAutoCloseStatement(sql);
+			pstmt.setString(1, name);
+			pstmt.setString(2, certificate);
+			pstmt.setString(3, key);
+			pstmt.setString(4, domainSuffix);
+			pstmt.setString(5, certificate);
+			pstmt.setString(6, key);
+			pstmt.setString(7, domainSuffix);
+
+			pstmt.executeUpdate();
+			txn.commit();
+		} catch(Exception e) {
+			txn.rollback();
+			throw new CloudRuntimeException("Unable to save certificate under name " + name + " due to exception", e);
+		}
+	}
+	
+	@Override
+	@DB
+	public void save(String alias, String certificate, Integer index, String domainSuffix) {
+		KeystoreVO ks = this.findByName(alias);
+		if (ks != null) {
+			ks.setCertificate(certificate);
+			ks.setName(alias);
+			ks.setIndex(index);
+			ks.setDomainSuffix(domainSuffix);
+			this.update(ks.getId(), ks);
+		} else {
+			KeystoreVO newks = new KeystoreVO();
+			newks.setCertificate(certificate);
+			newks.setName(alias);
+			newks.setIndex(index);
+			newks.setDomainSuffix(domainSuffix);
+			this.persist(newks);
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/keystore/KeystoreVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/keystore/KeystoreVO.java b/engine/schema/src/com/cloud/keystore/KeystoreVO.java
new file mode 100644
index 0000000..f590607
--- /dev/null
+++ b/engine/schema/src/com/cloud/keystore/KeystoreVO.java
@@ -0,0 +1,101 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.keystore;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="keystore")
+public class KeystoreVO implements InternalIdentity {
+	@Id
+	@GeneratedValue(strategy=GenerationType.IDENTITY)
+	@Column(name="id")
+	private Long id;
+
+	@Column(name="name")
+	private String name;
+	
+    @Column(name="certificate",length=65535)
+    private String certificate;
+
+    @Column(name="key",length=65535)
+    private String key;
+    
+    @Column(name="domain_suffix")
+    private String domainSuffix;
+    
+    @Column(name="seq")
+    private Integer index;
+
+    public KeystoreVO() {
+    }
+    
+	public long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getCertificate() {
+		return certificate;
+	}
+
+	public void setCertificate(String certificate) {
+		this.certificate = certificate;
+	}
+
+	public String getKey() {
+		return key;
+	}
+
+	public void setKey(String key) {
+		this.key = key;
+	}
+
+	public String getDomainSuffix() {
+		return domainSuffix;
+	}
+
+	public void setDomainSuffix(String domainSuffix) {
+		this.domainSuffix = domainSuffix;
+	}
+	
+	public void setIndex(Integer index) {
+		this.index = index;
+	}
+	
+	public Integer getIndex() {
+		return this.index;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/migration/DiskOffering20Dao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/migration/DiskOffering20Dao.java b/engine/schema/src/com/cloud/migration/DiskOffering20Dao.java
new file mode 100644
index 0000000..ce22f48
--- /dev/null
+++ b/engine/schema/src/com/cloud/migration/DiskOffering20Dao.java
@@ -0,0 +1,22 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.migration;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface DiskOffering20Dao extends GenericDao<DiskOffering20VO, Long>  {
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/migration/DiskOffering20DaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/migration/DiskOffering20DaoImpl.java b/engine/schema/src/com/cloud/migration/DiskOffering20DaoImpl.java
new file mode 100644
index 0000000..e0eb40e
--- /dev/null
+++ b/engine/schema/src/com/cloud/migration/DiskOffering20DaoImpl.java
@@ -0,0 +1,27 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.migration;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+
+@Local(value={DiskOffering20Dao.class})
+public class DiskOffering20DaoImpl extends GenericDaoBase<DiskOffering20VO, Long> implements DiskOffering20Dao {
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/migration/DiskOffering20VO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/migration/DiskOffering20VO.java b/engine/schema/src/com/cloud/migration/DiskOffering20VO.java
new file mode 100644
index 0000000..e50328d
--- /dev/null
+++ b/engine/schema/src/com/cloud/migration/DiskOffering20VO.java
@@ -0,0 +1,113 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.migration;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="disk_offering")
+public class DiskOffering20VO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    Long id;
+
+    @Column(name="domain_id")
+    long domainId;
+
+    @Column(name="name")
+    private String name = null;
+
+    @Column(name="display_text")
+    private String displayText = null;
+
+    @Column(name="disk_size")
+    long diskSize;
+
+    @Column(name="mirrored")
+    boolean mirrored;
+
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    private Date removed;
+
+    public DiskOffering20VO() {
+    }
+
+    public DiskOffering20VO(long domainId, String name, String displayText, long diskSize, boolean mirrored) {
+        this.domainId = domainId;
+        this.name = name;
+        this.displayText = displayText;
+        this.diskSize = diskSize;
+        this.mirrored = mirrored;
+    }
+
+    public long getId() {
+        return id;
+    }
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public long getDomainId() {
+        return domainId;
+    }
+    public void setDomainId(long domainId) {
+        this.domainId = domainId;
+    }
+
+    public String getName() {
+        return name;
+    }
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDisplayText() {
+        return displayText;
+    }
+    public void setDisplayText(String displayText) {
+        this.displayText = displayText;
+    }
+
+    public long getDiskSize() {
+        return diskSize;
+    }
+    public void setDiskSize(long diskSize) {
+        this.diskSize = diskSize;
+    }
+
+    public boolean getMirrored() {
+        return mirrored;
+    }
+    public void setMirrored(boolean mirrored) {
+        this.mirrored = mirrored;
+    }
+
+    public Date getRemoved() {
+        return removed;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/migration/DiskOffering21Dao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/migration/DiskOffering21Dao.java b/engine/schema/src/com/cloud/migration/DiskOffering21Dao.java
new file mode 100644
index 0000000..21781ea
--- /dev/null
+++ b/engine/schema/src/com/cloud/migration/DiskOffering21Dao.java
@@ -0,0 +1,23 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.migration;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface DiskOffering21Dao extends GenericDao<DiskOffering21VO, Long> {
+}
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/migration/DiskOffering21DaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/migration/DiskOffering21DaoImpl.java b/engine/schema/src/com/cloud/migration/DiskOffering21DaoImpl.java
new file mode 100644
index 0000000..b67d8fb
--- /dev/null
+++ b/engine/schema/src/com/cloud/migration/DiskOffering21DaoImpl.java
@@ -0,0 +1,27 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.migration;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+
+@Local(value={DiskOffering21Dao.class})
+public class DiskOffering21DaoImpl extends GenericDaoBase<DiskOffering21VO, Long> implements DiskOffering21Dao {
+}


Mime
View raw message