bug 8915: Adding events for TEMPLATE.CREATE, TEMPLATE.DELETE, ISO.DELETE, ISO.ATTACH, ISO.DETACH.

Status 8915: resolved fixed
This commit is contained in:
Nitin 2011-06-30 16:28:04 +05:30
parent 9c1bfc351a
commit 62078ffef2
6 changed files with 15 additions and 0 deletions

View File

@ -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);

View File

@ -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<TemplateResponse> response = new ListResponse<TemplateResponse>();

2
api/src/com/cloud/api/commands/DeleteIsoCmd.java Normal file → Executable file
View File

@ -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());

2
api/src/com/cloud/api/commands/DeleteTemplateCmd.java Normal file → Executable file
View File

@ -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());

View File

@ -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();

View File

@ -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) {