mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-14 17:42:24 +01:00
CLOUDSTACK-6247: Usage Events - hide them when display flag is off in the context of "Ability to have better control over first class objects in CS" feature
Work done for network offering.
This commit is contained in:
parent
7442b56fa8
commit
5d19a936a2
@ -321,4 +321,6 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I
|
||||
|
||||
long getUpdated();
|
||||
|
||||
boolean isDisplay();
|
||||
|
||||
}
|
||||
|
||||
@ -3422,7 +3422,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
long isDefault = (nic.isDefaultNic()) ? 1 : 0;
|
||||
// insert nic's Id into DB as resource_name
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmVO.getAccountId(), vmVO.getDataCenterId(), vmVO.getId(),
|
||||
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vmVO.getUuid());
|
||||
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vmVO.getUuid(), vm.isDisplay());
|
||||
return nic;
|
||||
} else {
|
||||
s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network);
|
||||
@ -3537,7 +3537,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network);
|
||||
long isDefault = (nic.isDefaultNic()) ? 1 : 0;
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(),
|
||||
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
|
||||
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay());
|
||||
} else {
|
||||
s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network);
|
||||
return false;
|
||||
|
||||
@ -384,10 +384,16 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
|
||||
return haEnabled;
|
||||
}
|
||||
|
||||
//FIXME - Remove this and use isDisplay() instead
|
||||
public boolean isDisplayVm() {
|
||||
return displayVm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay() {
|
||||
return displayVm;
|
||||
}
|
||||
|
||||
public void setDisplayVm(boolean displayVm) {
|
||||
this.displayVm = displayVm;
|
||||
}
|
||||
|
||||
@ -173,6 +173,9 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
|
||||
@Column(name = "disk_offering_id")
|
||||
protected Long diskOfferingId;
|
||||
|
||||
@Column(name = "display_vm", updatable = true, nullable = false)
|
||||
protected boolean display = true;
|
||||
|
||||
@Transient
|
||||
private VMReservationVO vmReservation;
|
||||
|
||||
@ -539,4 +542,13 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
|
||||
public Class<?> getEntityType() {
|
||||
return VirtualMachine.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisplay() {
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(boolean display) {
|
||||
this.display = display;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2277,9 +2277,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
||||
long isDefault = (nic.isDefaultNic()) ? 1 : 0;
|
||||
String nicIdString = Long.toString(nic.getId());
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), nicIdString,
|
||||
oldNetworkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
|
||||
oldNetworkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay());
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), nicIdString,
|
||||
networkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
|
||||
networkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -1188,13 +1188,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
String nicIdString = Long.toString(nic.getId());
|
||||
long newNetworkOfferingId = network.getNetworkOfferingId();
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vmInstance.getAccountId(), vmInstance.getDataCenterId(), vmInstance.getId(),
|
||||
oldNicIdString, oldNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid());
|
||||
oldNicIdString, oldNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid(), vmInstance.isDisplay());
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(), vmInstance.getDataCenterId(), vmInstance.getId(), nicIdString,
|
||||
newNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid());
|
||||
newNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid(), vmInstance.isDisplay());
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vmInstance.getAccountId(), vmInstance.getDataCenterId(), vmInstance.getId(), nicIdString,
|
||||
newNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid());
|
||||
newNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid(), vmInstance.isDisplay());
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(), vmInstance.getDataCenterId(), vmInstance.getId(),
|
||||
oldNicIdString, oldNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid());
|
||||
oldNicIdString, oldNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid(), vmInstance.isDisplay());
|
||||
return _vmDao.findById(vmInstance.getId());
|
||||
}
|
||||
|
||||
@ -1866,6 +1866,15 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
return updateVirtualMachine(id, displayName, group, ha, isDisplayVm, osTypeId, userData, isDynamicallyScalable, cmd.getHttpMethod(), cmd.getCustomId(), hostName);
|
||||
}
|
||||
|
||||
private void usage(VirtualMachine vm){
|
||||
List<NicVO> nics = _nicDao.listByVmId(vm.getId());
|
||||
for (NicVO nic : nics) {
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(),
|
||||
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, 0L, vm.getClass().getName(), vm.getUuid(), vm.isDisplay());
|
||||
}
|
||||
}
|
||||
|
||||
private void saveUsageEvent(UserVmVO vm) {
|
||||
|
||||
// If vm not destroyed
|
||||
@ -1874,23 +1883,43 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
if(vm.isDisplayVm()){
|
||||
//1. Allocated VM Usage Event
|
||||
generateUsageEvent(vm, true, EventTypes.EVENT_VM_CREATE);
|
||||
//2. Running VM Usage Event
|
||||
|
||||
if(vm.getState() == State.Running || vm.getState() == State.Stopping){
|
||||
//2. Running VM Usage Event
|
||||
generateUsageEvent(vm, true, EventTypes.EVENT_VM_START);
|
||||
|
||||
// 3. Network offering usage
|
||||
generateNetworkUsageForVm(vm, true, EventTypes.EVENT_NETWORK_OFFERING_ASSIGN);
|
||||
}
|
||||
|
||||
}else {
|
||||
//1. Allocated VM Usage Event
|
||||
generateUsageEvent(vm, true, EventTypes.EVENT_VM_DESTROY);
|
||||
//2. Running VM Usage Event
|
||||
|
||||
if(vm.getState() == State.Running || vm.getState() == State.Stopping){
|
||||
//2. Running VM Usage Event
|
||||
generateUsageEvent(vm, true, EventTypes.EVENT_VM_STOP);
|
||||
|
||||
// 3. Network offering usage
|
||||
generateNetworkUsageForVm(vm, true, EventTypes.EVENT_NETWORK_OFFERING_REMOVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void generateNetworkUsageForVm(VirtualMachine vm, boolean isDisplay, String eventType){
|
||||
|
||||
List<NicVO> nics = _nicDao.listByVmId(vm.getId());
|
||||
for (NicVO nic : nics) {
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
long isDefault = (nic.isDefaultNic()) ? 1 : 0;
|
||||
UsageEventUtils.publishUsageEvent(eventType, vm.getAccountId(), vm.getDataCenterId(), vm.getId(),
|
||||
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, vm.getClass().getName(), vm.getUuid(), isDisplay);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVm updateVirtualMachine(long id, String displayName, String group, Boolean ha, Boolean isDisplayVmEnabled, Long osTypeId, String userData,
|
||||
Boolean isDynamicallyScalable, HTTPMethod httpMethod, String customId, String hostName) throws ResourceUnavailableException, InsufficientCapacityException {
|
||||
@ -3175,7 +3204,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
long isDefault = (nic.isDefaultNic()) ? 1 : 0;
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), Long.toString(nic.getId()),
|
||||
network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
|
||||
network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay());
|
||||
if (network.getTrafficType() == TrafficType.Guest) {
|
||||
originalIp = nic.getIp4Address();
|
||||
guestNic = nic;
|
||||
|
||||
@ -93,7 +93,7 @@ public class UserVmStateListener implements StateListener<State, VirtualMachine.
|
||||
for (NicVO nic : nics) {
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vo.getAccountId(), vo.getDataCenterId(), vo.getId(),
|
||||
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, 0L, vo.getClass().getName(), vo.getUuid());
|
||||
Long.toString(nic.getId()), network.getNetworkOfferingId(), null, 0L, vo.getClass().getName(), vo.getUuid(), vo.isDisplay());
|
||||
}
|
||||
} else if (VirtualMachine.State.isVmDestroyed(oldState, event, newState)) {
|
||||
generateUsageEvent(vo.getServiceOfferingId(), vo, EventTypes.EVENT_VM_DESTROY);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user