use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class NexentaPrimaryDataStoreDriver method createAsync.
@Override
public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) {
String iqn = null;
String errorMessage = null;
if (dataObject.getType() != DataObjectType.VOLUME) {
errorMessage = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync";
} else {
VolumeInfo volumeInfo = (VolumeInfo) dataObject;
long storagePoolId = dataStore.getId();
NexentaStorAppliance appliance = getNexentaStorAppliance(storagePoolId);
// TODO: maybe we should use md5(volume name) as volume name
NexentaStorZvol zvol = (NexentaStorZvol) appliance.createVolume(volumeInfo.getName(), volumeInfo.getSize());
iqn = zvol.getIqn();
VolumeVO volume = this._volumeDao.findById(volumeInfo.getId());
volume.set_iScsiName(iqn);
volume.setFolder(zvol.getName());
volume.setPoolType(Storage.StoragePoolType.IscsiLUN);
volume.setPoolId(storagePoolId);
_volumeDao.update(volume.getId(), volume);
StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
long capacityBytes = storagePool.getCapacityBytes();
long usedBytes = storagePool.getUsedBytes();
usedBytes += volumeInfo.getSize();
storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes);
_storagePoolDao.update(storagePoolId, storagePool);
}
CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errorMessage == null, errorMessage));
result.setResult(errorMessage);
callback.complete(result);
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class ElastistorPrimaryDataStoreDriver method deleteAsync.
@Override
public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
String errMsg = null;
StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
if (!(storagePool.isManaged())) {
super.deleteAsync(dataStore, dataObject, callback);
return;
}
if (dataObject.getType() == DataObjectType.VOLUME) {
VolumeInfo volumeInfo = (VolumeInfo) dataObject;
long storagePoolId = dataStore.getId();
boolean result = false;
try {
result = ElastistorUtil.deleteElastistorVolume(volumeInfo.getUuid());
} catch (Throwable e) {
e.printStackTrace();
CommandResult result2 = new CommandResult();
result2.setResult(e.toString());
callback.complete(result2);
}
if (result) {
long usedBytes = storagePool.getUsedBytes();
long capacityIops = storagePool.getCapacityIops();
usedBytes -= volumeInfo.getSize();
capacityIops += volumeInfo.getMaxIops();
storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
storagePool.setCapacityIops(capacityIops < 0 ? 0 : capacityIops);
_storagePoolDao.update(storagePoolId, storagePool);
} else {
errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
}
} else {
errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
}
CommandResult result = new CommandResult();
result.setResult(errMsg);
callback.complete(result);
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class ElastistorPrimaryDataStoreDriver method resize.
@Override
public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
s_logger.debug("Resize elastistor volume started");
Boolean status = false;
VolumeObject vol = (VolumeObject) data;
StoragePool pool = (StoragePool) data.getDataStore();
ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
CreateCmdResult result = new CreateCmdResult(null, null);
StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());
if (!(poolVO.isManaged())) {
super.resize(data, callback);
return;
}
try {
status = ElastistorUtil.updateElastistorVolumeSize(vol.getUuid(), resizeParameter.newSize);
} catch (Throwable e) {
s_logger.error("Resize elastistor volume failed, please contact elastistor admin.", e);
result.setResult(e.toString());
callback.complete(result);
}
if (status) {
// now updating the cloudstack storagepool usedbytes and volume
Long usedBytes = poolVO.getUsedBytes();
Long currentVolumeSize = vol.getSize();
Long newUsedBytes;
if (currentVolumeSize < resizeParameter.newSize) {
newUsedBytes = usedBytes + (resizeParameter.newSize - currentVolumeSize);
poolVO.setUsedBytes(newUsedBytes);
} else {
newUsedBytes = usedBytes - (currentVolumeSize - resizeParameter.newSize);
poolVO.setUsedBytes(newUsedBytes);
}
_storagePoolDao.update(pool.getId(), poolVO);
vol.getVolume().setSize(resizeParameter.newSize);
vol.update();
callback.complete(result);
} else {
callback.complete(result);
}
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class ManagementServerImpl method searchForSystemVm.
@Override
public Pair<List<? extends VirtualMachine>, Integer> searchForSystemVm(final ListSystemVMsCmd cmd) {
final String type = cmd.getSystemVmType();
final Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
final Long id = cmd.getId();
final String name = cmd.getSystemVmName();
final String state = cmd.getState();
final String keyword = cmd.getKeyword();
final Long podId = cmd.getPodId();
final Long hostId = cmd.getHostId();
final Long storageId = cmd.getStorageId();
final Filter searchFilter = new Filter(VMInstanceVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
final SearchBuilder<VMInstanceVO> sb = _vmInstanceDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("hostName", sb.entity().getHostName(), SearchCriteria.Op.LIKE);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("podId", sb.entity().getPodIdToDeployIn(), SearchCriteria.Op.EQ);
sb.and("hostId", sb.entity().getHostId(), SearchCriteria.Op.EQ);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
sb.and("nulltype", sb.entity().getType(), SearchCriteria.Op.IN);
if (storageId != null) {
StoragePoolVO storagePool = _primaryDataStoreDao.findById(storageId);
if (storagePool.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
final SearchBuilder<VolumeVO> volumeSearch = _volumeDao.createSearchBuilder();
volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), SearchCriteria.Op.IN);
sb.join("volumeSearch", volumeSearch, sb.entity().getId(), volumeSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
} else {
final SearchBuilder<VolumeVO> volumeSearch = _volumeDao.createSearchBuilder();
volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
sb.join("volumeSearch", volumeSearch, sb.entity().getId(), volumeSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
}
}
final SearchCriteria<VMInstanceVO> sc = sb.create();
if (keyword != null) {
final SearchCriteria<VMInstanceVO> ssc = _vmInstanceDao.createSearchCriteria();
ssc.addOr("hostName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("state", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("hostName", SearchCriteria.Op.SC, ssc);
}
if (id != null) {
sc.setParameters("id", id);
}
if (name != null) {
sc.setParameters("hostName", name);
}
if (state != null) {
sc.setParameters("state", state);
}
if (zoneId != null) {
sc.setParameters("dataCenterId", zoneId);
}
if (podId != null) {
sc.setParameters("podId", podId);
}
if (hostId != null) {
sc.setParameters("hostId", hostId);
}
if (type != null) {
sc.setParameters("type", type);
} else {
sc.setParameters("nulltype", VirtualMachine.Type.SecondaryStorageVm, VirtualMachine.Type.ConsoleProxy);
}
if (storageId != null) {
StoragePoolVO storagePool = _primaryDataStoreDao.findById(storageId);
if (storagePool.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
List<StoragePoolVO> childDataStores = _primaryDataStoreDao.listChildStoragePoolsInDatastoreCluster(storageId);
List<Long> childDatastoreIds = childDataStores.stream().map(mo -> mo.getId()).collect(Collectors.toList());
sc.setJoinParameters("volumeSearch", "poolId", childDatastoreIds.toArray());
} else {
sc.setJoinParameters("volumeSearch", "poolId", storageId);
}
}
final Pair<List<VMInstanceVO>, Integer> result = _vmInstanceDao.searchAndCount(sc, searchFilter);
return new Pair<List<? extends VirtualMachine>, Integer>(result.first(), result.second());
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class ManagementServerImpl method getHypervisorType.
private HypervisorType getHypervisorType(VMInstanceVO vm, StoragePool srcVolumePool) {
HypervisorType type = null;
if (vm == null) {
StoragePoolVO poolVo = _poolDao.findById(srcVolumePool.getId());
if (ScopeType.CLUSTER.equals(poolVo.getScope())) {
Long clusterId = poolVo.getClusterId();
if (clusterId != null) {
ClusterVO cluster = _clusterDao.findById(clusterId);
type = cluster.getHypervisorType();
}
}
if (null == type) {
type = srcVolumePool.getHypervisor();
}
} else {
type = vm.getHypervisorType();
}
return type;
}
Aggregations