cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [26/72] [abbrv] [partial] Moved most of the VOs and DAOs from server package into engine-schema as well
Date Tue, 07 May 2013 22:01:42 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
new file mode 100644
index 0000000..3a164c4
--- /dev/null
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -0,0 +1,489 @@
+// 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.upgrade.dao;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+
+public class Upgrade410to420 implements DbUpgrade {
+	final static Logger s_logger = Logger.getLogger(Upgrade410to420.class);
+
+	@Override
+	public String[] getUpgradableVersionRange() {
+		return new String[] { "4.1.0", "4.2.0" };
+	}
+
+	@Override
+	public String getUpgradedVersion() {
+		return "4.2.0";
+	}
+
+	@Override
+	public boolean supportsRollingUpgrade() {
+		return false;
+	}
+
+	@Override
+	public File[] getPrepareScripts() {
+		String script = Script.findScript("", "db/schema-410to420.sql");
+        if (script == null) {
+            throw new CloudRuntimeException("Unable to find db/schema-410to420.sql");
+        }
+
+        return new File[] { new File(script) };
+	}
+
+	@Override
+	public void performDataMigration(Connection conn) {
+        upgradeVmwareLabels(conn);
+        createPlaceHolderNics(conn);
+        updateRemoteAccessVpn(conn);
+        updateSystemVmTemplates(conn);
+        updateCluster_details(conn);
+        updatePrimaryStore(conn);
+        addEgressFwRulesForSRXGuestNw(conn);
+        upgradeEIPNetworkOfferings(conn);
+        upgradeDefaultVpcOffering(conn);
+        upgradePhysicalNtwksWithInternalLbProvider(conn);
+    }
+	
+	private void updateSystemVmTemplates(Connection conn) {
+	    PreparedStatement sql = null;
+        try {
+            sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
+            sql.executeUpdate();
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString());
+        } finally {
+            if (sql != null) {
+                try {
+                    sql.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+	}
+	
+	private void updatePrimaryStore(Connection conn) {
+	    PreparedStatement sql = null;
+	    PreparedStatement sql2 = null;
+        try {
+            sql = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type = 'Filesystem' or pool_type = 'LVM'");
+            sql.setString(1, "ancient primary data store provider");
+            sql.setString(2, "HOST");
+            sql.executeUpdate();
+            
+            sql2 = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type != 'Filesystem' and pool_type != 'LVM'");
+            sql2.setString(1, "ancient primary data store provider");
+            sql2.setString(2, "CLUSTER");
+            sql2.executeUpdate();
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Failed to upgrade vm template data store uuid: " + e.toString());
+        } finally {
+            if (sql != null) {
+                try {
+                    sql.close();
+                } catch (SQLException e) {
+                }
+            }
+            
+            if (sql2 != null) {
+                try {
+                    sql2.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+	}
+
+    //update the cluster_details table with default overcommit ratios.
+    private void updateCluster_details(Connection conn) {
+        PreparedStatement pstmt = null;
+        PreparedStatement pstmt1 = null;
+        PreparedStatement pstmt2 =null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("select id from `cloud`.`cluster`");
+            pstmt1=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value)  VALUES(?, 'cpuOvercommitRatio', '1')");
+            pstmt2=conn.prepareStatement("INSERT INTO `cloud`.`cluster_details` (cluster_id, name, value)  VALUES(?, 'memoryOvercommitRatio', '1')");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                long id = rs.getLong(1);
+                //update cluster_details table with the default overcommit ratios.
+                pstmt1.setLong(1,id);
+                pstmt1.execute();
+                pstmt2.setLong(1,id);
+                pstmt2.execute();
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to update cluster_details with default overcommit ratios.", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+
+	@Override
+	public File[] getCleanupScripts() {
+        String script = Script.findScript("", "db/schema-410to420-cleanup.sql");
+        if (script == null) {
+            throw new CloudRuntimeException("Unable to find db/schema-410to420-cleanup.sql");
+        }
+
+        return new File[] { new File(script) };
+    }
+
+    private String getNewLabel(ResultSet rs, String oldParamValue) {
+        int separatorIndex;
+        String oldGuestLabel;
+        String newGuestLabel = oldParamValue;
+        try {
+            // No need to iterate because the global param setting applies to all physical networks irrespective of traffic type
+            if (rs.next()) {
+                oldGuestLabel = rs.getString("vmware_network_label");
+                // guestLabel is in format [[<VSWITCHNAME>],VLANID]
+                separatorIndex = oldGuestLabel.indexOf(",");
+                if(separatorIndex > -1) {
+                    newGuestLabel += oldGuestLabel.substring(separatorIndex);
+                }
+            }
+        } catch (SQLException e) {
+            s_logger.error(new CloudRuntimeException("Failed to read vmware_network_label : " + e));
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+        return newGuestLabel;
+    }
+
+    private void upgradeVmwareLabels(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rsParams = null;
+        ResultSet rsLabel = null;
+        String newLabel;
+        String trafficType = null;
+        String trafficTypeVswitchParam;
+        String trafficTypeVswitchParamValue;
+
+        try {
+            // update the existing vmware traffic labels
+            pstmt = conn.prepareStatement("select name,value from `cloud`.`configuration` where category='Hidden' and value is not NULL and name REGEXP 'vmware\\.*\\.vswitch';");
+            rsParams = pstmt.executeQuery();
+            while (rsParams.next()) {
+                trafficTypeVswitchParam = rsParams.getString("name");
+                trafficTypeVswitchParamValue = rsParams.getString("value");
+                // When upgraded from 4.0 to 4.1 update physical network traffic label with trafficTypeVswitchParam
+                if (trafficTypeVswitchParam.equals("vmware.private.vswitch")) {
+                    trafficType = "Management"; //TODO(sateesh): Ignore storage traffic, as required physical network already implemented, anything else tobe done?
+                } else if (trafficTypeVswitchParam.equals("vmware.public.vswitch")) {
+                    trafficType = "Public";
+                } else if (trafficTypeVswitchParam.equals("vmware.guest.vswitch")) {
+                    trafficType = "Guest";
+                }
+                s_logger.debug("Updating vmware label for " + trafficType + " traffic. Update SQL statement is " + pstmt);
+                pstmt = conn.prepareStatement("select physical_network_id, traffic_type, vmware_network_label from physical_network_traffic_types where vmware_network_label is not NULL and traffic_type='" + trafficType + "';");
+                rsLabel = pstmt.executeQuery();
+                newLabel = getNewLabel(rsLabel, trafficTypeVswitchParamValue);
+                pstmt = conn.prepareStatement("update physical_network_traffic_types set vmware_network_label = " + newLabel + " where traffic_type = '" + trafficType + "' and vmware_network_label is not NULL;");
+                pstmt.executeUpdate();
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to set vmware traffic labels ", e);
+        } finally {
+            try {
+                if (rsParams != null) {
+                    rsParams.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+    
+    private void createPlaceHolderNics(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("SELECT network_id, gateway, ip4_address FROM `cloud`.`nics` WHERE reserver_name IN ('DirectNetworkGuru','DirectPodBasedNetworkGuru') and vm_type='DomainRouter' AND removed IS null");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                    Long networkId = rs.getLong(1);
+                    String gateway = rs.getString(2);
+                    String ip = rs.getString(3);
+                    String uuid = UUID.randomUUID().toString();
+                    //Insert placeholder nic for each Domain router nic in Shared network
+                    pstmt = conn.prepareStatement("INSERT INTO `cloud`.`nics` (uuid, ip4_address, gateway, network_id, state, strategy, vm_type) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder', 'DomainRouter')");
+                    pstmt.setString(1, uuid);
+                    pstmt.setString(2, ip);
+                    pstmt.setString(3, gateway);
+                    pstmt.setLong(4, networkId);
+                    pstmt.executeUpdate();
+                    s_logger.debug("Created placeholder nic for the ipAddress " + ip);
+                
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to create placeholder nics", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+    
+    
+    private void updateRemoteAccessVpn(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("SELECT vpn_server_addr_id FROM `cloud`.`remote_access_vpn`");
+            rs = pstmt.executeQuery();
+            long id=1;
+            while (rs.next()) {
+                    String uuid = UUID.randomUUID().toString();
+                    Long ipId = rs.getLong(1);
+                    pstmt = conn.prepareStatement("UPDATE `cloud`.`remote_access_vpn` set uuid=?, id=? where vpn_server_addr_id=?");
+                    pstmt.setString(1, uuid);
+                    pstmt.setLong(2, id);
+                    pstmt.setLong(3, ipId);
+                    pstmt.executeUpdate();
+                    id++;
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to update id/uuid of remote_access_vpn table", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+    private void addEgressFwRulesForSRXGuestNw(Connection conn) {
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+        ResultSet rsId = null;
+        ResultSet rsNw = null;
+        try {
+            pstmt = conn.prepareStatement("select network_id FROM `cloud`.`ntwk_service_map` where service='Firewall' and provider='JuniperSRX' ");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                long netId = rs.getLong(1);
+                //checking for Isolated OR Virtual
+                pstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR guest_type='Virtual') and traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR state='Shutdown') and id=? ");
+                pstmt.setLong(1, netId);
+                s_logger.debug("Getting account_id, domain_id from networks table: " + pstmt);
+                rsNw = pstmt.executeQuery();
+
+                if(rsNw.next()) {
+                    long accountId = rsNw.getLong(1);
+                    long domainId = rsNw.getLong(2);
+
+                    //Add new rule for the existing networks
+                    s_logger.debug("Adding default egress firewall rule for network " + netId);
+                    pstmt = conn.prepareStatement("INSERT INTO firewall_rules (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created,  traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), 'Egress')");
+                    pstmt.setString(1, UUID.randomUUID().toString());
+                    pstmt.setLong(2, accountId);
+                    pstmt.setLong(3, domainId);
+                    pstmt.setLong(4, netId);
+                    pstmt.setString(5, UUID.randomUUID().toString());
+                    s_logger.debug("Inserting default egress firewall rule " + pstmt);
+                    pstmt.executeUpdate();
+
+                    pstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?");
+                    pstmt.setLong(1, netId);
+                    rsId = pstmt.executeQuery();
+
+                    long firewallRuleId;
+                    if(rsId.next()) {
+                        firewallRuleId = rsId.getLong(1);
+                        pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')");
+                        pstmt.setLong(1, firewallRuleId);
+                        s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt);
+                        pstmt.executeUpdate();
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to set egress firewall rules ", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+    private void upgradeEIPNetworkOfferings(Connection conn) {
+
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("select id, elastic_ip_service from `cloud`.`network_offerings` where traffic_type='Guest'");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                long id = rs.getLong(1);
+                // check if elastic IP service is enabled for network offering
+                if (rs.getLong(2) != 0) {
+                    //update network offering with eip_associate_public_ip set to true
+                    pstmt = conn.prepareStatement("UPDATE `cloud`.`network_offerings` set eip_associate_public_ip=? where id=?");
+                    pstmt.setBoolean(1, true);
+                    pstmt.setLong(2, id);
+                    pstmt.executeUpdate();
+                }
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to set elastic_ip_service for network offerings with EIP service enabled.", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+    
+    
+    private void upgradeDefaultVpcOffering(Connection conn) {
+
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("select distinct map.vpc_offering_id from `cloud`.`vpc_offering_service_map` map, `cloud`.`vpc_offerings` off where off.id=map.vpc_offering_id AND service='Lb'");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                long id = rs.getLong(1);
+                //Add internal LB vm as a supported provider for the load balancer service
+                pstmt = conn.prepareStatement("INSERT INTO `cloud`.`vpc_offering_service_map` (vpc_offering_id, service, provider) VALUES (?,?,?)");
+                pstmt.setLong(1, id);
+                pstmt.setString(2, "Lb");
+                pstmt.setString(3, "InternalLbVm");
+                pstmt.executeUpdate();
+            }
+            
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable update the default VPC offering with the internal lb service", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+    
+    
+    private void upgradePhysicalNtwksWithInternalLbProvider(Connection conn) {
+
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+
+        try {
+            pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`physical_network` where removed is null");
+            rs = pstmt.executeQuery();
+            while (rs.next()) {
+                long pNtwkId = rs.getLong(1);
+                String uuid = UUID.randomUUID().toString();
+                //Add internal LB VM to the list of physical network service providers
+                pstmt = conn.prepareStatement("INSERT INTO `cloud`.`physical_network_service_providers` " +
+                		"(uuid, physical_network_id, provider_name, state, load_balance_service_provided, destination_physical_network_id)" +
+                		" VALUES (?, ?, 'InternalLbVm', 'Enabled', 1, 0)");
+                pstmt.setString(1, uuid);
+                pstmt.setLong(2, pNtwkId);
+                pstmt.executeUpdate();
+                
+                //Add internal lb vm to the list of physical network elements
+                PreparedStatement pstmt1 = conn.prepareStatement("SELECT id FROM `cloud`.`physical_network_service_providers`" +
+                		" WHERE physical_network_id=? AND provider_name='InternalLbVm'");
+                ResultSet rs1 = pstmt1.executeQuery();
+                while (rs1.next()) {
+                    long providerId = rs1.getLong(1);
+                    uuid = UUID.randomUUID().toString();
+                    pstmt1 = conn.prepareStatement("INSERT INTO `cloud`.`virtual_router_providers` (nsp_id, uuid, type, enabled) VALUES (?, ?, 'InternalLbVm', 1)");
+                    pstmt1.setLong(1, providerId);
+                    pstmt1.setString(2, uuid);
+                    pstmt1.executeUpdate();
+                }
+            }
+            
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable existing physical networks with internal lb provider", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+        
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java b/engine/schema/src/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java
new file mode 100644
index 0000000..8c9f30c
--- /dev/null
+++ b/engine/schema/src/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java
@@ -0,0 +1,60 @@
+// 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.upgrade.dao;
+
+import java.io.File;
+import java.sql.Connection;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+
+public class UpgradeSnapshot217to224 implements DbUpgrade {
+
+    @Override
+    public File[] getPrepareScripts() {
+        String file = Script.findScript("", "db/schema-snapshot-217to224.sql");
+        if (file == null) {
+            throw new CloudRuntimeException("Unable to find the upgrade script, schema-snapshot-217to224.sql");
+        }
+        
+        return new File[] { new File(file)};
+    }
+
+    @Override
+    public void performDataMigration(Connection conn) {        
+    }
+
+    @Override
+    public File[] getCleanupScripts() {
+        return null;
+    }
+
+    @Override
+    public String[] getUpgradableVersionRange() {
+        return new String[] { "2.1.7", "2.1.7" };
+    }
+
+    @Override
+    public String getUpgradedVersion() {
+        return "2.2.4";
+    }
+    
+    @Override
+    public boolean supportsRollingUpgrade() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java b/engine/schema/src/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java
new file mode 100644
index 0000000..97fcbfc
--- /dev/null
+++ b/engine/schema/src/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java
@@ -0,0 +1,60 @@
+// 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.upgrade.dao;
+
+import java.io.File;
+import java.sql.Connection;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+
+public class UpgradeSnapshot223to224 implements DbUpgrade {
+
+    @Override
+    public File[] getPrepareScripts() {
+        String file = Script.findScript("", "db/schema-snapshot-223to224.sql");
+        if (file == null) {
+            throw new CloudRuntimeException("Unable to find the upgrade script, schema-snapshot-223to224.sql");
+        }
+        
+        return new File[] { new File(file)};
+    }
+
+    @Override
+    public void performDataMigration(Connection conn) {        
+    }
+
+    @Override
+    public File[] getCleanupScripts() {
+        return null;
+    }
+
+    @Override
+    public String[] getUpgradableVersionRange() {
+        return new String[] { "2.2.3", "2.2.3" };
+    }
+
+    @Override
+    public String getUpgradedVersion() {
+        return "2.2.4";
+    }
+    
+    @Override
+    public boolean supportsRollingUpgrade() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/upgrade/dao/VersionDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/VersionDao.java b/engine/schema/src/com/cloud/upgrade/dao/VersionDao.java
new file mode 100644
index 0000000..e12f7d6
--- /dev/null
+++ b/engine/schema/src/com/cloud/upgrade/dao/VersionDao.java
@@ -0,0 +1,25 @@
+// 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.upgrade.dao;
+
+import com.cloud.upgrade.dao.VersionVO.Step;
+import com.cloud.utils.db.GenericDao;
+
+public interface VersionDao extends GenericDao<VersionVO, Long> {
+    VersionVO findByVersion(String version, Step step);
+    String getCurrentVersion();
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/upgrade/dao/VersionDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/VersionDaoImpl.java b/engine/schema/src/com/cloud/upgrade/dao/VersionDaoImpl.java
new file mode 100644
index 0000000..7c5c9cc
--- /dev/null
+++ b/engine/schema/src/com/cloud/upgrade/dao/VersionDaoImpl.java
@@ -0,0 +1,172 @@
+// 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.upgrade.dao;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.upgrade.dao.VersionVO.Step;
+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.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;
+
+@Component
+@Local(value = VersionDao.class)
+@DB(txn = false)
+public class VersionDaoImpl extends GenericDaoBase<VersionVO, Long> implements VersionDao {
+    private static final Logger s_logger = Logger.getLogger(VersionDaoImpl.class);
+
+    final GenericSearchBuilder<VersionVO, String> CurrentVersionSearch;
+    final SearchBuilder<VersionVO> AllFieldsSearch;
+
+    public VersionDaoImpl() {
+        super();
+
+        CurrentVersionSearch = createSearchBuilder(String.class);
+        CurrentVersionSearch.selectField(CurrentVersionSearch.entity().getVersion());
+        CurrentVersionSearch.and("step", CurrentVersionSearch.entity().getStep(), Op.EQ);
+        CurrentVersionSearch.done();
+
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("version", AllFieldsSearch.entity().getVersion(), Op.EQ);
+        AllFieldsSearch.and("step", AllFieldsSearch.entity().getStep(), Op.EQ);
+        AllFieldsSearch.and("updated", AllFieldsSearch.entity().getUpdated(), Op.EQ);
+        AllFieldsSearch.done();
+
+    }
+
+    @Override
+    public VersionVO findByVersion(String version, Step step) {
+        SearchCriteria<VersionVO> sc = AllFieldsSearch.create();
+        sc.setParameters("version", version);
+        sc.setParameters("step", step);
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    public String getCurrentVersion() {
+        Connection conn = null;
+        try {
+            s_logger.debug("Checking to see if the database is at a version before it was the version table is created");
+
+            conn = Transaction.getStandaloneConnection();
+
+            PreparedStatement pstmt = conn.prepareStatement("SHOW TABLES LIKE 'version'");
+            ResultSet rs = pstmt.executeQuery();
+            if (!rs.next()) {
+                rs.close();
+                pstmt.close();
+                pstmt = conn.prepareStatement("SHOW TABLES LIKE 'nics'");
+                rs = pstmt.executeQuery();
+                if (!rs.next()) {
+                    rs.close();
+                    pstmt.close();
+
+                    pstmt = conn.prepareStatement("SELECT domain_id FROM account_vlan_map LIMIT 1");
+                    try {
+                        pstmt.executeQuery();
+                        return "2.1.8";
+                    } catch (SQLException e) {
+                        s_logger.debug("Assuming the exception means domain_id is not there.");
+                        s_logger.debug("No version table and no nics table, returning 2.1.7");
+                        return "2.1.7";
+                    } finally {
+                        pstmt.close();
+                    }
+                } else {
+                    try {
+                        rs.close();
+                        pstmt.close();
+                        pstmt = conn.prepareStatement("SELECT is_static_nat from firewall_rules");
+                        pstmt.executeQuery();
+                        return "2.2.1";
+                    } catch (SQLException e) {
+                        s_logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2");
+                        return "2.2.2";
+                    } finally {
+                        rs.close();
+                        pstmt.close();
+                    }
+                }
+            }
+
+            SearchCriteria<String> sc = CurrentVersionSearch.create();
+
+            sc.setParameters("step", Step.Complete);
+            Filter filter = new Filter(VersionVO.class, "id", false, 0l, 1l);
+            List<String> upgradedVersions = customSearch(sc, filter);
+
+            if (upgradedVersions.isEmpty()) {
+
+                // Check if there are records in Version table
+                filter = new Filter(VersionVO.class, "id", false, 0l, 1l);
+                sc = CurrentVersionSearch.create();
+                List<String> vers = customSearch(sc, filter);
+                if (!vers.isEmpty()) {
+                    throw new CloudRuntimeException("Version table contains records for which upgrade wasn't completed");
+                }
+
+                // Use nics table information and is_static_nat field from firewall_rules table to determine version information
+                try {
+                    s_logger.debug("Version table exists, but it's empty; have to confirm that version is 2.2.2");
+                    pstmt = conn.prepareStatement("SHOW TABLES LIKE 'nics'");
+                    rs = pstmt.executeQuery();
+                    if (!rs.next()) {
+                        throw new CloudRuntimeException("Unable to determine the current version, version table exists and empty, nics table doesn't exist");
+                    } else {
+                        pstmt = conn.prepareStatement("SELECT is_static_nat from firewall_rules");
+                        pstmt.executeQuery();
+                        throw new CloudRuntimeException(
+                        "Unable to determine the current version, version table exists and empty, nics table doesn't exist, is_static_nat field exists in firewall_rules table");
+                    }
+                } catch (SQLException e) {
+                    s_logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2");
+                    return "2.2.2";
+                } finally {
+                    rs.close();
+                    pstmt.close();
+                }
+            } else {
+                return upgradedVersions.get(0);
+            }
+
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to get the current version", e);
+        } finally {
+            try {
+                conn.close();
+            } catch (SQLException e) {
+            }
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/upgrade/dao/VersionVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/VersionVO.java b/engine/schema/src/com/cloud/upgrade/dao/VersionVO.java
new file mode 100644
index 0000000..b5e3f35
--- /dev/null
+++ b/engine/schema/src/com/cloud/upgrade/dao/VersionVO.java
@@ -0,0 +1,91 @@
+// 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.upgrade.dao;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import java.util.Date;
+
+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.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="version")
+public class VersionVO implements InternalIdentity {
+    public enum Step {
+        Upgrade,
+        Complete
+    };
+    
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    long id;
+    
+    @Column(name="version")
+    String version;
+    
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name="updated")
+    Date updated;
+    
+    @Enumerated(value=EnumType.STRING)
+    @Column(name="step")
+    Step step;
+    
+    public VersionVO(String version) {
+        this.version = version; 
+        this.updated = new Date();
+        this.step = Step.Upgrade;
+    }
+    
+    protected VersionVO() {
+    }
+    
+    public long getId() {
+        return id;
+    }
+    
+    public String getVersion() {
+        return version;
+    }
+    
+    public Date getUpdated() {
+        return updated;
+    }
+    
+    public void setUpdated(Date updated) {
+        this.updated = updated;
+    }
+    
+    public Step getStep() {
+        return step;
+    }
+    
+    public void setStep(Step step) {
+        this.step = step;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/ExternalPublicIpStatisticsVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/ExternalPublicIpStatisticsVO.java b/engine/schema/src/com/cloud/usage/ExternalPublicIpStatisticsVO.java
new file mode 100644
index 0000000..7ad933c
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/ExternalPublicIpStatisticsVO.java
@@ -0,0 +1,98 @@
+// 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.usage;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="external_public_ip_statistics")
+@PrimaryKeyJoinColumn(name="id")
+public class ExternalPublicIpStatisticsVO implements InternalIdentity {
+
+	@Id
+	@GeneratedValue(strategy=GenerationType.IDENTITY)
+	@Column(name="id")
+	private Long id;
+	
+	@Column(name="data_center_id", updatable=false)
+	private long zoneId;
+	
+	@Column(name="account_id", updatable=false)
+	private long accountId;
+	
+	@Column(name="public_ip_address")
+	private String publicIpAddress;
+	
+	@Column(name="current_bytes_received")
+	private long currentBytesReceived;
+	
+	@Column(name="current_bytes_sent")
+	private long currentBytesSent;
+	
+	protected ExternalPublicIpStatisticsVO() {
+	}
+	
+	public ExternalPublicIpStatisticsVO(long zoneId, long accountId, String publicIpAddress) {
+		this.zoneId = zoneId;
+		this.accountId = accountId;
+		this.publicIpAddress = publicIpAddress;
+		this.currentBytesReceived = 0;
+		this.currentBytesSent = 0;
+	}
+	
+	public long getId() {
+        return id;
+    }
+	
+	public long getZoneId() {
+        return zoneId;
+    }
+	
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public String getPublicIpAddress() {
+		return publicIpAddress;
+	}
+
+    public long getCurrentBytesReceived() {
+		return currentBytesReceived;
+	}
+    
+    public void setCurrentBytesReceived(long currentBytesReceived) {
+		this.currentBytesReceived = currentBytesReceived;
+	}
+
+	public long getCurrentBytesSent() {
+		return currentBytesSent;
+	}	
+
+	public void setCurrentBytesSent(long currentBytesSent) {
+		this.currentBytesSent = currentBytesSent;
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageIPAddressVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageIPAddressVO.java b/engine/schema/src/com/cloud/usage/UsageIPAddressVO.java
new file mode 100644
index 0000000..a11dfe2
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageIPAddressVO.java
@@ -0,0 +1,121 @@
+// 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.usage;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="usage_ip_address")
+public class UsageIPAddressVO implements InternalIdentity {
+	@Column(name="account_id")
+    private long accountId;
+
+    @Column(name="domain_id")
+	private long domainId;
+
+    @Column(name="zone_id")
+    private long zoneId;
+
+    @Column(name="id")
+    private long id;
+    
+	@Column(name="public_ip_address")
+    private String address = null;
+	
+	@Column(name="is_source_nat")
+	private boolean isSourceNat = false;
+
+	@Column(name="is_system")
+	private boolean isSystem = false;
+	
+	@Column(name="assigned")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date assigned = null;
+
+	@Column(name="released")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date released = null;
+
+	protected UsageIPAddressVO() {
+	}
+
+	public UsageIPAddressVO(long id, long accountId, long domainId, long zoneId, String address, boolean isSourceNat, boolean isSystem, Date assigned, Date released) {
+	    this.id = id;
+		this.accountId = accountId;
+		this.domainId = domainId;
+		this.zoneId = zoneId;
+		this.address = address;
+		this.isSourceNat = isSourceNat;
+		this.isSystem = isSystem;
+		this.assigned = assigned;
+		this.released = released;
+	}
+	
+	public UsageIPAddressVO(long accountId, String address, Date assigned, Date released) {
+        this.accountId = accountId;
+        this.address = address;
+        this.assigned = assigned;
+        this.released = released;
+    }
+
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public long getDomainId() {
+	    return domainId;
+	}
+
+	public long getZoneId() {
+	    return zoneId;
+	}
+
+	public long getId() {
+	    return id;
+	}
+	
+	public String getAddress() {
+		return address;
+	}
+	
+	public boolean isSourceNat() {
+	    return isSourceNat;
+	}
+	
+	public boolean isSystem() {
+	    return isSystem;
+	}
+
+	public Date getAssigned() {
+		return assigned;
+	}
+
+	public Date getReleased() {
+		return released;
+	}
+	public void setReleased(Date released) {
+	    this.released = released;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageJobVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageJobVO.java b/engine/schema/src/com/cloud/usage/UsageJobVO.java
new file mode 100644
index 0000000..7761e87
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageJobVO.java
@@ -0,0 +1,180 @@
+// 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.usage;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+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 javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="usage_job")
+public class UsageJobVO implements InternalIdentity {
+
+    public static final int JOB_TYPE_RECURRING = 0;
+    public static final int JOB_TYPE_SINGLE = 1;
+
+    public static final int JOB_NOT_SCHEDULED = 0;
+    public static final int JOB_SCHEDULED = 1;
+
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private Long id;
+
+    @Column(name="host")
+    private String host;
+
+    @Column(name="pid")
+    private Integer pid;
+
+    @Column(name="job_type")
+    private int jobType;
+
+    @Column(name="scheduled")
+    private int scheduled;
+
+    @Column(name="start_millis")
+    private long startMillis;
+
+    @Column(name="end_millis")
+    private long endMillis;
+
+    @Column(name="exec_time")
+    private long execTime;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name="start_date")
+    private Date startDate;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name="end_date")
+    private Date endDate;
+
+    @Column(name="success")
+    private Boolean success;
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name="heartbeat")
+    private Date heartbeat;
+
+    public UsageJobVO() {}
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    public Integer getPid() {
+        return pid;
+    }
+
+    public void setPid(Integer pid) {
+        this.pid = pid;
+    }
+
+    public int getJobType() {
+        return jobType;
+    }
+
+    public void setJobType(int jobType) {
+        this.jobType = jobType;
+    }
+
+    public int getScheduled() {
+        return scheduled;
+    }
+
+    public void setScheduled(int scheduled) {
+        this.scheduled = scheduled;
+    }
+
+    public long getStartMillis() {
+        return startMillis;
+    }
+
+    public void setStartMillis(long startMillis) {
+        this.startMillis = startMillis;
+    }
+
+    public long getEndMillis() {
+        return endMillis;
+    }
+
+    public void setEndMillis(long endMillis) {
+        this.endMillis = endMillis;
+    }
+
+    public long getExecTime() {
+        return execTime;
+    }
+
+    public void setExecTime(long execTime) {
+        this.execTime = execTime;
+    }
+
+    public Date getStartDate() {
+        return startDate;
+    }
+
+    public void setStartDate(Date startDate) {
+        this.startDate = startDate;
+    }
+
+    public Date getEndDate() {
+        return endDate;
+    }
+
+    public void setEndDate(Date endDate) {
+        this.endDate = endDate;
+    }
+
+    public Boolean getSuccess() {
+        return success;
+    }
+
+    public void setSuccess(Boolean success) {
+        this.success = success;
+    }
+
+    public Date getHeartbeat() {
+        return heartbeat;
+    }
+
+    public void setHeartbeat(Date heartbeat) {
+        this.heartbeat = heartbeat;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageLoadBalancerPolicyVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageLoadBalancerPolicyVO.java b/engine/schema/src/com/cloud/usage/UsageLoadBalancerPolicyVO.java
new file mode 100644
index 0000000..e952b1a
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageLoadBalancerPolicyVO.java
@@ -0,0 +1,91 @@
+// 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.usage;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="usage_load_balancer_policy")
+public class UsageLoadBalancerPolicyVO implements InternalIdentity {
+	
+	@Column(name="zone_id")
+    private long zoneId;
+	
+	@Column(name="account_id")
+    private long accountId;
+
+    @Column(name="domain_id")
+	private long domainId;
+
+	@Column(name="id")
+    private long id;
+	
+	@Column(name="created")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date created = null;
+
+	@Column(name="deleted")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date deleted = null;
+
+	protected UsageLoadBalancerPolicyVO() {
+	}
+
+	public UsageLoadBalancerPolicyVO(long id, long zoneId, long accountId, long domainId, Date created, Date deleted) {
+		this.zoneId = zoneId;
+		this.accountId = accountId;
+		this.domainId = domainId;
+		this.id = id;
+		this.created = created;
+		this.deleted = deleted;
+	}
+
+	public long getZoneId() {
+		return zoneId;
+	}
+	
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public long getDomainId() {
+	    return domainId;
+	}
+
+	public long getId() {
+	    return id;
+	}
+	
+	public Date getCreated() {
+		return created;
+	}
+
+	public Date getDeleted() {
+		return deleted;
+	}
+	public void setDeleted(Date deleted) {
+	    this.deleted = deleted;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageNetworkOfferingVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageNetworkOfferingVO.java b/engine/schema/src/com/cloud/usage/UsageNetworkOfferingVO.java
new file mode 100644
index 0000000..fdf758b
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageNetworkOfferingVO.java
@@ -0,0 +1,117 @@
+// 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.usage;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="usage_network_offering")
+public class UsageNetworkOfferingVO {
+	
+	@Column(name="zone_id")
+    private long zoneId;
+	
+	@Column(name="account_id")
+    private long accountId;
+
+    @Column(name="domain_id")
+	private long domainId;
+
+	@Column(name="vm_instance_id")
+	private long vmInstanceId;
+
+	@Column(name="network_offering_id")
+    private Long networkOfferingId;
+	
+    @Column(name="is_default")
+    private boolean isDefault = false;
+
+	@Column(name="created")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date created = null;
+
+	@Column(name="deleted")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date deleted = null;
+	
+	@Column(name="nic_id")
+	private Long nicId;
+
+	protected UsageNetworkOfferingVO() {
+	}
+
+	public UsageNetworkOfferingVO(long zoneId, long accountId, long domainId, long vmInstanceId, long networkOfferingId, long nicId, boolean isDefault, Date created, Date deleted) {
+		this.zoneId = zoneId;
+		this.accountId = accountId;
+		this.domainId = domainId;
+		this.vmInstanceId = vmInstanceId;
+		this.networkOfferingId = networkOfferingId;
+		this.isDefault = isDefault;
+		this.created = created;
+		this.deleted = deleted;
+		this.nicId = nicId;
+	}
+
+	public long getZoneId() {
+		return zoneId;
+	}
+	
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public long getDomainId() {
+	    return domainId;
+	}
+
+    public long getVmInstanceId() {
+        return vmInstanceId;
+    }
+
+    public Long getNetworkOfferingId() {
+        return networkOfferingId;
+    }
+
+    public boolean isDefault() {
+        return isDefault;
+    }
+
+    public Date getCreated() {
+		return created;
+	}
+
+	public Date getDeleted() {
+		return deleted;
+	}
+	public void setDeleted(Date deleted) {
+	    this.deleted = deleted;
+	}
+
+    public Long getNicId() {
+        return nicId;
+    }
+
+    public void setNicId(Long nicId) {
+        this.nicId = nicId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageNetworkVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageNetworkVO.java b/engine/schema/src/com/cloud/usage/UsageNetworkVO.java
new file mode 100644
index 0000000..2eaece2
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageNetworkVO.java
@@ -0,0 +1,144 @@
+// 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.usage;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="usage_network")
+public class UsageNetworkVO {
+	@Id
+    @Column(name="account_id")
+    private long accountId;
+
+	@Column(name="zone_id")
+	private long zoneId;
+	
+	@Column(name="host_id")
+	private long hostId;
+	
+	@Column(name="host_type")
+	private String hostType;
+	
+	@Column(name="network_id")
+	private Long networkId;
+
+	
+	@Column(name="bytes_sent")
+	private long bytesSent;
+
+    @Column(name="bytes_received")
+    private long bytesReceived;
+
+    @Column(name="agg_bytes_received")
+    private long aggBytesReceived;
+    
+    @Column(name="agg_bytes_sent")
+    private long aggBytesSent;
+    
+	@Column(name="event_time_millis")
+	private long eventTimeMillis = 0;
+	
+	protected UsageNetworkVO() {
+	}
+
+	public UsageNetworkVO(Long accountId, long zoneId, long hostId, String hostType, Long networkId, long bytesSent, long bytesReceived, long aggBytesReceived, long aggBytesSent, long eventTimeMillis) {
+		this.accountId = accountId;
+		this.zoneId = zoneId;
+		this.hostId = hostId;
+		this.hostType = hostType;
+		this.networkId = networkId;
+		this.bytesSent = bytesSent;
+        this.bytesReceived = bytesReceived;
+		this.aggBytesReceived = aggBytesReceived;
+		this.aggBytesSent = aggBytesSent;
+		this.eventTimeMillis = eventTimeMillis;
+	}
+
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public void setAccountId(long accountId) {
+		this.accountId = accountId;
+	}
+
+	public long getZoneId() {
+	    return zoneId;
+	}
+	public void setZoneId(long zoneId) {
+	    this.zoneId = zoneId;
+	}
+
+	public Long getBytesSent() {
+		return bytesSent;
+	}
+	
+	public void setBytesSent(Long bytesSent) {
+	    this.bytesSent = bytesSent;
+	}
+
+    public Long getBytesReceived() {
+        return bytesReceived;
+    }
+    
+    public void setBytes(Long bytesReceived) {
+        this.bytesReceived = bytesReceived;
+    }
+
+    public long getEventTimeMillis() {
+	    return eventTimeMillis;
+	}
+	public void setEventTimeMillis(long eventTimeMillis) {
+	    this.eventTimeMillis = eventTimeMillis;
+	}
+
+    public void setHostId(long hostId) {
+        this.hostId = hostId;
+    }
+
+    public long getHostId() {
+        return hostId;
+    }
+    
+    public String getHostType() {
+        return hostType;
+    }
+    
+    public Long getNetworkId() {
+        return networkId;
+    }
+
+	public long getAggBytesReceived() {
+		return aggBytesReceived;
+	}
+
+	public void setAggBytesReceived(long aggBytesReceived) {
+		this.aggBytesReceived = aggBytesReceived;
+	}
+
+	public long getAggBytesSent() {
+		return aggBytesSent;
+	}
+
+	public void setAggBytesSent(long aggBytesSent) {
+		this.aggBytesSent = aggBytesSent;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsagePortForwardingRuleVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsagePortForwardingRuleVO.java b/engine/schema/src/com/cloud/usage/UsagePortForwardingRuleVO.java
new file mode 100644
index 0000000..641ae76
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsagePortForwardingRuleVO.java
@@ -0,0 +1,91 @@
+// 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.usage;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="usage_port_forwarding")
+public class UsagePortForwardingRuleVO implements InternalIdentity {
+	
+	@Column(name="zone_id")
+    private long zoneId;
+	
+	@Column(name="account_id")
+    private long accountId;
+
+    @Column(name="domain_id")
+	private long domainId;
+
+	@Column(name="id")
+    private long id;
+	
+	@Column(name="created")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date created = null;
+
+	@Column(name="deleted")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date deleted = null;
+
+	protected UsagePortForwardingRuleVO() {
+	}
+
+	public UsagePortForwardingRuleVO(long id, long zoneId, long accountId, long domainId, Date created, Date deleted) {
+		this.zoneId = zoneId;
+		this.accountId = accountId;
+		this.domainId = domainId;
+		this.id = id;
+		this.created = created;
+		this.deleted = deleted;
+	}
+
+	public long getZoneId() {
+		return zoneId;
+	}
+	
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public long getDomainId() {
+	    return domainId;
+	}
+
+	public long getId() {
+	    return id;
+	}
+	
+	public Date getCreated() {
+		return created;
+	}
+
+	public Date getDeleted() {
+		return deleted;
+	}
+	public void setDeleted(Date deleted) {
+	    this.deleted = deleted;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageSecurityGroupVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageSecurityGroupVO.java b/engine/schema/src/com/cloud/usage/UsageSecurityGroupVO.java
new file mode 100644
index 0000000..80be6ce
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageSecurityGroupVO.java
@@ -0,0 +1,97 @@
+// 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.usage;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="usage_security_group")
+public class UsageSecurityGroupVO {
+	
+	@Column(name="zone_id")
+    private long zoneId;
+	
+	@Column(name="account_id")
+    private long accountId;
+
+    @Column(name="domain_id")
+	private long domainId;
+
+	@Column(name="vm_instance_id")
+	private long vmInstanceId;
+
+	@Column(name="security_group_id")
+    private Long securityGroupId;
+	
+	@Column(name="created")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date created = null;
+
+	@Column(name="deleted")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date deleted = null;
+
+	public UsageSecurityGroupVO(){
+	}
+	
+	public UsageSecurityGroupVO(long zoneId, long accountId, long domainId, long vmInstanceId, long securityGroupId, Date created, Date deleted) {
+		this.zoneId = zoneId;
+		this.accountId = accountId;
+		this.domainId = domainId;
+		this.vmInstanceId = vmInstanceId;
+		this.securityGroupId = securityGroupId;
+		this.created = created;
+		this.deleted = deleted;
+	}
+
+	public long getZoneId() {
+		return zoneId;
+	}
+	
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public long getDomainId() {
+	    return domainId;
+	}
+
+    public long getVmInstanceId() {
+        return vmInstanceId;
+    }
+
+    public Long getSecurityGroupId() {
+        return securityGroupId;
+    }
+
+    public Date getCreated() {
+		return created;
+	}
+
+	public Date getDeleted() {
+		return deleted;
+	}
+	public void setDeleted(Date deleted) {
+	    this.deleted = deleted;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageStorageVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageStorageVO.java b/engine/schema/src/com/cloud/usage/UsageStorageVO.java
new file mode 100644
index 0000000..1337edc
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageStorageVO.java
@@ -0,0 +1,115 @@
+// 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.usage;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="usage_storage")
+public class UsageStorageVO implements InternalIdentity {
+	
+	@Column(name="zone_id")
+    private long zoneId;
+	
+	@Column(name="account_id")
+    private long accountId;
+
+    @Column(name="domain_id")
+	private long domainId;
+
+	@Column(name="id")
+    private long id;
+
+	@Column(name="storage_type")
+    private int storageType;
+	
+	@Column(name="source_id")
+    private Long sourceId;
+	
+	@Column(name="size")
+    private long size;
+	
+	@Column(name="created")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date created = null;
+
+	@Column(name="deleted")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date deleted = null;
+
+	protected UsageStorageVO() {
+	}
+
+	public UsageStorageVO(long id, long zoneId, long accountId, long domainId, int storageType, Long sourceId, long size, Date created, Date deleted) {
+		this.zoneId = zoneId;
+		this.accountId = accountId;
+		this.domainId = domainId;
+		this.id = id;
+		this.storageType = storageType;
+		this.sourceId = sourceId;
+		this.size = size;
+		this.created = created;
+		this.deleted = deleted;
+	}
+
+	public long getZoneId() {
+		return zoneId;
+	}
+	
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public long getDomainId() {
+	    return domainId;
+	}
+
+	public long getId() {
+	    return id;
+	}
+	
+	public int getStorageType(){
+		return storageType;
+	}
+
+	public Long getSourceId(){
+        return sourceId;
+    }
+	
+	public long getSize(){
+		return size;
+	}
+	
+	public Date getCreated() {
+		return created;
+	}
+
+	public Date getDeleted() {
+		return deleted;
+	}
+	public void setDeleted(Date deleted) {
+	    this.deleted = deleted;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageVMInstanceVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageVMInstanceVO.java b/engine/schema/src/com/cloud/usage/UsageVMInstanceVO.java
new file mode 100644
index 0000000..6f40471
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageVMInstanceVO.java
@@ -0,0 +1,121 @@
+// 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.usage;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="usage_vm_instance")
+public class UsageVMInstanceVO {
+    @Column(name="usage_type")
+    private int usageType;
+
+    @Column(name="zone_id")
+    private long zoneId;
+
+	@Column(name="account_id")
+    private long accountId;
+
+	@Column(name="vm_instance_id")
+    private long vmInstanceId;
+
+	@Column(name="vm_name")
+    private String vmName = null;
+
+	@Column(name="service_offering_id")
+	private long serviceOfferingId;
+
+    @Column(name="template_id")
+    private long templateId;
+    
+    @Column(name="hypervisor_type")
+    private String hypervisorType;
+
+	@Column(name="start_date")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date startDate = null;
+
+    @Column(name="end_date")
+    @Temporal(value=TemporalType.TIMESTAMP)
+    private Date endDate = null;
+   
+	protected UsageVMInstanceVO() {
+	}
+
+	public UsageVMInstanceVO(int usageType, long zoneId, long accountId, long vmInstanceId, String vmName, long serviceOfferingId,
+	        long templateId, String hypervisorType, Date startDate, Date endDate) {
+	    this.usageType = usageType;
+	    this.zoneId = zoneId;
+		this.accountId = accountId;
+		this.vmInstanceId = vmInstanceId;
+		this.vmName = vmName;
+		this.serviceOfferingId = serviceOfferingId;
+		this.templateId = templateId;
+		this.hypervisorType = hypervisorType;
+		this.startDate = startDate;
+        this.endDate = endDate;
+	}
+
+	public int getUsageType() {
+	    return usageType;
+	}
+
+	public long getZoneId() {
+	    return zoneId;
+	}
+
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public long getVmInstanceId() {
+		return vmInstanceId;
+	}
+
+    public String getVmName() {
+        return vmName;
+    }
+
+    public long getSerivceOfferingId() {
+        return serviceOfferingId;
+    }
+
+    public long getTemplateId() {
+        return templateId;
+    }
+
+    public String getHypervisorType() {
+        return hypervisorType;
+    }
+    
+	public Date getStartDate() {
+		return startDate;
+	}
+
+	public Date getEndDate() {
+		return endDate;
+	}
+	public void setEndDate(Date endDate) {
+	    this.endDate = endDate;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageVO.java b/engine/schema/src/com/cloud/usage/UsageVO.java
new file mode 100644
index 0000000..18a3a6b
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageVO.java
@@ -0,0 +1,260 @@
+// 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.usage;
+
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.usage.Usage;
+
+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 javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="cloud_usage")
+public class UsageVO implements Usage, InternalIdentity {
+	@Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private Long id = null;
+
+    @Column(name="zone_id")
+    private Long zoneId = null;
+
+    @Column(name="account_id")
+	private Long accountId = null;
+
+    @Column(name="domain_id")
+    private Long domainId = null;
+
+	@Column(name="description")
+    private String description = null;
+	
+	@Column(name="usage_display")
+    private String usageDisplay = null;
+
+	@Column(name="usage_type")
+	private int usageType;
+	
+    @Column(name="raw_usage")
+    private Double rawUsage = null;
+
+    @Column(name="vm_instance_id")
+    private Long vmInstanceId;
+
+    @Column(name="vm_name")
+    private String vmName = null;
+
+    @Column(name="offering_id")
+    private Long offeringId = null;
+
+    @Column(name="template_id")
+    private Long templateId = null;
+
+    @Column(name="usage_id")
+    private Long usageId = null;
+    
+    @Column(name="type")
+    private String type = null;
+
+    @Column(name="size")
+    private Long size = null;
+    
+    @Column(name="network_id")
+    private Long networkId = null;
+
+    
+	@Column(name="start_date")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date startDate = null;
+	
+    @Column(name="end_date")
+    @Temporal(value=TemporalType.TIMESTAMP)
+    private Date endDate = null;
+
+    public UsageVO() {
+	}
+
+	public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay, 
+	               int usageType, Double rawUsage, Long vmId, String vmName, Long offeringId, Long templateId, 
+	               Long usageId, Long size, Date startDate, Date endDate) {
+		this.zoneId = zoneId;
+        this.accountId = accountId;
+		this.domainId = domainId;
+		this.description = description;
+		this.usageDisplay = usageDisplay;
+		this.usageType = usageType;
+        this.rawUsage = rawUsage;
+        this.vmInstanceId = vmId;
+        this.vmName = vmName;
+		this.offeringId = offeringId;
+		this.templateId = templateId;
+		this.usageId = usageId;
+		this.size = size;
+		this.startDate = startDate;
+		this.endDate = endDate;
+	}
+	
+	public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay, 
+	        int usageType, Double rawUsage, Long usageId, String type, Long networkId, Date startDate, Date endDate) {
+	    this.zoneId = zoneId;
+	    this.accountId = accountId;
+	    this.domainId = domainId;
+	    this.description = description;
+	    this.usageDisplay = usageDisplay;
+	    this.usageType = usageType;
+	    this.rawUsage = rawUsage;
+	    this.usageId = usageId;
+	    this.type = type;
+	    this.networkId = networkId;
+	    this.startDate = startDate;
+	    this.endDate = endDate;
+	}
+
+	public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay, 
+	        int usageType, Double rawUsage, Long vmId, String vmName, Long offeringId, Long templateId, 
+	        Long usageId, Date startDate, Date endDate, String type) {
+	    this.zoneId = zoneId;
+	    this.accountId = accountId;
+	    this.domainId = domainId;
+	    this.description = description;
+	    this.usageDisplay = usageDisplay;
+	    this.usageType = usageType;
+	    this.rawUsage = rawUsage;
+	    this.vmInstanceId = vmId;
+	    this.vmName = vmName;
+	    this.offeringId = offeringId;
+	    this.templateId = templateId;
+	    this.usageId = usageId;
+	    this.type = type;
+	    this.startDate = startDate;
+	    this.endDate = endDate;
+	}
+
+	//IPAddress Usage
+	public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay, 
+	        int usageType, Double rawUsage, Long usageId, long size, String type, Date startDate, Date endDate) {
+	    this.zoneId = zoneId;
+	    this.accountId = accountId;
+	    this.domainId = domainId;
+	    this.description = description;
+	    this.usageDisplay = usageDisplay;
+	    this.usageType = usageType;
+	    this.rawUsage = rawUsage;
+	    this.usageId = usageId;
+	    this.size = size;
+	    this.type = type;
+	    this.startDate = startDate;
+	    this.endDate = endDate;
+	}
+	
+	@Override
+	public long getId() {
+		return id;
+	}
+
+	@Override
+	public Long getZoneId() {
+	    return zoneId;
+	}
+
+	@Override
+	public Long getAccountId() {
+		return accountId;
+	}
+
+	@Override
+    public Long getDomainId() {
+        return domainId;
+    }
+
+	@Override
+	public String getDescription() {
+		return description;
+	}
+	
+	@Override
+	public String getUsageDisplay() {
+		return usageDisplay;
+	}
+
+	@Override
+	public int getUsageType() {
+	    return usageType;
+	}
+
+	@Override
+    public Double getRawUsage() {
+        return rawUsage;
+    }
+
+	@Override
+    public Long getVmInstanceId() {
+        return vmInstanceId;
+    }
+
+	@Override
+    public String getVmName() {
+        return vmName;
+    }
+
+	@Override
+    public Long getOfferingId() {
+        return offeringId;
+    }
+
+	@Override
+    public Long getTemplateId() {
+        return templateId;
+    }
+
+	@Override
+    public Long getUsageId() {
+        return usageId;
+    }
+    
+	@Override
+    public String getType() {
+        return type;
+    }
+    
+	@Override
+    public Long getNetworkId() {
+        return networkId;
+    }
+
+	@Override
+    public Long getSize() {
+        return size;
+    }
+    
+	@Override
+	public Date getStartDate() {
+		return startDate;
+	}
+
+	@Override
+	public Date getEndDate() {
+        return endDate;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageVPNUserVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageVPNUserVO.java b/engine/schema/src/com/cloud/usage/UsageVPNUserVO.java
new file mode 100644
index 0000000..549cef4
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageVPNUserVO.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.usage;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="usage_vpn_user")
+public class UsageVPNUserVO {
+	
+	@Column(name="zone_id")
+    private long zoneId;
+	
+	@Column(name="account_id")
+    private long accountId;
+
+    @Column(name="domain_id")
+	private long domainId;
+
+	@Column(name="user_id")
+	private long userId;
+
+	@Column(name="user_name")
+    private String username;
+	
+	@Column(name="created")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date created = null;
+
+	@Column(name="deleted")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date deleted = null;
+
+	protected UsageVPNUserVO() {
+	}
+
+	public UsageVPNUserVO(long zoneId, long accountId, long domainId, long userId, String username, Date created, Date deleted) {
+		this.zoneId = zoneId;
+		this.accountId = accountId;
+		this.domainId = domainId;
+		this.userId = userId;
+		this.username = username;
+		this.created = created;
+		this.deleted = deleted;
+	}
+
+	public long getZoneId() {
+		return zoneId;
+	}
+	
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public long getDomainId() {
+	    return domainId;
+	}
+
+    public Date getCreated() {
+		return created;
+	}
+
+	public Date getDeleted() {
+		return deleted;
+	}
+	public void setDeleted(Date deleted) {
+	    this.deleted = deleted;
+	}
+
+	public long getUserId() {
+		return userId;
+	}
+
+	public void setUserId(long userId) {
+		this.userId = userId;
+	}
+
+	public String getUsername() {
+		return username;
+	}
+
+	public void setUsername(String username) {
+		this.username = username;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/UsageVolumeVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/UsageVolumeVO.java b/engine/schema/src/com/cloud/usage/UsageVolumeVO.java
new file mode 100644
index 0000000..4ba8898
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/UsageVolumeVO.java
@@ -0,0 +1,115 @@
+// 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.usage;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="usage_volume")
+public class UsageVolumeVO implements InternalIdentity {
+	
+	@Column(name="zone_id")
+    private long zoneId;
+	
+	@Column(name="account_id")
+    private long accountId;
+
+    @Column(name="domain_id")
+	private long domainId;
+
+	@Column(name="id")
+    private long id;
+
+	@Column(name="disk_offering_id")
+    private Long diskOfferingId;
+	
+	@Column(name="template_id")
+	private Long templateId;
+	
+	@Column(name="size")
+    private long size;
+
+	@Column(name="created")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date created = null;
+
+	@Column(name="deleted")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date deleted = null;
+
+	protected UsageVolumeVO() {
+	}
+
+	public UsageVolumeVO(long id, long zoneId, long accountId, long domainId, Long diskOfferingId, Long templateId, long size, Date created, Date deleted) {
+		this.id = id;
+		this.zoneId = zoneId;
+		this.accountId = accountId;
+		this.domainId = domainId;
+		this.diskOfferingId = diskOfferingId;
+		this.templateId = templateId;
+		this.size = size;
+		this.created = created;
+		this.deleted = deleted;
+	}
+
+	public long getZoneId() {
+		return zoneId;
+	}
+	
+	public long getAccountId() {
+		return accountId;
+	}
+
+	public long getDomainId() {
+	    return domainId;
+	}
+
+	public long getId() {
+	    return id;
+	}
+	
+	public Long getDiskOfferingId() {
+	    return diskOfferingId;
+	}
+	
+	public Long getTemplateId() {
+        return templateId;
+    }
+	
+	public long getSize() {
+        return size;
+    }
+
+    public Date getCreated() {
+		return created;
+	}
+
+	public Date getDeleted() {
+		return deleted;
+	}
+	public void setDeleted(Date deleted) {
+	    this.deleted = deleted;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/usage/dao/ExternalPublicIpStatisticsDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/usage/dao/ExternalPublicIpStatisticsDao.java b/engine/schema/src/com/cloud/usage/dao/ExternalPublicIpStatisticsDao.java
new file mode 100644
index 0000000..decf28f
--- /dev/null
+++ b/engine/schema/src/com/cloud/usage/dao/ExternalPublicIpStatisticsDao.java
@@ -0,0 +1,33 @@
+// 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.usage.dao;
+
+import java.util.List;
+
+import com.cloud.usage.ExternalPublicIpStatisticsVO;
+import com.cloud.user.UserStatisticsVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface ExternalPublicIpStatisticsDao extends GenericDao<ExternalPublicIpStatisticsVO, Long> {
+	
+	ExternalPublicIpStatisticsVO lock(long accountId, long zoneId, String publicIpAddress);
+
+    ExternalPublicIpStatisticsVO findBy(long accountId, long zoneId, String publicIpAddress);    
+	
+	List<ExternalPublicIpStatisticsVO> listBy(long accountId, long zoneId);
+	
+}


Mime
View raw message