From 0b9fa1cc8a47c614ceb1aa5fc795c39133cf0657 Mon Sep 17 00:00:00 2001 From: kishan Date: Fri, 25 Feb 2011 16:29:16 +0530 Subject: [PATCH] bug 5747: Added action events for system Vms commands status 5747: resolved fixed --- .../api/commands/DestroySystemVmCmd.java | 11 +++- .../cloud/api/commands/RebootSystemVmCmd.java | 9 ++- .../cloud/api/commands/StartSystemVMCmd.java | 9 ++- .../cloud/api/commands/StopSystemVmCmd.java | 9 ++- .../com/cloud/server/ManagementService.java | 3 + .../com/cloud/server/ManagementServer.java | 5 +- .../cloud/server/ManagementServerImpl.java | 56 +++++++++++++------ 7 files changed, 78 insertions(+), 24 deletions(-) diff --git a/api/src/com/cloud/api/commands/DestroySystemVmCmd.java b/api/src/com/cloud/api/commands/DestroySystemVmCmd.java index c35464f50ac..276e6b1ff1b 100644 --- a/api/src/com/cloud/api/commands/DestroySystemVmCmd.java +++ b/api/src/com/cloud/api/commands/DestroySystemVmCmd.java @@ -49,9 +49,15 @@ public class DestroySystemVmCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_SSVM_START; + VirtualMachine.Type type = _mgr.findSystemVMTypeById(getId()); + if(type == VirtualMachine.Type.ConsoleProxy){ + return EventTypes.EVENT_PROXY_DESTROY; + } + else{ + return EventTypes.EVENT_SSVM_DESTROY; + } } - + @Override public String getEventDescription() { return "destroying system vm: " + getId(); @@ -69,6 +75,7 @@ public class DestroySystemVmCmd extends BaseAsyncCmd { @Override public void execute(){ + UserContext.current().setEventDetails("Vm Id: "+getId()); VirtualMachine instance = _mgr.destroySystemVM(this); if (instance != null) { SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance); diff --git a/api/src/com/cloud/api/commands/RebootSystemVmCmd.java b/api/src/com/cloud/api/commands/RebootSystemVmCmd.java index c401d9d4b1b..aefa42a59c7 100644 --- a/api/src/com/cloud/api/commands/RebootSystemVmCmd.java +++ b/api/src/com/cloud/api/commands/RebootSystemVmCmd.java @@ -75,7 +75,13 @@ public class RebootSystemVmCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_SSVM_REBOOT; + VirtualMachine.Type type = _mgr.findSystemVMTypeById(getId()); + if(type == VirtualMachine.Type.ConsoleProxy){ + return EventTypes.EVENT_PROXY_REBOOT; + } + else{ + return EventTypes.EVENT_SSVM_REBOOT; + } } @Override @@ -93,6 +99,7 @@ public class RebootSystemVmCmd extends BaseAsyncCmd { @Override public void execute(){ + UserContext.current().setEventDetails("Vm Id: "+getId()); VirtualMachine result = _mgr.rebootSystemVM(this); if (result != null) { SystemVmResponse response = _responseGenerator.createSystemVmResponse(result); diff --git a/api/src/com/cloud/api/commands/StartSystemVMCmd.java b/api/src/com/cloud/api/commands/StartSystemVMCmd.java index 536ebc8b988..02e01ee4728 100644 --- a/api/src/com/cloud/api/commands/StartSystemVMCmd.java +++ b/api/src/com/cloud/api/commands/StartSystemVMCmd.java @@ -79,7 +79,13 @@ public class StartSystemVMCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_SSVM_START; + VirtualMachine.Type type = _mgr.findSystemVMTypeById(getId()); + if(type == VirtualMachine.Type.ConsoleProxy){ + return EventTypes.EVENT_PROXY_START; + } + else{ + return EventTypes.EVENT_SSVM_START; + } } @Override @@ -97,6 +103,7 @@ public class StartSystemVMCmd extends BaseAsyncCmd { @Override public void execute(){ + UserContext.current().setEventDetails("Vm Id: "+getId()); VirtualMachine instance = _mgr.startSystemVM(this); if (instance != null) { SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance); diff --git a/api/src/com/cloud/api/commands/StopSystemVmCmd.java b/api/src/com/cloud/api/commands/StopSystemVmCmd.java index 6367d2896d6..a7e6b0f1e73 100644 --- a/api/src/com/cloud/api/commands/StopSystemVmCmd.java +++ b/api/src/com/cloud/api/commands/StopSystemVmCmd.java @@ -80,7 +80,13 @@ public class StopSystemVmCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_SSVM_STOP; + VirtualMachine.Type type = _mgr.findSystemVMTypeById(getId()); + if(type == VirtualMachine.Type.ConsoleProxy){ + return EventTypes.EVENT_PROXY_STOP; + } + else{ + return EventTypes.EVENT_SSVM_STOP; + } } @Override @@ -104,6 +110,7 @@ public class StopSystemVmCmd extends BaseAsyncCmd { @Override public void execute() throws ResourceUnavailableException, ConcurrentOperationException { + UserContext.current().setEventDetails("Vm Id: "+getId()); VirtualMachine result = _mgr.stopSystemVM(this); if (result != null) { SystemVmResponse response = _responseGenerator.createSystemVmResponse(result); diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index 4bff921391c..449a59b5cef 100644 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -105,6 +105,7 @@ import com.cloud.user.UserAccount; import com.cloud.utils.Pair; import com.cloud.vm.InstanceGroup; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.Type; /** * Hopefull this is temporary. @@ -425,4 +426,6 @@ public interface ManagementService { */ String getVMPassword(GetVMPasswordCmd cmd); + Type findSystemVMTypeById(long instanceId); + } diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index 84e454b2239..6cf123cb0ff 100755 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -30,8 +30,11 @@ import com.cloud.dc.HostPodVO; import com.cloud.dc.VlanVO; import com.cloud.domain.DomainVO; import com.cloud.event.EventVO; +import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InternalErrorException; import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceUnavailableException; import com.cloud.host.HostVO; import com.cloud.info.ConsoleProxyInfo; import com.cloud.network.IPAddressVO; @@ -365,7 +368,7 @@ public interface ManagementServer extends ManagementService { ConsoleProxyInfo getConsoleProxy(long dataCenterId, long userVmId); ConsoleProxyVO startConsoleProxy(long instanceId); - ConsoleProxyVO stopConsoleProxy(long instanceId); + ConsoleProxyVO stopConsoleProxy(VMInstanceVO systemVm, boolean isForced) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException; ConsoleProxyVO rebootConsoleProxy(long instanceId); String getConsoleAccessUrlRoot(long vmId); ConsoleProxyVO findConsoleProxyById(long instanceId); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index eb463ef582a..a8982b8928b 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -2721,23 +2721,29 @@ public class ManagementServerImpl implements ManagementServer { return _consoleProxyMgr.assignProxy(dataCenterId, userVmId); } - @Override + @Override @ActionEvent (eventType=EventTypes.EVENT_PROXY_START, eventDescription="starting console proxy Vm", async=true) public ConsoleProxyVO startConsoleProxy(long instanceId) { return _consoleProxyMgr.startProxy(instanceId); } - @Override - public ConsoleProxyVO stopConsoleProxy(long instanceId) { - _consoleProxyMgr.stopProxy(instanceId); - return _consoleProxyDao.findById(instanceId); + @Override @ActionEvent (eventType=EventTypes.EVENT_PROXY_STOP, eventDescription="stopping console proxy Vm", async=true) + public ConsoleProxyVO stopConsoleProxy(VMInstanceVO systemVm, boolean isForced) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException { + + User caller = _userDao.findById(UserContext.current().getCallerUserId()); + + if (_itMgr.advanceStop(systemVm, isForced, caller, UserContext.current().getCaller())) { + return _consoleProxyDao.findById(systemVm.getId()); + } + return null; } - @Override + @Override @ActionEvent (eventType=EventTypes.EVENT_PROXY_REBOOT, eventDescription="rebooting console proxy Vm", async=true) public ConsoleProxyVO rebootConsoleProxy(long instanceId) { _consoleProxyMgr.rebootProxy(instanceId); return _consoleProxyDao.findById(instanceId); } + @ActionEvent (eventType=EventTypes.EVENT_PROXY_DESTROY, eventDescription="destroying console proxy Vm", async=true) public ConsoleProxyVO destroyConsoleProxy(long instanceId) { ConsoleProxyVO proxy = _consoleProxyDao.findById(instanceId); @@ -3881,20 +3887,29 @@ public class ManagementServerImpl implements ManagementServer { return _domainDao.isChildDomain(parentId, childId); } + @ActionEvent (eventType=EventTypes.EVENT_SSVM_START, eventDescription="starting secondary storage Vm", async=true) public SecondaryStorageVmVO startSecondaryStorageVm(long instanceId) { return _secStorageVmMgr.startSecStorageVm(instanceId); } - public SecondaryStorageVmVO stopSecondaryStorageVm(long instanceId) { - _secStorageVmMgr.stopSecStorageVm(instanceId); - return _secStorageVmDao.findById(instanceId); + @ActionEvent (eventType=EventTypes.EVENT_SSVM_STOP, eventDescription="stopping secondary storage Vm", async=true) + public SecondaryStorageVmVO stopSecondaryStorageVm(VMInstanceVO systemVm, boolean isForced) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException { + + User caller = _userDao.findById(UserContext.current().getCallerUserId()); + + if (_itMgr.advanceStop(systemVm, isForced, caller, UserContext.current().getCaller())) { + return _secStorageVmDao.findById(systemVm.getId()); + } + return null; } + @ActionEvent (eventType=EventTypes.EVENT_SSVM_REBOOT, eventDescription="rebooting secondary storage Vm", async=true) public SecondaryStorageVmVO rebootSecondaryStorageVm(long instanceId) { _secStorageVmMgr.rebootSecStorageVm(instanceId); return _secStorageVmDao.findById(instanceId); } + @ActionEvent (eventType=EventTypes.EVENT_SSVM_DESTROY, eventDescription="destroying secondary storage Vm", async=true) public SecondaryStorageVmVO destroySecondaryStorageVm(long instanceId) { SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(instanceId); if(_secStorageVmMgr.destroySecStorageVm(instanceId)) { @@ -3986,6 +4001,15 @@ public class ManagementServerImpl implements ManagementServer { } return _secStorageVmDao.findById(instanceId); } + + @Override + public VirtualMachine.Type findSystemVMTypeById(long instanceId) { + VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); + if(systemVm == null) { + throw new InvalidParameterValueException("Unable to find a system vm: " + instanceId); + } + return systemVm.getType(); + } @Override public VirtualMachine startSystemVM(StartSystemVMCmd cmd) { @@ -4019,16 +4043,12 @@ public class ManagementServerImpl implements ManagementServer { throw new InvalidParameterValueException("unable to find a system vm with id " + id); } - User caller = _userDao.findById(UserContext.current().getCallerUserId()); - try { - if (_itMgr.advanceStop(systemVm, cmd.isForced(), caller, UserContext.current().getCaller())) { - if (systemVm.getType() == VirtualMachine.Type.ConsoleProxy) { - return _consoleProxyDao.findById(systemVm.getId()); - } else if (systemVm.getType() == VirtualMachine.Type.SecondaryStorageVm) { - return _secStorageVmDao.findById(systemVm.getId()); - } - } + if (systemVm.getType() == VirtualMachine.Type.ConsoleProxy) { + return stopConsoleProxy(systemVm, cmd.isForced()); + } else if (systemVm.getType() == VirtualMachine.Type.SecondaryStorageVm) { + return stopSecondaryStorageVm(systemVm, cmd.isForced()); + } return null; } catch (OperationTimedoutException e) { throw new CloudRuntimeException("Unable to stop " + systemVm, e);