use of com.cloud.simulator.MockSecStorageVO in project cloudstack by apache.
the class MockStorageManagerImpl method preinstallTemplates.
@Override
public void preinstallTemplates(String url, long zoneId) {
MockSecStorageVO storage = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
storage = _mockSecStorageDao.findByUrl(url);
if (storage == null) {
storage = new MockSecStorageVO();
URI uri;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
return;
}
String nfsHost = uri.getHost();
String nfsPath = uri.getPath();
String path = nfsHost + ":" + nfsPath;
String dir = "/mnt/" + UUID.nameUUIDFromBytes(path.getBytes()).toString() + File.separator;
storage.setUrl(url);
storage.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
storage.setMountPoint(dir);
storage = _mockSecStorageDao.persist(storage);
// preinstall default templates into secondary storage
long defaultTemplateSize = 2 * 1024 * 1024 * 1024L;
MockVolumeVO template = new MockVolumeVO();
template.setName("simulator-domR");
template.setPath(storage.getMountPoint() + "template/tmpl/1/100/" + UUID.randomUUID().toString());
template.setPoolId(storage.getId());
template.setSize(defaultTemplateSize);
template.setType(MockVolumeType.TEMPLATE);
template.setStatus(Status.DOWNLOADED);
template = _mockVolumeDao.persist(template);
template = new MockVolumeVO();
template.setName("simulator-Centos");
template.setPath(storage.getMountPoint() + "template/tmpl/1/111/" + UUID.randomUUID().toString());
template.setPoolId(storage.getId());
template.setSize(defaultTemplateSize);
template.setType(MockVolumeType.TEMPLATE);
template.setStatus(Status.DOWNLOADED);
template = _mockVolumeDao.persist(template);
txn.commit();
}
} catch (Exception ex) {
throw new CloudRuntimeException("Unable to find sec storage at " + url, ex);
} finally {
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.simulator.MockSecStorageVO 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.simulator.MockSecStorageVO 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.MockSecStorageVO 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.MockSecStorageVO in project cloudstack by apache.
the class MockStorageManagerImpl method CreatePrivateTemplateFromVolume.
@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO volume = null;
MockSecStorageVO sec = null;
try {
txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
if (volume == null) {
return new CreatePrivateTemplateAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath());
}
sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageUrl());
if (sec == null) {
return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when creating private template from volume");
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
MockVolumeVO template = new MockVolumeVO();
String uuid = UUID.randomUUID().toString();
template.setName(uuid);
template.setPath(sec.getMountPoint() + uuid);
template.setPoolId(sec.getId());
template.setSize(volume.getSize());
template.setStatus(Status.DOWNLOADED);
template.setType(MockVolumeType.TEMPLATE);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
template = _mockVolumeDao.persist(template);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when persisting template " + template.getName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new CreatePrivateTemplateAnswer(cmd, true, "", template.getName(), template.getSize(), template.getSize(), template.getName(), ImageFormat.QCOW2);
}
Aggregations