Package com.cloud.utils.db

Examples of com.cloud.utils.db.TransactionLegacy


        for (DbUpgrade upgrade : upgrades) {
            s_logger.debug("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-"
                    + upgrade.getUpgradableVersionRange()[1]
                    + " to " + upgrade.getUpgradedVersion());
            TransactionLegacy txn = TransactionLegacy.open("Upgrade");
            txn.start();
            try {
                Connection conn;
                try {
                    conn = txn.getConnection();
                } catch (SQLException e) {
                    s_logger.error("Unable to upgrade the database", e);
                    throw new CloudRuntimeException("Unable to upgrade the database", e);
                }
                File[] scripts = upgrade.getPrepareScripts();
                if (scripts != null) {
                    for (File script : scripts) {
                        runScript(conn, script);
                    }
                }

                upgrade.performDataMigration(conn);
                boolean upgradeVersion = true;

                if (upgrade.getUpgradedVersion().equals("2.1.8")) {
                    // we don't have VersionDao in 2.1.x
                    upgradeVersion = false;
                } else if (upgrade.getUpgradedVersion().equals("2.2.4")) {
                    try {
                        // specifically for domain vlan update from 2.1.8 to 2.2.4
                        PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM version WHERE version='2.2.4'");
                        ResultSet rs = pstmt.executeQuery();
                        if (rs.next()) {
                            upgradeVersion = false;
                        }
                    } catch (SQLException e) {
                        throw new CloudRuntimeException("Unable to update the version table", e);
                    }
                }

                if (upgradeVersion) {
                    VersionVO version = new VersionVO(upgrade.getUpgradedVersion());
                    _dao.persist(version);
                }

                txn.commit();
            } catch (CloudRuntimeException e) {
                s_logger.error("Unable to upgrade the database", e);
                throw new CloudRuntimeException("Unable to upgrade the database", e);
            } finally {
                txn.close();
            }
        }

        if (true) { // FIXME Needs to detect if management servers are running
                    // !ClusterManagerImpl.arePeersRunning(trimmedCurrentVersion)) {
            s_logger.info("Cleaning upgrades because all management server are now at the same version");
            TreeMap<String, List<DbUpgrade>> upgradedVersions = new TreeMap<String, List<DbUpgrade>>();

            for (DbUpgrade upgrade : upgrades) {
                String upgradedVerson = upgrade.getUpgradedVersion();
                List<DbUpgrade> upgradeList = upgradedVersions.get(upgradedVerson);
                if (upgradeList == null) {
                    upgradeList = new ArrayList<DbUpgrade>();
                }
                upgradeList.add(upgrade);
                upgradedVersions.put(upgradedVerson, upgradeList);
            }

            for (String upgradedVersion : upgradedVersions.keySet()) {
                List<DbUpgrade> versionUpgrades = upgradedVersions.get(upgradedVersion);
                VersionVO version = _dao.findByVersion(upgradedVersion, Step.Upgrade);
                s_logger.debug("Upgrading to version " + upgradedVersion + "...");

                TransactionLegacy txn = TransactionLegacy.open("Cleanup");
                try {
                    if (version != null) {
                        for (DbUpgrade upgrade : versionUpgrades) {
                            s_logger.info("Cleanup upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-"
                                    + upgrade.getUpgradableVersionRange()[1] + " to " + upgrade.getUpgradedVersion());

                            txn.start();

                            Connection conn;
                            try {
                                conn = txn.getConnection();
                            } catch (SQLException e) {
                                s_logger.error("Unable to cleanup the database", e);
                                throw new CloudRuntimeException("Unable to cleanup the database", e);
                            }

                            File[] scripts = upgrade.getCleanupScripts();
                            if (scripts != null) {
                                for (File script : scripts) {
                                    runScript(conn, script);
                                    s_logger.debug("Cleanup script " + script.getAbsolutePath() + " is executed successfully");
                                }
                            }
                            txn.commit();
                        }

                        txn.start();
                        version.setStep(Step.Complete);
                        s_logger.debug("Upgrade completed for version " + upgradedVersion);
                        version.setUpdated(new Date());
                        _dao.update(version.getId(), version);
                        txn.commit();
                    }
                } finally {
                    txn.close();
                }
            }
        }

    }
View Full Code Here


            if (tableName.equals("op_dc_ip_address_alloc")) {
                selectSql += " AND taken IS NOT NULL";
            }

            TransactionLegacy txn = TransactionLegacy.currentTxn();
            try {
                PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
                stmt.setLong(1, physicalNetworkId);
                ResultSet rs = stmt.executeQuery();
                if (rs != null && rs.next()) {
                    throw new CloudRuntimeException("The Physical Network is not deletable because " + errorMsg);
                }
View Full Code Here

            }
            return value;
        }

        // Execute all updates in a single transaction
        TransactionLegacy txn = TransactionLegacy.currentTxn();
        txn.start();

        if (!_configDao.update(name, category, value)) {
            s_logger.error("Failed to update configuration option, name: " + name + ", value:" + value);
            throw new CloudRuntimeException("Failed to update configuration value. Please contact Cloud Support.");
        }

        PreparedStatement pstmt = null;
        if (Config.XenGuestNetwork.key().equalsIgnoreCase(name)) {
            String sql = "update host_details set value=? where name=?";
            try {
                pstmt = txn.prepareAutoCloseStatement(sql);
                pstmt.setString(1, value);
                pstmt.setString(2, "guest.network.device");

                pstmt.executeUpdate();
            } catch (Throwable e) {
                throw new CloudRuntimeException(
                        "Failed to update guest.network.device in host_details due to exception ", e);
            }
        } else if (Config.XenPrivateNetwork.key().equalsIgnoreCase(name)) {
            String sql = "update host_details set value=? where name=?";
            try {
                pstmt = txn.prepareAutoCloseStatement(sql);
                pstmt.setString(1, value);
                pstmt.setString(2, "private.network.device");

                pstmt.executeUpdate();
            } catch (Throwable e) {
                throw new CloudRuntimeException(
                        "Failed to update private.network.device in host_details due to exception ", e);
            }
        } else if (Config.XenPublicNetwork.key().equalsIgnoreCase(name)) {
            String sql = "update host_details set value=? where name=?";
            try {
                pstmt = txn.prepareAutoCloseStatement(sql);
                pstmt.setString(1, value);
                pstmt.setString(2, "public.network.device");

                pstmt.executeUpdate();
            } catch (Throwable e) {
                throw new CloudRuntimeException(
                        "Failed to update public.network.device in host_details due to exception ", e);
            }
        } else if (Config.XenStorageNetwork1.key().equalsIgnoreCase(name)) {
            String sql = "update host_details set value=? where name=?";
            try {
                pstmt = txn.prepareAutoCloseStatement(sql);
                pstmt.setString(1, value);
                pstmt.setString(2, "storage.network.device1");

                pstmt.executeUpdate();
            } catch (Throwable e) {
                throw new CloudRuntimeException(
                        "Failed to update storage.network.device1 in host_details due to exception ", e);
            }
        } else if (Config.XenStorageNetwork2.key().equals(name)) {
            String sql = "update host_details set value=? where name=?";
            try {
                pstmt = txn.prepareAutoCloseStatement(sql);
                pstmt.setString(1, value);
                pstmt.setString(2, "storage.network.device2");

                pstmt.executeUpdate();
            } catch (Throwable e) {
                throw new CloudRuntimeException(
                        "Failed to update storage.network.device2 in host_details due to exception ", e);
            }
        } else if (Config.SystemVMUseLocalStorage.key().equalsIgnoreCase(name)) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Config 'system.vm.use.local.storage' changed to value:" + value
                        + ", need to update System VM offerings");
            }
            boolean useLocalStorage = Boolean.parseBoolean(_configDao.getValue(Config.SystemVMUseLocalStorage.key()));
            ServiceOfferingVO serviceOffering = _serviceOfferingDao
                    .findByName(ServiceOffering.consoleProxyDefaultOffUniqueName);
            if (serviceOffering != null) {
                serviceOffering.setUseLocalStorage(useLocalStorage);
                if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
                    throw new CloudRuntimeException(
                            "Failed to update ConsoleProxy offering's use_local_storage option to value:"
                                    + useLocalStorage);
                }
            }

            serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.routerDefaultOffUniqueName);
            if (serviceOffering != null) {
                serviceOffering.setUseLocalStorage(useLocalStorage);
                if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
                    throw new CloudRuntimeException(
                            "Failed to update SoftwareRouter offering's use_local_storage option to value:"
                                    + useLocalStorage);
                }
            }

            serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.ssvmDefaultOffUniqueName);
            if (serviceOffering != null) {
                serviceOffering.setUseLocalStorage(useLocalStorage);
                if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
                    throw new CloudRuntimeException(
                            "Failed to update SecondaryStorage offering's use_local_storage option to value:"
                                    + useLocalStorage);
                }
            }
        }

        txn.commit();
        return _configDao.getValue(name);
    }
View Full Code Here

            if (tableName.equals("host") || tableName.equals("cluster") || tableName.equals("volumes")
                    || tableName.equals("vm_instance")) {
                selectSql += " and removed IS NULL";
            }

            TransactionLegacy txn = TransactionLegacy.currentTxn();
            try {
                PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
                stmt.setLong(1, podId);
                ResultSet rs = stmt.executeQuery();
                if (rs != null && rs.next()) {
                    throw new CloudRuntimeException("The pod cannot be deleted because " + errorMsg);
                }
View Full Code Here

            if (tableName.equals("vm_instance")) {
                selectSql += " AND state != '" + VirtualMachine.State.Expunging.toString() + "'";
            }

            TransactionLegacy txn = TransactionLegacy.currentTxn();
            try {
                PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
                stmt.setLong(1, zoneId);
                ResultSet rs = stmt.executeQuery();
                if (rs != null && rs.next()) {
                    throw new CloudRuntimeException("The zone is not deletable because " + errorMsg);
                }
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) {
                Map<String, String> configParameters = config.getParameters();
                for (Map.Entry<String, String> entry : configParameters.entrySet()) {
                    if (entry.getKey().equalsIgnoreCase("enabled")) {
                        info.setEnabled(Boolean.parseBoolean(entry.getValue()));
                    } else if (entry.getKey().equalsIgnoreCase("timeout")) {
                        try {
                            info.setTimeout(Integer.valueOf(entry.getValue()));
                        } catch (NumberFormatException e) {
                            s_logger.debug("invalid timeout parameter: " + e.toString());
                        }
                    } else if (entry.getKey().equalsIgnoreCase("wait")) {
                        try {
                            int wait = Integer.valueOf(entry.getValue());
                            Thread.sleep(wait);
                        } catch (NumberFormatException e) {
                            s_logger.debug("invalid timeout parameter: " + e.toString());
                        } catch (InterruptedException e) {
                            s_logger.debug("thread is interrupted: " + e.toString());
                        }
                    }
                }
            }

            if (cmd instanceof GetHostStatsCommand) {
                return _mockAgentMgr.getHostStatistic((GetHostStatsCommand) cmd);
            } else if (cmd instanceof CheckHealthCommand) {
                return _mockAgentMgr.checkHealth((CheckHealthCommand) cmd);
            } else if (cmd instanceof PingTestCommand) {
                return _mockAgentMgr.pingTest((PingTestCommand) cmd);
            } else if (cmd instanceof PrepareForMigrationCommand) {
                return _mockVmMgr.prepareForMigrate((PrepareForMigrationCommand) cmd);
            } else if (cmd instanceof MigrateCommand) {
                return _mockVmMgr.Migrate((MigrateCommand) cmd, info);
            } else if (cmd instanceof StartCommand) {
                return _mockVmMgr.startVM((StartCommand) cmd, info);
            } else if (cmd instanceof CheckSshCommand) {
                return _mockVmMgr.checkSshCommand((CheckSshCommand) cmd);
            } else if (cmd instanceof CheckVirtualMachineCommand) {
                return _mockVmMgr.checkVmState((CheckVirtualMachineCommand) cmd);
            } else if (cmd instanceof SetStaticNatRulesCommand) {
                return _mockNetworkMgr.SetStaticNatRules((SetStaticNatRulesCommand) cmd);
            } else if (cmd instanceof SetFirewallRulesCommand) {
                return _mockNetworkMgr.SetFirewallRules((SetFirewallRulesCommand) cmd);
            } else if (cmd instanceof SetPortForwardingRulesCommand) {
                return _mockNetworkMgr.SetPortForwardingRules((SetPortForwardingRulesCommand) cmd);
            } else if (cmd instanceof NetworkUsageCommand) {
                return _mockNetworkMgr.getNetworkUsage((NetworkUsageCommand) cmd);
            } else if (cmd instanceof IpAssocCommand) {
                return _mockNetworkMgr.IpAssoc((IpAssocCommand) cmd);
            } else if (cmd instanceof LoadBalancerConfigCommand) {
                return _mockNetworkMgr.LoadBalancerConfig((LoadBalancerConfigCommand) cmd);
            } else if (cmd instanceof DhcpEntryCommand) {
                return _mockNetworkMgr.AddDhcpEntry((DhcpEntryCommand) cmd);
            } else if (cmd instanceof VmDataCommand) {
                return _mockVmMgr.setVmData((VmDataCommand) cmd);
            } else if (cmd instanceof CleanupNetworkRulesCmd) {
                return _mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd) cmd, info);
            } else if (cmd instanceof CheckNetworkCommand) {
                return _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
            }else if (cmd instanceof StopCommand) {
                return _mockVmMgr.stopVM((StopCommand)cmd);
            } else if (cmd instanceof RebootCommand) {
                return _mockVmMgr.rebootVM((RebootCommand) cmd);
            } else if (cmd instanceof GetVncPortCommand) {
                return _mockVmMgr.getVncPort((GetVncPortCommand)cmd);
            } else if (cmd instanceof CheckConsoleProxyLoadCommand) {
                return _mockVmMgr.CheckConsoleProxyLoad((CheckConsoleProxyLoadCommand)cmd);
            } else if (cmd instanceof WatchConsoleProxyLoadCommand) {
                return _mockVmMgr.WatchConsoleProxyLoad((WatchConsoleProxyLoadCommand)cmd);
            } else if (cmd instanceof SecurityGroupRulesCmd) {
                return _mockVmMgr.AddSecurityGroupRules((SecurityGroupRulesCmd)cmd, info);
            } else if (cmd instanceof SavePasswordCommand) {
                return _mockVmMgr.SavePassword((SavePasswordCommand)cmd);
            } else if (cmd instanceof PrimaryStorageDownloadCommand) {
                return _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand)cmd);
            } else if (cmd instanceof CreateCommand) {
                return _mockStorageMgr.createVolume((CreateCommand)cmd);
            } else if (cmd instanceof AttachVolumeCommand) {
                return _mockStorageMgr.AttachVolume((AttachVolumeCommand)cmd);
            } else if (cmd instanceof AttachIsoCommand) {
                return _mockStorageMgr.AttachIso((AttachIsoCommand)cmd);
            } else if (cmd instanceof DeleteStoragePoolCommand) {
                return _mockStorageMgr.DeleteStoragePool((DeleteStoragePoolCommand)cmd);
            } else if (cmd instanceof ModifyStoragePoolCommand) {
                return _mockStorageMgr.ModifyStoragePool((ModifyStoragePoolCommand)cmd);
            } else if (cmd instanceof CreateStoragePoolCommand) {
                return _mockStorageMgr.CreateStoragePool((CreateStoragePoolCommand)cmd);
            } else if (cmd instanceof SecStorageSetupCommand) {
                return _mockStorageMgr.SecStorageSetup((SecStorageSetupCommand)cmd);
            } else if (cmd instanceof ListTemplateCommand) {
                return _mockStorageMgr.ListTemplates((ListTemplateCommand)cmd);
            } else if (cmd instanceof ListVolumeCommand) {
                return _mockStorageMgr.ListVolumes((ListVolumeCommand)cmd);
            } else if (cmd instanceof DestroyCommand) {
                return _mockStorageMgr.Destroy((DestroyCommand)cmd);
            } else if (cmd instanceof DownloadProgressCommand) {
                return _mockStorageMgr.DownloadProcess((DownloadProgressCommand)cmd);
            } else if (cmd instanceof DownloadCommand) {
                return _mockStorageMgr.Download((DownloadCommand)cmd);
            } else if (cmd instanceof GetStorageStatsCommand) {
                return _mockStorageMgr.GetStorageStats((GetStorageStatsCommand)cmd);
            } else if (cmd instanceof ManageSnapshotCommand) {
                return _mockStorageMgr.ManageSnapshot((ManageSnapshotCommand)cmd);
            } else if (cmd instanceof BackupSnapshotCommand) {
                return _mockStorageMgr.BackupSnapshot((BackupSnapshotCommand)cmd, info);
            } else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
                return _mockStorageMgr.CreateVolumeFromSnapshot((CreateVolumeFromSnapshotCommand)cmd);
            } else if (cmd instanceof DeleteCommand) {
                return _mockStorageMgr.Delete((DeleteCommand)cmd);
            } else if (cmd instanceof SecStorageVMSetupCommand) {
                return _mockStorageMgr.SecStorageVMSetup((SecStorageVMSetupCommand)cmd);
            } else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
                return _mockStorageMgr.CreatePrivateTemplateFromSnapshot((CreatePrivateTemplateFromSnapshotCommand)cmd);
            } else if (cmd instanceof ComputeChecksumCommand) {
                return _mockStorageMgr.ComputeChecksum((ComputeChecksumCommand)cmd);
            } else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
                return _mockStorageMgr.CreatePrivateTemplateFromVolume((CreatePrivateTemplateFromVolumeCommand)cmd);
            } else if (cmd instanceof MaintainCommand) {
                return _mockAgentMgr.maintain((MaintainCommand)cmd);
            } else if (cmd instanceof GetVmStatsCommand) {
                return _mockVmMgr.getVmStats((GetVmStatsCommand)cmd);
            } else if (cmd instanceof CheckRouterCommand) {
                return _mockVmMgr.checkRouter((CheckRouterCommand) cmd);
            } else if (cmd instanceof BumpUpPriorityCommand) {
                return _mockVmMgr.bumpPriority((BumpUpPriorityCommand) cmd);
            } else if (cmd instanceof GetDomRVersionCmd) {
                return _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
            } else if (cmd instanceof ClusterSyncCommand) {
                return new Answer(cmd);
            } else if (cmd instanceof CopyVolumeCommand) {
                return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
            } else if (cmd instanceof PlugNicCommand) {
                return _mockNetworkMgr.plugNic((PlugNicCommand) cmd);
            } else if (cmd instanceof UnPlugNicCommand) {
                return _mockNetworkMgr.unplugNic((UnPlugNicCommand) cmd);
            } else if (cmd instanceof IpAssocVpcCommand) {
                return _mockNetworkMgr.ipAssoc((IpAssocVpcCommand) cmd);
            } else if (cmd instanceof SetSourceNatCommand) {
                return _mockNetworkMgr.setSourceNat((SetSourceNatCommand) cmd);
            } else if (cmd instanceof SetNetworkACLCommand) {
                return _mockNetworkMgr.setNetworkAcl((SetNetworkACLCommand) cmd);
            } else if (cmd instanceof SetupGuestNetworkCommand) {
                return _mockNetworkMgr.setUpGuestNetwork((SetupGuestNetworkCommand) cmd);
            } else if (cmd instanceof SetPortForwardingRulesVpcCommand) {
                return _mockNetworkMgr.setVpcPortForwards((SetPortForwardingRulesVpcCommand) cmd);
            } else if (cmd instanceof SetStaticNatRulesCommand) {
                return _mockNetworkMgr.setVPCStaticNatRules((SetStaticNatRulesCommand) cmd);
            } else if (cmd instanceof SetStaticRouteCommand) {
                return _mockNetworkMgr.setStaticRoute((SetStaticRouteCommand) cmd);
            } else if (cmd instanceof Site2SiteVpnCfgCommand) {
                return _mockNetworkMgr.siteToSiteVpn((Site2SiteVpnCfgCommand) cmd);
            } else if (cmd instanceof CheckS2SVpnConnectionsCommand) {
                return _mockNetworkMgr.checkSiteToSiteVpnConnection((CheckS2SVpnConnectionsCommand) cmd);
            } else if (cmd instanceof CreateVMSnapshotCommand) {
                return _mockVmMgr.createVmSnapshot((CreateVMSnapshotCommand) cmd);
            } else if (cmd instanceof DeleteVMSnapshotCommand) {
                return _mockVmMgr.deleteVmSnapshot((DeleteVMSnapshotCommand) cmd);
            } else if (cmd instanceof RevertToVMSnapshotCommand) {
                return _mockVmMgr.revertVmSnapshot((RevertToVMSnapshotCommand) cmd);
            } else if (cmd instanceof NetworkRulesVmSecondaryIpCommand) {
                return _mockVmMgr.plugSecondaryIp((NetworkRulesVmSecondaryIpCommand) cmd);
            } else if (cmd instanceof ScaleVmCommand) {
                return _mockVmMgr.scaleVm((ScaleVmCommand) cmd);
            } else if (cmd instanceof PvlanSetupCommand) {
                return _mockNetworkMgr.setupPVLAN((PvlanSetupCommand) cmd);
            } else if (cmd instanceof StorageSubSystemCommand) {
                return this.storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
            } else if (cmd instanceof VpnUsersCfgCommand || cmd instanceof RemoteAccessVpnCfgCommand || cmd instanceof SetMonitorServiceCommand) {
                return new Answer(cmd);
            } else {
                s_logger.error("Simulator does not implement command of type "+cmd.toString());
                return Answer.createUnsupportedCommandAnswer(cmd);
            }
        } catch(Exception e) {
            s_logger.error("Failed execute cmd: ", e);
            txn.rollback();
            return new Answer(cmd, false, e.toString());
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
    }
View Full Code Here

    @DB
    List<Long> findAllVolumeIdInSnapshotTable(Long storeId) {
        String sql = "SELECT volume_id from snapshots, snapshot_store_ref WHERE snapshots.id = snapshot_store_ref.snapshot_id and store_id=? GROUP BY volume_id";
        List<Long> list = new ArrayList<Long>();
        try {
            TransactionLegacy txn = TransactionLegacy.currentTxn();
            ResultSet rs = null;
            PreparedStatement pstmt = null;
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setLong(1, storeId);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                list.add(rs.getLong(1));
            }
View Full Code Here

    }

    List<String> findAllSnapshotForVolume(Long volumeId) {
        String sql = "SELECT backup_snap_id FROM snapshots WHERE volume_id=? and backup_snap_id is not NULL";
        try {
            TransactionLegacy txn = TransactionLegacy.currentTxn();
            ResultSet rs = null;
            PreparedStatement pstmt = null;
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setLong(1, volumeId);
            rs = pstmt.executeQuery();
            List<String> list = new ArrayList<String>();
            while (rs.next()) {
                list.add(rs.getString(1));
View Full Code Here

    }

    @Override
    public boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command,
            String values) {
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
            MockConfigurationVO config = _mockConfigDao.findByCommand(zoneId, podId, clusterId, hostId, command);
            if (config == null) {
                config = new MockConfigurationVO();
                config.setClusterId(clusterId);
                config.setDataCenterId(zoneId);
                config.setPodId(podId);
                config.setHostId(hostId);
                config.setName(command);
                config.setValues(values);
                _mockConfigDao.persist(config);
                txn.commit();
            } else {
                config.setValues(values);
                _mockConfigDao.update(config.getId(), config);
                txn.commit();
            }
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Unable to configure simulator because of " + ex.getMessage(), ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
        return true;
    }
View Full Code Here

                     "AND h.id = ? AND i.power_state_update_time < ? AND i.host_id = h.id " +
                "AND (i.state ='Starting' OR i.state='Stopping' OR i.state='Migrating') " +
                "AND i.id NOT IN (SELECT w.vm_instance_id FROM vm_work_job AS w JOIN async_job AS j ON w.id = j.id WHERE j.job_status = ?)";

        List<Long> l = new ArrayList<Long>();
        TransactionLegacy txn = null;
        try {
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);

            PreparedStatement pstmt = null;
            try {
                pstmt = txn.prepareAutoCloseStatement(sql);

                pstmt.setLong(1, hostId);
                pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutTime));
                pstmt.setInt(3, JobInfo.Status.IN_PROGRESS.ordinal());
                ResultSet rs = pstmt.executeQuery();
                while (rs.next()) {
                    l.add(rs.getLong(1));
                }
            } catch (SQLException e) {
            } catch (Throwable e) {
            }

        } finally {
            if (txn != null)
                txn.close();
        }
        return l;
    }
View Full Code Here

TOP

Related Classes of com.cloud.utils.db.TransactionLegacy

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.