use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class MockStorageManagerImpl method findVolumeFromSecondary.
private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
String volumePath = path.replaceAll(ssUrl, "");
MockSecStorageVO secStorage = _mockSecStorageDao.findByUrl(ssUrl);
if (secStorage == null) {
return null;
}
volumePath = secStorage.getMountPoint() + volumePath;
volumePath = volumePath.replaceAll("//", "/");
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(volumePath);
txn.commit();
if (volume == null) {
return null;
}
return volume;
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Unable to find volume " + path + " on secondary " + ssUrl, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class MockVmManagerImpl method getVms.
@Override
public Map<String, MockVMVO> getVms(final String hostGuid) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
final List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
final Map<String, MockVMVO> vmMap = new HashMap<String, MockVMVO>();
for (final MockVMVO vm : vms) {
vmMap.put(vm.getName(), vm);
}
txn.commit();
return vmMap;
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class MockVmManagerImpl method stopVM.
@Override
public StopAnswer stopVM(final StopCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
final String vmName = cmd.getVmName();
final MockVm vm = _mockVmDao.findByVmName(vmName);
if (vm != null) {
vm.setPowerState(PowerState.PowerOff);
_mockVmDao.update(vm.getId(), (MockVMVO) vm);
}
if (vmName.startsWith("s-")) {
_mockAgentMgr.handleSystemVMStop(vm.getId());
}
txn.commit();
return new StopAnswer(cmd, null, true);
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class MockStorageManagerImpl method GetStorageStats.
@Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
String uuid = cmd.getStorageId();
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
if (uuid == null) {
String secUrl = cmd.getSecUrl();
MockSecStorageVO secondary = _mockSecStorageDao.findByUrl(secUrl);
if (secondary == null) {
return new GetStorageStatsAnswer(cmd, "Can't find the secondary storage:" + secUrl);
}
Long totalUsed = _mockVolumeDao.findTotalStorageId(secondary.getId());
txn.commit();
return new GetStorageStatsAnswer(cmd, secondary.getCapacity(), totalUsed);
} else {
MockStoragePoolVO pool = _mockStoragePoolDao.findByUuid(uuid);
if (pool == null) {
return new GetStorageStatsAnswer(cmd, "Can't find the pool");
}
Long totalUsed = _mockVolumeDao.findTotalStorageId(pool.getId());
if (totalUsed == null) {
totalUsed = 0L;
}
txn.commit();
return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
}
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("DBException during storage stats collection for pool " + uuid, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class MockStorageManagerImpl method ListTemplates.
@Override
public Answer ListTemplates(ListTemplateCommand cmd) {
DataStoreTO store = cmd.getDataStore();
if (!(store instanceof NfsTO)) {
return new Answer(cmd, false, "Unsupported image data store: " + store);
}
MockSecStorageVO storage = null;
String nfsUrl = ((NfsTO) store).getUrl();
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
storage = _mockSecStorageDao.findByUrl(nfsUrl);
try {
txn.start();
List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.TEMPLATE);
Map<String, TemplateProp> templateInfos = new HashMap<String, TemplateProp>();
for (MockVolumeVO template : templates) {
templateInfos.put(template.getName(), new TemplateProp(template.getName(), template.getPath().replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
}
return new ListTemplateAnswer(nfsUrl, templateInfos);
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when finding template on sec storage " + storage.getId(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
Aggregations