use of com.cloud.utils.db.SearchCriteria in project CloudStack-archive by CloudStack-extras.
the class UsageManagerImpl method createNetworkOfferingEvent.
private void createNetworkOfferingEvent(UsageEventVO event) {
long zoneId = -1L;
long vmId = event.getResourceId();
long networkOfferingId = event.getOfferingId();
if (EventTypes.EVENT_NETWORK_OFFERING_CREATE.equals(event.getType()) || EventTypes.EVENT_NETWORK_OFFERING_ASSIGN.equals(event.getType())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating networking offering: " + networkOfferingId + " for Vm: " + vmId + " for account: " + event.getAccountId());
}
zoneId = event.getZoneId();
Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
boolean isDefault = (event.getSize() == 1) ? true : false;
UsageNetworkOfferingVO networkOffering = new UsageNetworkOfferingVO(zoneId, event.getAccountId(), acct.getDomainId(), vmId, networkOfferingId, isDefault, event.getCreateDate(), null);
m_usageNetworkOfferingDao.persist(networkOffering);
} else if (EventTypes.EVENT_NETWORK_OFFERING_DELETE.equals(event.getType()) || EventTypes.EVENT_NETWORK_OFFERING_REMOVE.equals(event.getType())) {
SearchCriteria<UsageNetworkOfferingVO> sc = m_usageNetworkOfferingDao.createSearchCriteria();
sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
sc.addAnd("vmInstanceId", SearchCriteria.Op.EQ, vmId);
sc.addAnd("networkOfferingId", SearchCriteria.Op.EQ, networkOfferingId);
sc.addAnd("deleted", SearchCriteria.Op.NULL);
List<UsageNetworkOfferingVO> noVOs = m_usageNetworkOfferingDao.search(sc, null);
if (noVOs.size() > 1) {
s_logger.warn("More that one usage entry for networking offering: " + networkOfferingId + " for Vm: " + vmId + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
}
for (UsageNetworkOfferingVO noVO : noVOs) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("deleting network offering: " + noVO.getNetworkOfferingId() + " from Vm: " + noVO.getVmInstanceId());
}
// there really shouldn't be more than one
noVO.setDeleted(event.getCreateDate());
m_usageNetworkOfferingDao.update(noVO);
}
}
}
use of com.cloud.utils.db.SearchCriteria in project CloudStack-archive by CloudStack-extras.
the class UsageManagerImpl method createVPNUserEvent.
private void createVPNUserEvent(UsageEventVO event) {
long zoneId = 0L;
long userId = event.getResourceId();
if (EventTypes.EVENT_VPN_USER_ADD.equals(event.getType())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating VPN user: " + userId + " for account: " + event.getAccountId());
}
Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
String userName = event.getResourceName();
UsageVPNUserVO vpnUser = new UsageVPNUserVO(zoneId, event.getAccountId(), acct.getDomainId(), userId, userName, event.getCreateDate(), null);
m_usageVPNUserDao.persist(vpnUser);
} else if (EventTypes.EVENT_VPN_USER_REMOVE.equals(event.getType())) {
SearchCriteria<UsageVPNUserVO> sc = m_usageVPNUserDao.createSearchCriteria();
sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
sc.addAnd("userId", SearchCriteria.Op.EQ, userId);
sc.addAnd("deleted", SearchCriteria.Op.NULL);
List<UsageVPNUserVO> vuVOs = m_usageVPNUserDao.search(sc, null);
if (vuVOs.size() > 1) {
s_logger.warn("More that one usage entry for vpn user: " + userId + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
}
for (UsageVPNUserVO vuVO : vuVOs) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("deleting vpn user: " + vuVO.getUserId());
}
// there really shouldn't be more than one
vuVO.setDeleted(event.getCreateDate());
m_usageVPNUserDao.update(vuVO);
}
}
}
use of com.cloud.utils.db.SearchCriteria in project CloudStack-archive by CloudStack-extras.
the class UsageManagerImpl method createIPHelperEvent.
private void createIPHelperEvent(UsageEventVO event) {
String ipAddress = event.getResourceName();
if (EventTypes.EVENT_NET_IP_ASSIGN.equals(event.getType())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("assigning ip address: " + ipAddress + " to account: " + event.getAccountId());
}
Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
long zoneId = event.getZoneId();
long id = event.getResourceId();
long sourceNat = event.getSize();
boolean isSourceNat = (sourceNat == 1) ? true : false;
boolean isSystem = (event.getTemplateId() == null || event.getTemplateId() == 0) ? false : true;
UsageIPAddressVO ipAddressVO = new UsageIPAddressVO(id, event.getAccountId(), acct.getDomainId(), zoneId, ipAddress, isSourceNat, isSystem, event.getCreateDate(), null);
m_usageIPAddressDao.persist(ipAddressVO);
} else if (EventTypes.EVENT_NET_IP_RELEASE.equals(event.getType())) {
SearchCriteria<UsageIPAddressVO> sc = m_usageIPAddressDao.createSearchCriteria();
sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
sc.addAnd("address", SearchCriteria.Op.EQ, ipAddress);
sc.addAnd("released", SearchCriteria.Op.NULL);
List<UsageIPAddressVO> ipAddressVOs = m_usageIPAddressDao.search(sc, null);
if (ipAddressVOs.size() > 1) {
s_logger.warn("More that one usage entry for ip address: " + ipAddress + " assigned to account: " + event.getAccountId() + "; marking them all as released...");
}
for (UsageIPAddressVO ipAddressVO : ipAddressVOs) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("releasing ip address: " + ipAddressVO.getAddress() + " from account: " + ipAddressVO.getAccountId());
}
// there really shouldn't be more than one
ipAddressVO.setReleased(event.getCreateDate());
m_usageIPAddressDao.update(ipAddressVO);
}
}
}
use of com.cloud.utils.db.SearchCriteria in project cloudstack by apache.
the class LunDaoImpl method listLunsByVolId.
@Override
public List<LunVO> listLunsByVolId(Long volId) {
Filter searchFilter = new Filter(LunVO.class, "id", Boolean.TRUE, Long.valueOf(0), Long.valueOf(10000));
SearchCriteria sc = LunSearch.create();
sc.setParameters("volumeId", volId);
List<LunVO> lunList = listBy(sc, searchFilter);
return lunList;
}
use of com.cloud.utils.db.SearchCriteria in project cloudstack by apache.
the class UsageManagerImpl method createVPNUserEvent.
private void createVPNUserEvent(UsageEventVO event) {
long zoneId = 0L;
long userId = event.getResourceId();
if (EventTypes.EVENT_VPN_USER_ADD.equals(event.getType())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating VPN user: " + userId + " for account: " + event.getAccountId());
}
Account acct = _accountDao.findByIdIncludingRemoved(event.getAccountId());
String userName = event.getResourceName();
UsageVPNUserVO vpnUser = new UsageVPNUserVO(zoneId, event.getAccountId(), acct.getDomainId(), userId, userName, event.getCreateDate(), null);
_usageVPNUserDao.persist(vpnUser);
} else if (EventTypes.EVENT_VPN_USER_REMOVE.equals(event.getType())) {
SearchCriteria<UsageVPNUserVO> sc = _usageVPNUserDao.createSearchCriteria();
sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
sc.addAnd("userId", SearchCriteria.Op.EQ, userId);
sc.addAnd("deleted", SearchCriteria.Op.NULL);
List<UsageVPNUserVO> vuVOs = _usageVPNUserDao.search(sc, null);
if (vuVOs.size() > 1) {
s_logger.warn("More that one usage entry for vpn user: " + userId + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
}
for (UsageVPNUserVO vuVO : vuVOs) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("deleting vpn user: " + vuVO.getUserId());
}
// there really shouldn't be more than one
vuVO.setDeleted(event.getCreateDate());
_usageVPNUserDao.update(vuVO);
}
}
}
Aggregations