mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
bug 7504: Added usage events and made corresponding changes in usage server
This commit is contained in:
parent
a7626fc991
commit
b12cd70216
@ -29,7 +29,6 @@
|
||||
<param name="cache.size">50</param>
|
||||
<param name="cache.time.to.live">-1</param>
|
||||
</dao>
|
||||
<dao name="Events" class="com.cloud.event.dao.EventDaoImpl"/>
|
||||
<dao name="UserStats" class="com.cloud.user.dao.UserStatisticsDaoImpl"/>
|
||||
<dao name="IP Addresses" class="com.cloud.network.dao.IPAddressDaoImpl"/>
|
||||
<dao name="Usage" class="com.cloud.usage.dao.UsageDaoImpl"/>
|
||||
@ -41,6 +40,8 @@
|
||||
<dao name="Usage IPAddress" class="com.cloud.usage.dao.UsageIPAddressDaoImpl"/>
|
||||
<dao name="Usage Job" class="com.cloud.usage.dao.UsageJobDaoImpl"/>
|
||||
<dao name="Configuration" class="com.cloud.configuration.dao.ConfigurationDaoImpl"/>
|
||||
<dao name="Usage Event" class="com.cloud.event.dao.UsageEventDaoImpl"/>
|
||||
<manager name="Usage alert manager" class="com.cloud.usage.UsageAlertManagerImpl"/>
|
||||
<manager name="usage manager" class="com.cloud.usage.UsageManagerImpl">
|
||||
<param name="period">DAILY</param> <!-- DAILY, WEEKLY, MONTHLY; how often it creates usage records -->
|
||||
</manager>
|
||||
|
||||
@ -255,7 +255,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
throw new CloudRuntimeException("Found address to allocate but unable to update: " + addr);
|
||||
}
|
||||
if(!sourceNat){
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getAccountId(), dcId, -1, addr.getAddress());
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getAccountId(), dcId, 0, addr.getAddress());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
|
||||
@ -673,7 +673,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
_ipAddressDao.unassignIpAddress(ipAddress);
|
||||
s_logger.debug("released a public ip: " + ipAddress);
|
||||
if(!ip.isSourceNat()){
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ownerId, ip.getDataCenterId(), -1, ipAddress);
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ownerId, ip.getDataCenterId(), 0, ipAddress);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,9 @@ import com.cloud.dc.dao.VlanDao;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.EventVO;
|
||||
import com.cloud.event.UsageEventVO;
|
||||
import com.cloud.event.dao.EventDao;
|
||||
import com.cloud.event.dao.UsageEventDao;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
@ -105,6 +107,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
||||
@Inject AccountDao _accountDao;
|
||||
@Inject DomainDao _domainDao;
|
||||
@Inject NicDao _nicDao;
|
||||
@Inject UsageEventDao _usageEventDao;
|
||||
|
||||
@Override @DB
|
||||
public boolean assignToLoadBalancer(long loadBalancerId, List<Long> instanceIds) {
|
||||
@ -241,6 +244,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
||||
}
|
||||
|
||||
_rulesDao.remove(lb.getId());
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_LOAD_BALANCER_DELETE, lb.getAccountId(), 0 , lb.getId(), null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
s_logger.debug("Load balancer with id " + lb.getId() + " is removed successfully");
|
||||
return true;
|
||||
}
|
||||
@ -327,6 +332,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
||||
String params = "id=" + newRule.getId() + "\ndcId=" + ipAddr.getDataCenterId();
|
||||
event.setParameters(params);
|
||||
event.setLevel(EventVO.LEVEL_INFO);
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_LOAD_BALANCER_CREATE, ipAddr.getAllocatedToAccountId(), ipAddr.getDataCenterId(), newRule.getId(), null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
_eventDao.persist(event);
|
||||
}
|
||||
|
||||
@ -700,6 +700,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
if (createdVolume.getPath() != null) {
|
||||
event.setDescription("Created volume: "+ createdVolume.getName() + " with size: " + sizeMB + " MB in pool: " + poolName + " from snapshot id: " + snapshotId);
|
||||
event.setLevel(EventVO.LEVEL_INFO);
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), diskOfferingId, templateId , sizeMB);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
else {
|
||||
details = "CreateVolume From Snapshot for snapshotId: " + snapshotId + " failed at the backend, reason " + details;
|
||||
@ -2684,6 +2686,11 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
|
||||
vol = _volsDao.persist(vol);
|
||||
|
||||
if(vm instanceof UserVm){
|
||||
long sizeMB = size / (1024 * 1024);
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), null , sizeMB);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
return toDiskProfile(vol, offering);
|
||||
}
|
||||
|
||||
@ -2716,6 +2723,11 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
|
||||
vol = _volsDao.persist(vol);
|
||||
|
||||
if(vm instanceof UserVm){
|
||||
long sizeMB = vol.getSize() / (1024 * 1024);
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), template.getId() , sizeMB);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
return toDiskProfile(vol, offering);
|
||||
}
|
||||
|
||||
|
||||
@ -59,7 +59,9 @@ import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.EventUtils;
|
||||
import com.cloud.event.EventVO;
|
||||
import com.cloud.event.UsageEventVO;
|
||||
import com.cloud.event.dao.EventDao;
|
||||
import com.cloud.event.dao.UsageEventDao;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
@ -138,6 +140,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
@Inject protected AsyncJobManager _asyncMgr;
|
||||
@Inject protected AccountManager _accountMgr;
|
||||
@Inject protected ClusterDao _clusterDao;
|
||||
@Inject private UsageEventDao _usageEventDao;
|
||||
String _name;
|
||||
private int _totalRetries;
|
||||
private int _pauseInterval;
|
||||
@ -524,6 +527,8 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
event.setDescription("Backed up snapshot id: " + snapshotId + " to secondary for volume:" + volumeId);
|
||||
event.setLevel(EventVO.LEVEL_INFO);
|
||||
event.setParameters(eventParams);
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), volume.getDataCenterId(), snapshotId, snapshotName, null, null, volume.getSize());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
|
||||
}
|
||||
else {
|
||||
@ -769,6 +774,12 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
event.setLevel(success ? EventVO.LEVEL_INFO : EventVO.LEVEL_ERROR);
|
||||
_eventDao.persist(event);
|
||||
|
||||
if(success){
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_DELETE, snapshot.getAccountId(), volume.getDataCenterId(), snapshotId, snapshot.getName(), null, null, volume.getSize());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
|
||||
|
||||
return success;
|
||||
|
||||
}
|
||||
@ -955,6 +966,8 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
event.setParameters(eventParams);
|
||||
event.setLevel(EventVO.LEVEL_INFO);
|
||||
_eventDao.persist(event);
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_DELETE, snapshot.getAccountId(), volume.getDataCenterId(), snapshot.getId(), snapshot.getName(), null, null, volume.getSize());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,6 +129,7 @@ import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
|
||||
@Local(value={TemplateManager.class, TemplateService.class})
|
||||
public class TemplateManagerImpl implements TemplateManager, Manager, TemplateService {
|
||||
private final static Logger s_logger = Logger.getLogger(TemplateManagerImpl.class);
|
||||
@ -160,7 +161,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
@Inject AsyncJobManager _asyncMgr;
|
||||
@Inject UserVmManager _vmMgr;
|
||||
@Inject ConfigurationDao _configDao;
|
||||
@Inject UsageEventDao _usageEventDao;
|
||||
@Inject UsageEventDao _usageEventDao;
|
||||
protected SearchBuilder<VMTemplateHostVO> HostTemplateStatesSearch;
|
||||
|
||||
@Override
|
||||
@ -817,6 +818,8 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
_downloadMonitor.copyTemplate(vmTemplate, srcSecHost, dstSecHost);
|
||||
|
||||
UsageEventVO usageEvent = new UsageEventVO(copyEventType, account.getId(), destZoneId, templateId, null, null, null, srcTmpltHost.getSize());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
saveEvent(userId, account.getId(), account.getDomainId(), copyEventType, copyEventDescription, EventVO.LEVEL_INFO, params, startEventId);
|
||||
return true;
|
||||
}
|
||||
@ -963,6 +966,8 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
String zoneParams = params + "\ndcId=" + sZoneId;
|
||||
saveEvent(userId, account.getId(), account.getDomainId(), eventType, description + template.getName() + " succesfully deleted.", EventVO.LEVEL_INFO, zoneParams, 0);
|
||||
UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), sZoneId, templateId, null, null, null, null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
} finally {
|
||||
if (lock != null) {
|
||||
_tmpltHostDao.releaseFromLockTable(lock.getId());
|
||||
|
||||
@ -76,6 +76,7 @@ import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.Journal;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
@ -434,8 +435,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster
|
||||
if (!stateTransitTo(vm, Event.OperationSucceeded, dest.getHost().getId())) {
|
||||
throw new CloudRuntimeException("Unable to transition to a new state.");
|
||||
}
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_START, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
if(vm instanceof UserVm){
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_START, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
return vm;
|
||||
}
|
||||
s_logger.info("Unable to start VM on " + dest.getHost() + " due to " + answers[0].getDetails());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user