Search in sources :

Example 26 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class MockStorageManagerImpl method findVolumeFromSecondary.

private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        String volumePath = path.replaceAll(ssUrl, "");
        MockSecStorageVO secStorage = _mockSecStorageDao.findByUrl(ssUrl);
        if (secStorage == null) {
            return null;
        }
        volumePath = secStorage.getMountPoint() + volumePath;
        volumePath = volumePath.replaceAll("//", "/");
        MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(volumePath);
        txn.commit();
        if (volume == null) {
            return null;
        }
        return volume;
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Unable to find volume " + path + " on secondary " + ssUrl, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 27 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class MockVmManagerImpl method getVms.

@Override
public Map<String, MockVMVO> getVms(final String hostGuid) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        final List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
        final Map<String, MockVMVO> vmMap = new HashMap<String, MockVMVO>();
        for (final MockVMVO vm : vms) {
            vmMap.put(vm.getName(), vm);
        }
        txn.commit();
        return vmMap;
    } catch (final Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 28 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class MockVmManagerImpl method stopVM.

@Override
public StopAnswer stopVM(final StopCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        final String vmName = cmd.getVmName();
        final MockVm vm = _mockVmDao.findByVmName(vmName);
        if (vm != null) {
            vm.setPowerState(PowerState.PowerOff);
            _mockVmDao.update(vm.getId(), (MockVMVO) vm);
        }
        if (vmName.startsWith("s-")) {
            _mockAgentMgr.handleSystemVMStop(vm.getId());
        }
        txn.commit();
        return new StopAnswer(cmd, null, true);
    } catch (final Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StopAnswer(com.cloud.agent.api.StopAnswer) MockVm(com.cloud.simulator.MockVm) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 29 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class MockStorageManagerImpl method GetStorageStats.

@Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
    String uuid = cmd.getStorageId();
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        if (uuid == null) {
            String secUrl = cmd.getSecUrl();
            MockSecStorageVO secondary = _mockSecStorageDao.findByUrl(secUrl);
            if (secondary == null) {
                return new GetStorageStatsAnswer(cmd, "Can't find the secondary storage:" + secUrl);
            }
            Long totalUsed = _mockVolumeDao.findTotalStorageId(secondary.getId());
            txn.commit();
            return new GetStorageStatsAnswer(cmd, secondary.getCapacity(), totalUsed);
        } else {
            MockStoragePoolVO pool = _mockStoragePoolDao.findByUuid(uuid);
            if (pool == null) {
                return new GetStorageStatsAnswer(cmd, "Can't find the pool");
            }
            Long totalUsed = _mockVolumeDao.findTotalStorageId(pool.getId());
            if (totalUsed == null) {
                totalUsed = 0L;
            }
            txn.commit();
            return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
        }
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("DBException during storage stats collection for pool " + uuid, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 30 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class MockStorageManagerImpl method ListTemplates.

@Override
public Answer ListTemplates(ListTemplateCommand cmd) {
    DataStoreTO store = cmd.getDataStore();
    if (!(store instanceof NfsTO)) {
        return new Answer(cmd, false, "Unsupported image data store: " + store);
    }
    MockSecStorageVO storage = null;
    String nfsUrl = ((NfsTO) store).getUrl();
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    storage = _mockSecStorageDao.findByUrl(nfsUrl);
    try {
        txn.start();
        List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.TEMPLATE);
        Map<String, TemplateProp> templateInfos = new HashMap<String, TemplateProp>();
        for (MockVolumeVO template : templates) {
            templateInfos.put(template.getName(), new TemplateProp(template.getName(), template.getPath().replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
        }
        return new ListTemplateAnswer(nfsUrl, templateInfos);
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when finding template on sec storage " + storage.getId(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) HashMap(java.util.HashMap) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) NfsTO(com.cloud.agent.api.to.NfsTO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) UploadStatusAnswer(org.apache.cloudstack.storage.command.UploadStatusAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Aggregations

TransactionLegacy (com.cloud.utils.db.TransactionLegacy)368 PreparedStatement (java.sql.PreparedStatement)174 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)149 SQLException (java.sql.SQLException)133 ResultSet (java.sql.ResultSet)102 ArrayList (java.util.ArrayList)98 DB (com.cloud.utils.db.DB)95 ConfigurationException (javax.naming.ConfigurationException)54 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)35 Date (java.util.Date)34 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)31 HashMap (java.util.HashMap)29 URISyntaxException (java.net.URISyntaxException)28 AccountVO (com.cloud.user.AccountVO)21 CloudException (com.cloud.exception.CloudException)20 Account (com.cloud.user.Account)20 Field (java.lang.reflect.Field)19 MockVolumeVO (com.cloud.simulator.MockVolumeVO)18 AgentManager (com.cloud.agent.AgentManager)13 IPAddressDao (com.cloud.network.dao.IPAddressDao)13