Package com.cloud.utils.db

Examples of com.cloud.utils.db.Transaction


    }

    @Override
    public void persist(long vmId, List<String> computeTags) {
        Transaction txn = Transaction.currentTxn();

        txn.start();
        SearchCriteria<VMComputeTagVO> sc = VmIdSearch.create();
        sc.setParameters("vmId", vmId);
        expunge(sc);

        for (String tag : computeTags) {
            if(tag != null){
                tag = tag.trim();
                if(tag.length() > 0) {
                    VMComputeTagVO vo = new VMComputeTagVO(vmId, tag);
                    persist(vo);
                }
            }
        }
        txn.commit();
    }
View Full Code Here


    }

    @Override
    @DB
    public VMEntityVO persist(VMEntityVO vm) {
        Transaction txn = Transaction.currentTxn();
        txn.start();

        VMEntityVO dbVO = super.persist(vm);

        saveVmNetworks(vm);
        loadVmNetworks(dbVO);
        saveVmReservation(vm);
        loadVmReservation(dbVO);
        saveComputeTags(vm.getId(), vm.getComputeTags());
        loadComputeTags(dbVO);
        saveRootDiskTags(vm.getId(), vm.getRootDiskTags());
        loadRootDiskTags(dbVO);

        txn.commit();

        return dbVO;
    }
View Full Code Here

        return virtualRouter;
    }

    @DB
    public void processStopOrRebootAnswer(final DomainRouterVO router, Answer answer) {
        final Transaction txn = Transaction.currentTxn();
        try {
            txn.start();
            //FIXME!!! - UserStats command should grab bytesSent/Received for all guest interfaces of the VR
            List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
            for (Long guestNtwkId : routerGuestNtwkIds) {
                final UserStatisticsVO userStats = _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(),
                        guestNtwkId, null, router.getId(), router.getType().toString());
            if (userStats != null) {
                final long currentBytesRcvd = userStats.getCurrentBytesReceived();
                userStats.setCurrentBytesReceived(0);
                userStats.setNetBytesReceived(userStats.getNetBytesReceived() + currentBytesRcvd);

                final long currentBytesSent = userStats.getCurrentBytesSent();
                userStats.setCurrentBytesSent(0);
                userStats.setNetBytesSent(userStats.getNetBytesSent() + currentBytesSent);
                _userStatsDao.update(userStats.getId(), userStats);
                s_logger.debug("Successfully updated user statistics as a part of domR " + router + " reboot/stop");
            } else {
                s_logger.warn("User stats were not created for account " + router.getAccountId() + " and dc " + router.getDataCenterId());
            }
            }
           
            txn.commit();
        } catch (final Exception e) {
            txn.rollback();
            throw new CloudRuntimeException("Problem updating stats after reboot/stop ", e);
        }
    }
View Full Code Here

                    router.setIsPriorityBumpUp(isBumped);
                    updated = true;
                }
            }
            if (updated) {
                Transaction txn = Transaction.open(Transaction.CLOUD_DB);
                try {
                    txn.start();
                    _routerDao.update(router.getId(), router);
                    txn.commit();
                } catch (Exception e) {
                    txn.rollback();
                    s_logger.warn("Unable to update router status for account: " + router.getAccountId());
                } finally {
                    txn.close();
                }
            }
            RedundantState currState = router.getRedundantState();
            if (prevState != currState) {
                String title = "Redundant virtual router " + router.getInstanceName() +
View Full Code Here

    }

    @Override
    @DB
    public VMReservationVO persist(VMReservationVO reservation) {
        Transaction txn = Transaction.currentTxn();
        txn.start();

        VMReservationVO dbVO = super.persist(reservation);

        saveVolumeReservation(reservation);
        loadVolumeReservation(dbVO);

        txn.commit();

        return dbVO;
    }
View Full Code Here

                //also add the required configuration to the dnsmasq for supporting dhcp and dns on the new ip.
                configDnsMasq(router, network, cmds);
                boolean result = sendCommandsToRouter(router, cmds);
                if (result == false) {
                    NicIpAliasVO ipAliasVO = _nicIpAliasDao.findByInstanceIdAndNetworkId(network.getId(), router.getId());
                    Transaction txn = Transaction.currentTxn();
                    txn.start();
                    _nicIpAliasDao.expunge(ipAliasVO.getId());
                    _ipAddressDao.unassignIpAddress(routerPublicIP.getId());
                    txn.commit();
                    throw new CloudRuntimeException("failed to configure ip alias on the router as a part of dhcp config");
                }
            }
            return true;
        }
View Full Code Here

            }
            createDeleteIpAliasCommand(router, revokedIpAliasTOs, activeIpAliasTOs, network.getId(), cmds);
            configDnsMasq(router, network, cmds);
            boolean result = sendCommandsToRouter(router, cmds);
            if (result) {
                Transaction txn= Transaction.currentTxn();
                txn.start();
                for (NicIpAliasVO revokedAliasVO : revokedIpAliasVOs) {
                    _nicIpAliasDao.expunge(revokedAliasVO.getId());
                }
                txn.commit();
                return true;
            }
        }
        return  false;
    }
View Full Code Here

    }

    @Override
    public void persist(long vmId, List<String> rootDiskTags) {
        Transaction txn = Transaction.currentTxn();

        txn.start();
        SearchCriteria<VMRootDiskTagVO> sc = VmIdSearch.create();
        sc.setParameters("vmId", vmId);
        expunge(sc);

        for (String tag : rootDiskTags) {
            if(tag != null){
                tag = tag.trim();
                if(tag.length() > 0) {
                    VMRootDiskTagVO vo = new VMRootDiskTagVO(vmId, tag);
                    persist(vo);
                }
            }
        }
        txn.commit();
    }
View Full Code Here

                    if (answer != null) {
                        if (!answer.getResult()) {
                            s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId() + "; details: " + answer.getDetails());
                            continue;
                        }
                        Transaction txn = Transaction.open(Transaction.CLOUD_DB);
                        try {
                            if ((answer.getBytesReceived() == 0) && (answer.getBytesSent() == 0)) {
                                s_logger.debug("Recieved and Sent bytes are both 0. Not updating user_statistics");
                                continue;
                            }
                            txn.start();
                            UserStatisticsVO stats = _userStatsDao.lock(router.getAccountId(),
                                    router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
                            if (stats == null) {
                                s_logger.warn("unable to find stats for account: " + router.getAccountId());
                                continue;
                            }

                            if (previousStats != null
                                    && ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived())
                                    || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){
                                s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. " +
                                        "Ignoring current answer. Router: " + answer.getRouterName() + " Rcvd: " +
                                        answer.getBytesReceived() + "Sent: " + answer.getBytesSent());
                                continue;
                            }

                            if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) {
                                if (s_logger.isDebugEnabled()) {
                                    s_logger.debug("Received # of bytes that's less than the last one.  " +
                                            "Assuming something went wrong and persisting it. Router: " +
                                            answer.getRouterName() + " Reported: " + answer.getBytesReceived()
                                            + " Stored: " + stats.getCurrentBytesReceived());
                                }
                                stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
                            }
                            stats.setCurrentBytesReceived(answer.getBytesReceived());
                            if (stats.getCurrentBytesSent() > answer.getBytesSent()) {
                                if (s_logger.isDebugEnabled()) {
                                    s_logger.debug("Received # of bytes that's less than the last one.  " +
                                            "Assuming something went wrong and persisting it. Router: " +
                                            answer.getRouterName() + " Reported: " + answer.getBytesSent()
                                            + " Stored: " + stats.getCurrentBytesSent());
                                }
                                stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
                            }
                            stats.setCurrentBytesSent(answer.getBytesSent());
                            if (! _dailyOrHourly) {
                                //update agg bytes
                                stats.setAggBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
                                stats.setAggBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
                            }
                            _userStatsDao.update(stats.getId(), stats);
                            txn.commit();
                        } catch (Exception e) {
                            txn.rollback();
                            s_logger.warn("Unable to update user statistics for account: " + router.getAccountId()
                                    + " Rx: " + answer.getBytesReceived() + "; Tx: " + answer.getBytesSent());
                        } finally {
                            txn.close();
                        }
                    }
                }
            }
        }
View Full Code Here

    }

    @Override
    public void persist(long vmId, List<Long> networks) {
        Transaction txn = Transaction.currentTxn();

        txn.start();
        SearchCriteria<VMNetworkMapVO> sc = VmIdSearch.create();
        sc.setParameters("vmId", vmId);
        expunge(sc);

        for (Long networkId : networks) {
            VMNetworkMapVO vo = new VMNetworkMapVO(vmId, networkId);
            persist(vo);
        }

        txn.commit();
    }
View Full Code Here

TOP

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

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.