use of com.cloud.simulator.MockSecStorageVO 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.MockSecStorageVO in project cloudstack by apache.
the class MockStorageManagerImpl method handleConfigDriveIso.
@Override
public Answer handleConfigDriveIso(HandleConfigDriveIsoCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockSecStorageVO sec;
try {
txn.start();
sec = _mockSecStorageDao.findByUrl(cmd.getDestStore().getUrl());
if (sec == null) {
return new Answer(cmd, false, "can't find secondary storage");
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when creating config drive.");
} 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() + cmd.getIsoFile());
template.setPoolId(sec.getId());
template.setSize((long) (Math.random() * 200L) + 200L);
template.setStatus(Status.DOWNLOADED);
template.setType(MockVolumeType.ISO);
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 config drive " + template.getName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new Answer(cmd);
}
use of com.cloud.simulator.MockSecStorageVO in project cloudstack by apache.
the class MockStorageManagerImpl method SecStorageSetup.
@Override
public Answer SecStorageSetup(SecStorageSetupCommand 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, "can't find the storage");
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when setting up sec storage" + cmd.getSecUrl(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new SecStorageSetupAnswer(storage.getMountPoint());
}
use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method ListTemplates.
@Override
public Answer ListTemplates(ListTemplateCommand cmd) {
MockSecStorageVO storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
if (storage == null) {
return new Answer(cmd, false, "Failed to get secondary storage");
}
List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.TEMPLATE);
Map<String, TemplateInfo> templateInfos = new HashMap<String, TemplateInfo>();
for (MockVolumeVO template : templates) {
templateInfos.put(template.getName(), new TemplateInfo(template.getName(), template.getPath().replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
}
return new ListTemplateAnswer(cmd.getSecUrl(), templateInfos);
}
use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method preinstallTemplates.
@Override
public void preinstallTemplates(String url, long zoneId) {
MockSecStorageVO 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/9/" + UUID.randomUUID().toString());
template.setPoolId(storage.getId());
template.setSize(defaultTemplateSize);
template.setType(MockVolumeType.TEMPLATE);
template.setStatus(Status.DOWNLOADED);
_mockVolumeDao.persist(template);
template = new MockVolumeVO();
template.setName("simulator-Centos");
template.setPath(storage.getMountPoint() + "template/tmpl/1/10/" + UUID.randomUUID().toString());
template.setPoolId(storage.getId());
template.setSize(defaultTemplateSize);
template.setType(MockVolumeType.TEMPLATE);
template.setStatus(Status.DOWNLOADED);
_mockVolumeDao.persist(template);
}
}
Aggregations