use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class NotAValidCommand method testModifyStoragePoolCommand.
@Test
public void testModifyStoragePoolCommand() {
final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final ModifyStoragePoolCommand modifyStorageCommand = new ModifyStoragePoolCommand(false, poolVO);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getHost()).thenReturn(xsHost);
final Answer answer = wrapper.execute(modifyStorageCommand, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class DateraHostListener method hostRemoved.
@Override
public boolean hostRemoved(long hostId, long clusterId) {
ClusterVO clusterVO = _clusterDao.findById(clusterId);
HostVO hostVO = _hostDao.findByIdIncludingRemoved(hostId);
String initiatorName = DateraUtil.INITIATOR_PREFIX + "-" + hostVO.getUuid();
int s_lockTimeInSeconds = 5;
GlobalLock lock = GlobalLock.getInternLock(clusterVO.getUuid());
if (!lock.lock(s_lockTimeInSeconds)) {
String errMsg = "Couldn't lock the DB on the following string: " + clusterVO.getUuid();
s_logger.debug(errMsg);
throw new CloudRuntimeException(errMsg);
}
try {
List<StoragePoolVO> storagePools = _storagePoolDao.findPoolsByProvider(DateraUtil.PROVIDER_NAME);
if (storagePools != null && storagePools.size() > 0) {
for (StoragePoolVO storagePool : storagePools) {
ClusterDetailsVO clusterDetail = _clusterDetailsDao.findDetail(clusterId, DateraUtil.getInitiatorGroupKey(storagePool.getId()));
String initiatorGroupName = clusterDetail != null ? clusterDetail.getValue() : null;
if (initiatorGroupName != null && DateraUtil.hostSupport_iScsi(hostVO)) {
DateraObject.DateraConnection conn = DateraUtil.getDateraConnection(storagePool.getId(), _storagePoolDetailsDao);
DateraObject.Initiator initiator = DateraUtil.getInitiator(conn, hostVO.getStorageUrl());
DateraObject.InitiatorGroup initiatorGroup = DateraUtil.getInitiatorGroup(conn, initiatorGroupName);
if (initiator != null && DateraUtil.isInitiatorPresentInGroup(initiator, initiatorGroup)) {
DateraUtil.removeInitiatorFromGroup(conn, initiator.getPath(), initiatorGroupName);
}
}
}
}
} catch (DateraObject.DateraError | UnsupportedEncodingException e) {
s_logger.warn("Error while removing host from initiator groups ", e);
} finally {
lock.unlock();
lock.releaseRef();
}
return true;
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class CloudStackPrimaryDataStoreDriverImpl method updateVolumePathDetails.
private void updateVolumePathDetails(VolumeObject vol, ResizeVolumeAnswer answer) {
VolumeVO volumeVO = volumeDao.findById(vol.getId());
String datastoreUUID = answer.getContextParam("datastoreUUID");
if (datastoreUUID != null) {
StoragePoolVO storagePoolVO = primaryStoreDao.findByUuid(datastoreUUID);
if (storagePoolVO != null) {
volumeVO.setPoolId(storagePoolVO.getId());
} else {
s_logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreUUID, vol.getId()));
}
}
String volumePath = answer.getContextParam("volumePath");
if (volumePath != null) {
volumeVO.setPath(volumePath);
}
String chainInfo = answer.getContextParam("chainInfo");
if (chainInfo != null) {
volumeVO.setChainInfo(chainInfo);
}
volumeDao.update(volumeVO.getId(), volumeVO);
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class CloudStackPrimaryDataStoreDriverImpl method copyAsync.
@Override
public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
DataStore store = destData.getDataStore();
if (store.getRole() == DataStoreRole.Primary) {
if ((srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.TEMPLATE)) {
// For CLVM, we need to copy template to primary storage at all, just fake the copy result.
TemplateObjectTO templateObjectTO = new TemplateObjectTO();
templateObjectTO.setPath(UUID.randomUUID().toString());
templateObjectTO.setSize(srcdata.getSize());
templateObjectTO.setPhysicalSize(srcdata.getSize());
templateObjectTO.setFormat(Storage.ImageFormat.RAW);
CopyCmdAnswer answer = new CopyCmdAnswer(templateObjectTO);
CopyCommandResult result = new CopyCommandResult("", answer);
callback.complete(result);
} else if (srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.VOLUME) {
// For CLVM, we need to pass template on secondary storage to hypervisor
int primaryStorageDownloadWait = StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value();
StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId());
DataStore imageStore = templateManager.getImageStore(storagePoolVO.getDataCenterId(), srcdata.getId());
DataObject srcData = templateDataFactory.getTemplate(srcdata.getId(), imageStore);
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), primaryStorageDownloadWait, true);
EndPoint ep = epSelector.select(srcData, destData);
Answer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send CopyCommand, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
CopyCommandResult result = new CopyCommandResult("", answer);
callback.complete(result);
} else if (srcdata.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.VOLUME) {
SnapshotObjectTO srcTO = (SnapshotObjectTO) srcdata.getTO();
CopyCommand cmd = new CopyCommand(srcTO, destData.getTO(), StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value(), true);
EndPoint ep = epSelector.select(srcdata, destData);
CopyCmdAnswer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new CopyCmdAnswer(errMsg);
} else {
answer = (CopyCmdAnswer) ep.sendMessage(cmd);
}
CopyCommandResult result = new CopyCommandResult("", answer);
callback.complete(result);
}
}
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class LinstorPrimaryDataStoreDriverImpl method deleteAsync.
@Override
public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
s_logger.debug("deleteAsync: " + dataObject.getType() + ";" + dataObject.getUuid());
String errMsg = null;
final long storagePoolId = dataStore.getId();
final StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
switch(dataObject.getType()) {
case VOLUME:
{
final VolumeInfo volumeInfo = (VolumeInfo) dataObject;
final String rscName = LinstorUtil.RSC_PREFIX + volumeInfo.getPath();
deleteResourceDefinition(storagePool, rscName);
long usedBytes = storagePool.getUsedBytes();
long capacityIops = storagePool.getCapacityIops();
usedBytes -= volumeInfo.getSize();
if (volumeInfo.getMaxIops() != null)
capacityIops += volumeInfo.getMaxIops();
storagePool.setUsedBytes(Math.max(0, usedBytes));
storagePool.setCapacityIops(Math.max(0, capacityIops));
_storagePoolDao.update(storagePoolId, storagePool);
}
break;
case SNAPSHOT:
final SnapshotInfo snapshotInfo = (SnapshotInfo) dataObject;
final String rscName = LinstorUtil.RSC_PREFIX + snapshotInfo.getBaseVolume().getPath();
deleteSnapshot(dataStore, rscName, getSnapshotName(snapshotInfo.getUuid()));
long usedBytes = storagePool.getUsedBytes() - snapshotInfo.getSize();
storagePool.setUsedBytes(Math.max(0, usedBytes));
_storagePoolDao.update(storagePoolId, storagePool);
break;
default:
errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
s_logger.error(errMsg);
}
if (callback != null) {
CommandResult result = new CommandResult();
result.setResult(errMsg);
callback.complete(result);
}
}
Aggregations