Search in sources :

Example 6 with MockHost

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

Example 7 with MockHost

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

Example 8 with MockHost

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();
    }
}
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)

Example 9 with MockHost

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);
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) MockHost(com.cloud.simulator.MockHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 10 with MockHost

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();
    }
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) MockHost(com.cloud.simulator.MockHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

MockHost (com.cloud.simulator.MockHost)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 ConfigurationException (javax.naming.ConfigurationException)8 MockVMVO (com.cloud.simulator.MockVMVO)6 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)6 StoragePoolInfo (com.cloud.agent.api.StoragePoolInfo)4 MockStoragePoolVO (com.cloud.simulator.MockStoragePoolVO)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Answer (com.cloud.agent.api.Answer)2 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)2 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)2 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)2 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)2 CleanupNetworkRulesCmd (com.cloud.agent.api.CleanupNetworkRulesCmd)2 ComputeChecksumCommand (com.cloud.agent.api.ComputeChecksumCommand)2 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)2 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)2 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)2 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)2 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)2