Search in sources :

Example 11 with MockVMVO

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 };
}
Also used : HashMap(java.util.HashMap) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) RouterPrivateIpStrategy(com.cloud.network.Networks.RouterPrivateIpStrategy) MockVMVO(com.cloud.simulator.MockVMVO) StartupCommand(com.cloud.agent.api.StartupCommand) State(com.cloud.vm.VirtualMachine.State) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with MockVMVO

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);
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) MockHost(com.cloud.simulator.MockHost)

Example 13 with MockVMVO

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;
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) State(com.cloud.vm.VirtualMachine.State) MockVm(com.cloud.simulator.MockVm)

Example 14 with MockVMVO

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;
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 15 with MockVMVO

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();
    }
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) MockHost(com.cloud.simulator.MockHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostStatsEntry(com.cloud.agent.api.HostStatsEntry) DiscoveryException(com.cloud.exception.DiscoveryException) PatternSyntaxException(java.util.regex.PatternSyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

MockVMVO (com.cloud.simulator.MockVMVO)21 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 ConfigurationException (javax.naming.ConfigurationException)10 MockHost (com.cloud.simulator.MockHost)6 HashMap (java.util.HashMap)6 MockVm (com.cloud.simulator.MockVm)5 Answer (com.cloud.agent.api.Answer)4 MockVolumeVO (com.cloud.simulator.MockVolumeVO)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AttachVolumeAnswer (com.cloud.agent.api.AttachVolumeAnswer)3 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)3 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)3 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)3 ManageSnapshotAnswer (com.cloud.agent.api.ManageSnapshotAnswer)3 MigrateAnswer (com.cloud.agent.api.MigrateAnswer)3 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)3 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)3 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)2 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)2