Search in sources :

Example 56 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class VolumeDaoImpl method listZoneWidePoolIdsByVolumeCount.

@Override
public List<Long> listZoneWidePoolIdsByVolumeCount(final long dcId, final long accountId) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    final List<Long> result = new ArrayList<>();
    try {
        final String sql = ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT;
        pstmt = txn.prepareAutoCloseStatement(sql);
        pstmt.setLong(1, accountId);
        pstmt.setLong(2, dcId);
        final ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            result.add(rs.getLong(1));
        }
        return result;
    } catch (final SQLException e) {
        throw new CloudRuntimeException("DB Exception on: " + ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e);
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 57 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class VolumeDaoImpl method listPoolIdsByVolumeCount.

@Override
public List<Long> listPoolIdsByVolumeCount(final long dcId, final Long podId, final Long clusterId, final long accountId) {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    final List<Long> result = new ArrayList<>();
    try {
        final String sql = ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT;
        pstmt = txn.prepareAutoCloseStatement(sql);
        pstmt.setLong(1, accountId);
        pstmt.setLong(2, dcId);
        pstmt.setLong(3, podId);
        pstmt.setLong(4, clusterId);
        final ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            result.add(rs.getLong(1));
        }
        return result;
    } catch (final SQLException e) {
        throw new CloudRuntimeException("DB Exception on: " + ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e);
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 58 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class VolumeDaoImpl method getVolumeStoragePoolScope.

@Override
public ScopeType getVolumeStoragePoolScope(final long volumeId) {
    // finding the storage scope where the volume is present
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    try {
        final String sql = SELECT_POOLSCOPE;
        pstmt = txn.prepareAutoCloseStatement(sql);
        pstmt.setLong(1, volumeId);
        final ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            final String scope = rs.getString(1);
            if (scope != null) {
                try {
                    return Enum.valueOf(ScopeType.class, scope.toUpperCase());
                } catch (final Exception e) {
                    throw new InvalidParameterValueException("invalid scope for pool " + scope);
                }
            }
        }
    } catch (final SQLException e) {
        throw new CloudRuntimeException("DB Exception on: " + SELECT_POOLSCOPE, e);
    }
    return null;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Example 59 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class VolumeDaoImpl method getHypervisorType.

@Override
@DB
public HypervisorType getHypervisorType(final long volumeId) {
    /* lookup from cluster of pool */
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    String sql = null;
    try {
        final ScopeType scope = getVolumeStoragePoolScope(volumeId);
        if (scope != null) {
            if (scope == ScopeType.CLUSTER || scope == ScopeType.HOST) {
                sql = SELECT_HYPERTYPE_FROM_CLUSTER_VOLUME;
            } else if (scope == ScopeType.ZONE) {
                sql = SELECT_HYPERTYPE_FROM_ZONE_VOLUME;
            } else {
                s_logger.error("Unhandled scope type '" + scope + "' when running getHypervisorType on volume id " + volumeId);
            }
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setLong(1, volumeId);
            final ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                if (rs.getString(1) != null) {
                    return HypervisorType.getType(rs.getString(1));
                }
            }
        }
        return HypervisorType.None;
    } catch (final SQLException e) {
        throw new CloudRuntimeException("DB Exception on: " + sql, e);
    }
}
Also used : ScopeType(com.cloud.storage.ScopeType) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DB(com.cloud.utils.db.DB)

Example 60 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class ServiceOfferingDaoImpl method findDefaultSystemOffering.

@Override
public ServiceOfferingVO findDefaultSystemOffering(final String offeringName, final Boolean useLocalStorage) {
    String name = offeringName;
    if (useLocalStorage != null && useLocalStorage.booleanValue()) {
        name += "-Local";
    }
    final ServiceOfferingVO serviceOffering = findByName(name);
    if (serviceOffering == null) {
        final String message = "System service offering " + name + " not found";
        s_logger.error(message);
        throw new CloudRuntimeException(message);
    }
    return serviceOffering;
}
Also used : CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Aggregations

CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)587 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)159 ArrayList (java.util.ArrayList)110 DB (com.cloud.utils.db.DB)90 Account (com.cloud.legacymodel.user.Account)84 SQLException (java.sql.SQLException)84 ActionEvent (com.cloud.event.ActionEvent)73 ConfigurationException (javax.naming.ConfigurationException)73 PreparedStatement (java.sql.PreparedStatement)68 HashMap (java.util.HashMap)68 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)62 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)52 HostVO (com.cloud.host.HostVO)50 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)50 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)50 XenAPIException (com.xensource.xenapi.Types.XenAPIException)47 Answer (com.cloud.legacymodel.communication.answer.Answer)45 XmlRpcException (org.apache.xmlrpc.XmlRpcException)45 TransactionStatus (com.cloud.utils.db.TransactionStatus)44 IOException (java.io.IOException)44