From 62078ffef2bd5f35318dc3403906c1a67ead1fc8 Mon Sep 17 00:00:00 2001 From: Nitin Date: Thu, 30 Jun 2011 16:28:04 +0530 Subject: [PATCH] bug 8915: Adding events for TEMPLATE.CREATE, TEMPLATE.DELETE, ISO.DELETE, ISO.ATTACH, ISO.DETACH. Status 8915: resolved fixed --- api/src/com/cloud/api/commands/AttachIsoCmd.java | 2 ++ api/src/com/cloud/api/commands/CreateTemplateCmd.java | 2 ++ api/src/com/cloud/api/commands/DeleteIsoCmd.java | 2 ++ api/src/com/cloud/api/commands/DeleteTemplateCmd.java | 2 ++ server/src/com/cloud/template/TemplateManagerImpl.java | 5 +++++ server/src/com/cloud/vm/UserVmManagerImpl.java | 2 ++ 6 files changed, 15 insertions(+) mode change 100644 => 100755 api/src/com/cloud/api/commands/DeleteIsoCmd.java mode change 100644 => 100755 api/src/com/cloud/api/commands/DeleteTemplateCmd.java diff --git a/api/src/com/cloud/api/commands/AttachIsoCmd.java b/api/src/com/cloud/api/commands/AttachIsoCmd.java index 4cb34d1536b..968c4b316b9 100755 --- a/api/src/com/cloud/api/commands/AttachIsoCmd.java +++ b/api/src/com/cloud/api/commands/AttachIsoCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.UserVmResponse; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.UserContext; import com.cloud.uservm.UserVm; @Implementation(description="Attaches an ISO to a virtual machine.", responseObject=UserVmResponse.class) @@ -91,6 +92,7 @@ public class AttachIsoCmd extends BaseAsyncCmd { @Override public void execute(){ + UserContext.current().setEventDetails("Vm Id: " +getVirtualMachineId()+ " ISO Id: "+getId()); boolean result = _templateService.attachIso(this); if (result) { UserVm userVm = _responseGenerator.findUserVmById(virtualMachineId); diff --git a/api/src/com/cloud/api/commands/CreateTemplateCmd.java b/api/src/com/cloud/api/commands/CreateTemplateCmd.java index e79e6bf183a..47990092b53 100755 --- a/api/src/com/cloud/api/commands/CreateTemplateCmd.java +++ b/api/src/com/cloud/api/commands/CreateTemplateCmd.java @@ -38,6 +38,7 @@ import com.cloud.storage.Snapshot; import com.cloud.storage.Volume; import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(responseObject = StoragePoolResponse.class, description = "Creates a template of a virtual machine. " + "The virtual machine must be in a STOPPED state. " + "A template created from this command is automatically designated as a private template visible to the account that created it.") @@ -185,6 +186,7 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd { @Override public void execute() { + UserContext.current().setEventDetails("Template Id: "+getEntityId()+((getSnapshotId() == null) ? " from volume Id: " + getVolumeId() : " from snapshot Id: " + getSnapshotId())); VirtualMachineTemplate template = _userVmService.createPrivateTemplate(this); if (template != null){ ListResponse response = new ListResponse(); diff --git a/api/src/com/cloud/api/commands/DeleteIsoCmd.java b/api/src/com/cloud/api/commands/DeleteIsoCmd.java old mode 100644 new mode 100755 index 898c39857f7..f48e249b01d --- a/api/src/com/cloud/api/commands/DeleteIsoCmd.java +++ b/api/src/com/cloud/api/commands/DeleteIsoCmd.java @@ -30,6 +30,7 @@ import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(description="Deletes an ISO file.", responseObject=SuccessResponse.class) public class DeleteIsoCmd extends BaseAsyncCmd { @@ -102,6 +103,7 @@ public class DeleteIsoCmd extends BaseAsyncCmd { @Override public void execute(){ + UserContext.current().setEventDetails("ISO Id: "+getId()); boolean result = _templateService.deleteIso(this); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); diff --git a/api/src/com/cloud/api/commands/DeleteTemplateCmd.java b/api/src/com/cloud/api/commands/DeleteTemplateCmd.java old mode 100644 new mode 100755 index c474040608d..b9e00589c9f --- a/api/src/com/cloud/api/commands/DeleteTemplateCmd.java +++ b/api/src/com/cloud/api/commands/DeleteTemplateCmd.java @@ -31,6 +31,7 @@ import com.cloud.async.AsyncJob; import com.cloud.event.EventTypes; import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(responseObject=SuccessResponse.class, description="Deletes a template from the system. All virtual machines using the deleted template will not be affected.") public class DeleteTemplateCmd extends BaseAsyncCmd { @@ -104,6 +105,7 @@ public class DeleteTemplateCmd extends BaseAsyncCmd { @Override public void execute(){ + UserContext.current().setEventDetails("Template Id: "+getId()); boolean result = _templateService.deleteTemplate(this); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index c1d99a9f241..80234ec98f2 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -755,6 +755,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe } @Override + @ActionEvent(eventType = EventTypes.EVENT_ISO_DETACH, eventDescription = "detaching ISO", async = true) public boolean detachIso(DetachIsoCmd cmd) { Account account = UserContext.current().getCaller(); Long userId = UserContext.current().getCallerUserId(); @@ -775,6 +776,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe if (isoId == null) { throw new InvalidParameterValueException("The specified VM has no ISO attached to it."); } + UserContext.current().setEventDetails("Vm Id: " +vmId+ " ISO Id: "+isoId); State vmState = userVM.getState(); if (vmState != State.Running && vmState != State.Stopped) { @@ -789,6 +791,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe } @Override + @ActionEvent(eventType = EventTypes.EVENT_ISO_ATTACH, eventDescription = "attaching ISO", async = true) public boolean attachIso(AttachIsoCmd cmd) { Account caller = UserContext.current().getCaller(); Long userId = UserContext.current().getCallerUserId(); @@ -872,6 +875,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe } @Override + @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_DELETE, eventDescription = "deleting template", async = true) public boolean deleteTemplate(DeleteTemplateCmd cmd) { Long templateId = cmd.getId(); Account caller = UserContext.current().getCaller(); @@ -901,6 +905,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe } @Override + @ActionEvent(eventType = EventTypes.EVENT_ISO_DELETE, eventDescription = "deleting iso", async = true) public boolean deleteIso(DeleteIsoCmd cmd) { Long templateId = cmd.getId(); Account caller = UserContext.current().getCaller(); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 7e2f9210b53..a229b97836d 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1281,6 +1281,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } @Override + @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template", create = true) public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd) throws ResourceAllocationException { Long userId = UserContext.current().getCallerUserId(); if (userId == null) { @@ -1430,6 +1431,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager @Override @DB + @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template", async = true) public VMTemplateVO createPrivateTemplate(CreateTemplateCmd command) throws CloudRuntimeException { Long userId = UserContext.current().getCallerUserId(); if (userId == null) {