use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method ListVolumes.
@Override
public Answer ListVolumes(ListVolumeCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockSecStorageVO storage = null;
try {
txn.start();
storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
if (storage == null) {
return new Answer(cmd, false, "Failed to get secondary storage");
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when finding sec storage " + cmd.getSecUrl(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
List<MockVolumeVO> volumes = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.VOLUME);
Map<Long, TemplateProp> templateInfos = new HashMap<Long, TemplateProp>();
for (MockVolumeVO volume : volumes) {
templateInfos.put(volume.getId(), new TemplateProp(volume.getName(), volume.getPath().replaceAll(storage.getMountPoint(), ""), volume.getSize(), volume.getSize(), true, false));
}
txn.commit();
return new ListVolumeAnswer(cmd.getSecUrl(), 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();
}
}
use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method ComputeChecksum.
@Override
public Answer ComputeChecksum(ComputeChecksumCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockVolumeVO volume = _mockVolumeDao.findByName(cmd.getTemplatePath());
if (volume == null) {
return new Answer(cmd, false, "cant' find volume:" + cmd.getTemplatePath());
}
String md5 = null;
try {
MessageDigest md = MessageDigest.getInstance("md5");
md5 = String.format("%032x", new BigInteger(1, md.digest(cmd.getTemplatePath().getBytes())));
} catch (NoSuchAlgorithmException e) {
s_logger.debug("failed to gernerate md5:" + e.toString());
}
txn.commit();
return new Answer(cmd, true, md5);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.simulator.MockVolumeVO 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.simulator.MockVolumeVO 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();
}
}
use of com.cloud.simulator.MockVolumeVO in project cloudstack by apache.
the class MockStorageManagerImpl method Delete.
@Override
public Answer Delete(DeleteCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockVolumeVO template = _mockVolumeDao.findByStoragePathAndType(cmd.getData().getPath());
if (template == null) {
return new Answer(cmd, false, "can't find object to delete:" + cmd.getData().getPath());
}
_mockVolumeDao.remove(template.getId());
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when deleting object");
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new Answer(cmd);
}
Aggregations