Package com.cloud.simulator

Examples of com.cloud.simulator.MockHost


    }

    @Override
    public StoragePoolInfo getLocalStorage(String hostGuid) {
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        MockHost host = null;
        MockStoragePoolVO storagePool = null;
        try {
            txn.start();
            host = _mockHostDao.findByGuid(hostGuid);
            storagePool = _mockStoragePoolDao.findByHost(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 (storagePool == null) {
            String uuid = UUID.randomUUID().toString();
            storagePool = new MockStoragePoolVO();
            storagePool.setUuid(uuid);
            storagePool.setMountPoint("/mnt/" + uuid + File.separator);
            storagePool.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
            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);
    }
View Full Code Here


    }

    @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 + File.separator);
            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);
    }
View Full Code Here

    @Override
    public MockHost getHost(String guid) {
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
            MockHost _host = _mockHostDao.findByGuid(guid);
            txn.commit();
            if (_host != null) {
                return _host;
            } else {
                s_logger.error("Host with guid " + guid + " was not found");
View Full Code Here

    }

    @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();
View Full Code Here

        private void handleSystemVMStop() {
            TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
            try {
                if (this.mode.equalsIgnoreCase("Stop")) {
                    txn.start();
                    MockHost host = _mockHostDao.findByVmId(this.vmId);
                    if (host != null) {
                        String guid = host.getGuid();
                        if (guid != null) {
                            AgentResourceBase res = _resources.get(guid);
                            if (res != null) {
                                res.stop();
                                _resources.remove(guid);
                            }
                        }
                    }
                    txn.commit();
                    return;
                }
            } catch (Exception ex) {
                txn.rollback();
                throw new CloudRuntimeException("Unable to get host " + guid + " due to " + ex.getMessage(), ex);
            } finally {
                txn.close();
                txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
                txn.close();
            }

            //stop ssvm agent
            HostVO host = hostDao.findByGuid(this.guid);
            if (host != null) {
                try {
                    _resourceMgr.deleteHost(host.getId(), true, true);
                } catch (Exception e) {
                    s_logger.debug("Failed to delete host: ", e);
                }
            }
        }
View Full Code Here

    @DB
    @Override
    public Answer simulate(Command cmd, String hostGuid) {
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            MockHost host = _mockHost.findByGuid(hostGuid);
            String cmdName = cmd.toString();
            int index = cmdName.lastIndexOf(".");
            if (index != -1) {
                cmdName = cmdName.substring(index + 1);
            }
            MockConfigurationVO config = _mockConfigDao.findByNameBottomUP(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), cmdName);

            SimulatorInfo info = new SimulatorInfo();
            info.setHostUuid(hostGuid);

            if (config != null) {
View Full Code Here

TOP

Related Classes of com.cloud.simulator.MockHost

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.