Skip to content

Commit 4761ae4

Browse files
shwstpprrohityadavcloud
authored andcommitted
FR568 - VR migration between clusters (#28)
Signed-off-by: Abhishek Kumar <[email protected]> ui: fix UI label bug #28 (#34) Signed-off-by: Abhishek Kumar <[email protected]> fix system vm migration with zone wide storage (#35) * fix system vm migration with zone wide storage Signed-off-by: Abhishek Kumar <[email protected]> * fix Signed-off-by: Abhishek Kumar <[email protected]> * fix spacing Signed-off-by: Abhishek Kumar <[email protected]> * add empty volumes check Signed-off-by: Abhishek Kumar <[email protected]> fix fr568 issue #28 (#36) Fixes systemvm migration with zone-wide storage Check only for usable volumes Signed-off-by: Abhishek Kumar <[email protected]> vmware: fix error msg for vmotion without shared storage (#37) Fixes error message which wrongly mentions worker VM Signed-off-by: Abhishek Kumar <[email protected]> refactor error message for interpod systemvm migration (#38) Fixes error message introduced in #28 Signed-off-by: Abhishek Kumar <[email protected]>
1 parent bff610e commit 4761ae4

File tree

10 files changed

+824
-70
lines changed

10 files changed

+824
-70
lines changed

api/src/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java

+48-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.systemvm;
1818

19-
import org.apache.log4j.Logger;
19+
import java.util.HashMap;
2020

2121
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
2222
import org.apache.cloudstack.api.ACL;
@@ -27,8 +27,10 @@
2727
import org.apache.cloudstack.api.Parameter;
2828
import org.apache.cloudstack.api.ServerApiException;
2929
import org.apache.cloudstack.api.response.HostResponse;
30+
import org.apache.cloudstack.api.response.StoragePoolResponse;
3031
import org.apache.cloudstack.api.response.SystemVmResponse;
3132
import org.apache.cloudstack.context.CallContext;
33+
import org.apache.log4j.Logger;
3234

3335
import com.cloud.event.EventTypes;
3436
import com.cloud.exception.ConcurrentOperationException;
@@ -37,6 +39,7 @@
3739
import com.cloud.exception.ResourceUnavailableException;
3840
import com.cloud.exception.VirtualMachineMigrationException;
3941
import com.cloud.host.Host;
42+
import com.cloud.storage.StoragePool;
4043
import com.cloud.user.Account;
4144
import com.cloud.vm.VirtualMachine;
4245

@@ -54,7 +57,6 @@ public class MigrateSystemVMCmd extends BaseAsyncCmd {
5457
@Parameter(name = ApiConstants.HOST_ID,
5558
type = CommandType.UUID,
5659
entityType = HostResponse.class,
57-
required = true,
5860
description = "destination Host ID to migrate VM to")
5961
private Long hostId;
6062

@@ -66,6 +68,13 @@ public class MigrateSystemVMCmd extends BaseAsyncCmd {
6668
description = "the ID of the virtual machine")
6769
private Long virtualMachineId;
6870

71+
@Parameter(name = ApiConstants.STORAGE_ID,
72+
since = "4.16.0",
73+
type = CommandType.UUID,
74+
entityType = StoragePoolResponse.class,
75+
description = "Destination storage pool ID to migrate VM volumes to. Required for migrating the root disk volume")
76+
private Long storageId;
77+
6978
/////////////////////////////////////////////////////
7079
/////////////////// Accessors ///////////////////////
7180
/////////////////////////////////////////////////////
@@ -78,6 +87,10 @@ public Long getVirtualMachineId() {
7887
return virtualMachineId;
7988
}
8089

90+
public Long getStoragePoolId() {
91+
return storageId;
92+
}
93+
8194
/////////////////////////////////////////////////////
8295
/////////////// API Implementation///////////////////
8396
/////////////////////////////////////////////////////
@@ -109,15 +122,43 @@ public String getEventDescription() {
109122

110123
@Override
111124
public void execute() {
125+
if (getHostId() == null && getStoragePoolId() == null) {
126+
throw new InvalidParameterValueException("Either hostId or storageId must be specified");
127+
}
112128

113-
Host destinationHost = _resourceService.getHost(getHostId());
114-
if (destinationHost == null) {
115-
throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
129+
if (getHostId() != null && getStoragePoolId() != null) {
130+
throw new InvalidParameterValueException("Only one of hostId and storageId can be specified");
116131
}
117-
try {
132+
133+
Host destinationHost = null;
134+
if (getHostId() != null) {
135+
destinationHost = _resourceService.getHost(getHostId());
136+
if (destinationHost == null) {
137+
throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
138+
}
139+
if (destinationHost.getType() != Host.Type.Routing) {
140+
throw new InvalidParameterValueException("The specified host(" + destinationHost.getName() + ") is not suitable to migrate the VM, please specify another one");
141+
}
118142
CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId());
143+
}
144+
145+
// OfflineMigration performed when this parameter is specified
146+
StoragePool destStoragePool = null;
147+
if (getStoragePoolId() != null) {
148+
destStoragePool = _storageService.getStoragePool(getStoragePoolId());
149+
if (destStoragePool == null) {
150+
throw new InvalidParameterValueException("Unable to find the storage pool to migrate the VM");
151+
}
152+
CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to storage pool Id: " + getStoragePoolId());
153+
}
154+
try {
119155
//FIXME : Should not be calling UserVmService to migrate all types of VMs - need a generic VM layer
120-
VirtualMachine migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
156+
VirtualMachine migratedVm = null;
157+
if (getHostId() != null) {
158+
migratedVm = _userVmService.migrateVirtualMachineWithVolume(getVirtualMachineId(), destinationHost, new HashMap<String, String>());
159+
} else if (getStoragePoolId() != null) {
160+
migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), destStoragePool);
161+
}
121162
if (migratedVm != null) {
122163
// return the generic system VM instance response
123164
SystemVmResponse response = _responseGenerator.createSystemVmResponse(migratedVm);

client/WEB-INF/classes/resources/messages.properties

+6
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,10 @@ label.action.migrate.instance.processing=Migrating Instance....
247247
label.action.migrate.instance=Migrate Instance
248248
label.action.migrate.router.processing=Migrating Router....
249249
label.action.migrate.router=Migrate Router
250+
label.action.migrate.router.to.ps=Migrate router to another primary storage
250251
label.action.migrate.systemvm.processing=Migrating System VM....
251252
label.action.migrate.systemvm=Migrate System VM
253+
label.action.migrate.systemvm.to.ps=Migrate system VM to another primary storage
252254
label.action.reboot.instance.processing=Rebooting Instance....
253255
label.action.reboot.instance=Reboot Instance
254256
label.action.reboot.router.processing=Rebooting Router....
@@ -1532,6 +1534,7 @@ label.virtual.appliance.details=Virtual applicance details
15321534
label.start.lb.vm=Start LB VM
15331535
label.stop.lb.vm=Stop LB VM
15341536
label.migrate.lb.vm=Migrate LB VM
1537+
label.migrate.lb.vm.to.ps=Migrate LB VM to another primary storage
15351538
label.vpc.virtual.router=VPC Virtual Router
15361539
label.ovs=OVS
15371540
label.gslb.service=GSLB service
@@ -1998,6 +2001,9 @@ message.lock.account=Please confirm that you want to lock this account. By lock
19982001
message.migrate.instance.confirm=Please confirm the host you wish to migrate the virtual instance to.
19992002
message.migrate.instance.to.host=Please confirm that you want to migrate instance to another host.
20002003
message.migrate.instance.to.ps=Please confirm that you want to migrate instance to another primary storage.
2004+
message.migrate.lb.vm.to.ps=Please confirm that you want to migrate LB VM to another primary storage.
2005+
message.migrate.router.to.ps=Please confirm that you want to migrate router to another primary storage.
2006+
message.migrate.system.vm.to.ps=Please confirm that you want to migrate system VM to another primary storage.
20012007
message.migrate.router.confirm=Please confirm the host you wish to migrate the router to\:
20022008
message.migrate.systemvm.confirm=Please confirm the host you wish to migrate the system VM to\:
20032009
message.migrate.volume=Please confirm that you want to migrate volume to another primary storage.

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2491,7 +2491,7 @@ private void orchestrateMigrateWithStorage(final String vmUuid, final long srcHo
24912491
Nic defaultNic = _networkModel.getDefaultNic(vm.getId());
24922492

24932493
List<String[]> vmData = null;
2494-
if (defaultNic != null) {
2494+
if (defaultNic != null && VirtualMachine.Type.User.equals(vm.getType())) {
24952495
UserVmVO userVm = _userVmDao.findById(vm.getId());
24962496
Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(vm.getId());
24972497
vm.setDetails(details);

plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public List<Command> finalizeMigrate(VirtualMachine vm, Map<Volume, StoragePool>
639639
hostInTargetCluster = hosts.get(0);
640640
}
641641
if (hostInTargetCluster == null) {
642-
throw new CloudRuntimeException("Migration failed, unable to find suitable target host for worker VM placement while migrating between storage pools of different clusters without shared storages");
642+
throw new CloudRuntimeException("Migration failed, unable to find suitable target host for VM placement while migrating between storage pools of different clusters without shared storages");
643643
}
644644
}
645645
MigrateVmToPoolCommand migrateVmToPoolCommand = new MigrateVmToPoolCommand(vm.getInstanceName(),

server/src/com/cloud/api/ApiDBUtils.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
import com.cloud.utils.EnumUtils;
292292
import com.cloud.utils.NumbersUtil;
293293
import com.cloud.utils.Pair;
294+
import com.cloud.utils.StringUtils;
294295
import com.cloud.vm.ConsoleProxyVO;
295296
import com.cloud.vm.DomainRouterVO;
296297
import com.cloud.vm.InstanceGroup;
@@ -1628,7 +1629,17 @@ public static String findJobInstanceUuid(AsyncJob job) {
16281629
///////////////////////////////////////////////////////////////////////
16291630

16301631
public static DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO vr, Account caller) {
1631-
return s_domainRouterJoinDao.newDomainRouterResponse(vr, caller);
1632+
DomainRouterResponse response = s_domainRouterJoinDao.newDomainRouterResponse(vr, caller);
1633+
if (StringUtils.isBlank(response.getHypervisor())) {
1634+
VMInstanceVO vm = ApiDBUtils.findVMInstanceById(vr.getId());
1635+
if (vm.getLastHostId() != null) {
1636+
HostVO lastHost = ApiDBUtils.findHostById(vm.getLastHostId());
1637+
if (lastHost != null) {
1638+
response.setHypervisor(lastHost.getHypervisorType().toString());
1639+
}
1640+
}
1641+
}
1642+
return response;
16321643
}
16331644

16341645
public static DomainRouterResponse fillRouterDetails(DomainRouterResponse vrData, DomainRouterJoinVO vr) {

server/src/com/cloud/api/ApiResponseHelper.java

+5
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,11 @@ public SystemVmResponse createSystemVmResponse(VirtualMachine vm) {
12641264
vmResponse.setHostName(host.getName());
12651265
vmResponse.setHypervisor(host.getHypervisorType().toString());
12661266
}
1267+
} else if (vm.getLastHostId() != null) {
1268+
Host lastHost = ApiDBUtils.findHostById(vm.getLastHostId());
1269+
if (lastHost != null) {
1270+
vmResponse.setHypervisor(lastHost.getHypervisorType().toString());
1271+
}
12671272
}
12681273

12691274
if (vm.getState() != null) {

server/src/com/cloud/server/ManagementServerImpl.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Ho
11761176
// Check if the vm can be migrated with storage.
11771177
boolean canMigrateWithStorage = false;
11781178

1179-
if (vm.getType() == VirtualMachine.Type.User) {
1179+
if (VirtualMachine.Type.User.equals(vm.getType()) || HypervisorType.VMware.equals(vm.getHypervisorType())) {
11801180
canMigrateWithStorage = Boolean.TRUE.equals(_hypervisorCapabilitiesDao.isStorageMotionSupported(srcHost.getHypervisorType(), srcHostVersion));
11811181
}
11821182

@@ -1204,7 +1204,8 @@ public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Ho
12041204
DataCenterDeployment plan = null;
12051205

12061206
if (canMigrateWithStorage) {
1207-
allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, srcHost.getDataCenterId(), null, null, null, null, null, null,
1207+
Long podId = !VirtualMachine.Type.User.equals(vm.getType()) ? srcHost.getPodId() : null;
1208+
allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, srcHost.getDataCenterId(), podId, null, null, null, null, null,
12081209
srcHost.getHypervisorType(), null);
12091210
allHosts = allHostsPair.first();
12101211
allHosts.remove(srcHost);
@@ -1233,7 +1234,7 @@ public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Ho
12331234
}
12341235
}
12351236
}
1236-
plan = new DataCenterDeployment(srcHost.getDataCenterId(), null, null, null, null, null);
1237+
plan = new DataCenterDeployment(srcHost.getDataCenterId(), podId, null, null, null, null);
12371238
} else {
12381239
final Long cluster = srcHost.getClusterId();
12391240
if (s_logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)