Skip to content

Commit 38b4f84

Browse files
Harikrishna PatnalaAbhinandan Prateek
authored andcommitted
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>
1 parent 64fb826 commit 38b4f84

5 files changed

Lines changed: 19 additions & 42 deletions

File tree

api/src/com/cloud/vm/UserVmService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,6 @@ VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost,
451451

452452
UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException;
453453

454-
UserVm upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
454+
boolean upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
455455

456456
}

api/src/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
import com.cloud.uservm.UserVm;
2323
import org.apache.cloudstack.api.*;
2424
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
25+
import org.apache.cloudstack.api.response.SuccessResponse;
2526
import org.apache.cloudstack.api.response.UserVmResponse;
2627
import org.apache.log4j.Logger;
2728

2829

29-
@APICommand(name = "scaleVirtualMachine", description="Scales the virtual machine to a new service offering.", responseObject=UserVmResponse.class)
30+
@APICommand(name = "scaleVirtualMachine", description="Scales the virtual machine to a new service offering.", responseObject=SuccessResponse.class)
3031
public class ScaleVMCmd extends BaseCmd {
3132
public static final Logger s_logger = Logger.getLogger(ScaleVMCmd.class.getName());
3233
private static final String s_name = "scalevirtualmachineresponse";
@@ -83,7 +84,7 @@ public long getEntityOwnerId() {
8384
@Override
8485
public void execute(){
8586
//UserContext.current().setEventDetails("Vm Id: "+getId());
86-
UserVm result = null;
87+
boolean result;
8788
try {
8889
result = _userVmService.upgradeVirtualMachine(this);
8990
} catch (ResourceUnavailableException ex) {
@@ -99,9 +100,8 @@ public void execute(){
99100
s_logger.warn("Exception: ", ex);
100101
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
101102
}
102-
if (result != null){
103-
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
104-
response.setResponseName(getCommandName());
103+
if (result){
104+
SuccessResponse response = new SuccessResponse(getCommandName());
105105
this.setResponseObject(response);
106106
} else {
107107
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to scale vm");

api/test/org/apache/cloudstack/api/command/test/ScaleVMCmdTest.java

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,20 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.test;
1818

19-
import com.cloud.user.Account;
20-
import com.cloud.user.UserContext;
2119
import com.cloud.uservm.UserVm;
2220
import com.cloud.vm.UserVmService;
2321
import junit.framework.Assert;
2422
import junit.framework.TestCase;
2523
import org.apache.cloudstack.api.ResponseGenerator;
2624
import org.apache.cloudstack.api.ServerApiException;
27-
import org.apache.cloudstack.api.command.admin.region.AddRegionCmd;
2825
import org.apache.cloudstack.api.command.user.vm.ScaleVMCmd;
29-
import org.apache.cloudstack.api.response.RegionResponse;
30-
import org.apache.cloudstack.api.response.UserVmResponse;
31-
import org.apache.cloudstack.region.Region;
32-
import org.apache.cloudstack.region.RegionService;
26+
3327
import org.junit.Before;
3428
import org.junit.Rule;
3529
import org.junit.Test;
3630
import org.junit.rules.ExpectedException;
3731
import org.mockito.Mockito;
3832

39-
import java.util.ArrayList;
40-
import java.util.List;
41-
import java.util.UUID;
42-
43-
4433
public class ScaleVMCmdTest extends TestCase{
4534

4635
private ScaleVMCmd scaleVMCmd;
@@ -57,12 +46,11 @@ public void setUp() {
5746
public Long getId() {
5847
return 2L;
5948
}
49+
@Override
50+
public String getCommandName() {
51+
return "scalevirtualmachineresponse";
52+
}
6053
};
61-
62-
//Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
63-
//UserContext.registerContext(1, account, null, true);
64-
65-
6654
}
6755

6856

@@ -71,25 +59,17 @@ public void testCreateSuccess() {
7159

7260
UserVmService userVmService = Mockito.mock(UserVmService.class);
7361

74-
UserVm uservm = Mockito.mock(UserVm.class);
7562
try {
7663
Mockito.when(
7764
userVmService.upgradeVirtualMachine(scaleVMCmd))
78-
.thenReturn(uservm);
65+
.thenReturn(true);
7966
}catch (Exception e){
8067
Assert.fail("Received exception when success expected " +e.getMessage());
8168
}
8269

8370
scaleVMCmd._userVmService = userVmService;
8471
responseGenerator = Mockito.mock(ResponseGenerator.class);
8572

86-
UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class);
87-
List<UserVmResponse> responseList = new ArrayList<UserVmResponse>();
88-
responseList.add(userVmResponse);
89-
90-
Mockito.when(responseGenerator.createUserVmResponse("virtualmachine",uservm))
91-
.thenReturn(responseList);
92-
9373
scaleVMCmd._responseGenerator = responseGenerator;
9474
scaleVMCmd.execute();
9575

@@ -101,10 +81,9 @@ public void testCreateFailure() {
10181
UserVmService userVmService = Mockito.mock(UserVmService.class);
10282

10383
try {
104-
UserVm uservm = Mockito.mock(UserVm.class);
10584
Mockito.when(
10685
userVmService.upgradeVirtualMachine(scaleVMCmd))
107-
.thenReturn(null);
86+
.thenReturn(false);
10887
}catch (Exception e){
10988
Assert.fail("Received exception when success expected " +e.getMessage());
11089
}

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) th
10501050

10511051
@Override
10521052
@ActionEvent(eventType = EventTypes.EVENT_VM_SCALE, eventDescription = "scaling Vm")
1053-
public UserVm
1053+
public boolean
10541054
upgradeVirtualMachine(ScaleVMCmd cmd) throws InvalidParameterValueException {
10551055
Long vmId = cmd.getId();
10561056
Long newServiceOfferingId = cmd.getServiceOfferingId();
@@ -1076,8 +1076,8 @@ public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) th
10761076
}
10771077

10781078
// Dynamically upgrade the running vms
1079+
boolean success = false;
10791080
if(vmInstance.getState().equals(State.Running)){
1080-
boolean success = false;
10811081
int retry = _scaleRetry;
10821082
while (retry-- != 0) { // It's != so that it can match -1.
10831083
try{
@@ -1095,7 +1095,7 @@ public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) th
10951095
vmInstance = _vmInstanceDao.findById(vmId);
10961096
vmInstance = _itMgr.reConfigureVm(vmInstance, oldServiceOffering, existingHostHasCapacity);
10971097
success = true;
1098-
return _vmDao.findById(vmInstance.getId());
1098+
return success;
10991099
}catch(InsufficientCapacityException e ){
11001100
s_logger.warn("Received exception while scaling ",e);
11011101
} catch (ResourceUnavailableException e) {
@@ -1112,11 +1112,9 @@ public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) th
11121112
}
11131113
}
11141114
}
1115-
if (!success)
1116-
return null;
11171115
}
11181116

1119-
return _vmDao.findById(vmInstance.getId());
1117+
return success;
11201118

11211119
}
11221120

server/test/com/cloud/vm/MockUserVmManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ public UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException,
407407
}
408408

409409
@Override
410-
public UserVm upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {
411-
return null; //To change body of implemented methods use File | Settings | File Templates.
410+
public boolean upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {
411+
return false; //To change body of implemented methods use File | Settings | File Templates.
412412
}
413413

414414

0 commit comments

Comments
 (0)