use of com.cloud.storage.ScopeType in project cosmic by MissionCriticalCloud.
the class SnapshotManagerImpl method supportedByHypervisor.
private boolean supportedByHypervisor(final VolumeInfo volume) {
final HypervisorType hypervisorType;
final StoragePoolVO storagePool = _storagePoolDao.findById(volume.getDataStore().getId());
final ScopeType scope = storagePool.getScope();
if (scope.equals(ScopeType.ZONE)) {
hypervisorType = storagePool.getHypervisor();
} else {
hypervisorType = volume.getHypervisorType();
}
if (hypervisorType.equals(HypervisorType.KVM)) {
List<HostVO> hosts = null;
if (scope.equals(ScopeType.CLUSTER)) {
final 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()) {
final HostVO host = hosts.get(0);
if (!hostSupportSnapsthotForVolume(host, volume)) {
throw new CloudRuntimeException("KVM Snapshot is not supported: " + host.getId());
}
}
}
// if volume is attached to a vm in destroyed or expunging state; disallow
if (volume.getInstanceId() != null) {
final 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.KVM) {
final 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");
}
}
final 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;
}
use of com.cloud.storage.ScopeType in project cloudstack by apache.
the class VirtualMachineManagerImpl method isRootVolumeOnLocalStorage.
public boolean isRootVolumeOnLocalStorage(long vmId) {
ScopeType poolScope = ScopeType.ZONE;
List<VolumeVO> volumes = _volsDao.findByInstanceAndType(vmId, Type.ROOT);
if (CollectionUtils.isNotEmpty(volumes)) {
VolumeVO rootDisk = volumes.get(0);
Long poolId = rootDisk.getPoolId();
if (poolId != null) {
StoragePoolVO storagePoolVO = _storagePoolDao.findById(poolId);
poolScope = storagePoolVO.getScope();
}
}
return ScopeType.HOST == poolScope;
}
use of com.cloud.storage.ScopeType in project cloudstack by apache.
the class S3ImageStoreLifeCycleImpl method initialize.
@SuppressWarnings("unchecked")
@Override
public DataStore initialize(Map<String, Object> dsInfos) {
String url = (String) dsInfos.get("url");
String name = (String) dsInfos.get("name");
String providerName = (String) dsInfos.get("providerName");
ScopeType scope = (ScopeType) dsInfos.get("scope");
DataStoreRole role = (DataStoreRole) dsInfos.get("role");
Map<String, String> details = (Map<String, String>) dsInfos.get("details");
s_logger.info("Trying to add a S3 store with endpoint: " + details.get(ApiConstants.S3_END_POINT));
Map<String, Object> imageStoreParameters = new HashMap();
imageStoreParameters.put("name", name);
imageStoreParameters.put("url", url);
String protocol = "http";
String useHttps = details.get(ApiConstants.S3_HTTPS_FLAG);
if (useHttps != null && Boolean.parseBoolean(useHttps)) {
protocol = "https";
}
imageStoreParameters.put("protocol", protocol);
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());
}
use of com.cloud.storage.ScopeType in project cloudstack by apache.
the class QueryManagerImpl method searchForStoragePoolsInternal.
private Pair<List<StoragePoolJoinVO>, Integer> searchForStoragePoolsInternal(ListStoragePoolsCmd cmd) {
ScopeType scopeType = null;
if (cmd.getScope() != null) {
try {
scopeType = Enum.valueOf(ScopeType.class, cmd.getScope().toUpperCase());
} catch (Exception e) {
throw new InvalidParameterValueException("Invalid scope type: " + cmd.getScope());
}
}
Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
Object id = cmd.getId();
Object name = cmd.getStoragePoolName();
Object path = cmd.getPath();
Object pod = cmd.getPodId();
Object cluster = cmd.getClusterId();
Object address = cmd.getIpAddress();
Object keyword = cmd.getKeyword();
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
Filter searchFilter = new Filter(StoragePoolJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
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);
sb.and("parent", sb.entity().getParent(), Op.EQ);
SearchCriteria<StoragePoolJoinVO> sc = sb.create();
if (keyword != null) {
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) {
SearchCriteria<StoragePoolJoinVO> ssc = _poolJoinDao.createSearchCriteria();
ssc.addOr("podId", Op.EQ, pod);
ssc.addOr("podId", Op.NULL);
sc.addAnd("podId", SearchCriteria.Op.SC, ssc);
}
if (address != null) {
sc.setParameters("hostAddress", address);
}
if (cluster != null) {
SearchCriteria<StoragePoolJoinVO> ssc = _poolJoinDao.createSearchCriteria();
ssc.addOr("clusterId", Op.EQ, cluster);
ssc.addOr("clusterId", Op.NULL);
sc.addAnd("clusterId", SearchCriteria.Op.SC, ssc);
}
if (scopeType != null) {
sc.setParameters("scope", scopeType.toString());
}
sc.setParameters("parent", 0);
// search Pool details by ids
Pair<List<StoragePoolJoinVO>, Integer> uniquePoolPair = _poolJoinDao.searchAndCount(sc, searchFilter);
Integer count = uniquePoolPair.second();
if (count.intValue() == 0) {
// empty result
return uniquePoolPair;
}
List<StoragePoolJoinVO> uniquePools = uniquePoolPair.first();
Long[] vrIds = new Long[uniquePools.size()];
int i = 0;
for (StoragePoolJoinVO v : uniquePools) {
vrIds[i++] = v.getId();
}
List<StoragePoolJoinVO> vrs = _poolJoinDao.searchByIds(vrIds);
return new Pair<List<StoragePoolJoinVO>, Integer>(vrs, count);
}
use of com.cloud.storage.ScopeType in project cloudstack by apache.
the class VmwareStorageMotionStrategy method getHostIdForVmAndHostGuidInTargetCluster.
private Pair<Long, String> getHostIdForVmAndHostGuidInTargetCluster(VirtualMachine vm, DataObject srcData, StoragePool sourcePool, DataObject destData, StoragePool targetPool) {
ScopeType sourceScopeType = srcData.getDataStore().getScope().getScopeType();
ScopeType targetScopeType = destData.getDataStore().getScope().getScopeType();
if (vm != null) {
return getHostIdForVmAndHostGuidInTargetClusterForAttachedVm(vm, targetPool, targetScopeType);
}
return getHostIdForVmAndHostGuidInTargetClusterForWorkerVm(sourcePool, sourceScopeType, targetPool, targetScopeType);
}
Aggregations