From 5774fd163d6f814c56071f8703bf3ba8d79536da Mon Sep 17 00:00:00 2001 From: nit Date: Mon, 25 Oct 2010 17:19:22 +0530 Subject: [PATCH] bug 6480: detachVolume API would start returning an embedded object, like attachVolume API does. status 6480: resolved fixed --- .../com/cloud/api/commands/DetachVolumeCmd.java | 8 +++----- server/src/com/cloud/vm/UserVmManagerImpl.java | 17 ++++++++++++++++- server/src/com/cloud/vm/UserVmService.java | 4 +++- 3 files changed, 22 insertions(+), 7 deletions(-) mode change 100644 => 100755 server/src/com/cloud/api/commands/DetachVolumeCmd.java mode change 100644 => 100755 server/src/com/cloud/vm/UserVmManagerImpl.java mode change 100644 => 100755 server/src/com/cloud/vm/UserVmService.java diff --git a/server/src/com/cloud/api/commands/DetachVolumeCmd.java b/server/src/com/cloud/api/commands/DetachVolumeCmd.java old mode 100644 new mode 100755 index 28629966b81..8fc0b7cb0b8 --- a/server/src/com/cloud/api/commands/DetachVolumeCmd.java +++ b/server/src/com/cloud/api/commands/DetachVolumeCmd.java @@ -25,6 +25,7 @@ import com.cloud.api.BaseCmd.Manager; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.SuccessResponse; +import com.cloud.api.response.VolumeResponse; import com.cloud.event.EventTypes; import com.cloud.storage.VolumeVO; import com.cloud.user.Account; @@ -115,11 +116,8 @@ public class DetachVolumeCmd extends BaseAsyncCmd { } @Override @SuppressWarnings("unchecked") - public SuccessResponse getResponse() { - Boolean success = (Boolean)getResponseObject(); - SuccessResponse response = new SuccessResponse(); - response.setSuccess(success); - response.setResponseName(getName()); + public VolumeResponse getResponse() { + VolumeResponse response = (VolumeResponse)getResponseObject(); return response; } } \ No newline at end of file diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java old mode 100644 new mode 100755 index d01fba559ce..58b888adb6b --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -63,6 +63,7 @@ import com.cloud.agent.api.VmStatsEntry; import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer; import com.cloud.agent.manager.Commands; import com.cloud.alert.AlertManager; +import com.cloud.api.ApiDBUtils; import com.cloud.api.BaseCmd; import com.cloud.api.ServerApiException; import com.cloud.api.commands.AttachVolumeCmd; @@ -79,6 +80,7 @@ import com.cloud.api.commands.StartVMCmd; import com.cloud.api.commands.StopVMCmd; import com.cloud.api.commands.UpdateVMCmd; import com.cloud.api.commands.UpgradeVMCmd; +import com.cloud.api.response.VolumeResponse; import com.cloud.async.AsyncJobExecutor; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobResult; @@ -589,7 +591,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService { } @Override - public void detachVolumeFromVM(DetachVolumeCmd cmmd) throws InternalErrorException, InvalidParameterValueException { + public VolumeResponse detachVolumeFromVM(DetachVolumeCmd cmmd) throws InternalErrorException, InvalidParameterValueException { Account account = UserContext.current().getAccount(); if ((cmmd.getId() == null && cmmd.getDeviceId() == null && cmmd.getVirtualMachineId() == null) || (cmmd.getId() != null && (cmmd.getDeviceId() != null || cmmd.getVirtualMachineId() != null)) || @@ -703,6 +705,19 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService { event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getName()); event.setLevel(EventVO.LEVEL_INFO); _eventDao.persist(event); + + // Prepare the response object + VolumeResponse response = new VolumeResponse(); + response.setVirtualMachineName(vm.getName()); + response.setVirtualMachineDisplayName(vm.getDisplayName()); + response.setVirtualMachineId(vm.getId()); + response.setVirtualMachineState(vm.getState().toString()); + response.setStorageType("shared"); // NOTE: You can never attach a local disk volume but if that changes, we need to change this + response.setId(volume.getId()); + response.setName(volume.getName()); + response.setVolumeType(volume.getVolumeType().toString()); + response.setResponseName(cmmd.getName()); + return response; } else { if (answer != null) { diff --git a/server/src/com/cloud/vm/UserVmService.java b/server/src/com/cloud/vm/UserVmService.java old mode 100644 new mode 100755 index a3d9072f597..c31e9a64db2 --- a/server/src/com/cloud/vm/UserVmService.java +++ b/server/src/com/cloud/vm/UserVmService.java @@ -32,6 +32,7 @@ import com.cloud.api.commands.StartVMCmd; import com.cloud.api.commands.StopVMCmd; import com.cloud.api.commands.UpdateVMCmd; import com.cloud.api.commands.UpgradeVMCmd; +import com.cloud.api.response.VolumeResponse; import com.cloud.async.executor.OperationResponse; import com.cloud.async.executor.RebootVMExecutor; import com.cloud.async.executor.VMOperationParam; @@ -74,10 +75,11 @@ public interface UserVmService extends Manager { /** * Detaches the specified volume from the VM it is currently attached to. * @param cmd - the command specifying volumeId + * @return the VolumeResponse object if detach worked successfully. * @throws InternalErrorException * @throws InvalidParameterValueException */ - void detachVolumeFromVM(DetachVolumeCmd cmmd) throws InternalErrorException, InvalidParameterValueException; + VolumeResponse detachVolumeFromVM(DetachVolumeCmd cmmd) throws InternalErrorException, InvalidParameterValueException; UserVmVO startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException; UserVmVO stopVirtualMachine(StopVMCmd cmd) throws ServerApiException;