Package com.cloud.simulator

Examples of com.cloud.simulator.MockHost


    public String startVM(String vmName, NicTO[] nics,
            int cpuHz, long ramSize,
            String bootArgs, String hostGuid) {

        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        MockHost host = null;
        MockVm vm = null;
        try {
            txn.start();
            host = _mockHostDao.findByGuid(hostGuid);
            if (host == null) {
                return "can't find host";
            }

            vm = _mockVmDao.findByVmName(vmName);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Unable to start VM " + vmName, ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        if(vm == null) {
            int vncPort = 0;
            if(vncPort < 0)
                return "Unable to allocate VNC port";
            vm = new MockVMVO();
            vm.setCpu(cpuHz);
            vm.setMemory(ramSize);
            vm.setState(State.Running);
            vm.setName(vmName);
            vm.setVncPort(vncPort);
            vm.setHostId(host.getId());
            vm.setBootargs(bootArgs);
            if(vmName.startsWith("s-")) {
                vm.setType("SecondaryStorageVm");
            } else if (vmName.startsWith("v-")) {
                vm.setType("ConsoleProxy");
View Full Code Here


                if (vm.getState() == State.Migrating) {
                    vm.setState(State.Running);
                }
            }

            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);
            txn.commit();
            return new MigrateAnswer(cmd, true, null, 0);
        } catch (Exception ex) {
            txn.rollback();
View Full Code Here

        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public boolean removeByGuid(String guid) {
       MockHost host = this.findByGuid(guid);
       if (host == null) {
           return false;
       }
       return this.remove(host.getId());
    }
View Full Code Here

    }

    @Override
    public StoragePoolInfo getLocalStorage(String hostGuid) {
        Transaction txn = Transaction.open(Transaction.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 = Transaction.open(Transaction.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 = Transaction.open(Transaction.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 = Transaction.open(Transaction.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) {
        Transaction txn = Transaction.open(Transaction.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 = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }
        if (storageSize == null) {
            storageSize = DEFAULT_HOST_STORAGE_SIZE;
        }
        txn = Transaction.open(Transaction.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 = Transaction.open(Transaction.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 = Transaction.open(Transaction.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 = Transaction.open(Transaction.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) {
        Transaction txn = Transaction.open(Transaction.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;
        Transaction txn = Transaction.open(Transaction.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 = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        Transaction vmtxn = Transaction.open(Transaction.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 = Transaction.open(Transaction.CLOUD_DB);
            vmtxn.close();
View Full Code Here

        private void handleSystemVMStop() {
            Transaction txn = Transaction.open(Transaction.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 = Transaction.open(Transaction.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) {
        Transaction txn = Transaction.open(Transaction.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

    @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.