Skip to content

Commit 0b9fa1c

Browse files
author
kishan
committed
bug 5747: Added action events for system Vms commands
status 5747: resolved fixed
1 parent 44d6057 commit 0b9fa1c

7 files changed

Lines changed: 78 additions & 24 deletions

File tree

‎api/src/com/cloud/api/commands/DestroySystemVmCmd.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ public long getEntityOwnerId() {
4949

5050
@Override
5151
public String getEventType() {
52-
return EventTypes.EVENT_SSVM_START;
52+
VirtualMachine.Type type = _mgr.findSystemVMTypeById(getId());
53+
if(type == VirtualMachine.Type.ConsoleProxy){
54+
return EventTypes.EVENT_PROXY_DESTROY;
55+
}
56+
else{
57+
return EventTypes.EVENT_SSVM_DESTROY;
58+
}
5359
}
54-
60+
5561
@Override
5662
public String getEventDescription() {
5763
return "destroying system vm: " + getId();
@@ -69,6 +75,7 @@ public Long getInstanceId() {
6975

7076
@Override
7177
public void execute(){
78+
UserContext.current().setEventDetails("Vm Id: "+getId());
7279
VirtualMachine instance = _mgr.destroySystemVM(this);
7380
if (instance != null) {
7481
SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);

‎api/src/com/cloud/api/commands/RebootSystemVmCmd.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ public long getEntityOwnerId() {
7575

7676
@Override
7777
public String getEventType() {
78-
return EventTypes.EVENT_SSVM_REBOOT;
78+
VirtualMachine.Type type = _mgr.findSystemVMTypeById(getId());
79+
if(type == VirtualMachine.Type.ConsoleProxy){
80+
return EventTypes.EVENT_PROXY_REBOOT;
81+
}
82+
else{
83+
return EventTypes.EVENT_SSVM_REBOOT;
84+
}
7985
}
8086

8187
@Override
@@ -93,6 +99,7 @@ public Long getInstanceId() {
9399

94100
@Override
95101
public void execute(){
102+
UserContext.current().setEventDetails("Vm Id: "+getId());
96103
VirtualMachine result = _mgr.rebootSystemVM(this);
97104
if (result != null) {
98105
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);

‎api/src/com/cloud/api/commands/StartSystemVMCmd.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ public long getEntityOwnerId() {
7979

8080
@Override
8181
public String getEventType() {
82-
return EventTypes.EVENT_SSVM_START;
82+
VirtualMachine.Type type = _mgr.findSystemVMTypeById(getId());
83+
if(type == VirtualMachine.Type.ConsoleProxy){
84+
return EventTypes.EVENT_PROXY_START;
85+
}
86+
else{
87+
return EventTypes.EVENT_SSVM_START;
88+
}
8389
}
8490

8591
@Override
@@ -97,6 +103,7 @@ public Long getInstanceId() {
97103

98104
@Override
99105
public void execute(){
106+
UserContext.current().setEventDetails("Vm Id: "+getId());
100107
VirtualMachine instance = _mgr.startSystemVM(this);
101108
if (instance != null) {
102109
SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);

‎api/src/com/cloud/api/commands/StopSystemVmCmd.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ public long getEntityOwnerId() {
8080

8181
@Override
8282
public String getEventType() {
83-
return EventTypes.EVENT_SSVM_STOP;
83+
VirtualMachine.Type type = _mgr.findSystemVMTypeById(getId());
84+
if(type == VirtualMachine.Type.ConsoleProxy){
85+
return EventTypes.EVENT_PROXY_STOP;
86+
}
87+
else{
88+
return EventTypes.EVENT_SSVM_STOP;
89+
}
8490
}
8591

8692
@Override
@@ -104,6 +110,7 @@ public boolean isForced() {
104110

105111
@Override
106112
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
113+
UserContext.current().setEventDetails("Vm Id: "+getId());
107114
VirtualMachine result = _mgr.stopSystemVM(this);
108115
if (result != null) {
109116
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);

‎api/src/com/cloud/server/ManagementService.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
import com.cloud.utils.Pair;
106106
import com.cloud.vm.InstanceGroup;
107107
import com.cloud.vm.VirtualMachine;
108+
import com.cloud.vm.VirtualMachine.Type;
108109

109110
/**
110111
* Hopefull this is temporary.
@@ -425,4 +426,6 @@ public interface ManagementService {
425426
*/
426427
String getVMPassword(GetVMPasswordCmd cmd);
427428

429+
Type findSystemVMTypeById(long instanceId);
430+
428431
}

‎server/src/com/cloud/server/ManagementServer.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@
3030
import com.cloud.dc.VlanVO;
3131
import com.cloud.domain.DomainVO;
3232
import com.cloud.event.EventVO;
33+
import com.cloud.exception.ConcurrentOperationException;
3334
import com.cloud.exception.InternalErrorException;
3435
import com.cloud.exception.InvalidParameterValueException;
36+
import com.cloud.exception.OperationTimedoutException;
37+
import com.cloud.exception.ResourceUnavailableException;
3538
import com.cloud.host.HostVO;
3639
import com.cloud.info.ConsoleProxyInfo;
3740
import com.cloud.network.IPAddressVO;
@@ -365,7 +368,7 @@ public interface ManagementServer extends ManagementService {
365368

366369
ConsoleProxyInfo getConsoleProxy(long dataCenterId, long userVmId);
367370
ConsoleProxyVO startConsoleProxy(long instanceId);
368-
ConsoleProxyVO stopConsoleProxy(long instanceId);
371+
ConsoleProxyVO stopConsoleProxy(VMInstanceVO systemVm, boolean isForced) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
369372
ConsoleProxyVO rebootConsoleProxy(long instanceId);
370373
String getConsoleAccessUrlRoot(long vmId);
371374
ConsoleProxyVO findConsoleProxyById(long instanceId);

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,23 +2721,29 @@ public ConsoleProxyInfo getConsoleProxy(long dataCenterId, long userVmId) {
27212721
return _consoleProxyMgr.assignProxy(dataCenterId, userVmId);
27222722
}
27232723

2724-
@Override
2724+
@Override @ActionEvent (eventType=EventTypes.EVENT_PROXY_START, eventDescription="starting console proxy Vm", async=true)
27252725
public ConsoleProxyVO startConsoleProxy(long instanceId) {
27262726
return _consoleProxyMgr.startProxy(instanceId);
27272727
}
27282728

2729-
@Override
2730-
public ConsoleProxyVO stopConsoleProxy(long instanceId) {
2731-
_consoleProxyMgr.stopProxy(instanceId);
2732-
return _consoleProxyDao.findById(instanceId);
2729+
@Override @ActionEvent (eventType=EventTypes.EVENT_PROXY_STOP, eventDescription="stopping console proxy Vm", async=true)
2730+
public ConsoleProxyVO stopConsoleProxy(VMInstanceVO systemVm, boolean isForced) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException {
2731+
2732+
User caller = _userDao.findById(UserContext.current().getCallerUserId());
2733+
2734+
if (_itMgr.advanceStop(systemVm, isForced, caller, UserContext.current().getCaller())) {
2735+
return _consoleProxyDao.findById(systemVm.getId());
2736+
}
2737+
return null;
27332738
}
27342739

2735-
@Override
2740+
@Override @ActionEvent (eventType=EventTypes.EVENT_PROXY_REBOOT, eventDescription="rebooting console proxy Vm", async=true)
27362741
public ConsoleProxyVO rebootConsoleProxy(long instanceId) {
27372742
_consoleProxyMgr.rebootProxy(instanceId);
27382743
return _consoleProxyDao.findById(instanceId);
27392744
}
27402745

2746+
@ActionEvent (eventType=EventTypes.EVENT_PROXY_DESTROY, eventDescription="destroying console proxy Vm", async=true)
27412747
public ConsoleProxyVO destroyConsoleProxy(long instanceId) {
27422748
ConsoleProxyVO proxy = _consoleProxyDao.findById(instanceId);
27432749

@@ -3881,20 +3887,29 @@ public boolean isChildDomain(Long parentId, Long childId) {
38813887
return _domainDao.isChildDomain(parentId, childId);
38823888
}
38833889

3890+
@ActionEvent (eventType=EventTypes.EVENT_SSVM_START, eventDescription="starting secondary storage Vm", async=true)
38843891
public SecondaryStorageVmVO startSecondaryStorageVm(long instanceId) {
38853892
return _secStorageVmMgr.startSecStorageVm(instanceId);
38863893
}
38873894

3888-
public SecondaryStorageVmVO stopSecondaryStorageVm(long instanceId) {
3889-
_secStorageVmMgr.stopSecStorageVm(instanceId);
3890-
return _secStorageVmDao.findById(instanceId);
3895+
@ActionEvent (eventType=EventTypes.EVENT_SSVM_STOP, eventDescription="stopping secondary storage Vm", async=true)
3896+
public SecondaryStorageVmVO stopSecondaryStorageVm(VMInstanceVO systemVm, boolean isForced) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException {
3897+
3898+
User caller = _userDao.findById(UserContext.current().getCallerUserId());
3899+
3900+
if (_itMgr.advanceStop(systemVm, isForced, caller, UserContext.current().getCaller())) {
3901+
return _secStorageVmDao.findById(systemVm.getId());
3902+
}
3903+
return null;
38913904
}
38923905

3906+
@ActionEvent (eventType=EventTypes.EVENT_SSVM_REBOOT, eventDescription="rebooting secondary storage Vm", async=true)
38933907
public SecondaryStorageVmVO rebootSecondaryStorageVm(long instanceId) {
38943908
_secStorageVmMgr.rebootSecStorageVm(instanceId);
38953909
return _secStorageVmDao.findById(instanceId);
38963910
}
38973911

3912+
@ActionEvent (eventType=EventTypes.EVENT_SSVM_DESTROY, eventDescription="destroying secondary storage Vm", async=true)
38983913
public SecondaryStorageVmVO destroySecondaryStorageVm(long instanceId) {
38993914
SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(instanceId);
39003915
if(_secStorageVmMgr.destroySecStorageVm(instanceId)) {
@@ -3986,6 +4001,15 @@ public VMInstanceVO findSystemVMById(long instanceId) {
39864001
}
39874002
return _secStorageVmDao.findById(instanceId);
39884003
}
4004+
4005+
@Override
4006+
public VirtualMachine.Type findSystemVMTypeById(long instanceId) {
4007+
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
4008+
if(systemVm == null) {
4009+
throw new InvalidParameterValueException("Unable to find a system vm: " + instanceId);
4010+
}
4011+
return systemVm.getType();
4012+
}
39894013

39904014
@Override
39914015
public VirtualMachine startSystemVM(StartSystemVMCmd cmd) {
@@ -4019,16 +4043,12 @@ public VMInstanceVO stopSystemVM(StopSystemVmCmd cmd) throws ResourceUnavailable
40194043
throw new InvalidParameterValueException("unable to find a system vm with id " + id);
40204044
}
40214045

4022-
User caller = _userDao.findById(UserContext.current().getCallerUserId());
4023-
40244046
try {
4025-
if (_itMgr.advanceStop(systemVm, cmd.isForced(), caller, UserContext.current().getCaller())) {
4026-
if (systemVm.getType() == VirtualMachine.Type.ConsoleProxy) {
4027-
return _consoleProxyDao.findById(systemVm.getId());
4028-
} else if (systemVm.getType() == VirtualMachine.Type.SecondaryStorageVm) {
4029-
return _secStorageVmDao.findById(systemVm.getId());
4030-
}
4031-
}
4047+
if (systemVm.getType() == VirtualMachine.Type.ConsoleProxy) {
4048+
return stopConsoleProxy(systemVm, cmd.isForced());
4049+
} else if (systemVm.getType() == VirtualMachine.Type.SecondaryStorageVm) {
4050+
return stopSecondaryStorageVm(systemVm, cmd.isForced());
4051+
}
40324052
return null;
40334053
} catch (OperationTimedoutException e) {
40344054
throw new CloudRuntimeException("Unable to stop " + systemVm, e);

0 commit comments

Comments
 (0)