use of com.cloud.user.Account 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);
}
}
}
use of com.cloud.user.Account 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);
}
}
}
use of com.cloud.user.Account 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);
}
}
}
use of com.cloud.user.Account in project CloudStack-archive by CloudStack-extras.
the class UsageManagerImpl method createTemplateHelperEvent.
private void createTemplateHelperEvent(UsageEventVO event) {
long templateId = -1L;
long zoneId = -1L;
long templateSize = -1L;
templateId = event.getResourceId();
zoneId = event.getZoneId();
if (EventTypes.EVENT_TEMPLATE_CREATE.equals(event.getType()) || EventTypes.EVENT_TEMPLATE_COPY.equals(event.getType())) {
templateSize = event.getSize();
if (templateSize < 1) {
s_logger.error("Incorrect size for template with Id " + templateId);
return;
}
if (zoneId == -1L) {
s_logger.error("Incorrect zoneId for template with Id " + templateId);
return;
}
}
if (EventTypes.EVENT_TEMPLATE_CREATE.equals(event.getType()) || EventTypes.EVENT_TEMPLATE_COPY.equals(event.getType())) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("create template with id : " + templateId + " for account: " + event.getAccountId());
}
List<UsageStorageVO> storageVOs = m_usageStorageDao.listByIdAndZone(event.getAccountId(), templateId, StorageTypes.TEMPLATE, zoneId);
if (storageVOs.size() > 0) {
s_logger.warn("Usage entry for Template: " + templateId + " assigned to account: " + event.getAccountId() + "already exists in zone " + zoneId);
return;
}
Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
UsageStorageVO storageVO = new UsageStorageVO(templateId, zoneId, event.getAccountId(), acct.getDomainId(), StorageTypes.TEMPLATE, event.getTemplateId(), templateSize, event.getCreateDate(), null);
m_usageStorageDao.persist(storageVO);
} else if (EventTypes.EVENT_TEMPLATE_DELETE.equals(event.getType())) {
List<UsageStorageVO> storageVOs;
if (zoneId != -1L) {
storageVOs = m_usageStorageDao.listByIdAndZone(event.getAccountId(), templateId, StorageTypes.TEMPLATE, zoneId);
} else {
storageVOs = m_usageStorageDao.listById(event.getAccountId(), templateId, StorageTypes.TEMPLATE);
}
if (storageVOs.size() > 1) {
s_logger.warn("More that one usage entry for storage: " + templateId + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
}
for (UsageStorageVO storageVO : storageVOs) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("deleting template: " + storageVO.getId() + " from account: " + storageVO.getAccountId());
}
// there really shouldn't be more than one
storageVO.setDeleted(event.getCreateDate());
m_usageStorageDao.update(storageVO);
}
}
}
use of com.cloud.user.Account 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);
}
}
}
Aggregations