Updated Branches: refs/heads/master e520ff456 -> 4eb310e92
iCLOUDSTACK-2321 Fix the response of scaleVMCmd Add Scale System vm command Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4eb310e9 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4eb310e9 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4eb310e9 Branch: refs/heads/master Commit: 4eb310e926771c30515034bb056f71f52afe1a19 Parents: e520ff4 Author: Nitin Mehta <nitin.me...@citrix.com> Authored: Fri May 17 17:38:21 2013 +0530 Committer: Nitin Mehta <nitin.me...@citrix.com> Committed: Fri May 17 17:43:43 2013 +0530 ---------------------------------------------------------------------- api/src/com/cloud/event/EventTypes.java | 3 + api/src/com/cloud/server/ManagementService.java | 12 +- api/src/com/cloud/vm/UserVmService.java | 2 +- .../command/admin/systemvm/ScaleSystemVMCmd.java | 131 +++++++++++++++ .../cloudstack/api/command/user/vm/ScaleVMCmd.java | 23 ++- .../api/command/test/ScaleVMCmdTest.java | 30 +++- client/tomcatconf/commands.properties.in | 1 + server/src/com/cloud/server/ManagementServer.java | 6 + .../src/com/cloud/server/ManagementServerImpl.java | 47 +++--- server/src/com/cloud/vm/UserVmManager.java | 6 +- server/src/com/cloud/vm/UserVmManagerImpl.java | 17 ++- .../test/com/cloud/vm/MockUserVmManagerImpl.java | 9 +- 12 files changed, 238 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/api/src/com/cloud/event/EventTypes.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index ee7f5b7..9c83f13 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -92,6 +92,8 @@ public class EventTypes { public static final String EVENT_PROXY_STOP = "PROXY.STOP"; public static final String EVENT_PROXY_REBOOT = "PROXY.REBOOT"; public static final String EVENT_PROXY_HA = "PROXY.HA"; + public static final String EVENT_PROXY_SCALE = "PROXY.SCALE"; + // VNC Console Events public static final String EVENT_VNC_CONNECT = "VNC.CONNECT"; @@ -213,6 +215,7 @@ public class EventTypes { public static final String EVENT_SSVM_STOP = "SSVM.STOP"; public static final String EVENT_SSVM_REBOOT = "SSVM.REBOOT"; public static final String EVENT_SSVM_HA = "SSVM.HA"; + public static final String EVENT_SSVM_SCALE = "SSVM.SCALE"; // Service Offerings public static final String EVENT_SERVICE_OFFERING_CREATE = "SERVICE.OFFERING.CREATE"; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/api/src/com/cloud/server/ManagementService.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index 59b83c9..24d33d5 100755 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.cloud.exception.*; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd; import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd; @@ -34,11 +35,7 @@ import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd; import org.apache.cloudstack.api.command.admin.resource.ListAlertsCmd; import org.apache.cloudstack.api.command.admin.resource.ListCapacityCmd; import org.apache.cloudstack.api.command.admin.resource.UploadCustomCertificateCmd; -import org.apache.cloudstack.api.command.admin.systemvm.DestroySystemVmCmd; -import org.apache.cloudstack.api.command.admin.systemvm.ListSystemVMsCmd; -import org.apache.cloudstack.api.command.admin.systemvm.RebootSystemVmCmd; -import org.apache.cloudstack.api.command.admin.systemvm.StopSystemVmCmd; -import org.apache.cloudstack.api.command.admin.systemvm.UpgradeSystemVMCmd; +import org.apache.cloudstack.api.command.admin.systemvm.*; import org.apache.cloudstack.api.command.admin.vlan.ListVlanIpRangesCmd; import org.apache.cloudstack.api.command.user.address.ListPublicIpAddressesCmd; import org.apache.cloudstack.api.command.user.config.ListCapabilitiesCmd; @@ -64,10 +61,6 @@ import com.cloud.configuration.Configuration; import com.cloud.dc.Pod; import com.cloud.dc.Vlan; import com.cloud.domain.Domain; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InternalErrorException; -import com.cloud.exception.PermissionDeniedException; -import com.cloud.exception.ResourceUnavailableException; import com.cloud.host.Host; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.HypervisorCapabilities; @@ -422,4 +415,5 @@ public interface ManagementService { List<String> listDeploymentPlanners(); + VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableException, ManagementServerException, VirtualMachineMigrationException, ConcurrentOperationException; } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/api/src/com/cloud/vm/UserVmService.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java index 0a0660a..7d459b9 100755 --- a/api/src/com/cloud/vm/UserVmService.java +++ b/api/src/com/cloud/vm/UserVmService.java @@ -461,6 +461,6 @@ public interface UserVmService { UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException; - boolean upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException; + UserVm upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException; } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/api/src/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java b/api/src/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java new file mode 100644 index 0000000..a077e24 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java @@ -0,0 +1,131 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.systemvm; + +import com.cloud.event.EventTypes; +import com.cloud.exception.*; +import org.apache.cloudstack.api.*; +import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; +import org.apache.cloudstack.api.response.SystemVmResponse; +import org.apache.log4j.Logger; + +import com.cloud.offering.ServiceOffering; +import com.cloud.user.Account; +import com.cloud.user.UserContext; +import com.cloud.vm.VirtualMachine; + +@APICommand(name = "scaleSystemVm", responseObject=SystemVmResponse.class, description="Scale the service offering for a system vm (console proxy or secondary storage). " + + "The system vm must be in a \"Stopped\" state for " + + "this command to take effect.") +public class ScaleSystemVMCmd extends BaseAsyncCmd { + public static final Logger s_logger = Logger.getLogger(UpgradeVMCmd.class.getName()); + private static final String s_name = "changeserviceforsystemvmresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=SystemVmResponse.class, + required=true, description="The ID of the system vm") + private Long id; + + @Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.UUID, entityType=ServiceOfferingResponse.class, + required=true, description="the service offering ID to apply to the system vm") + private Long serviceOfferingId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public Long getServiceOfferingId() { + return serviceOfferingId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if (account != null) { + return account.getId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + + @Override + public void execute(){ + UserContext.current().setEventDetails("SystemVm Id: "+getId()); + + ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId); + if (serviceOffering == null) { + throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId); + } + + VirtualMachine result = null; + try { + result = _mgr.upgradeSystemVM(this); + } catch (ResourceUnavailableException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + } catch (ConcurrentOperationException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } catch (ManagementServerException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } catch (VirtualMachineMigrationException ex) { + s_logger.warn("Exception: ", ex); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + if (result != null) { + SystemVmResponse response = _responseGenerator.createSystemVmResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to scale system vm"); + } + } + + @Override + public String getEventType() { + VirtualMachine.Type type = _mgr.findSystemVMTypeById(getId()); + if(type == VirtualMachine.Type.ConsoleProxy){ + return EventTypes.EVENT_PROXY_SCALE; + } + else{ + return EventTypes.EVENT_SSVM_SCALE; + } + } + + @Override + public String getEventDescription() { + return "scaling system vm: " + getId() + " to service offering: " + getServiceOfferingId(); + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/api/src/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java index 4f2ac75..758d9c1 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java @@ -16,6 +16,7 @@ // under the License. package org.apache.cloudstack.api.command.user.vm; +import com.cloud.event.EventTypes; import com.cloud.exception.*; import com.cloud.user.Account; import com.cloud.user.UserContext; @@ -26,9 +27,11 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.log4j.Logger; +import java.util.List; + @APICommand(name = "scaleVirtualMachine", description="Scales the virtual machine to a new service offering.", responseObject=SuccessResponse.class) -public class ScaleVMCmd extends BaseCmd { +public class ScaleVMCmd extends BaseAsyncCmd { public static final Logger s_logger = Logger.getLogger(ScaleVMCmd.class.getName()); private static final String s_name = "scalevirtualmachineresponse"; @@ -84,7 +87,7 @@ public class ScaleVMCmd extends BaseCmd { @Override public void execute(){ //UserContext.current().setEventDetails("Vm Id: "+getId()); - boolean result; + UserVm result; try { result = _userVmService.upgradeVirtualMachine(this); } catch (ResourceUnavailableException ex) { @@ -100,11 +103,23 @@ public class ScaleVMCmd extends BaseCmd { s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } - if (result){ - SuccessResponse response = new SuccessResponse(getCommandName()); + if (result != null){ + List<UserVmResponse> responseList = _responseGenerator.createUserVmResponse("virtualmachine", result); + UserVmResponse response = responseList.get(0); + response.setResponseName(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to scale vm"); } } + + @Override + public String getEventType() { + return EventTypes.EVENT_VM_SCALE; + } + + @Override + public String getEventDescription() { + return "scaling volume: " + getId() + " to service offering: " + getServiceOfferingId(); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/api/test/org/apache/cloudstack/api/command/test/ScaleVMCmdTest.java ---------------------------------------------------------------------- diff --git a/api/test/org/apache/cloudstack/api/command/test/ScaleVMCmdTest.java b/api/test/org/apache/cloudstack/api/command/test/ScaleVMCmdTest.java index 8a28290..bb02298 100644 --- a/api/test/org/apache/cloudstack/api/command/test/ScaleVMCmdTest.java +++ b/api/test/org/apache/cloudstack/api/command/test/ScaleVMCmdTest.java @@ -24,11 +24,18 @@ import org.apache.cloudstack.api.ResponseGenerator; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.user.vm.ScaleVMCmd; +import org.apache.cloudstack.api.response.SwiftResponse; +import org.apache.cloudstack.api.response.UserVmResponse; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mockito; +import static org.mockito.Matchers.anyInt; + + +import java.util.LinkedList; +import java.util.List; public class ScaleVMCmdTest extends TestCase{ @@ -58,19 +65,34 @@ public class ScaleVMCmdTest extends TestCase{ public void testCreateSuccess() { UserVmService userVmService = Mockito.mock(UserVmService.class); + UserVm userVm = Mockito.mock(UserVm.class); + try { Mockito.when( userVmService.upgradeVirtualMachine(scaleVMCmd)) - .thenReturn(true); + .thenReturn(userVm); }catch (Exception e){ Assert.fail("Received exception when success expected " +e.getMessage()); } + ResponseGenerator responseGenerator = Mockito.mock(ResponseGenerator.class); + scaleVMCmd._responseGenerator = responseGenerator; + + UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class); + //List<UserVmResponse> list = Mockito.mock(UserVmResponse.class); + //list.add(userVmResponse); + //LinkedList<UserVmResponse> mockedList = Mockito.mock(LinkedList.class); + //Mockito.when(mockedList.get(0)).thenReturn(userVmResponse); + + List<UserVmResponse> list = new LinkedList<UserVmResponse>(); + list.add(userVmResponse); + + Mockito.when(responseGenerator.createUserVmResponse("virtualmachine", userVm)).thenReturn( + list); + scaleVMCmd._userVmService = userVmService; - responseGenerator = Mockito.mock(ResponseGenerator.class); - scaleVMCmd._responseGenerator = responseGenerator; scaleVMCmd.execute(); } @@ -83,7 +105,7 @@ public class ScaleVMCmdTest extends TestCase{ try { Mockito.when( userVmService.upgradeVirtualMachine(scaleVMCmd)) - .thenReturn(false); + .thenReturn(null); }catch (Exception e){ Assert.fail("Received exception when success expected " +e.getMessage()); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/client/tomcatconf/commands.properties.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 4cd9065..68a7511 100644 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -205,6 +205,7 @@ destroySystemVm=1 listSystemVms=3 migrateSystemVm=1 changeServiceForSystemVm=1 +scaleSystemVm=1 #### configuration commands updateConfiguration=1 http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/server/src/com/cloud/server/ManagementServer.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index 240464e..969bc65 100755 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -19,6 +19,11 @@ package com.cloud.server; import java.util.Date; import java.util.List; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.ManagementServerException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; +import org.apache.cloudstack.api.command.admin.systemvm.ScaleSystemVMCmd; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import com.cloud.event.EventVO; @@ -100,4 +105,5 @@ public interface ManagementServer extends ManagementService, PluggableService { void resetEncryptionKeyIV(); public void enableAdminUser(String password); + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/server/src/com/cloud/server/ManagementServerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 06c0f96..8b3eea4 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -43,6 +43,8 @@ import javax.crypto.spec.SecretKeySpec; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.exception.*; +import com.cloud.vm.*; import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.affinity.AffinityGroupProcessor; @@ -151,13 +153,7 @@ import org.apache.cloudstack.api.command.admin.storage.PreparePrimaryStorageForM import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd; import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd; import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd; -import org.apache.cloudstack.api.command.admin.systemvm.DestroySystemVmCmd; -import org.apache.cloudstack.api.command.admin.systemvm.ListSystemVMsCmd; -import org.apache.cloudstack.api.command.admin.systemvm.MigrateSystemVMCmd; -import org.apache.cloudstack.api.command.admin.systemvm.RebootSystemVmCmd; -import org.apache.cloudstack.api.command.admin.systemvm.StartSystemVMCmd; -import org.apache.cloudstack.api.command.admin.systemvm.StopSystemVmCmd; -import org.apache.cloudstack.api.command.admin.systemvm.UpgradeSystemVMCmd; +import org.apache.cloudstack.api.command.admin.systemvm.*; import org.apache.cloudstack.api.command.admin.template.PrepareTemplateCmd; import org.apache.cloudstack.api.command.admin.usage.AddTrafficMonitorCmd; import org.apache.cloudstack.api.command.admin.usage.AddTrafficTypeCmd; @@ -472,12 +468,6 @@ import com.cloud.event.ActionEventUtils; import com.cloud.event.EventTypes; import com.cloud.event.EventVO; import com.cloud.event.dao.EventDao; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.exception.OperationTimedoutException; -import com.cloud.exception.PermissionDeniedException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.exception.StorageUnavailableException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.host.DetailVO; import com.cloud.host.Host; @@ -571,17 +561,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.MacAddress; import com.cloud.utils.net.NetUtils; import com.cloud.utils.ssh.SSHKeysHelper; -import com.cloud.vm.ConsoleProxyVO; -import com.cloud.vm.DiskProfile; -import com.cloud.vm.InstanceGroupVO; -import com.cloud.vm.SecondaryStorageVmVO; -import com.cloud.vm.UserVmVO; -import com.cloud.vm.VMInstanceVO; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; -import com.cloud.vm.VirtualMachineManager; -import com.cloud.vm.VirtualMachineProfile; -import com.cloud.vm.VirtualMachineProfileImpl; import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.InstanceGroupDao; @@ -717,6 +697,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Inject ConfigurationServer _configServer; + @Inject + UserVmManager _userVmMgr; private final ScheduledExecutorService _eventExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("EventChecker")); private final ScheduledExecutorService _alertExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AlertChecker")); @@ -2917,6 +2899,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe cmdList.add(ListAffinityGroupTypesCmd.class); cmdList.add(ListDeploymentPlannersCmd.class); cmdList.add(ReleaseHostReservationCmd.class); + cmdList.add(ScaleSystemVMCmd.class); cmdList.add(AddResourceDetailCmd.class); cmdList.add(RemoveResourceDetailCmd.class); cmdList.add(ListResourceDetailsCmd.class); @@ -4021,9 +4004,27 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } @Override + public VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableException, ManagementServerException, VirtualMachineMigrationException, ConcurrentOperationException { + + boolean result = _userVmMgr.upgradeVirtualMachine(cmd.getId(), cmd.getServiceOfferingId()); + if(result){ + VirtualMachine vm = _vmInstanceDao.findById(cmd.getId()); + return vm; + }else{ + return null; + } + } + + + @Override public VirtualMachine upgradeSystemVM(UpgradeSystemVMCmd cmd) { Long systemVmId = cmd.getId(); Long serviceOfferingId = cmd.getServiceOfferingId(); + return upgradeStoppedSystemVm(systemVmId, serviceOfferingId); + + } + + private VirtualMachine upgradeStoppedSystemVm(Long systemVmId, Long serviceOfferingId){ Account caller = UserContext.current().getCaller(); VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(systemVmId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/server/src/com/cloud/vm/UserVmManager.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManager.java b/server/src/com/cloud/vm/UserVmManager.java index cc1fffd..0f8e368 100755 --- a/server/src/com/cloud/vm/UserVmManager.java +++ b/server/src/com/cloud/vm/UserVmManager.java @@ -22,9 +22,7 @@ import java.util.Map; import com.cloud.agent.api.VmStatsEntry; import com.cloud.api.query.vo.UserVmJoinVO; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.*; import com.cloud.projects.Project.ListProjectResourcesCriteria; import com.cloud.server.Criteria; import com.cloud.user.Account; @@ -94,4 +92,6 @@ public interface UserVmManager extends VirtualMachineGuru<UserVmVO>, UserVmServi Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; + boolean upgradeVirtualMachine(Long id, Long serviceOfferingId) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException; + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index a3b731a..860daaf 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1076,11 +1076,22 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override @ActionEvent(eventType = EventTypes.EVENT_VM_SCALE, eventDescription = "scaling Vm") - public boolean - upgradeVirtualMachine(ScaleVMCmd cmd) throws InvalidParameterValueException, ResourceAllocationException { + public UserVm + upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException{ Long vmId = cmd.getId(); Long newServiceOfferingId = cmd.getServiceOfferingId(); + boolean result = upgradeVirtualMachine(vmId, newServiceOfferingId); + if(result){ + return _vmDao.findById(vmId); + }else{ + return null; + } + + } + + @Override + public boolean upgradeVirtualMachine(Long vmId, Long newServiceOfferingId) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException{ Account caller = UserContext.current().getCaller(); // Verify input parameters @@ -1147,9 +1158,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } return success; - } + @Override public HashMap<Long, VmStatsEntry> getVirtualMachineStatistics(long hostId, String hostName, List<Long> vmIds) throws CloudRuntimeException { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4eb310e9/server/test/com/cloud/vm/MockUserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vm/MockUserVmManagerImpl.java b/server/test/com/cloud/vm/MockUserVmManagerImpl.java index a88625a..50a90f2 100644 --- a/server/test/com/cloud/vm/MockUserVmManagerImpl.java +++ b/server/test/com/cloud/vm/MockUserVmManagerImpl.java @@ -409,8 +409,8 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager, } @Override - public boolean upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { - return false; //To change body of implemented methods use File | Settings | File Templates. + public UserVm upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { + return null; //To change body of implemented methods use File | Settings | File Templates. } @@ -421,6 +421,11 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager, } @Override + public boolean upgradeVirtualMachine(Long id, Long serviceOfferingId) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override public void prepareStop(VirtualMachineProfile<UserVmVO> profile) { // TODO Auto-generated method stub