use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method CopyVolume.
@Override
public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
boolean toSecondaryStorage = cmd.toSecondaryStorage();
MockSecStorageVO sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageURL());
if (sec == null) {
return new CopyVolumeAnswer(cmd, false, "can't find secondary storage", null, null);
}
MockStoragePoolVO primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
if (primaryStorage == null) {
return new CopyVolumeAnswer(cmd, false, "Can't find primary storage", null, null);
}
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
if (volume == null) {
return new CopyVolumeAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath(), null, null);
}
String name = UUID.randomUUID().toString();
if (toSecondaryStorage) {
MockVolumeVO vol = new MockVolumeVO();
vol.setName(name);
vol.setPath(sec.getMountPoint() + name);
vol.setPoolId(sec.getId());
vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME);
vol = _mockVolumeDao.persist(vol);
return new CopyVolumeAnswer(cmd, true, null, sec.getMountPoint(), vol.getPath());
} else {
MockVolumeVO vol = new MockVolumeVO();
vol.setName(name);
vol.setPath(primaryStorage.getMountPoint() + name);
vol.setPoolId(primaryStorage.getId());
vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME);
vol = _mockVolumeDao.persist(vol);
return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());
}
}
use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method GetStorageStats.
@Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
String uuid = cmd.getStorageId();
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());
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;
}
return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
}
}
use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method CreatePrivateTemplateFromSnapshot.
@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromSnapshot(CreatePrivateTemplateFromSnapshotCommand cmd) {
String snapshotUUId = cmd.getSnapshotUuid();
MockVolumeVO snapshot = _mockVolumeDao.findByName(snapshotUUId);
if (snapshot == null) {
snapshotUUId = cmd.getSnapshotName();
snapshot = _mockVolumeDao.findByName(snapshotUUId);
if (snapshot == null) {
return new CreatePrivateTemplateAnswer(cmd, false, "can't find snapshot:" + snapshotUUId);
}
}
MockSecStorageVO sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageUrl());
if (sec == null) {
return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
}
MockVolumeVO template = new MockVolumeVO();
String uuid = UUID.randomUUID().toString();
template.setName(uuid);
template.setPath(sec.getMountPoint() + uuid);
template.setPoolId(sec.getId());
template.setSize(snapshot.getSize());
template.setStatus(Status.DOWNLOADED);
template.setType(MockVolumeType.TEMPLATE);
template = _mockVolumeDao.persist(template);
return new CreatePrivateTemplateAnswer(cmd, true, "", template.getName(), template.getSize(), template.getSize(), template.getName(), ImageFormat.QCOW2);
}
use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method findVolumeFromSecondary.
private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
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);
if (volume == null) {
return null;
}
return volume;
}
use of com.cloud.simulator.MockSecStorageVO in project cloudstack by apache.
the class MockStorageManagerImpl method CopyVolume.
@Override
public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
boolean toSecondaryStorage = cmd.toSecondaryStorage();
MockSecStorageVO sec = null;
MockStoragePoolVO primaryStorage = null;
try {
txn.start();
sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageURL());
if (sec == null) {
return new CopyVolumeAnswer(cmd, false, "can't find secondary storage", null, null);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing secondary at " + cmd.getSecondaryStorageURL(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
if (primaryStorage == null) {
return new CopyVolumeAnswer(cmd, false, "Can't find primary storage", null, null);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing primary at " + cmd.getPool(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
MockVolumeVO volume = null;
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
if (volume == null) {
return new CopyVolumeAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath(), null, null);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing volume at " + cmd.getVolumePath(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
String name = UUID.randomUUID().toString();
if (toSecondaryStorage) {
MockVolumeVO vol = new MockVolumeVO();
vol.setName(name);
vol.setPath(sec.getMountPoint() + name);
vol.setPoolId(sec.getId());
vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
vol = _mockVolumeDao.persist(vol);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when persisting volume " + vol.getName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new CopyVolumeAnswer(cmd, true, null, sec.getMountPoint(), vol.getPath());
} else {
MockVolumeVO vol = new MockVolumeVO();
vol.setName(name);
vol.setPath(primaryStorage.getMountPoint() + name);
vol.setPoolId(primaryStorage.getId());
vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
vol = _mockVolumeDao.persist(vol);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when persisting volume " + vol.getName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());
}
}
Aggregations