cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From muralire...@apache.org
Subject [15/93] [abbrv] [partial] merge master
Date Mon, 13 May 2013 15:53:35 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/domain/dao/DomainDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/domain/dao/DomainDaoImpl.java b/engine/schema/src/com/cloud/domain/dao/DomainDaoImpl.java
new file mode 100644
index 0000000..c30ca5e
--- /dev/null
+++ b/engine/schema/src/com/cloud/domain/dao/DomainDaoImpl.java
@@ -0,0 +1,278 @@
+// 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.domain.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.domain.Domain;
+import com.cloud.domain.DomainVO;
+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.Transaction;
+
+@Component
+@Local(value={DomainDao.class})
+public class DomainDaoImpl extends GenericDaoBase<DomainVO, Long> implements DomainDao {
+    private static final Logger s_logger = Logger.getLogger(DomainDaoImpl.class);
+    
+	protected SearchBuilder<DomainVO> DomainNameLikeSearch;
+	protected SearchBuilder<DomainVO> ParentDomainNameLikeSearch;
+	protected SearchBuilder<DomainVO> DomainPairSearch;
+	protected SearchBuilder<DomainVO> ImmediateChildDomainSearch;
+	protected SearchBuilder<DomainVO> FindAllChildrenSearch;
+	protected SearchBuilder<DomainVO> AllFieldsSearch;
+	
+	public DomainDaoImpl () {
+		DomainNameLikeSearch = createSearchBuilder();
+		DomainNameLikeSearch.and("name", DomainNameLikeSearch.entity().getName(), SearchCriteria.Op.LIKE);
+		DomainNameLikeSearch.done();
+		
+		ParentDomainNameLikeSearch = createSearchBuilder();
+		ParentDomainNameLikeSearch.and("name", ParentDomainNameLikeSearch.entity().getName(), SearchCriteria.Op.LIKE);
+		ParentDomainNameLikeSearch.and("parent", ParentDomainNameLikeSearch.entity().getName(), SearchCriteria.Op.EQ);
+		ParentDomainNameLikeSearch.done();
+
+		DomainPairSearch = createSearchBuilder();
+		DomainPairSearch.and("id", DomainPairSearch.entity().getId(), SearchCriteria.Op.IN);
+		DomainPairSearch.done();
+
+		ImmediateChildDomainSearch = createSearchBuilder();
+		ImmediateChildDomainSearch.and("parent", ImmediateChildDomainSearch.entity().getParent(), SearchCriteria.Op.EQ);
+		ImmediateChildDomainSearch.done();
+		
+		FindAllChildrenSearch = createSearchBuilder();
+		FindAllChildrenSearch.and("path", FindAllChildrenSearch.entity().getPath(), SearchCriteria.Op.LIKE);
+		FindAllChildrenSearch.and("id", FindAllChildrenSearch.entity().getId(), SearchCriteria.Op.NEQ);
+		FindAllChildrenSearch.done();
+		
+		AllFieldsSearch = createSearchBuilder();
+		AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), SearchCriteria.Op.EQ);
+		AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
+		AllFieldsSearch.and("owner", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+		AllFieldsSearch.and("path", AllFieldsSearch.entity().getPath(), SearchCriteria.Op.EQ);
+		AllFieldsSearch.and("parent", AllFieldsSearch.entity().getParent(), SearchCriteria.Op.EQ);
+		AllFieldsSearch.done();
+
+	}
+	
+    
+    private static String allocPath(DomainVO parentDomain, String name) {
+        String parentPath = parentDomain.getPath();
+        return parentPath + name + "/";
+    }
+
+    @Override
+    public synchronized DomainVO create(DomainVO domain) {
+        // make sure domain name is valid
+        String domainName = domain.getName();
+        if (domainName != null) {
+            if (domainName.contains("/")) {
+                throw new IllegalArgumentException("Domain name contains one or more invalid characters.  Please enter a name without '/' characters.");
+            }
+        } else {
+            throw new IllegalArgumentException("Domain name is null.  Please specify a valid domain name.");
+        }
+
+    	long parent = DomainVO.ROOT_DOMAIN;
+    	if(domain.getParent() != null && domain.getParent().longValue() >= DomainVO.ROOT_DOMAIN) {
+    		parent = domain.getParent().longValue();
+    	}
+    	
+    	DomainVO parentDomain = findById(parent);
+    	if(parentDomain == null) {
+            s_logger.error("Unable to load parent domain: " + parent);
+    		return null;
+    	}
+    	
+        Transaction txn = Transaction.currentTxn();
+    	try {
+    		txn.start();
+
+    		parentDomain = this.lockRow(parent, true);
+            if(parentDomain == null) {
+                s_logger.error("Unable to lock parent domain: " + parent);
+                return null;
+            }
+    		
+            domain.setPath(allocPath(parentDomain, domain.getName()));
+            domain.setLevel(parentDomain.getLevel() + 1);
+            
+            parentDomain.setNextChildSeq(parentDomain.getNextChildSeq() + 1); // FIXME:  remove sequence number?
+            parentDomain.setChildCount(parentDomain.getChildCount() + 1);
+            persist(domain);
+            update(parentDomain.getId(), parentDomain);
+            
+    		txn.commit();
+    		return domain;
+    	} catch(Exception e) {
+    		s_logger.error("Unable to create domain due to " + e.getMessage(), e);
+    		txn.rollback();
+    		return null;
+    	} 
+    }
+
+    @Override
+    @DB
+    public boolean remove(Long id) {
+        // check for any active users / domains assigned to the given domain id and don't remove the domain if there are any
+    	if (id != null && id.longValue() == DomainVO.ROOT_DOMAIN) {
+    		s_logger.error("Can not remove domain " + id + " as it is ROOT domain");
+    		return false;
+    	}
+    	
+        DomainVO domain = findById(id);
+        if(domain == null) {
+        	s_logger.error("Unable to remove domain as domain " + id + " no longer exists");
+        	return false;
+        }
+        
+        if(domain.getParent() == null) {
+        	s_logger.error("Invalid domain " + id + ", orphan?");
+        	return false;
+        }
+    	
+        String sql = "SELECT * from account where domain_id = " + id + " and removed is null";
+        String sql1 = "SELECT * from domain where parent = " + id + " and removed is null";
+
+        boolean success = false;
+        Transaction txn = Transaction.currentTxn();
+        try {
+        	txn.start();
+            DomainVO parentDomain = super.lockRow(domain.getParent(), true);
+            if(parentDomain == null) {
+                s_logger.error("Unable to load parent domain: " + domain.getParent());
+                return false;
+            }
+        	
+            PreparedStatement stmt = txn.prepareAutoCloseStatement(sql);
+            ResultSet rs = stmt.executeQuery();
+            if (rs.next()) {
+                return false;
+            }
+            stmt = txn.prepareAutoCloseStatement(sql1);
+            rs = stmt.executeQuery();
+            if (rs.next()) {
+                return false;
+            }
+            
+        	parentDomain.setChildCount(parentDomain.getChildCount() - 1);
+        	update(parentDomain.getId(), parentDomain);
+            success = super.remove(id);
+            txn.commit();
+        } catch (SQLException ex) {
+            success = false;
+            s_logger.error("error removing domain: " + id, ex);
+            txn.rollback();
+        } 
+        return success;
+    }
+
+    @Override
+    public DomainVO findDomainByPath(String domainPath) {
+        SearchCriteria<DomainVO> sc = createSearchCriteria();
+        sc.addAnd("path", SearchCriteria.Op.EQ, domainPath);
+        return findOneBy(sc);
+    }
+    
+    @Override
+    public DomainVO findImmediateChildForParent(Long parentId){
+        SearchCriteria<DomainVO> sc = ImmediateChildDomainSearch.create();
+    	sc.setParameters("parent", parentId);
+    	return (listBy(sc).size() > 0 ? listBy(sc).get(0) : null);//may need to revisit for multiple children case
+    }
+
+    @Override
+    public List<DomainVO> findImmediateChildrenForParent(Long parentId){
+        SearchCriteria<DomainVO> sc = ImmediateChildDomainSearch.create();
+    	sc.setParameters("parent", parentId);
+    	return listBy(sc);
+    }
+
+    @Override
+    public List<DomainVO> findAllChildren(String path, Long parentId){
+    	SearchCriteria<DomainVO> sc = FindAllChildrenSearch.create();
+    	sc.setParameters("path", "%"+path+"%");
+    	sc.setParameters("id", parentId);
+    	return listBy(sc);
+    }
+    
+    @Override
+    public boolean isChildDomain(Long parentId, Long childId) {
+        if ((parentId == null) || (childId == null)) {
+            return false;
+        }
+
+        if (parentId.equals(childId)) {
+            return true;
+        }
+
+        boolean result = false;
+        SearchCriteria<DomainVO> sc = DomainPairSearch.create();
+        sc.setParameters("id", parentId, childId);
+
+        List<DomainVO> domainPair = listBy(sc);
+
+        if ((domainPair != null) && (domainPair.size() == 2)) {
+            DomainVO d1 = domainPair.get(0);
+            DomainVO d2 = domainPair.get(1);
+
+            if (d1.getId() == parentId) {
+                result = d2.getPath().startsWith(d1.getPath());
+            } else {
+                result = d1.getPath().startsWith(d2.getPath());
+            }
+        }
+        return result;
+    }
+    
+    @Override
+    public List<DomainVO> findInactiveDomains() {
+        SearchCriteria<DomainVO> sc = AllFieldsSearch.create();
+        sc.setParameters("state", Domain.State.Inactive);
+        return listBy(sc);
+    }
+    
+    @Override
+    public Set<Long> getDomainParentIds(long domainId) {
+        Set<Long> parentDomains = new HashSet<Long>();
+        Domain domain = findById(domainId);
+
+        if (domain != null) {
+            parentDomains.add(domain.getId());
+
+            while (domain.getParent() != null) {
+                domain = findById(domain.getParent());
+                parentDomains.add(domain.getId());
+            }
+        }
+        
+        return parentDomains;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/event/EventVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/EventVO.java b/engine/schema/src/com/cloud/event/EventVO.java
new file mode 100644
index 0000000..2c30ead
--- /dev/null
+++ b/engine/schema/src/com/cloud/event/EventVO.java
@@ -0,0 +1,194 @@
+// 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.event;
+
+import java.util.Date;
+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 javax.persistence.Transient;
+
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name="event")
+public class EventVO implements Event {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private long id = -1;
+
+    @Column(name="type")
+    private String type;
+
+    @Enumerated(value=EnumType.STRING)
+    @Column(name="state")
+    private State state = State.Completed;
+
+    @Column(name="description", length=1024)
+    private String description;
+
+    @Column(name=GenericDao.CREATED_COLUMN)
+    private Date createDate;
+
+    @Column(name="user_id")
+    private long userId;
+
+    @Column(name="account_id")
+    private long accountId;
+
+    @Column(name="domain_id")
+    private long domainId;
+
+    @Column(name="level")
+    private String level = LEVEL_INFO;
+
+    @Column(name="start_id")
+    private long startId;
+
+    @Column(name="parameters", length=1024)
+    private String parameters;
+
+    @Column(name="uuid")
+    private String uuid;
+
+    @Column(name="archived")
+    private boolean archived;
+
+    @Transient
+    private int totalSize;
+
+    public static final String LEVEL_INFO = "INFO";
+    public static final String LEVEL_WARN = "WARN";
+    public static final String LEVEL_ERROR = "ERROR";
+
+    public EventVO() {
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public long getId() {
+        return id;
+    }
+    @Override
+    public String getType() {
+        return type;
+    }
+    public void setType(String type) {
+        this.type = type;
+    }
+    @Override
+    public State getState() {
+        return state;
+    }
+
+    public void setState(State state) {
+        this.state = state;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+    public void setDescription(String description) {
+        this.description = description;
+    }
+    @Override
+    public Date getCreateDate() {
+        return createDate;
+    }
+    public void setCreatedDate(Date createdDate) {
+        createDate = createdDate;
+    }
+    @Override
+    public long getUserId() {
+        return userId;
+    }
+    public void setUserId(long userId) {
+        this.userId = userId;
+    }
+    @Override
+    public long getAccountId() {
+        return accountId;
+    }
+    public void setAccountId(long accountId) {
+        this.accountId = accountId;
+    }
+    @Override
+    public long getDomainId() {
+        return domainId;
+    }
+
+	public void setDomainId(long domainId) {
+		this.domainId = domainId;
+	}
+
+	@Override
+    public int getTotalSize() {
+		return totalSize;
+	}
+	public void setTotalSize(int totalSize) {
+		this.totalSize = totalSize;
+	}
+	@Override
+    public String getLevel() {
+		return level;
+	}
+	public void setLevel(String level) {
+		this.level = level;
+	}
+	@Override
+    public long getStartId() {
+        return startId;
+    }
+
+    public void setStartId(long startId) {
+        this.startId = startId;
+    }
+
+    @Override
+    public String getParameters() {
+        return parameters;
+    }
+    public void setParameters(String parameters) {
+        this.parameters = parameters;
+    }
+
+    @Override
+    public String getUuid() {
+        return this.uuid;
+    }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
+
+    @Override
+    public boolean getArchived() {
+        return archived;
+    }
+
+    public void setArchived(Boolean archived) {
+        this.archived = archived;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/event/UsageEventVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/UsageEventVO.java b/engine/schema/src/com/cloud/event/UsageEventVO.java
new file mode 100644
index 0000000..c92972b
--- /dev/null
+++ b/engine/schema/src/com/cloud/event/UsageEventVO.java
@@ -0,0 +1,216 @@
+// 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.event;
+
+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="usage_event")
+public class UsageEventVO implements UsageEvent {
+	@Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+	private long id = -1;
+
+	@Column(name="type")
+	private String type;
+	
+	@Column(name=GenericDao.CREATED_COLUMN)
+	private Date createDate;
+
+	@Column(name="account_id")
+	private long accountId;
+
+    @Column(name="zone_id")
+	private long zoneId;
+
+    @Column(name="resource_id")
+    private long resourceId;
+
+    @Column(name="resource_name")
+    private String resourceName;
+    
+    @Column(name="offering_id")
+    private Long offeringId;
+    
+    @Column(name="template_id")
+    private Long templateId;
+
+    @Column(name="size")
+    private Long size;
+    
+    @Column(name="resource_type")
+    private String resourceType;
+    
+    @Column(name="processed")
+    boolean processed;
+
+    
+	public UsageEventVO() {
+	}
+	
+	public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, Long size) {
+	    this.type = usageType;
+	    this.accountId = accountId;
+	    this.zoneId = zoneId;
+	    this.resourceId = resourceId;
+	    this.resourceName = resourceName;
+	    this.offeringId = offeringId;
+	    this.templateId = templateId;
+	    this.size = size;
+	}
+	
+    public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName) {
+        this.type = usageType;
+        this.accountId = accountId;
+        this.zoneId = zoneId;
+        this.resourceId = resourceId;
+        this.resourceName = resourceName;
+    }
+	
+    //IPAddress usage event
+	public UsageEventVO(String usageType, long accountId, long zoneId, long ipAddressId, String ipAddress, boolean isSourceNat, String guestType, boolean isSystem) {
+	    this.type = usageType;
+        this.accountId = accountId;
+        this.zoneId = zoneId;
+        this.resourceId = ipAddressId;
+        this.resourceName = ipAddress;
+        this.size = (isSourceNat ? 1L : 0L);
+        this.resourceType = guestType;
+        this.templateId = (isSystem ? 1L : 0L);
+    }
+	
+	public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, String resourceType) {
+	    this.type = usageType;
+	    this.accountId = accountId;
+	    this.zoneId = zoneId;
+	    this.resourceId = resourceId;
+	    this.resourceName = resourceName;
+	    this.offeringId = offeringId;
+	    this.templateId = templateId;
+	    this.resourceType = resourceType;
+	}
+	
+	//Security Group usage event
+	public UsageEventVO(String usageType, long accountId,
+			long zoneId, long vmId, long securityGroupId) {
+	    this.type = usageType;
+	    this.accountId = accountId;
+	    this.zoneId = zoneId;
+	    this.resourceId = vmId;
+	    this.offeringId = securityGroupId;
+	}
+
+	@Override
+    public long getId() {
+		return id;
+	}
+	@Override
+    public String getType() {
+		return type;
+	}
+	public void setType(String type) {
+		this.type = type;
+	}
+
+	@Override
+    public Date getCreateDate() {
+		return createDate;
+	}
+	public void setCreatedDate(Date createdDate) {
+	    createDate = createdDate;
+	}
+	
+    @Override
+    public long getAccountId() {
+        return accountId;
+    }
+    public void setAccountId(long accountId) {
+        this.accountId = accountId;
+    }
+
+    public void setZoneId(long zoneId) {
+        this.zoneId = zoneId;
+    }
+    @Override
+    public long getZoneId() {
+        return zoneId;
+    }
+
+    public void setResourceId(long resourceId) {
+        this.resourceId = resourceId;
+    }
+    @Override
+    public long getResourceId() {
+        return resourceId;
+    }
+    
+    public void setResourceName(String resourceName) {
+        this.resourceName = resourceName;
+    }
+
+    public String getResourceName() {
+        return resourceName;
+    }
+
+    public void setOfferingId(long offeringId) {
+        this.offeringId = offeringId;
+    }
+    @Override
+    public Long getOfferingId() {
+        return offeringId;
+    }
+
+    public void setTemplateId(long templateId) {
+        this.templateId = templateId;
+    }
+    @Override
+    public Long getTemplateId() {
+        return templateId;
+    }
+
+    public void setSize(long size) {
+        this.size = size;
+    }
+    @Override
+    public Long getSize() {
+        return size;
+    }
+
+    public boolean isProcessed() {
+        return processed;
+    }
+
+    public void setProcessed(boolean processed) {
+        this.processed = processed;
+    }
+    
+    public String getResourceType() {
+        return resourceType;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/event/dao/EventDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/dao/EventDao.java b/engine/schema/src/com/cloud/event/dao/EventDao.java
new file mode 100644
index 0000000..da5f47a
--- /dev/null
+++ b/engine/schema/src/com/cloud/event/dao/EventDao.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.event.dao;
+
+import java.util.Date;
+import java.util.List;
+
+import com.cloud.event.EventVO;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.db.SearchCriteria;
+
+public interface EventDao extends GenericDao<EventVO, Long> {
+    public List<EventVO> searchAllEvents(SearchCriteria<EventVO> sc, Filter filter);
+
+    public List<EventVO> listOlderEvents(Date oldTime);
+
+    EventVO findCompletedEvent(long startId);
+
+    public List<EventVO> listToArchiveOrDeleteEvents(List<Long> ids, String type, Date olderThan, Long accountId);
+
+    public void archiveEvents(List<EventVO> events);
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/event/dao/EventDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/dao/EventDaoImpl.java b/engine/schema/src/com/cloud/event/dao/EventDaoImpl.java
new file mode 100644
index 0000000..6ba59c5
--- /dev/null
+++ b/engine/schema/src/com/cloud/event/dao/EventDaoImpl.java
@@ -0,0 +1,109 @@
+// 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.event.dao;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.event.Event.State;
+import com.cloud.event.EventVO;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+@Local(value={EventDao.class})
+public class EventDaoImpl extends GenericDaoBase<EventVO, Long> implements EventDao {
+    public static final Logger s_logger = Logger.getLogger(EventDaoImpl.class.getName());
+    protected final SearchBuilder<EventVO> CompletedEventSearch;
+    protected final SearchBuilder<EventVO> ToArchiveOrDeleteEventSearch;
+
+    public EventDaoImpl () {
+        CompletedEventSearch = createSearchBuilder();
+        CompletedEventSearch.and("state",CompletedEventSearch.entity().getState(),SearchCriteria.Op.EQ);
+        CompletedEventSearch.and("startId", CompletedEventSearch.entity().getStartId(), SearchCriteria.Op.EQ);
+        CompletedEventSearch.done();
+
+        ToArchiveOrDeleteEventSearch = createSearchBuilder();
+        ToArchiveOrDeleteEventSearch.and("id", ToArchiveOrDeleteEventSearch.entity().getId(), Op.IN);
+        ToArchiveOrDeleteEventSearch.and("type", ToArchiveOrDeleteEventSearch.entity().getType(), Op.EQ);
+        ToArchiveOrDeleteEventSearch.and("accountId", ToArchiveOrDeleteEventSearch.entity().getAccountId(), Op.EQ);
+        ToArchiveOrDeleteEventSearch.and("createDateL", ToArchiveOrDeleteEventSearch.entity().getCreateDate(), Op.LT);
+        ToArchiveOrDeleteEventSearch.done();
+    }
+
+    @Override
+    public List<EventVO> searchAllEvents(SearchCriteria<EventVO> sc, Filter filter) {
+        return listIncludingRemovedBy(sc, filter);
+    }
+
+    @Override
+    public List<EventVO> listOlderEvents(Date oldTime) {
+        if (oldTime == null) return null;
+        SearchCriteria<EventVO> sc = createSearchCriteria();
+        sc.addAnd("createDate", SearchCriteria.Op.LT, oldTime);
+        return listIncludingRemovedBy(sc, null);
+    }
+
+    @Override
+    public EventVO findCompletedEvent(long startId) {
+        SearchCriteria<EventVO> sc = CompletedEventSearch.create();
+        sc.setParameters("state", State.Completed);
+        sc.setParameters("startId", startId);
+        return findOneIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<EventVO> listToArchiveOrDeleteEvents(List<Long> ids, String type, Date olderThan, Long accountId) {
+        SearchCriteria<EventVO> sc = ToArchiveOrDeleteEventSearch.create();
+        if (ids != null) {
+            sc.setParameters("id", ids.toArray(new Object[ids.size()]));
+        }
+        if (type != null) {
+            sc.setParameters("type", type);
+        }
+        if (olderThan != null) {
+            sc.setParameters("createDateL", olderThan);
+        }
+        if (accountId != null) {
+            sc.setParameters("accountId", accountId);
+        }
+        return search(sc, null);
+    }
+
+    @Override
+    public void archiveEvents(List<EventVO> events) {
+
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        for (EventVO event : events) {
+            event = lockRow(event.getId(), true);
+            event.setArchived(true);
+            update(event.getId(), event);
+            txn.commit();
+        }
+        txn.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/event/dao/UsageEventDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/dao/UsageEventDao.java b/engine/schema/src/com/cloud/event/dao/UsageEventDao.java
new file mode 100644
index 0000000..01979e1
--- /dev/null
+++ b/engine/schema/src/com/cloud/event/dao/UsageEventDao.java
@@ -0,0 +1,35 @@
+// 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.event.dao;
+
+import java.util.Date;
+import java.util.List;
+
+import com.cloud.event.UsageEventVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface UsageEventDao extends GenericDao<UsageEventVO, Long> {
+
+    public List<UsageEventVO> listLatestEvents(Date endDate);
+
+    public List<UsageEventVO> getLatestEvent();
+
+    List<UsageEventVO> getRecentEvents(Date endDate);
+
+    List<UsageEventVO> listDirectIpEvents(Date startDate, Date endDate, long zoneId);
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java b/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
new file mode 100644
index 0000000..004ab7c
--- /dev/null
+++ b/engine/schema/src/com/cloud/event/dao/UsageEventDaoImpl.java
@@ -0,0 +1,187 @@
+// 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.event.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.dc.Vlan;
+import com.cloud.event.EventTypes;
+import com.cloud.event.UsageEventVO;
+import com.cloud.utils.DateUtil;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Component
+@Local(value={UsageEventDao.class})
+public class UsageEventDaoImpl extends GenericDaoBase<UsageEventVO, Long> implements UsageEventDao {
+    public static final Logger s_logger = Logger.getLogger(UsageEventDaoImpl.class.getName());
+
+    private final SearchBuilder<UsageEventVO> latestEventsSearch;
+    private final SearchBuilder<UsageEventVO> IpeventsSearch;
+    private static final String COPY_EVENTS = "INSERT INTO cloud_usage.usage_event (id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type) " +
+    		"SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type FROM cloud.usage_event vmevt WHERE vmevt.id > ? and vmevt.id <= ? ";
+    private static final String COPY_ALL_EVENTS = "INSERT INTO cloud_usage.usage_event (id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type) " +
+    		"SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type FROM cloud.usage_event vmevt WHERE vmevt.id <= ?";
+    private static final String MAX_EVENT = "select max(id) from cloud.usage_event where created <= ?";
+
+
+    public UsageEventDaoImpl () {
+        latestEventsSearch = createSearchBuilder();
+        latestEventsSearch.and("processed", latestEventsSearch.entity().isProcessed(), SearchCriteria.Op.EQ);
+        latestEventsSearch.and("enddate", latestEventsSearch.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
+        latestEventsSearch.done();
+
+        IpeventsSearch = createSearchBuilder();
+        IpeventsSearch.and("startdate", IpeventsSearch.entity().getCreateDate(), SearchCriteria.Op.GTEQ);
+        IpeventsSearch.and("enddate", IpeventsSearch.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
+        IpeventsSearch.and("zoneid", IpeventsSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
+        IpeventsSearch.and("networktype", IpeventsSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+        IpeventsSearch.and().op("assignEvent", IpeventsSearch.entity().getType(), SearchCriteria.Op.EQ);
+        IpeventsSearch.or("releaseEvent", IpeventsSearch.entity().getType(), SearchCriteria.Op.EQ);
+        IpeventsSearch.closeParen();
+        IpeventsSearch.done();
+    }
+
+    @Override
+    public List<UsageEventVO> listLatestEvents(Date endDate) {
+        Filter filter = new Filter(UsageEventVO.class, "createDate", Boolean.TRUE, null, null);
+        SearchCriteria<UsageEventVO> sc = latestEventsSearch.create();
+        sc.setParameters("processed", false);
+        sc.setParameters("enddate", endDate);
+        return listBy(sc, filter);
+    }
+
+    @Override
+    public List<UsageEventVO> getLatestEvent() {
+        Filter filter = new Filter(UsageEventVO.class, "id", Boolean.FALSE, Long.valueOf(0), Long.valueOf(1));
+        return listAll(filter);
+    }
+
+    @Override
+    @DB
+    public synchronized List<UsageEventVO> getRecentEvents(Date endDate) {
+        long recentEventId = getMostRecentEventId();
+        long maxEventId = getMaxEventId(endDate);
+        Transaction txn = Transaction.open(Transaction.USAGE_DB);
+        String sql = COPY_EVENTS;
+        if (recentEventId == 0) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("no recent event date, copying all events");
+            }
+            sql = COPY_ALL_EVENTS;
+        }
+
+        PreparedStatement pstmt = null;
+        try {
+            txn.start();
+            pstmt = txn.prepareAutoCloseStatement(sql);
+            int i = 1;
+            if (recentEventId != 0) {
+                pstmt.setLong(i++, recentEventId);
+            }
+            pstmt.setLong(i++, maxEventId);
+            pstmt.executeUpdate();
+            txn.commit();
+            return findRecentEvents(endDate);
+        } catch (Exception ex) {
+            txn.rollback();
+            s_logger.error("error copying events from cloud db to usage db", ex);
+            throw new CloudRuntimeException(ex.getMessage());
+        }
+    }
+
+    @DB
+    private long getMostRecentEventId() {
+        Transaction txn = Transaction.open(Transaction.USAGE_DB);
+        try {
+            List<UsageEventVO> latestEvents = getLatestEvent();
+
+            if(latestEvents !=null && latestEvents.size() == 1){
+                UsageEventVO latestEvent = latestEvents.get(0);
+                if(latestEvent != null){
+                    return latestEvent.getId();
+                }
+            }
+            return 0;
+        } catch (Exception ex) {
+            s_logger.error("error getting most recent event id", ex);
+            throw new CloudRuntimeException(ex.getMessage());
+        } finally {
+            txn.close();
+        }
+    }
+
+    private List<UsageEventVO> findRecentEvents(Date endDate) {
+        Transaction txn = Transaction.open(Transaction.USAGE_DB);
+        try {
+            return listLatestEvents(endDate);
+        } catch (Exception ex) {
+            s_logger.error("error getting most recent event date", ex);
+            throw new CloudRuntimeException(ex.getMessage());
+        } finally {
+            txn.close();
+        }
+    }
+
+    private long getMaxEventId(Date endDate) {
+        Transaction txn = Transaction.currentTxn();
+        PreparedStatement pstmt = null;
+        try {
+            String sql = MAX_EVENT;
+            pstmt = txn.prepareAutoCloseStatement(sql);
+            pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate));
+            ResultSet rs = pstmt.executeQuery();
+            if (rs.next()) {
+                return Long.valueOf(rs.getLong(1));
+            }
+            return 0;
+        } catch (Exception ex) {
+            s_logger.error("error getting max event id", ex);
+            throw new CloudRuntimeException(ex.getMessage());
+        } finally {
+            txn.close();
+        }
+    }
+
+    @Override
+    public List<UsageEventVO> listDirectIpEvents(Date startDate, Date endDate, long zoneId) {
+        Filter filter = new Filter(UsageEventVO.class, "createDate", Boolean.TRUE, null, null);
+        SearchCriteria<UsageEventVO> sc = IpeventsSearch.create();
+        sc.setParameters("startdate", startDate);
+        sc.setParameters("enddate", endDate);
+        sc.setParameters("assignEvent", EventTypes.EVENT_NET_IP_ASSIGN);
+        sc.setParameters("releaseEvent", EventTypes.EVENT_NET_IP_RELEASE);
+        sc.setParameters("zoneid", zoneId);
+        sc.setParameters("networktype", Vlan.VlanType.DirectAttached.toString());
+        return listBy(sc, filter);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/host/DetailVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/DetailVO.java b/engine/schema/src/com/cloud/host/DetailVO.java
new file mode 100644
index 0000000..4e62490
--- /dev/null
+++ b/engine/schema/src/com/cloud/host/DetailVO.java
@@ -0,0 +1,73 @@
+// 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;
+
+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="host_details")
+public class DetailVO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private long id;
+    
+    @Column(name="host_id")
+    private long hostId;
+    
+    @Column(name="name")
+    private String name;
+    
+    @Column(name="value")
+    private String value;
+    
+    protected DetailVO() {
+    }
+    
+    public DetailVO(long hostId, String name, String value) {
+        this.hostId = hostId;
+        this.name = name;
+        this.value = value;
+    }
+
+    public long getHostId() {
+        return hostId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public long getId() {
+        return id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/host/HostTagVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/HostTagVO.java b/engine/schema/src/com/cloud/host/HostTagVO.java
new file mode 100644
index 0000000..b1f5ace
--- /dev/null
+++ b/engine/schema/src/com/cloud/host/HostTagVO.java
@@ -0,0 +1,65 @@
+// 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;
+
+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="host_tags")
+public class HostTagVO implements InternalIdentity {
+	@Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private long id;
+    
+    @Column(name="host_id")
+    private long hostId;
+    
+    @Column(name="tag")
+    private String tag;
+    
+    protected HostTagVO() {
+    }
+    
+    public HostTagVO(long hostId, String tag) {
+        this.hostId = hostId;
+        this.tag = tag;
+    }
+
+    public long getHostId() {
+        return hostId;
+    }
+
+    public String getTag() {
+        return tag;
+    }
+
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
+
+    public long getId() {
+        return id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/host/HostVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/HostVO.java b/engine/schema/src/com/cloud/host/HostVO.java
new file mode 100755
index 0000000..c814b94
--- /dev/null
+++ b/engine/schema/src/com/cloud/host/HostVO.java
@@ -0,0 +1,732 @@
+// 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;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
+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.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+import org.apache.cloudstack.api.Identity;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.resource.ResourceState;
+import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="host")
+@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
+@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING, length=32)
+public class HostVO implements Host {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private long id;
+
+    @Column(name="disconnected")
+    @Temporal(value=TemporalType.TIMESTAMP)
+    private Date disconnectedOn;
+
+    @Column(name="name", nullable=false)
+    private String name = null;
+
+    /**
+     * Note: There is no setter for status because it has to be set in the dao code.
+     */
+    @Column(name="status", nullable=false)
+    private Status status = null;
+
+    @Column(name="type", updatable = true, nullable=false)
+    @Enumerated(value=EnumType.STRING)
+    private Type type;
+
+    @Column(name="private_ip_address", nullable=false)
+    private String privateIpAddress;
+
+    @Column(name="private_mac_address", nullable=false)
+    private String privateMacAddress;
+
+    @Column(name="private_netmask", nullable=false)
+    private String privateNetmask;
+
+    @Column(name="public_netmask")
+    private String publicNetmask;
+
+    @Column(name="public_ip_address")
+    private String publicIpAddress;
+
+    @Column(name="public_mac_address")
+    private String publicMacAddress;
+
+    @Column(name="storage_ip_address")
+    private String storageIpAddress;
+
+    @Column(name="cluster_id")
+    private Long clusterId;
+
+    @Column(name="storage_netmask")
+    private String storageNetmask;
+
+    @Column(name="storage_mac_address")
+    private String storageMacAddress;
+
+    @Column(name="storage_ip_address_2")
+    private String storageIpAddressDeux;
+
+    @Column(name="storage_netmask_2")
+    private String storageNetmaskDeux;
+
+    @Column(name="storage_mac_address_2")
+    private String storageMacAddressDeux;
+
+    @Column(name="hypervisor_type", updatable = true, nullable=false)
+    @Enumerated(value=EnumType.STRING)
+    private HypervisorType hypervisorType;
+
+    @Column(name="proxy_port")
+    private Integer proxyPort;
+
+    @Column(name="resource")
+    private String resource;
+
+    @Column(name="fs_type")
+    private StoragePoolType fsType;
+
+    @Column(name="available")
+    private boolean available = true;
+
+    @Column(name="setup")
+    private boolean setup = false;
+
+    @Column(name="resource_state", nullable=false)
+    @Enumerated(value=EnumType.STRING)
+    private ResourceState resourceState;
+
+    @Column(name="hypervisor_version")
+    private String hypervisorVersion;
+
+    @Column(name="update_count", updatable = true, nullable=false)
+    protected long updated;	// This field should be updated everytime the state is updated.  There's no set method in the vo object because it is done with in the dao code.
+
+    @Column(name="uuid")
+    private String uuid;
+
+    // This is a delayed load value.  If the value is null,
+    // then this field has not been loaded yet.
+    // Call host dao to load it.
+    @Transient
+    Map<String, String> details;
+
+    // This is a delayed load value.  If the value is null,
+    // then this field has not been loaded yet.
+    // Call host dao to load it.
+    @Transient
+    List<String> hostTags;
+
+    @Override
+    public String getStorageIpAddressDeux() {
+        return storageIpAddressDeux;
+    }
+
+    public void setStorageIpAddressDeux(String deuxStorageIpAddress) {
+        this.storageIpAddressDeux = deuxStorageIpAddress;
+    }
+
+    @Override
+    public String getStorageNetmaskDeux() {
+        return storageNetmaskDeux;
+    }
+
+    @Override
+    public Long getClusterId() {
+        return clusterId;
+    }
+
+    public void setClusterId(Long clusterId) {
+        this.clusterId = clusterId;
+    }
+
+    public void setStorageNetmaskDeux(String deuxStorageNetmask) {
+        this.storageNetmaskDeux = deuxStorageNetmask;
+    }
+
+    @Override
+    public String getStorageMacAddressDeux() {
+        return storageMacAddressDeux;
+    }
+
+    public void setStorageMacAddressDeux(String duexStorageMacAddress) {
+        this.storageMacAddressDeux = duexStorageMacAddress;
+    }
+
+    @Override
+    public String getPrivateMacAddress() {
+        return privateMacAddress;
+    }
+
+    public void setPrivateMacAddress(String privateMacAddress) {
+        this.privateMacAddress = privateMacAddress;
+    }
+
+    public boolean isAvailable() {
+        return available;
+    }
+
+    public void setAvailable(boolean available) {
+        this.available = available;
+    }
+
+    @Override
+    public String getPrivateNetmask() {
+        return privateNetmask;
+    }
+
+    public void setPrivateNetmask(String privateNetmask) {
+        this.privateNetmask = privateNetmask;
+    }
+
+    @Override
+    public String getPublicNetmask() {
+        return publicNetmask;
+    }
+
+    public void setPublicNetmask(String publicNetmask) {
+        this.publicNetmask = publicNetmask;
+    }
+
+    @Override
+    public String getPublicIpAddress() {
+        return publicIpAddress;
+    }
+
+    public void setPublicIpAddress(String publicIpAddress) {
+        this.publicIpAddress = publicIpAddress;
+    }
+
+    @Override
+    public String getPublicMacAddress() {
+        return publicMacAddress;
+    }
+
+    public void setPublicMacAddress(String publicMacAddress) {
+        this.publicMacAddress = publicMacAddress;
+    }
+
+    @Override
+    public String getStorageIpAddress() {
+        return storageIpAddress;
+    }
+
+    public void setStorageIpAddress(String storageIpAddress) {
+        this.storageIpAddress = storageIpAddress;
+    }
+
+    @Override
+    public String getStorageNetmask() {
+        return storageNetmask;
+    }
+
+    public void setStorageNetmask(String storageNetmask) {
+        this.storageNetmask = storageNetmask;
+    }
+
+    @Override
+    public String getStorageMacAddress() {
+        return storageMacAddress;
+    }
+
+    public boolean isSetup() {
+        return setup;
+    }
+
+    public void setSetup(boolean setup) {
+        this.setup = setup;
+    }
+
+    public void setStorageMacAddress(String storageMacAddress) {
+        this.storageMacAddress = storageMacAddress;
+    }
+
+    public String getResource() {
+        return resource;
+    }
+
+    public void setResource(String resource) {
+        this.resource = resource;
+    }
+
+    public Map<String, String> getDetails() {
+        return details;
+    }
+
+    public String getDetail(String name) {
+        assert (details != null) : "Did you forget to load the details?";
+
+        return details != null ? details.get(name) : null;
+    }
+
+    public void setDetail(String name, String value) {
+        assert (details != null) : "Did you forget to load the details?";
+
+        details.put(name, value);
+    }
+
+    public void setDetails(Map<String, String> details) {
+        this.details = details;
+    }
+
+    public List<String> getHostTags() {
+        return hostTags;
+    }
+
+    public void setHostTags(List<String> hostTags) {
+        this.hostTags = hostTags;
+    }
+
+    @Column(name="data_center_id", nullable=false)
+    private long dataCenterId;
+
+    @Column(name="pod_id")
+    private Long podId;
+
+    @Column(name="cpus")
+    private Integer cpus;
+
+    @Column(name="url")
+    private String storageUrl;
+
+    @Column(name="speed")
+    private Long speed;
+
+    @Column(name="ram")
+    private long totalMemory;
+
+    @Column(name="parent", nullable=false)
+    private String parent;
+
+    @Column(name="guid", updatable=true, nullable=false)
+    private String guid;
+
+    @Column(name="capabilities")
+    private String caps;
+
+    @Column(name="total_size")
+    private Long totalSize;
+
+    @Column(name="last_ping")
+    private long lastPinged;
+
+    @Column(name="mgmt_server_id")
+    private Long managementServerId;
+
+    @Column(name="dom0_memory")
+    private long dom0MinMemory;
+
+    @Column(name="version")
+    private String version;
+
+    @Column(name=GenericDao.CREATED_COLUMN)
+    private Date created;
+
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    private Date removed;
+
+    public HostVO(String guid) {
+        this.guid = guid;
+        this.status = Status.Creating;
+        this.totalMemory = 0;
+        this.dom0MinMemory = 0;
+        this.resourceState = ResourceState.Creating;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    protected HostVO() {
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public HostVO(long id,
+            String name,
+            Type type,
+            String privateIpAddress,
+            String privateNetmask,
+            String privateMacAddress,
+            String publicIpAddress,
+            String publicNetmask,
+            String publicMacAddress,
+            String storageIpAddress,
+            String storageNetmask,
+            String storageMacAddress,
+            String deuxStorageIpAddress,
+            String duxStorageNetmask,
+            String deuxStorageMacAddress,
+            String guid,
+            Status status,
+            String version,
+            String iqn,
+            Date disconnectedOn,
+            long dcId,
+            Long podId,
+            long serverId,
+            long ping,
+            String parent,
+            long totalSize,
+            StoragePoolType fsType) {
+        this(id, name, type, privateIpAddress, privateNetmask, privateMacAddress, publicIpAddress, publicNetmask, publicMacAddress, storageIpAddress, storageNetmask, storageMacAddress, guid, status, version, iqn, disconnectedOn, dcId, podId, serverId, ping, null, null, null, 0, null);
+        this.parent = parent;
+        this.totalSize = totalSize;
+        this.fsType = fsType;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public HostVO(long id,
+            String name,
+            Type type,
+            String privateIpAddress,
+            String privateNetmask,
+            String privateMacAddress,
+            String publicIpAddress,
+            String publicNetmask,
+            String publicMacAddress,
+            String storageIpAddress,
+            String storageNetmask,
+            String storageMacAddress,
+            String guid,
+            Status status,
+            String version,
+            String url,
+            Date disconnectedOn,
+            long dcId,
+            Long podId,
+            long serverId,
+            long ping,
+            Integer cpus,
+            Long speed,
+            Long totalMemory,
+            long dom0MinMemory,
+            String caps) {
+        this.id = id;
+        this.name = name;
+        this.status = status;
+        this.type = type;
+        this.privateIpAddress = privateIpAddress;
+        this.privateNetmask = privateNetmask;
+        this.privateMacAddress = privateMacAddress;
+        this.publicIpAddress = publicIpAddress;
+        this.publicNetmask = publicNetmask;
+        this.publicMacAddress = publicMacAddress;
+        this.storageIpAddress = storageIpAddress;
+        this.storageNetmask = storageNetmask;
+        this.storageMacAddress = storageMacAddress;
+        this.dataCenterId = dcId;
+        this.podId = podId;
+        this.cpus = cpus;
+        this.version = version;
+        this.speed = speed;
+        this.totalMemory = totalMemory != null ? totalMemory : 0;
+        this.guid = guid;
+        this.parent = null;
+        this.totalSize = null;
+        this.fsType = null;
+        this.managementServerId = serverId;
+        this.lastPinged = ping;
+        this.caps = caps;
+        this.disconnectedOn = disconnectedOn;
+        this.dom0MinMemory = dom0MinMemory;
+        this.storageUrl = url;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public void setPodId(Long podId) {
+
+        this.podId = podId;
+    }
+
+    public void setDataCenterId(long dcId) {
+        this.dataCenterId = dcId;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public void setStorageUrl(String url) {
+        this.storageUrl = url;
+    }
+
+    public void setDisconnectedOn(Date disconnectedOn) {
+        this.disconnectedOn = disconnectedOn;
+    }
+
+    public String getStorageUrl() {
+        return storageUrl;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setPrivateIpAddress(String ipAddress) {
+        this.privateIpAddress = ipAddress;
+    }
+
+    public void setCpus(Integer cpus) {
+        this.cpus = cpus;
+    }
+
+    public void setSpeed(Long speed) {
+        this.speed = speed;
+    }
+
+    public void setTotalMemory(long totalMemory) {
+        this.totalMemory = totalMemory;
+    }
+
+    public void setParent(String parent) {
+        this.parent = parent;
+    }
+
+    public void setCaps(String caps) {
+        this.caps = caps;
+    }
+
+    public void setTotalSize(Long totalSize) {
+        this.totalSize = totalSize;
+    }
+
+    public void setLastPinged(long lastPinged) {
+        this.lastPinged = lastPinged;
+    }
+
+    public void setManagementServerId(Long managementServerId) {
+        this.managementServerId = managementServerId;
+    }
+
+    @Override
+    public long getLastPinged() {
+        return lastPinged;
+    }
+
+    @Override
+    public String getParent() {
+        return parent;
+    }
+
+    @Override
+    public long getTotalSize() {
+        return totalSize;
+    }
+
+    @Override
+    public String getCapabilities() {
+        return caps;
+    }
+
+    @Override
+    public Date getCreated() {
+        return created;
+    }
+
+    @Override
+    public Date getRemoved() {
+        return removed;
+    }
+
+    @Override
+    public String getVersion() {
+        return version;
+    }
+
+    public void setType(Type type) {
+        this.type = type;
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public Status getStatus() {
+        return status;
+    }
+
+    @Override
+    public long getDataCenterId() {
+        return dataCenterId;
+    }
+
+    @Override
+    public Long getPodId() {
+        return podId;
+    }
+
+    @Override
+    public Long getManagementServerId() {
+        return managementServerId;
+    }
+
+    @Override
+    public Date getDisconnectedOn() {
+        return disconnectedOn;
+    }
+
+    @Override
+    public String getPrivateIpAddress() {
+        return privateIpAddress;
+    }
+
+    @Override
+    public String getGuid() {
+        return guid;
+    }
+
+    public void setGuid(String guid) {
+        this.guid = guid;
+    }
+
+    @Override
+    public Integer getCpus() {
+        return cpus;
+    }
+
+    @Override
+    public Long getSpeed() {
+        return speed;
+    }
+
+    @Override
+    public Long getTotalMemory() {
+        return totalMemory;
+    }
+
+    @Override
+    public Integer getProxyPort() {
+        return proxyPort;
+    }
+
+    public void setProxyPort(Integer port) {
+        proxyPort = port;
+    }
+
+    public StoragePoolType getFsType() {
+        return fsType;
+    }
+
+    @Override
+    public Type getType() {
+        return type;
+    }
+
+    @Override
+    public int hashCode() {
+        return NumbersUtil.hash(id);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof HostVO) {
+            return ((HostVO)obj).getId() == this.getId();
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public String toString() {
+        return new StringBuilder("Host[").append("-").append(id).append("-").append(type).append("]").toString();
+    }
+
+    public void setHypervisorType(HypervisorType hypervisorType) {
+        this.hypervisorType = hypervisorType;
+    }
+
+    @Override
+    public HypervisorType getHypervisorType() {
+        return hypervisorType;
+    }
+
+    public void setHypervisorVersion(String hypervisorVersion) {
+        this.hypervisorVersion = hypervisorVersion;
+    }
+
+    @Override
+    public String getHypervisorVersion() {
+        return hypervisorVersion;
+    }
+
+	@Override
+	@Transient
+	public Status getState() {
+		return status;
+	}
+
+    @Override
+    public ResourceState getResourceState() {
+        return resourceState;
+    }
+
+    public void setResourceState(ResourceState state) {
+    	resourceState = state;
+    }
+
+    @Override
+    public boolean isInMaintenanceStates() {
+        return (getResourceState() == ResourceState.Maintenance || getResourceState() == ResourceState.ErrorInMaintenance
+                || getResourceState() == ResourceState.PrepareForMaintenance);
+    }
+
+    public long getUpdated() {
+    	return updated;
+    }
+
+	public long incrUpdated() {
+		updated++;
+		return updated;
+	}
+
+	@Override
+	public String getUuid() {
+		return this.uuid;
+	}
+
+	public void setUuid(String uuid) {
+		this.uuid = uuid;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/host/dao/HostDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostDao.java b/engine/schema/src/com/cloud/host/dao/HostDao.java
new file mode 100755
index 0000000..98bdcb4
--- /dev/null
+++ b/engine/schema/src/com/cloud/host/dao/HostDao.java
@@ -0,0 +1,83 @@
+// 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.Date;
+import java.util.List;
+
+import com.cloud.host.Host;
+import com.cloud.host.Host.Type;
+import com.cloud.host.HostVO;
+import com.cloud.host.Status;
+import com.cloud.info.RunningHostCountInfo;
+import com.cloud.resource.ResourceState;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.fsm.StateDao;
+
+/**
+ * Data Access Object for server
+ *
+ */
+public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Status.Event, Host> {
+    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<HostVO> findLostHosts(long timeout);
+
+    List<HostVO> findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId);
+
+    List<RunningHostCountInfo> getRunningHostCounts(Date cutTime);
+
+    long getNextSequence(long hostId);
+
+    void loadDetails(HostVO host);
+
+    void saveDetails(HostVO host);
+
+    void loadHostTags(HostVO host);
+
+    List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag);
+
+    long countRoutingHostsByDataCenter(long dcId);
+
+	List<HostVO> findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId);
+
+    boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo);
+
+	HostVO findByGuid(String guid);
+	
+	HostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type);
+	List<HostVO> findHypervisorHostInCluster(long clusterId);
+
+
+    /**
+     * @param type
+     * @param clusterId
+     * @param podId
+     * @param dcId
+     * @param haTag TODO
+     * @return
+     */
+    List<HostVO> listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag);
+}


Mime
View raw message