CLOUDSTACK-2146: system vm scaleup failed ;{ "scalevirtualmachineresponse" : {"errorcode":530,"cserrorcode":9999,"errortext":"Failed to scale vm"} }

Only response generation for system vm scale up failed so fixed by changing the response object.

Signed-off-by: Abhinandan Prateek <aprateek@apache.org>
This commit is contained in:
Harikrishna Patnala 2013-05-03 14:52:45 +05:30 committed by Abhinandan Prateek
parent 64fb826640
commit 38b4f84f17
5 changed files with 19 additions and 42 deletions

View File

@ -451,6 +451,6 @@ public interface UserVmService {
UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException;
UserVm upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
boolean upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
}

View File

@ -22,11 +22,12 @@ import com.cloud.user.UserContext;
import com.cloud.uservm.UserVm;
import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.log4j.Logger;
@APICommand(name = "scaleVirtualMachine", description="Scales the virtual machine to a new service offering.", responseObject=UserVmResponse.class)
@APICommand(name = "scaleVirtualMachine", description="Scales the virtual machine to a new service offering.", responseObject=SuccessResponse.class)
public class ScaleVMCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(ScaleVMCmd.class.getName());
private static final String s_name = "scalevirtualmachineresponse";
@ -83,7 +84,7 @@ public class ScaleVMCmd extends BaseCmd {
@Override
public void execute(){
//UserContext.current().setEventDetails("Vm Id: "+getId());
UserVm result = null;
boolean result;
try {
result = _userVmService.upgradeVirtualMachine(this);
} catch (ResourceUnavailableException ex) {
@ -99,9 +100,8 @@ public class ScaleVMCmd extends BaseCmd {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
if (result != null){
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
response.setResponseName(getCommandName());
if (result){
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to scale vm");

View File

@ -16,31 +16,20 @@
// under the License.
package org.apache.cloudstack.api.command.test;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.uservm.UserVm;
import com.cloud.vm.UserVmService;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.cloudstack.api.ResponseGenerator;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.admin.region.AddRegionCmd;
import org.apache.cloudstack.api.command.user.vm.ScaleVMCmd;
import org.apache.cloudstack.api.response.RegionResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.region.Region;
import org.apache.cloudstack.region.RegionService;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class ScaleVMCmdTest extends TestCase{
private ScaleVMCmd scaleVMCmd;
@ -57,12 +46,11 @@ public class ScaleVMCmdTest extends TestCase{
public Long getId() {
return 2L;
}
@Override
public String getCommandName() {
return "scalevirtualmachineresponse";
}
};
//Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
//UserContext.registerContext(1, account, null, true);
}
@ -71,11 +59,10 @@ public class ScaleVMCmdTest extends TestCase{
UserVmService userVmService = Mockito.mock(UserVmService.class);
UserVm uservm = Mockito.mock(UserVm.class);
try {
Mockito.when(
userVmService.upgradeVirtualMachine(scaleVMCmd))
.thenReturn(uservm);
.thenReturn(true);
}catch (Exception e){
Assert.fail("Received exception when success expected " +e.getMessage());
}
@ -83,13 +70,6 @@ public class ScaleVMCmdTest extends TestCase{
scaleVMCmd._userVmService = userVmService;
responseGenerator = Mockito.mock(ResponseGenerator.class);
UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class);
List<UserVmResponse> responseList = new ArrayList<UserVmResponse>();
responseList.add(userVmResponse);
Mockito.when(responseGenerator.createUserVmResponse("virtualmachine",uservm))
.thenReturn(responseList);
scaleVMCmd._responseGenerator = responseGenerator;
scaleVMCmd.execute();
@ -101,10 +81,9 @@ public class ScaleVMCmdTest extends TestCase{
UserVmService userVmService = Mockito.mock(UserVmService.class);
try {
UserVm uservm = Mockito.mock(UserVm.class);
Mockito.when(
userVmService.upgradeVirtualMachine(scaleVMCmd))
.thenReturn(null);
.thenReturn(false);
}catch (Exception e){
Assert.fail("Received exception when success expected " +e.getMessage());
}

View File

@ -1050,7 +1050,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_SCALE, eventDescription = "scaling Vm")
public UserVm
public boolean
upgradeVirtualMachine(ScaleVMCmd cmd) throws InvalidParameterValueException {
Long vmId = cmd.getId();
Long newServiceOfferingId = cmd.getServiceOfferingId();
@ -1076,8 +1076,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
}
// Dynamically upgrade the running vms
boolean success = false;
if(vmInstance.getState().equals(State.Running)){
boolean success = false;
int retry = _scaleRetry;
while (retry-- != 0) { // It's != so that it can match -1.
try{
@ -1095,7 +1095,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
vmInstance = _vmInstanceDao.findById(vmId);
vmInstance = _itMgr.reConfigureVm(vmInstance, oldServiceOffering, existingHostHasCapacity);
success = true;
return _vmDao.findById(vmInstance.getId());
return success;
}catch(InsufficientCapacityException e ){
s_logger.warn("Received exception while scaling ",e);
} catch (ResourceUnavailableException e) {
@ -1112,11 +1112,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
}
}
}
if (!success)
return null;
}
return _vmDao.findById(vmInstance.getId());
return success;
}

View File

@ -407,8 +407,8 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
}
@Override
public UserVm upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {
return null; //To change body of implemented methods use File | Settings | File Templates.
public boolean upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {
return false; //To change body of implemented methods use File | Settings | File Templates.
}