use of com.cloud.simulator.MockHost in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method getLocalStorage.
@Override
public StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize) {
MockHost host = _mockHostDao.findByGuid(hostGuid);
if (storageSize == null) {
storageSize = DEFAULT_HOST_STORAGE_SIZE;
}
MockStoragePoolVO storagePool = _mockStoragePoolDao.findByHost(hostGuid);
if (storagePool == null) {
String uuid = UUID.randomUUID().toString();
storagePool = new MockStoragePoolVO();
storagePool.setUuid(uuid);
storagePool.setMountPoint("/mnt/" + uuid + File.separator);
storagePool.setCapacity(storageSize);
storagePool.setHostGuid(hostGuid);
storagePool.setStorageType(StoragePoolType.Filesystem);
storagePool = _mockStoragePoolDao.persist(storagePool);
}
return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), 0);
}
use of com.cloud.simulator.MockHost in project CloudStack-archive by CloudStack-extras.
the class MockVmManagerImpl method Migrate.
@Override
public MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info) {
String vmName = cmd.getVmName();
String destGuid = cmd.getHostGuid();
MockVMVO vm = _mockVmDao.findByVmNameAndHost(vmName, info.getHostUuid());
if (vm == null) {
return new MigrateAnswer(cmd, false, "can;t find vm:" + vmName + " on host:" + info.getHostUuid(), null);
}
MockHost destHost = _mockHostDao.findByGuid(destGuid);
if (destHost == null) {
return new MigrateAnswer(cmd, false, "can;t find host:" + info.getHostUuid(), null);
}
vm.setHostId(destHost.getId());
_mockVmDao.update(vm.getId(), vm);
return new MigrateAnswer(cmd, true, null, 0);
}
use of com.cloud.simulator.MockHost in project cloudstack by apache.
the class MockAgentManagerImpl method getHostStatistic.
@Override
public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) {
String hostGuid = cmd.getHostGuid();
MockHost host = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
host = _mockHostDao.findByGuid(hostGuid);
txn.commit();
if (host == null) {
return null;
}
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Unable to get host " + hostGuid + " due to " + ex.getMessage(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
TransactionLegacy vmtxn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
vmtxn.start();
List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId());
vmtxn.commit();
double usedMem = 0.0;
double usedCpu = 0.0;
for (MockVMVO vm : vms) {
usedMem += vm.getMemory();
usedCpu += vm.getCpu();
}
HostStatsEntry hostStats = new HostStatsEntry();
hostStats.setTotalMemoryKBs(host.getMemorySize());
hostStats.setFreeMemoryKBs(host.getMemorySize() - usedMem);
hostStats.setNetworkReadKBs(32768);
hostStats.setNetworkWriteKBs(16384);
hostStats.setCpuUtilization(usedCpu / (host.getCpuCount() * host.getCpuSpeed()));
hostStats.setEntityType("simulator-host");
hostStats.setHostId(cmd.getHostId());
return new GetHostStatsAnswer(cmd, hostStats);
} catch (Exception ex) {
vmtxn.rollback();
throw new CloudRuntimeException("Unable to get Vms on host " + host.getGuid() + " due to " + ex.getMessage(), ex);
} finally {
vmtxn.close();
vmtxn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
vmtxn.close();
}
}
use of com.cloud.simulator.MockHost in project cloudstack by apache.
the class MockStorageManagerImpl method getLocalStorage.
@Override
public StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockHost host = null;
try {
txn.start();
host = _mockHostDao.findByGuid(hostGuid);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
if (storageSize == null) {
storageSize = DEFAULT_HOST_STORAGE_SIZE;
}
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockStoragePoolVO storagePool = null;
try {
txn.start();
storagePool = _mockStoragePoolDao.findByHost(hostGuid);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when finding storagePool " + storagePool, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
if (storagePool == null) {
String uuid = UUID.randomUUID().toString();
storagePool = new MockStoragePoolVO();
storagePool.setUuid(uuid);
storagePool.setMountPoint("/mnt/" + uuid);
storagePool.setCapacity(storageSize);
storagePool.setHostGuid(hostGuid);
storagePool.setStorageType(StoragePoolType.Filesystem);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
storagePool = _mockStoragePoolDao.persist(storagePool);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), 0);
}
use of com.cloud.simulator.MockHost in project cloudstack by apache.
the class MockVmManagerImpl method migrate.
@Override
public MigrateAnswer migrate(final MigrateCommand cmd, final SimulatorInfo info) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
final String vmName = cmd.getVmName();
final String destGuid = cmd.getHostGuid();
final MockVMVO vm = _mockVmDao.findByVmNameAndHost(vmName, info.getHostUuid());
if (vm == null) {
return new MigrateAnswer(cmd, false, "can't find vm:" + vmName + " on host:" + info.getHostUuid(), null);
}
final MockHost destHost = _mockHostDao.findByGuid(destGuid);
if (destHost == null) {
return new MigrateAnswer(cmd, false, "can't find destination host:" + destGuid, null);
}
vm.setHostId(destHost.getId());
_mockVmDao.update(vm.getId(), vm);
txn.commit();
return new MigrateAnswer(cmd, true, null, 0);
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("unable to migrate vm " + cmd.getVmName(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
Aggregations