Skip to content

Commit 7a64d8f

Browse files
author
Kelven Yang
committed
add VmwareInvestigator and VmwareFencer, use short worker VM name to avoid vCenter truncation
1 parent 797d5ff commit 7a64d8f

7 files changed

Lines changed: 160 additions & 52 deletions

File tree

‎api/src/com/cloud/vm/VirtualMachine.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,12 @@ public static StateMachine2<State, VirtualMachine.Event, VirtualMachine> getStat
7979
s_fsm.addTransition(State.Stopped, VirtualMachine.Event.OperationFailed, State.Stopped);
8080
s_fsm.addTransition(State.Stopped, VirtualMachine.Event.ExpungeOperation, State.Expunging);
8181
s_fsm.addTransition(State.Stopped, VirtualMachine.Event.AgentReportShutdowned, State.Stopped);
82-
s_fsm.addTransition(State.Stopped, VirtualMachine.Event.AgentReportMigrated, State.Stopped);
8382
s_fsm.addTransition(State.Starting, VirtualMachine.Event.OperationRetry, State.Starting);
8483
s_fsm.addTransition(State.Starting, VirtualMachine.Event.OperationSucceeded, State.Running);
8584
s_fsm.addTransition(State.Starting, VirtualMachine.Event.OperationFailed, State.Stopped);
8685
s_fsm.addTransition(State.Starting, VirtualMachine.Event.AgentReportRunning, State.Running);
8786
s_fsm.addTransition(State.Starting, VirtualMachine.Event.AgentReportStopped, State.Stopped);
8887
s_fsm.addTransition(State.Starting, VirtualMachine.Event.AgentReportShutdowned, State.Stopped);
89-
s_fsm.addTransition(State.Starting, VirtualMachine.Event.AgentReportMigrated, State.Starting);
9088
s_fsm.addTransition(State.Destroyed, VirtualMachine.Event.RecoveryRequested, State.Stopped);
9189
s_fsm.addTransition(State.Destroyed, VirtualMachine.Event.ExpungeOperation, State.Expunging);
9290
s_fsm.addTransition(State.Running, VirtualMachine.Event.MigrationRequested, State.Migrating);
@@ -107,7 +105,6 @@ public static StateMachine2<State, VirtualMachine.Event, VirtualMachine> getStat
107105
s_fsm.addTransition(State.Stopping, VirtualMachine.Event.AgentReportStopped, State.Stopped);
108106
s_fsm.addTransition(State.Stopping, VirtualMachine.Event.StopRequested, State.Stopping);
109107
s_fsm.addTransition(State.Stopping, VirtualMachine.Event.AgentReportShutdowned, State.Stopped);
110-
s_fsm.addTransition(State.Stopping, VirtualMachine.Event.AgentReportMigrated, State.Stopping);
111108
s_fsm.addTransition(State.Expunging, VirtualMachine.Event.OperationFailed, State.Expunging);
112109
s_fsm.addTransition(State.Expunging, VirtualMachine.Event.ExpungeOperation, State.Expunging);
113110
s_fsm.addTransition(State.Error, VirtualMachine.Event.DestroyRequested, State.Expunging);

‎client/tomcatconf/components.xml.in‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@
7373
<adapter name="PingInvestigator" class="com.cloud.ha.UserVmDomRInvestigator"/>
7474
<adapter name="XenServerInvestigator" class="com.cloud.ha.XenServerInvestigator"/>
7575
<adapter name="ManagementIPSysVMInvestigator" class="com.cloud.ha.ManagementIPSystemVMInvestigator"/>
76+
<adapter name="VmwareInvestigator" class="com.cloud.ha.VmwareInvestigator"/>
7677
</adapters>
7778
<adapters key="com.cloud.ha.FenceBuilder">
7879
<adapter name="XenServerFenceBuilder" class="com.cloud.ha.XenServerFencer"/>
7980
<adapter name="KVMFenceBuilder" class="com.cloud.ha.KVMFencer"/>
81+
<adapter name="VmwareFenceBuilder" class="com.cloud.ha.VmwareFencer"/>
8082
</adapters>
8183
<adapters key="com.cloud.hypervisor.HypervisorGuru">
8284
<adapter name="XenServerGuru" class="com.cloud.hypervisor.XenServerGuru"/>

‎core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java‎

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -161,46 +161,61 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd)
161161
boolean success = false;
162162
String snapshotBackupUuid = null;
163163

164-
VmwareContext context = hostService.getServiceContext(cmd);
164+
VmwareContext context = hostService.getServiceContext(cmd);
165+
VirtualMachineMO vmMo;
166+
165167
try {
166168
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
167169
morDs = hyperHost.findDatastore(cmd.getPool().getUuid());
168-
169-
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
170-
if (vmMo == null) {
171-
if(s_logger.isDebugEnabled())
172-
s_logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter");
173-
174-
vmMo = hyperHost.findVmOnPeerHyperHost(cmd.getVmName());
175-
if(vmMo == null) {
176-
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
177-
// restrict VM name to 32 chars, (else snapshot descriptor file name will be truncated to 32 chars of vm name)
178-
workerVMName = UUID.randomUUID().toString().replaceAll("-", "");
179-
180-
// attach a volume to dummay wrapper VM for taking snapshot and exporting the VM for backup
181-
if (!hyperHost.createBlankVm(workerVMName, 1, 512, 0, false, 4, 0, VirtualMachineGuestOsIdentifier._otherGuest.toString(), morDs, false)) {
182-
String msg = "Unable to create worker VM to execute BackupSnapshotCommand";
183-
s_logger.error(msg);
184-
throw new Exception(msg);
185-
}
186-
vmMo = hyperHost.findVmOnHyperHost(workerVMName);
187-
if (vmMo == null) {
188-
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
189-
}
190-
workerVm = vmMo;
191170

192-
// attach volume to worker VM
193-
String datastoreVolumePath = String.format("[%s] %s.vmdk", dsMo.getName(), volumePath);
194-
vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs);
195-
snapshotUUID = UUID.randomUUID().toString();
196-
if (!vmMo.createSnapshot(snapshotUUID, "Snapshot taken for " + cmd.getSnapshotName(), false, false)) {
197-
throw new Exception("Failed to take snapshot " + cmd.getSnapshotName() + " on vm: " + cmd.getVmName());
171+
try {
172+
vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
173+
if (vmMo == null) {
174+
if(s_logger.isDebugEnabled())
175+
s_logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter");
176+
177+
vmMo = hyperHost.findVmOnPeerHyperHost(cmd.getVmName());
178+
if(vmMo == null) {
179+
dsMo = new DatastoreMO(hyperHost.getContext(), morDs);
180+
181+
workerVMName = hostService.getWorkerName(context, cmd);
182+
183+
// attach a volume to dummay wrapper VM for taking snapshot and exporting the VM for backup
184+
if (!hyperHost.createBlankVm(workerVMName, 1, 512, 0, false, 4, 0, VirtualMachineGuestOsIdentifier._otherGuest.toString(), morDs, false)) {
185+
String msg = "Unable to create worker VM to execute BackupSnapshotCommand";
186+
s_logger.error(msg);
187+
throw new Exception(msg);
188+
}
189+
vmMo = hyperHost.findVmOnHyperHost(workerVMName);
190+
if (vmMo == null) {
191+
throw new Exception("Failed to find the newly create or relocated VM. vmName: " + workerVMName);
192+
}
193+
workerVm = vmMo;
194+
195+
// attach volume to worker VM
196+
String datastoreVolumePath = String.format("[%s] %s.vmdk", dsMo.getName(), volumePath);
197+
vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs);
198+
snapshotUUID = UUID.randomUUID().toString();
199+
if (!vmMo.createSnapshot(snapshotUUID, "Snapshot taken for " + cmd.getSnapshotName(), false, false)) {
200+
throw new Exception("Failed to take snapshot " + cmd.getSnapshotName() + " on vm: " + cmd.getVmName());
201+
}
198202
}
199-
}
200-
} else {
201-
if (!vmMo.createSnapshot(snapshotUuid, "Snapshot taken for " + cmd.getSnapshotName(), false, false)) {
202-
throw new Exception("Failed to take snapshot " + cmd.getSnapshotName() + " on vm: " + cmd.getVmName());
203-
}
203+
} else {
204+
if (!vmMo.createSnapshot(snapshotUuid, "Snapshot taken for " + cmd.getSnapshotName(), false, false)) {
205+
throw new Exception("Failed to take snapshot " + cmd.getSnapshotName() + " on vm: " + cmd.getVmName());
206+
}
207+
}
208+
} finally {
209+
try {
210+
if (workerVm != null) {
211+
// detach volume and destroy worker vm
212+
workerVm.moveAllVmDiskFiles(dsMo, "", false);
213+
workerVm.detachAllDisks();
214+
workerVm.destroy();
215+
}
216+
} catch (Throwable e) {
217+
s_logger.warn("Failed to destroy worker VM: " + workerVMName);
218+
}
204219
}
205220

206221
snapshotBackupUuid = backupSnapshotToSecondaryStorage(vmMo, accountId,
@@ -224,17 +239,6 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd)
224239

225240
details = "BackupSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
226241
return new BackupSnapshotAnswer(cmd, false, details, snapshotBackupUuid, true);
227-
} finally {
228-
try {
229-
if (workerVm != null) {
230-
// detach volume and destroy worker vm
231-
workerVm.moveAllVmDiskFiles(dsMo, "", false);
232-
workerVm.detachAllDisks();
233-
workerVm.destroy();
234-
}
235-
} catch (Throwable e) {
236-
s_logger.warn("Failed to destroy worker VM: " + workerVMName);
237-
}
238242
}
239243

240244
return new BackupSnapshotAnswer(cmd, success, details, snapshotBackupUuid, true);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
package com.cloud.ha;
19+
20+
import java.util.Map;
21+
22+
import javax.ejb.Local;
23+
import javax.naming.ConfigurationException;
24+
25+
import com.cloud.host.HostVO;
26+
import com.cloud.vm.VMInstanceVO;
27+
28+
@Local(value=FenceBuilder.class)
29+
public class VmwareFencer implements FenceBuilder {
30+
String _name;
31+
32+
@Override
33+
public Boolean fenceOff(VMInstanceVO vm, HostVO host) {
34+
return null;
35+
}
36+
37+
public VmwareFencer() {
38+
super();
39+
}
40+
41+
@Override
42+
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
43+
_name = name;
44+
return true;
45+
}
46+
47+
@Override
48+
public String getName() {
49+
return _name;
50+
}
51+
52+
@Override
53+
public boolean start() {
54+
return true;
55+
}
56+
57+
@Override
58+
public boolean stop() {
59+
return true;
60+
}
61+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
package com.cloud.ha;
19+
20+
import javax.ejb.Local;
21+
22+
import com.cloud.host.HostVO;
23+
import com.cloud.host.Status;
24+
import com.cloud.utils.component.AdapterBase;
25+
import com.cloud.vm.VMInstanceVO;
26+
27+
@Local(value=Investigator.class)
28+
public class VmwareInvestigator extends AdapterBase implements Investigator {
29+
protected VmwareInvestigator() {
30+
}
31+
32+
@Override
33+
public Status isAgentAlive(HostVO agent) {
34+
return null;
35+
}
36+
37+
@Override
38+
public Boolean isVmAlive(VMInstanceVO vm, HostVO host) {
39+
return null;
40+
}
41+
}

‎server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import com.cloud.hypervisor.vmware.mo.HostVirtualNicType;
5454
import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
5555
import com.cloud.hypervisor.vmware.mo.TaskMO;
56-
import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
5756
import com.cloud.hypervisor.vmware.mo.VmwareHostType;
5857
import com.cloud.hypervisor.vmware.resource.SshHelper;
5958
import com.cloud.hypervisor.vmware.util.VmwareContext;
@@ -284,7 +283,7 @@ public String getName() {
284283

285284
@Override
286285
public String composeWorkerName() {
287-
return "cloud.worker." + _clusterMgr.getManagementNodeId() + "." + _clusterMgr.getCurrentRunId() + "." + UUID.randomUUID().toString();
286+
return UUID.randomUUID().toString().replace("-", "");
288287
}
289288

290289
@Override

‎server/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,11 @@ protected Command compareState(long hostId, VMInstanceVO vm, final AgentVmInfo i
15961596

15971597
if(serverState == State.Running) {
15981598
try {
1599-
if(hostId != vm.getHostId()) {
1599+
//
1600+
// we had a bug that sometimes VM may be at Running State but host_id is null, we will cover it here.
1601+
// means that when CloudStack DB lost of host information, we will heal it with the info reported from host
1602+
//
1603+
if(vm.getHostId() == null || hostId != vm.getHostId()) {
16001604
if (s_logger.isDebugEnabled()) {
16011605
s_logger.debug("detected host change when VM " + vm + " is at running state, VM could be live-migrated externally from host "
16021606
+ vm.getHostId() + " to host " + hostId);

0 commit comments

Comments
 (0)