Search in sources :

Example 1 with ScopeType

use of com.cloud.storage.ScopeType in project cloudstack by apache.

the class VolumeDaoImpl method getHypervisorType.

@Override
@DB
public HypervisorType getHypervisorType(long volumeId) {
    /* lookup from cluster of pool */
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    String sql = null;
    try {
        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);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                if (rs.getString(1) != null) {
                    return HypervisorType.getType(rs.getString(1));
                }
            }
        }
        return HypervisorType.None;
    } catch (SQLException e) {
        throw new CloudRuntimeException("DB Exception on: " + sql, e);
    } catch (Throwable e) {
        throw new CloudRuntimeException("Caught: " + sql, e);
    }
}
Also used : ScopeType(com.cloud.storage.ScopeType) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DB(com.cloud.utils.db.DB)

Example 2 with ScopeType

use of com.cloud.storage.ScopeType in project cloudstack by apache.

the class SwiftImageStoreLifeCycleImpl method initialize.

@Override
public DataStore initialize(Map<String, Object> dsInfos) {
    Long dcId = (Long) dsInfos.get("zoneId");
    String url = (String) dsInfos.get("url");
    String name = (String) dsInfos.get("name");
    ScopeType scope = (ScopeType) dsInfos.get("scope");
    String providerName = (String) dsInfos.get("providerName");
    DataStoreRole role = (DataStoreRole) dsInfos.get("role");
    Map<String, String> details = (Map<String, String>) dsInfos.get("details");
    s_logger.info("Trying to add a swift store at " + url + " in data center " + dcId);
    // just need to insert an entry in DB
    Map<String, Object> imageStoreParameters = new HashMap<String, Object>();
    imageStoreParameters.put("name", name);
    imageStoreParameters.put("zoneId", dcId);
    imageStoreParameters.put("url", url);
    imageStoreParameters.put("protocol", "http");
    if (scope != null) {
        imageStoreParameters.put("scope", scope);
    } else {
        imageStoreParameters.put("scope", ScopeType.REGION);
    }
    imageStoreParameters.put("providerName", providerName);
    imageStoreParameters.put("role", role);
    ImageStoreVO ids = imageStoreHelper.createImageStore(imageStoreParameters, details);
    return imageStoreMgr.getImageStore(ids.getId());
}
Also used : ScopeType(com.cloud.storage.ScopeType) DataStoreRole(com.cloud.storage.DataStoreRole) HashMap(java.util.HashMap) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ScopeType

use of com.cloud.storage.ScopeType in project cloudstack by apache.

the class SnapshotManagerImpl method supportedByHypervisor.

private boolean supportedByHypervisor(VolumeInfo volume) {
    HypervisorType hypervisorType;
    StoragePoolVO storagePool = _storagePoolDao.findById(volume.getDataStore().getId());
    ScopeType scope = storagePool.getScope();
    if (scope.equals(ScopeType.ZONE)) {
        hypervisorType = storagePool.getHypervisor();
    } else {
        hypervisorType = volume.getHypervisorType();
    }
    if (hypervisorType.equals(HypervisorType.Ovm)) {
        throw new InvalidParameterValueException("Ovm won't support taking snapshot");
    }
    if (hypervisorType.equals(HypervisorType.KVM)) {
        List<HostVO> hosts = null;
        if (scope.equals(ScopeType.CLUSTER)) {
            ClusterVO cluster = _clusterDao.findById(storagePool.getClusterId());
            hosts = _resourceMgr.listAllHostsInCluster(cluster.getId());
        } else if (scope.equals(ScopeType.ZONE)) {
            hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, volume.getDataCenterId());
        }
        if (hosts != null && !hosts.isEmpty()) {
            HostVO host = hosts.get(0);
            if (!hostSupportSnapsthotForVolume(host, volume)) {
                throw new CloudRuntimeException("KVM Snapshot is not supported for Running VMs. It is disabled by default due to a possible volume corruption in certain cases. To enable it set global settings kvm.snapshot.enabled to True. See the documentation for more details.");
            }
        }
    }
    // if volume is attached to a vm in destroyed or expunging state; disallow
    if (volume.getInstanceId() != null) {
        UserVmVO userVm = _vmDao.findById(volume.getInstanceId());
        if (userVm != null) {
            if (userVm.getState().equals(State.Destroyed) || userVm.getState().equals(State.Expunging)) {
                throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volume.getId() + " is associated with vm:" + userVm.getInstanceName() + " is in " + userVm.getState().toString() + " state");
            }
            if (userVm.getHypervisorType() == HypervisorType.VMware || userVm.getHypervisorType() == HypervisorType.KVM) {
                List<SnapshotVO> activeSnapshots = _snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.State.Creating, Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp);
                if (activeSnapshots.size() > 0) {
                    throw new InvalidParameterValueException("There is other active snapshot tasks on the instance to which the volume is attached, please try again later");
                }
            }
            List<VMSnapshotVO> activeVMSnapshots = _vmSnapshotDao.listByInstanceId(userVm.getId(), VMSnapshot.State.Creating, VMSnapshot.State.Reverting, VMSnapshot.State.Expunging);
            if (activeVMSnapshots.size() > 0) {
                throw new CloudRuntimeException("There is other active vm snapshot tasks on the instance to which the volume is attached, please try again later");
            }
        }
    }
    return true;
}
Also used : ScopeType(com.cloud.storage.ScopeType) UserVmVO(com.cloud.vm.UserVmVO) ClusterVO(com.cloud.dc.ClusterVO) HostVO(com.cloud.host.HostVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) SnapshotVO(com.cloud.storage.SnapshotVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 4 with ScopeType

use of com.cloud.storage.ScopeType 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.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DB(com.cloud.utils.db.DB)

Example 5 with ScopeType

use of com.cloud.storage.ScopeType in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method searchForStoragePoolsInternal.

private Pair<List<StoragePoolJoinVO>, Integer> searchForStoragePoolsInternal(final ListStoragePoolsCmd cmd) {
    ScopeType scopeType = null;
    if (cmd.getScope() != null) {
        try {
            scopeType = Enum.valueOf(ScopeType.class, cmd.getScope().toUpperCase());
        } catch (final Exception e) {
            throw new InvalidParameterValueException("Invalid scope type: " + cmd.getScope());
        }
    }
    final Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
    final Object id = cmd.getId();
    final Object name = cmd.getStoragePoolName();
    final Object path = cmd.getPath();
    final Object pod = cmd.getPodId();
    final Object cluster = cmd.getClusterId();
    final Object address = cmd.getIpAddress();
    final Object keyword = cmd.getKeyword();
    final Long startIndex = cmd.getStartIndex();
    final Long pageSize = cmd.getPageSizeVal();
    final Filter searchFilter = new Filter(StoragePoolJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
    final SearchBuilder<StoragePoolJoinVO> sb = _poolJoinDao.createSearchBuilder();
    // select distinct
    sb.select(null, Func.DISTINCT, sb.entity().getId());
    // ids
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
    sb.and("path", sb.entity().getPath(), SearchCriteria.Op.EQ);
    sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
    sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
    sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
    sb.and("hostAddress", sb.entity().getHostAddress(), SearchCriteria.Op.EQ);
    sb.and("scope", sb.entity().getScope(), SearchCriteria.Op.EQ);
    final SearchCriteria<StoragePoolJoinVO> sc = sb.create();
    if (keyword != null) {
        final SearchCriteria<StoragePoolJoinVO> ssc = _poolJoinDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("poolType", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (id != null) {
        sc.setParameters("id", id);
    }
    if (name != null) {
        sc.setParameters("name", name);
    }
    if (path != null) {
        sc.setParameters("path", path);
    }
    if (zoneId != null) {
        sc.setParameters("dataCenterId", zoneId);
    }
    if (pod != null) {
        sc.setParameters("podId", pod);
    }
    if (address != null) {
        sc.setParameters("hostAddress", address);
    }
    if (cluster != null) {
        sc.setParameters("clusterId", cluster);
    }
    if (scopeType != null) {
        sc.setParameters("scope", scopeType.toString());
    }
    // search Pool details by ids
    final Pair<List<StoragePoolJoinVO>, Integer> uniquePoolPair = _poolJoinDao.searchAndCount(sc, searchFilter);
    final Integer count = uniquePoolPair.second();
    if (count.intValue() == 0) {
        // empty result
        return uniquePoolPair;
    }
    final List<StoragePoolJoinVO> uniquePools = uniquePoolPair.first();
    final Long[] vrIds = new Long[uniquePools.size()];
    int i = 0;
    for (final StoragePoolJoinVO v : uniquePools) {
        vrIds[i++] = v.getId();
    }
    final List<StoragePoolJoinVO> vrs = _poolJoinDao.searchByIds(vrIds);
    return new Pair<>(vrs, count);
}
Also used : ScopeType(com.cloud.storage.ScopeType) CloudAuthenticationException(com.cloud.exception.CloudAuthenticationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) StoragePoolJoinVO(com.cloud.api.query.vo.StoragePoolJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Aggregations

ScopeType (com.cloud.storage.ScopeType)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 StoragePoolJoinVO (com.cloud.api.query.vo.StoragePoolJoinVO)2 ClusterVO (com.cloud.dc.ClusterVO)2 CloudAuthenticationException (com.cloud.exception.CloudAuthenticationException)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 HostVO (com.cloud.host.HostVO)2 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)2 DataStoreRole (com.cloud.storage.DataStoreRole)2 SnapshotVO (com.cloud.storage.SnapshotVO)2 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)2 Pair (com.cloud.utils.Pair)2 DB (com.cloud.utils.db.DB)2 Filter (com.cloud.utils.db.Filter)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)2 UserVmVO (com.cloud.vm.UserVmVO)2 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)2 PreparedStatement (java.sql.PreparedStatement)2