Package com.cloud.utils.db

Examples of com.cloud.utils.db.Transaction


            }
        }

        Map<Long, Long> lbRuleWeightMap = assignToGslbCmd.getLoadBalancerRuleWeightMap();

        Transaction txn = Transaction.currentTxn();
        txn.start();

        // persist the mapping for the new Lb rule that needs to assigned to a gslb rule
        for (Long lbRuleId : newLbRuleIds) {
            GlobalLoadBalancerLbRuleMapVO newGslbLbMap = new GlobalLoadBalancerLbRuleMapVO();
            newGslbLbMap.setGslbLoadBalancerId(gslbRuleId);
            newGslbLbMap.setLoadBalancerId(lbRuleId);
            if (lbRuleWeightMap != null && lbRuleWeightMap.get(lbRuleId) != null) {
                newGslbLbMap.setWeight(lbRuleWeightMap.get(lbRuleId));
            }
            _gslbLbMapDao.persist(newGslbLbMap);
        }

        // mark the gslb rule state as add
        if (gslbRule.getState() == GlobalLoadBalancerRule.State.Staged || gslbRule.getState() ==
                GlobalLoadBalancerRule.State.Active ) {
            gslbRule.setState(GlobalLoadBalancerRule.State.Add);
            _gslbRuleDao.update(gslbRule.getId(), gslbRule);
        }

        txn.commit();

        boolean success = false;
        try {
            s_logger.debug("Configuring gslb rule configuration on the gslb service providers in the participating zones");
View Full Code Here


                throw new InvalidParameterValueException("Load balancer ID " + loadBalancer.getUuid() + " is not assigned"
                        + " to global load balancer rule: " + gslbRule.getUuid());
            }
        }

        Transaction txn = Transaction.currentTxn();
        txn.start();

        // update the mapping of gslb rule to Lb rule, to revoke state
        for (Long lbRuleId : lbRuleIdsToremove) {
            GlobalLoadBalancerLbRuleMapVO removeGslbLbMap = _gslbLbMapDao.findByGslbRuleIdAndLbRuleId(gslbRuleId, lbRuleId);
            removeGslbLbMap.setRevoke(true);
            _gslbLbMapDao.update(removeGslbLbMap.getId(), removeGslbLbMap);
        }

        // mark the gslb rule state as add
        if (gslbRule.getState() == GlobalLoadBalancerRule.State.Staged) {
            gslbRule.setState(GlobalLoadBalancerRule.State.Add);
            _gslbRuleDao.update(gslbRule.getId(), gslbRule);
        }

        txn.commit();

        boolean success = false;
        try {
            s_logger.debug("Attempting to configure global load balancer rule configuration on the gslb service providers ");

            // apply the gslb rule on to the back end gslb service providers
            if (!applyGlobalLoadBalancerRuleConfig(gslbRuleId, false)) {
                s_logger.warn("Failed to remove load balancer rules " + lbRuleIdsToremove + " from global load balancer rule id "
                        + gslbRuleId);
                CloudRuntimeException ex = new CloudRuntimeException(
                        "Failed to remove load balancer rule ids from GSLB rule ");
                throw ex;
            }

            txn.start();

            // remove the mappings of gslb rule to Lb rule that are in revoked state
            for (Long lbRuleId : lbRuleIdsToremove) {
                GlobalLoadBalancerLbRuleMapVO removeGslbLbMap = _gslbLbMapDao.findByGslbRuleIdAndLbRuleId(gslbRuleId, lbRuleId);
                _gslbLbMapDao.remove(removeGslbLbMap.getId());
            }

            // on success set state back to Active
            gslbRule.setState(GlobalLoadBalancerRule.State.Active);
            _gslbRuleDao.update(gslbRule.getId(), gslbRule);

            txn.commit();

            success = true;
        } catch (ResourceUnavailableException e) {
            throw new CloudRuntimeException("Failed to update removed load balancer details from gloabal load balancer");
        }
View Full Code Here

        return listBy(sc);
    }

    @Override
    public boolean remove(Long id) {
        Transaction txn = Transaction.currentTxn();
        txn.start();
        DedicatedResourceVO resource = createForUpdate();
        update(id, resource);

        boolean result = super.remove(id);
        txn.commit();
        return result;
    }
View Full Code Here

            //mark the GSlb rule to be in revoke state
            gslbRule.setState(GlobalLoadBalancerRule.State.Revoke);
            _gslbRuleDao.update(gslbRuleId, gslbRule);
        }

        Transaction txn = Transaction.currentTxn();
        txn.start();

        List<GlobalLoadBalancerLbRuleMapVO> gslbLbMapVos = _gslbLbMapDao.listByGslbRuleId(gslbRuleId);
        if (gslbLbMapVos != null) {
            //mark all the GSLB-LB mapping to be in revoke state
            for (GlobalLoadBalancerLbRuleMapVO gslbLbMap : gslbLbMapVos) {
                gslbLbMap.setRevoke(true);
                _gslbLbMapDao.update(gslbLbMap.getId(), gslbLbMap);
            }
        }

        txn.commit();

        boolean success = false;
        try {
            if (gslbLbMapVos != null) {
                applyGlobalLoadBalancerRuleConfig(gslbRuleId, true);
            }
            success = true;
        } catch (ResourceUnavailableException e) {
            throw new CloudRuntimeException("Failed to update the gloabal load balancer");
        }

        txn.start();
        //remove all mappings between GSLB rule and load balancer rules
        if (gslbLbMapVos != null) {
            for (GlobalLoadBalancerLbRuleMapVO gslbLbMap : gslbLbMapVos) {
                _gslbLbMapDao.remove(gslbLbMap.getId());
            }
        }

        //remove the GSLB rule itself
        _gslbRuleDao.remove(gslbRuleId);

        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_GLOBAL_LOAD_BALANCER_DELETE, gslbRule.getAccountId(),
                0, gslbRule.getId(), gslbRule.getName(), GlobalLoadBalancerRule.class.getName(),
                gslbRule.getUuid());

        txn.commit();
    }
View Full Code Here

        if (stickyMethod != null && !GlobalLoadBalancerRule.Persistence.isValidPersistence(stickyMethod)) {
            throw new InvalidParameterValueException("Invalid persistence: " + stickyMethod);
        }

        Transaction txn = Transaction.currentTxn();
        txn.start();
        if (algorithm != null) {
            gslbRule.setAlgorithm(algorithm);
        }
        if (stickyMethod != null) {
            gslbRule.setPersistence(stickyMethod);
        }
        if (description != null) {
            gslbRule.setDescription(description);
        }
        gslbRule.setState(GlobalLoadBalancerRule.State.Add);
        _gslbRuleDao.update(gslbRule.getId(), gslbRule);
        txn.commit();

        try {
            s_logger.debug("Updating global load balancer with id " + gslbRule.getUuid());

            // apply the gslb rule on to the back end gslb service providers on zones participating in gslb
View Full Code Here

                     " WHERE q.queue_size < q.queue_size_limit AND i.queue_proc_number IS NULL " +
           " GROUP BY q.id " +
           " ORDER BY i.id " +
           " LIMIT 0, ?";

        Transaction txn = Transaction.currentTxn();
        PreparedStatement pstmt = null;
        try {
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setInt(1, maxItems);
            ResultSet rs = pstmt.executeQuery();
            while(rs.next()) {
              SyncQueueItemVO item = new SyncQueueItemVO();
              item.setId(rs.getLong(1));
View Full Code Here

  @DB
  public void resetJobProcess(long msid, int jobResultCode, String jobResultMessage) {
    String sql = "UPDATE async_job SET job_status=" + AsyncJobResult.STATUS_FAILED + ", job_result_code=" + jobResultCode
      + ", job_result='" + jobResultMessage + "' where job_status=0 AND (job_complete_msid=? OR (job_complete_msid IS NULL AND job_init_msid=?))";
   
        Transaction txn = Transaction.currentTxn();
        PreparedStatement pstmt = null;
        try {
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setLong(1, msid);
            pstmt.setLong(2, msid);
            pstmt.execute();
        } catch (SQLException e) {
          s_logger.warn("Unable to reset job status for management server " + msid, e);
View Full Code Here

  public void ensureQueue(String syncObjType, long syncObjId) {
    Date dt = DateUtil.currentGMTTime();
        String sql = "INSERT IGNORE INTO sync_queue(sync_objtype, sync_objid, created, last_updated)" +
                " values(?, ?, ?, ?)";
   
        Transaction txn = Transaction.currentTxn();
        PreparedStatement pstmt = null;
        try {
            pstmt = txn.prepareAutoCloseStatement(sql);
            pstmt.setString(1, syncObjType);
            pstmt.setLong(2, syncObjId);
            pstmt.setString(3, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), dt));
            pstmt.setString(4, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), dt));
            pstmt.execute();
View Full Code Here

        if (domainLevel && _affinityGroupDao.findDomainLevelGroupByName(domainId, affinityGroupName) != null) {
            throw new InvalidParameterValueException("Unable to create affinity group, a group with name "
                    + affinityGroupName + " already exisits under the domain.");
        }

        Transaction txn = Transaction.currentTxn();
        txn.start();
       
        AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, affinityGroupType, description, owner.getDomainId(),
                owner.getId(), aclType);
        _affinityGroupDao.persist(group);

        if (domainId != null && aclType == ACLType.Domain) {
            boolean subDomainAccess = false;
            subDomainAccess = processor.subDomainAccess();
            AffinityGroupDomainMapVO domainMap = new AffinityGroupDomainMapVO(group.getId(), domainId, subDomainAccess);
            _affinityGroupDomainMapDao.persist(domainMap);
        }

        txn.commit();

        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Created affinity group =" + affinityGroupName);
        }
View Full Code Here

            affinityGroupId = group.getId();
        }
        // check permissions
        _accountMgr.checkAccess(caller, AccessType.ModifyEntry, true, group);

        final Transaction txn = Transaction.currentTxn();
        txn.start();

        group = _affinityGroupDao.lockRow(affinityGroupId, true);
        if (group == null) {
            throw new InvalidParameterValueException("Unable to find affinity group by id " + affinityGroupId);
        }

        List<AffinityGroupVMMapVO> affinityGroupVmMap = _affinityGroupVMMapDao.listByAffinityGroup(affinityGroupId);
        if (!affinityGroupVmMap.isEmpty()) {
            SearchBuilder<AffinityGroupVMMapVO> listByAffinityGroup = _affinityGroupVMMapDao.createSearchBuilder();
            listByAffinityGroup.and("affinityGroupId", listByAffinityGroup.entity().getAffinityGroupId(),
                    SearchCriteria.Op.EQ);
            listByAffinityGroup.done();
            SearchCriteria<AffinityGroupVMMapVO> sc = listByAffinityGroup.create();
            sc.setParameters("affinityGroupId", affinityGroupId);

            _affinityGroupVMMapDao.lockRows(sc, null, true);
            _affinityGroupVMMapDao.remove(sc);
        }

        // call processor to handle the group delete
        AffinityGroupProcessor processor = getAffinityGroupProcessorForType(group.getType());
        if (processor != null) {
            processor.handleDeleteGroup(group);
        }

        _affinityGroupDao.expunge(affinityGroupId);
        txn.commit();

        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Deleted affinity group id=" + affinityGroupId);
        }
        return true;
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.