use of com.cloud.simulator.MockVMVO in project CloudStack-archive by CloudStack-extras.
the class AgentRoutingResource method initialize.
@Override
public StartupCommand[] initialize() {
synchronized (_vms) {
_vms.clear();
}
Map<String, State> changes = _simMgr.getVmStates(this.hostGuid);
Map<String, MockVMVO> vmsMaps = _simMgr.getVms(this.hostGuid);
totalCpu = agentHost.getCpuCount() * agentHost.getCpuSpeed();
totalMem = agentHost.getMemorySize();
for (Map.Entry<String, MockVMVO> entry : vmsMaps.entrySet()) {
MockVMVO vm = entry.getValue();
usedCpu += vm.getCpu();
usedMem += vm.getMemory();
_runningVms.put(entry.getKey(), new Pair<Long, Long>(Long.valueOf(vm.getCpu()), vm.getMemory()));
}
List<Object> info = getHostInfo();
StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(2), (Long) info.get(4), (String) info.get(3), HypervisorType.Simulator, RouterPrivateIpStrategy.HostLocal);
cmd.setStateChanges(changes);
Map<String, String> hostDetails = new HashMap<String, String>();
hostDetails.put(RouterPrivateIpStrategy.class.getCanonicalName(), RouterPrivateIpStrategy.DcGlobal.toString());
cmd.setHostDetails(hostDetails);
cmd.setAgentTag("agent-simulator");
cmd.setPrivateIpAddress(agentHost.getPrivateIpAddress());
cmd.setPrivateNetmask(agentHost.getPrivateNetMask());
cmd.setPrivateMacAddress(agentHost.getPrivateMacAddress());
cmd.setStorageIpAddress(agentHost.getStorageIpAddress());
cmd.setStorageNetmask(agentHost.getStorageNetMask());
cmd.setStorageMacAddress(agentHost.getStorageMacAddress());
cmd.setStorageIpAddressDeux(agentHost.getStorageIpAddress());
cmd.setStorageNetmaskDeux(agentHost.getStorageNetMask());
cmd.setStorageMacAddressDeux(agentHost.getStorageIpAddress());
cmd.setName(agentHost.getName());
cmd.setGuid(agentHost.getGuid());
cmd.setVersion(agentHost.getVersion());
cmd.setAgentTag("agent-simulator");
cmd.setDataCenter(String.valueOf(agentHost.getDataCenterId()));
cmd.setPod(String.valueOf(agentHost.getPodId()));
cmd.setCluster(String.valueOf(agentHost.getClusterId()));
StartupStorageCommand ssCmd = initializeLocalSR();
return new StartupCommand[] { cmd, ssCmd };
}
use of com.cloud.simulator.MockVMVO 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.MockVMVO in project CloudStack-archive by CloudStack-extras.
the class MockVmManagerImpl method getVmStates.
@Override
public Map<String, State> getVmStates(String hostGuid) {
Map<String, State> states = new HashMap<String, State>();
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
if (vms.isEmpty()) {
return states;
}
for (MockVm vm : vms) {
states.put(vm.getName(), vm.getState());
}
return states;
}
use of com.cloud.simulator.MockVMVO in project CloudStack-archive by CloudStack-extras.
the class MockVmManagerImpl method getVms.
@Override
public Map<String, MockVMVO> getVms(String hostGuid) {
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
Map<String, MockVMVO> vmMap = new HashMap<String, MockVMVO>();
for (MockVMVO vm : vms) {
vmMap.put(vm.getName(), vm);
}
return vmMap;
}
use of com.cloud.simulator.MockVMVO 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();
}
}
Aggregations