Search in sources :

Example 1 with CloudException

use of com.cloud.exception.CloudException in project cloudstack by apache.

the class UsageLoadBalancerPolicyDaoImpl method update.

@Override
public void update(UsageLoadBalancerPolicyVO usage) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
    try {
        txn.start();
        if (usage.getDeleted() != null) {
            try (PreparedStatement pstmt = txn.prepareStatement(UPDATE_DELETED)) {
                if (pstmt != null) {
                    pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
                    pstmt.setLong(2, usage.getAccountId());
                    pstmt.setLong(3, usage.getId());
                    pstmt.executeUpdate();
                }
            } catch (SQLException e) {
                throw new CloudException("Error updating UsageLoadBalancerPolicyVO:" + e.getMessage(), e);
            }
        }
        txn.commit();
    } catch (Exception e) {
        txn.rollback();
        s_logger.warn("Error updating UsageLoadBalancerPolicyVO" + e.getMessage(), e);
    } finally {
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) CloudException(com.cloud.exception.CloudException) SQLException(java.sql.SQLException) CloudException(com.cloud.exception.CloudException)

Example 2 with CloudException

use of com.cloud.exception.CloudException in project cloudstack by apache.

the class UsageNetworkOfferingDaoImpl method update.

@Override
public void update(UsageNetworkOfferingVO usage) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
    try {
        txn.start();
        if (usage.getDeleted() != null) {
            try (PreparedStatement pstmt = txn.prepareStatement(UPDATE_DELETED)) {
                if (pstmt != null) {
                    pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
                    pstmt.setLong(2, usage.getAccountId());
                    pstmt.setLong(3, usage.getVmInstanceId());
                    pstmt.setLong(4, usage.getNetworkOfferingId());
                    pstmt.executeUpdate();
                }
            } catch (SQLException e) {
                throw new CloudException("Error updating UsageNetworkOfferingVO:" + e.getMessage(), e);
            }
        }
        txn.commit();
    } catch (Exception e) {
        txn.rollback();
        s_logger.warn("Error updating UsageNetworkOfferingVO:" + e.getMessage(), e);
    } finally {
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) CloudException(com.cloud.exception.CloudException) SQLException(java.sql.SQLException) CloudException(com.cloud.exception.CloudException)

Example 3 with CloudException

use of com.cloud.exception.CloudException in project cloudstack by apache.

the class UsageSecurityGroupDaoImpl method update.

@Override
public void update(UsageSecurityGroupVO usage) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
    try {
        txn.start();
        if (usage.getDeleted() != null) {
            try (PreparedStatement pstmt = txn.prepareStatement(UPDATE_DELETED)) {
                if (pstmt != null) {
                    pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted()));
                    pstmt.setLong(2, usage.getAccountId());
                    pstmt.setLong(3, usage.getVmInstanceId());
                    pstmt.setLong(4, usage.getSecurityGroupId());
                    pstmt.executeUpdate();
                }
            } catch (SQLException e) {
                throw new CloudException("Error updating UsageSecurityGroupVO:" + e.getMessage(), e);
            }
        }
        txn.commit();
    } catch (Exception e) {
        txn.rollback();
        s_logger.warn("Error updating UsageSecurityGroupVO:" + e.getMessage(), e);
    } finally {
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) CloudException(com.cloud.exception.CloudException) SQLException(java.sql.SQLException) CloudException(com.cloud.exception.CloudException)

Example 4 with CloudException

use of com.cloud.exception.CloudException in project cloudstack by apache.

the class UsageStorageDaoImpl method getUsageRecords.

@Override
public List<UsageStorageVO> getUsageRecords(Long accountId, Long domainId, Date startDate, Date endDate, boolean limit, int page) {
    List<UsageStorageVO> usageRecords = new ArrayList<UsageStorageVO>();
    Long param1 = null;
    String sql = null;
    if (accountId != null) {
        sql = GET_USAGE_RECORDS_BY_ACCOUNT;
        param1 = accountId;
    } else if (domainId != null) {
        sql = GET_USAGE_RECORDS_BY_DOMAIN;
        param1 = domainId;
    } else {
        sql = GET_ALL_USAGE_RECORDS;
    }
    if (limit) {
        int startIndex = 0;
        if (page > 0) {
            startIndex = 500 * (page - 1);
        }
        sql += " LIMIT " + startIndex + ",500";
    }
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
    int i = 1;
    try (PreparedStatement pstmt = txn.prepareStatement(sql)) {
        if (param1 != null) {
            pstmt.setLong(i++, param1);
        }
        pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), startDate));
        pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate));
        pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), startDate));
        pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate));
        pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), startDate));
        pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate));
        try (ResultSet rs = pstmt.executeQuery()) {
            while (rs.next()) {
                //id, zone_id, account_id, domain_id, storage_type, size, created, deleted
                Long id = Long.valueOf(rs.getLong(1));
                Long zoneId = Long.valueOf(rs.getLong(2));
                Long acctId = Long.valueOf(rs.getLong(3));
                Long dId = Long.valueOf(rs.getLong(4));
                Integer type = Integer.valueOf(rs.getInt(5));
                Long sourceId = Long.valueOf(rs.getLong(6));
                Long size = Long.valueOf(rs.getLong(7));
                Long virtualSize = Long.valueOf(rs.getLong(10));
                Date createdDate = null;
                Date deletedDate = null;
                String createdTS = rs.getString(8);
                String deletedTS = rs.getString(9);
                if (createdTS != null) {
                    createdDate = DateUtil.parseDateString(s_gmtTimeZone, createdTS);
                }
                if (deletedTS != null) {
                    deletedDate = DateUtil.parseDateString(s_gmtTimeZone, deletedTS);
                }
                usageRecords.add(new UsageStorageVO(id, zoneId, acctId, dId, type, sourceId, size, virtualSize, createdDate, deletedDate));
            }
        } catch (SQLException e) {
            throw new CloudException("getUsageRecords:" + e.getMessage(), e);
        }
    } catch (Exception e) {
        txn.rollback();
        s_logger.error("getUsageRecords:Exception:" + e.getMessage(), e);
    } finally {
        txn.close();
    }
    return usageRecords;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) CloudException(com.cloud.exception.CloudException) Date(java.util.Date) SQLException(java.sql.SQLException) CloudException(com.cloud.exception.CloudException) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ResultSet(java.sql.ResultSet) UsageStorageVO(com.cloud.usage.UsageStorageVO)

Example 5 with CloudException

use of com.cloud.exception.CloudException in project cloudstack by apache.

the class UsageStorageDaoImpl method removeBy.

@Override
public void removeBy(long accountId, long volId, int storageType) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
    try {
        txn.start();
        String sql = REMOVE_BY_USERID_STORAGEID;
        try (PreparedStatement pstmt = txn.prepareStatement(sql)) {
            pstmt.setLong(1, accountId);
            pstmt.setLong(2, volId);
            pstmt.setInt(3, storageType);
            pstmt.executeUpdate();
        } catch (SQLException e) {
            throw new CloudException("removeBy:Exception:" + e.getMessage(), e);
        }
        txn.commit();
    } catch (Exception e) {
        txn.rollback();
        s_logger.error("Error removing usageStorageVO", e);
    } finally {
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) CloudException(com.cloud.exception.CloudException) SQLException(java.sql.SQLException) CloudException(com.cloud.exception.CloudException)

Aggregations

CloudException (com.cloud.exception.CloudException)18 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)11 PreparedStatement (java.sql.PreparedStatement)11 SQLException (java.sql.SQLException)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 VirtualMachineEntity (org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 Account (com.cloud.user.Account)2 ResultSet (java.sql.ResultSet)2 DataCenter (com.cloud.dc.DataCenter)1 ActionEvent (com.cloud.event.ActionEvent)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 VirtualSwitchType (com.cloud.hypervisor.vmware.mo.VirtualSwitchType)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 Network (com.cloud.network.Network)1 TrafficType (com.cloud.network.Networks.TrafficType)1 VmwareTrafficLabel (com.cloud.network.VmwareTrafficLabel)1 ResourceState (com.cloud.resource.ResourceState)1 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)1