Search in sources :

Example 1 with SearchCriteria

use of com.cloud.utils.db.SearchCriteria in project CloudStack-archive by CloudStack-extras.

the class UsageManagerImpl method createSecurityGroupEvent.

private void createSecurityGroupEvent(UsageEventVO event) {
    long zoneId = -1L;
    long vmId = event.getResourceId();
    long sgId = event.getOfferingId();
    if (EventTypes.EVENT_SECURITY_GROUP_ASSIGN.equals(event.getType())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Assigning : security group" + sgId + " to Vm: " + vmId + " for account: " + event.getAccountId());
        }
        zoneId = event.getZoneId();
        Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
        UsageSecurityGroupVO securityGroup = new UsageSecurityGroupVO(zoneId, event.getAccountId(), acct.getDomainId(), vmId, sgId, event.getCreateDate(), null);
        m_usageSecurityGroupDao.persist(securityGroup);
    } else if (EventTypes.EVENT_SECURITY_GROUP_REMOVE.equals(event.getType())) {
        SearchCriteria<UsageSecurityGroupVO> sc = m_usageSecurityGroupDao.createSearchCriteria();
        sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
        sc.addAnd("vmInstanceId", SearchCriteria.Op.EQ, vmId);
        sc.addAnd("securityGroupId", SearchCriteria.Op.EQ, sgId);
        sc.addAnd("deleted", SearchCriteria.Op.NULL);
        List<UsageSecurityGroupVO> sgVOs = m_usageSecurityGroupDao.search(sc, null);
        if (sgVOs.size() > 1) {
            s_logger.warn("More that one usage entry for security group: " + sgId + " for Vm: " + vmId + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
        }
        for (UsageSecurityGroupVO sgVO : sgVOs) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("deleting security group: " + sgVO.getSecurityGroupId() + " from Vm: " + sgVO.getVmInstanceId());
            }
            // there really shouldn't be more than one
            sgVO.setDeleted(event.getCreateDate());
            m_usageSecurityGroupDao.update(sgVO);
        }
    }
}
Also used : Account(com.cloud.user.Account) List(java.util.List) SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 2 with SearchCriteria

use of com.cloud.utils.db.SearchCriteria in project CloudStack-archive by CloudStack-extras.

the class UsageManagerImpl method createLoadBalancerHelperEvent.

private void createLoadBalancerHelperEvent(UsageEventVO event) {
    long zoneId = -1L;
    long id = event.getResourceId();
    if (EventTypes.EVENT_LOAD_BALANCER_CREATE.equals(event.getType())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Creating load balancer : " + id + " for account: " + event.getAccountId());
        }
        zoneId = event.getZoneId();
        Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
        UsageLoadBalancerPolicyVO lbVO = new UsageLoadBalancerPolicyVO(id, zoneId, event.getAccountId(), acct.getDomainId(), event.getCreateDate(), null);
        m_usageLoadBalancerPolicyDao.persist(lbVO);
    } else if (EventTypes.EVENT_LOAD_BALANCER_DELETE.equals(event.getType())) {
        SearchCriteria<UsageLoadBalancerPolicyVO> sc = m_usageLoadBalancerPolicyDao.createSearchCriteria();
        sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
        sc.addAnd("deleted", SearchCriteria.Op.NULL);
        List<UsageLoadBalancerPolicyVO> lbVOs = m_usageLoadBalancerPolicyDao.search(sc, null);
        if (lbVOs.size() > 1) {
            s_logger.warn("More that one usage entry for load balancer policy: " + id + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
        }
        for (UsageLoadBalancerPolicyVO lbVO : lbVOs) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("deleting load balancer policy: " + lbVO.getId() + " from account: " + lbVO.getAccountId());
            }
            // there really shouldn't be more than one
            lbVO.setDeleted(event.getCreateDate());
            m_usageLoadBalancerPolicyDao.update(lbVO);
        }
    }
}
Also used : Account(com.cloud.user.Account) List(java.util.List) SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 3 with SearchCriteria

use of com.cloud.utils.db.SearchCriteria in project CloudStack-archive by CloudStack-extras.

the class UsageManagerImpl method createPortForwardingHelperEvent.

private void createPortForwardingHelperEvent(UsageEventVO event) {
    long zoneId = -1L;
    long id = event.getResourceId();
    if (EventTypes.EVENT_NET_RULE_ADD.equals(event.getType())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Creating port forwarding rule : " + id + " for account: " + event.getAccountId());
        }
        zoneId = event.getZoneId();
        Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
        UsagePortForwardingRuleVO pfVO = new UsagePortForwardingRuleVO(id, zoneId, event.getAccountId(), acct.getDomainId(), event.getCreateDate(), null);
        m_usagePortForwardingRuleDao.persist(pfVO);
    } else if (EventTypes.EVENT_NET_RULE_DELETE.equals(event.getType())) {
        SearchCriteria<UsagePortForwardingRuleVO> sc = m_usagePortForwardingRuleDao.createSearchCriteria();
        sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
        sc.addAnd("deleted", SearchCriteria.Op.NULL);
        List<UsagePortForwardingRuleVO> pfVOs = m_usagePortForwardingRuleDao.search(sc, null);
        if (pfVOs.size() > 1) {
            s_logger.warn("More that one usage entry for port forwarding rule: " + id + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
        }
        for (UsagePortForwardingRuleVO pfVO : pfVOs) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("deleting port forwarding rule: " + pfVO.getId() + " from account: " + pfVO.getAccountId());
            }
            // there really shouldn't be more than one
            pfVO.setDeleted(event.getCreateDate());
            m_usagePortForwardingRuleDao.update(pfVO);
        }
    }
}
Also used : Account(com.cloud.user.Account) List(java.util.List) SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 4 with SearchCriteria

use of com.cloud.utils.db.SearchCriteria in project CloudStack-archive by CloudStack-extras.

the class UsageManagerImpl method createVolumeHelperEvent.

private void createVolumeHelperEvent(UsageEventVO event) {
    Long doId = -1L;
    long zoneId = -1L;
    Long templateId = -1L;
    long size = -1L;
    long volId = event.getResourceId();
    if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) {
        doId = event.getOfferingId();
        zoneId = event.getZoneId();
        templateId = event.getTemplateId();
        size = event.getSize();
    }
    if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) {
        SearchCriteria<UsageVolumeVO> sc = m_usageVolumeDao.createSearchCriteria();
        sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
        sc.addAnd("id", SearchCriteria.Op.EQ, volId);
        sc.addAnd("deleted", SearchCriteria.Op.NULL);
        List<UsageVolumeVO> volumesVOs = m_usageVolumeDao.search(sc, null);
        if (volumesVOs.size() > 0) {
            //This is a safeguard to avoid double counting of volumes.
            s_logger.error("Found duplicate usage entry for volume: " + volId + " assigned to account: " + event.getAccountId() + "; marking as deleted...");
        }
        for (UsageVolumeVO volumesVO : volumesVOs) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("deleting volume: " + volumesVO.getId() + " from account: " + volumesVO.getAccountId());
            }
            volumesVO.setDeleted(event.getCreateDate());
            m_usageVolumeDao.update(volumesVO);
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("create volume with id : " + volId + " for account: " + event.getAccountId());
        }
        Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
        UsageVolumeVO volumeVO = new UsageVolumeVO(volId, zoneId, event.getAccountId(), acct.getDomainId(), doId, templateId, size, event.getCreateDate(), null);
        m_usageVolumeDao.persist(volumeVO);
    } else if (EventTypes.EVENT_VOLUME_DELETE.equals(event.getType())) {
        SearchCriteria<UsageVolumeVO> sc = m_usageVolumeDao.createSearchCriteria();
        sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
        sc.addAnd("id", SearchCriteria.Op.EQ, volId);
        sc.addAnd("deleted", SearchCriteria.Op.NULL);
        List<UsageVolumeVO> volumesVOs = m_usageVolumeDao.search(sc, null);
        if (volumesVOs.size() > 1) {
            s_logger.warn("More that one usage entry for volume: " + volId + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
        }
        for (UsageVolumeVO volumesVO : volumesVOs) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("deleting volume: " + volumesVO.getId() + " from account: " + volumesVO.getAccountId());
            }
            // there really shouldn't be more than one
            volumesVO.setDeleted(event.getCreateDate());
            m_usageVolumeDao.update(volumesVO);
        }
    }
}
Also used : Account(com.cloud.user.Account) List(java.util.List) SearchCriteria(com.cloud.utils.db.SearchCriteria)

Example 5 with SearchCriteria

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

the class LunDaoImpl method findByName.

@Override
public LunVO findByName(String name) {
    SearchCriteria sc = LunNameSearch.create();
    sc.setParameters("name", name);
    return findOneBy(sc);
}
Also used : SearchCriteria(com.cloud.utils.db.SearchCriteria)

Aggregations

SearchCriteria (com.cloud.utils.db.SearchCriteria)54 List (java.util.List)40 ArrayList (java.util.ArrayList)31 Account (com.cloud.user.Account)23 TransactionStatus (com.cloud.utils.db.TransactionStatus)18 DB (com.cloud.utils.db.DB)13 DomainVO (com.cloud.domain.DomainVO)12 Filter (com.cloud.utils.db.Filter)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 HashMap (java.util.HashMap)11 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)10 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)9 Map (java.util.Map)8 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)7 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)7 HostVO (com.cloud.host.HostVO)7 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)7 Pair (com.cloud.utils.Pair)6 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)6