Skip to content

Commit 7be9b12

Browse files
committed
CLOUDSTACK-669: Add host level side-by-side VM state report for graceful sync model migration
1 parent 43c3b8d commit 7be9b12

22 files changed

Lines changed: 584 additions & 131 deletions

File tree

agent/src/com/cloud/agent/resource/DummyResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public StartupCommand[] initialize() {
169169
final StartupRoutingCommand cmd = new StartupRoutingCommand(
170170
(Integer) info.get(0), (Long) info.get(1), (Long) info.get(2),
171171
(Long) info.get(4), (String) info.get(3), HypervisorType.KVM,
172-
RouterPrivateIpStrategy.HostLocal, changes);
172+
RouterPrivateIpStrategy.HostLocal, changes, null);
173173
fillNetworkInformation(cmd);
174174
cmd.getHostDetails().putAll(getVersionStrings());
175175
cmd.setCluster(getConfiguredProperty("cluster", "1"));

api/src/com/cloud/agent/api/HostVmStateReportEntry.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,29 @@
1919
import com.cloud.vm.VirtualMachine;
2020
import com.cloud.vm.VirtualMachine.PowerState;
2121

22+
//
23+
// TODO vmsync
24+
// We should also have a HostVmStateReport class instead of using raw Map<> data structure,
25+
// for now, we store host-specific info at each VM entry and host fields are fixed
26+
//
27+
// This needs to be refactor-ed afterwards
28+
//
2229
public class HostVmStateReportEntry {
2330
VirtualMachine.PowerState state;
31+
32+
// host name or host uuid
2433
String host;
34+
35+
// XS needs Xen Tools version info
36+
String hostToolsVersion;
2537

2638
public HostVmStateReportEntry() {
2739
}
2840

29-
public HostVmStateReportEntry(PowerState state, String host) {
41+
public HostVmStateReportEntry(PowerState state, String host, String hostToolsVersion) {
3042
this.state = state;
3143
this.host = host;
44+
this.hostToolsVersion = hostToolsVersion;
3245
}
3346

3447
public PowerState getState() {
@@ -38,4 +51,8 @@ public PowerState getState() {
3851
public String getHost() {
3952
return host;
4053
}
54+
55+
public String getHostToolsVersion() {
56+
return hostToolsVersion;
57+
}
4158
}

core/src/com/cloud/agent/api/PingRoutingCommand.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,33 @@
2222
import com.cloud.vm.VirtualMachine.State;
2323

2424
public class PingRoutingCommand extends PingCommand {
25-
Map<String, State> newStates;
25+
26+
// TODO vmsync {
27+
Map<String, State> newStates;
28+
// TODO vmsync }
29+
30+
Map<String, HostVmStateReportEntry> _hostVmStateReport;
31+
2632
boolean _gatewayAccessible = true;
2733
boolean _vnetAccessible = true;
2834

2935
protected PingRoutingCommand() {
3036
}
3137

32-
public PingRoutingCommand(Host.Type type, long id, Map<String, State> states) {
38+
public PingRoutingCommand(Host.Type type, long id, Map<String, State> states,
39+
Map<String, HostVmStateReportEntry> hostVmStateReport) {
3340
super(type, id);
3441
this.newStates = states;
42+
this._hostVmStateReport = hostVmStateReport;
3543
}
3644

3745
public Map<String, State> getNewStates() {
3846
return newStates;
3947
}
48+
49+
public Map<String, HostVmStateReportEntry> getHostVmStateReport() {
50+
return this._hostVmStateReport;
51+
}
4052

4153
public boolean isGatewayAccessible() {
4254
return _gatewayAccessible;

core/src/com/cloud/agent/api/PingRoutingWithNwGroupsCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ protected PingRoutingWithNwGroupsCommand() {
3131
super();
3232
}
3333

34-
public PingRoutingWithNwGroupsCommand(Host.Type type, long id, Map<String, State> states, HashMap<String, Pair<Long, Long>> nwGrpStates) {
35-
super(type, id, states);
34+
public PingRoutingWithNwGroupsCommand(Host.Type type, long id,
35+
Map<String, State> states, Map<String, HostVmStateReportEntry> hostVmStateReport,
36+
HashMap<String, Pair<Long, Long>> nwGrpStates) {
37+
super(type, id, states, hostVmStateReport);
3638
newGroupStates = nwGrpStates;
3739
}
3840

core/src/com/cloud/agent/api/PingRoutingWithOvsCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ protected PingRoutingWithOvsCommand() {
3131
}
3232

3333
public PingRoutingWithOvsCommand(Host.Type type, long id,
34-
Map<String, State> states, List<Pair<String, Long>> ovsStates) {
35-
super(type, id, states);
34+
Map<String, State> states, Map<String, HostVmStateReportEntry> hostVmStateReport,
35+
List<Pair<String, Long>> ovsStates) {
36+
super(type, id, states, hostVmStateReport);
37+
3638
this.states = ovsStates;
3739
}
3840

core/src/com/cloud/agent/api/StartupRoutingCommand.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,18 @@ public String getHost() {
4848
long memory;
4949
long dom0MinMemory;
5050
boolean poolSync;
51+
52+
// VM power state report is added in a side-by-side way as old VM state report
53+
// this is to allow a graceful migration from the old VM state sync model to the new model
54+
//
55+
// side-by-side addition of power state sync
56+
Map<String, HostVmStateReportEntry> _hostVmStateReport;
57+
58+
// TODO vmsync
59+
// deprecated, will delete after full replacement
5160
Map<String, VmState> vms;
5261
HashMap<String, Ternary<String, State, String>> _clusterVMStates;
62+
5363
String caps;
5464
String pool;
5565
HypervisorType hypervisorType;
@@ -70,8 +80,10 @@ public StartupRoutingCommand(int cpus,
7080
String caps,
7181
HypervisorType hypervisorType,
7282
RouterPrivateIpStrategy privIpStrategy,
73-
Map<String, VmState> vms) {
74-
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, vms);
83+
Map<String, VmState> vms,
84+
Map<String, HostVmStateReportEntry> hostVmStateReport
85+
) {
86+
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, vms, hostVmStateReport);
7587
getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStrategy.toString());
7688
}
7789

@@ -82,9 +94,11 @@ public StartupRoutingCommand(int cpus,
8294
String caps,
8395
HypervisorType hypervisorType,
8496
RouterPrivateIpStrategy privIpStrategy) {
85-
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, new HashMap<String,String>(), new HashMap<String, VmState>());
86-
getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStrategy.toString());
87-
}
97+
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, new HashMap<String,String>(),
98+
new HashMap<String, VmState>(), new HashMap<String, HostVmStateReportEntry>());
99+
100+
getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStrategy.toString());
101+
}
88102

89103
public StartupRoutingCommand(int cpus,
90104
long speed,
@@ -93,13 +107,15 @@ public StartupRoutingCommand(int cpus,
93107
final String caps,
94108
final HypervisorType hypervisorType,
95109
final Map<String, String> hostDetails,
96-
Map<String, VmState> vms) {
110+
Map<String, VmState> vms,
111+
Map<String, HostVmStateReportEntry> hostVmStateReport) {
97112
super(Host.Type.Routing);
98113
this.cpus = cpus;
99114
this.speed = speed;
100115
this.memory = memory;
101116
this.dom0MinMemory = dom0MinMemory;
102117
this.vms = vms;
118+
this._hostVmStateReport = hostVmStateReport;
103119
this.hypervisorType = hypervisorType;
104120
this.hostDetails = hostDetails;
105121
this.caps = caps;
@@ -108,12 +124,14 @@ public StartupRoutingCommand(int cpus,
108124

109125
public StartupRoutingCommand(int cpus2, long speed2, long memory2,
110126
long dom0MinMemory2, String caps2, HypervisorType hypervisorType2,
111-
Map<String, VmState> vms2) {
112-
this(cpus2, speed2, memory2, dom0MinMemory2, caps2, hypervisorType2, new HashMap<String,String>(), vms2);
127+
Map<String, VmState> vms2, Map<String, HostVmStateReportEntry> hostVmStateReport
128+
) {
129+
this(cpus2, speed2, memory2, dom0MinMemory2, caps2, hypervisorType2, new HashMap<String,String>(), vms2, hostVmStateReport);
113130
}
114131

115-
public StartupRoutingCommand(int cpus, long speed, long memory, long dom0MinMemory, final String caps, final HypervisorType hypervisorType, final Map<String, String> hostDetails, Map<String, VmState> vms, String hypervisorVersion) {
116-
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, hostDetails, vms);
132+
public StartupRoutingCommand(int cpus, long speed, long memory, long dom0MinMemory, final String caps, final HypervisorType hypervisorType, final Map<String, String> hostDetails,
133+
Map<String, VmState> vms, Map<String, HostVmStateReportEntry> vmPowerStates, String hypervisorVersion) {
134+
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, hostDetails, vms, vmPowerStates);
117135
this.hypervisorVersion = hypervisorVersion;
118136
}
119137

@@ -229,5 +247,13 @@ public String getHypervisorVersion() {
229247
public void setHypervisorVersion(String hypervisorVersion) {
230248
this.hypervisorVersion = hypervisorVersion;
231249
}
250+
251+
public Map<String, HostVmStateReportEntry> getHostVmStateReport() {
252+
return this._hostVmStateReport;
253+
}
254+
255+
public void setHostVmStateReport(Map<String, HostVmStateReportEntry> hostVmStateReport) {
256+
this._hostVmStateReport = hostVmStateReport;
257+
}
232258
}
233259

plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalResourceBase.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import javax.naming.ConfigurationException;
3232

3333
import org.apache.log4j.Logger;
34-
3534
import org.apache.cloudstack.api.ApiConstants;
3635

3736
import com.cloud.agent.IAgentControl;
@@ -41,6 +40,7 @@
4140
import com.cloud.agent.api.CheckVirtualMachineAnswer;
4241
import com.cloud.agent.api.CheckVirtualMachineCommand;
4342
import com.cloud.agent.api.Command;
43+
import com.cloud.agent.api.HostVmStateReportEntry;
4444
import com.cloud.agent.api.MaintainAnswer;
4545
import com.cloud.agent.api.MaintainCommand;
4646
import com.cloud.agent.api.MigrateAnswer;
@@ -77,6 +77,7 @@
7777
import com.cloud.utils.script.Script2.ParamType;
7878
import com.cloud.vm.VMInstanceVO;
7979
import com.cloud.vm.VirtualMachine;
80+
import com.cloud.vm.VirtualMachine.PowerState;
8081
import com.cloud.vm.VirtualMachine.State;
8182
import com.cloud.vm.dao.VMInstanceDao;
8283

@@ -332,10 +333,36 @@ protected Map<String, State> fullSync() {
332333

333334
return states;
334335
}
336+
337+
protected Map<String, HostVmStateReportEntry> getHostVmStateReport() {
338+
Map<String, HostVmStateReportEntry> states = new HashMap<String, HostVmStateReportEntry>();
339+
if (hostId != null) {
340+
vmDao = ComponentContext.getComponent(VMInstanceDao.class);
341+
final List<? extends VMInstanceVO> vms = vmDao.listByHostId(hostId);
342+
for (VMInstanceVO vm : vms) {
343+
states.put(
344+
vm.getInstanceName(),
345+
new HostVmStateReportEntry(
346+
vm.getState() == State.Running ? PowerState.PowerOn : PowerState.PowerOff, "host-" + hostId, null
347+
)
348+
);
349+
}
350+
}
351+
/*
352+
* Map<String, State> changes = new HashMap<String, State>();
353+
*
354+
* if (_vmName != null) { State state = getVmState(); if (state != null)
355+
* { changes.put(_vmName, state); } }
356+
*/
357+
358+
return states;
359+
}
335360

336361
@Override
337362
public StartupCommand[] initialize() {
338-
StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.BareMetal, new HashMap<String, String>(), null);
363+
StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.BareMetal,
364+
new HashMap<String, String>(), null, null);
365+
339366
cmd.setDataCenter(_zone);
340367
cmd.setPod(_pod);
341368
cmd.setCluster(_cluster);
@@ -372,7 +399,7 @@ public PingCommand getCurrentStatus(long id) {
372399
return null;
373400
}
374401

375-
return new PingRoutingCommand(getType(), id, deltaSync());
402+
return new PingRoutingCommand(getType(), id, deltaSync(), getHostVmStateReport());
376403
}
377404

378405
protected Answer execute(IpmISetBootDevCommand cmd) {

plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.cloud.agent.IAgentControl;
3333
import com.cloud.agent.api.Answer;
3434
import com.cloud.agent.api.Command;
35+
import com.cloud.agent.api.HostVmStateReportEntry;
3536
import com.cloud.agent.api.PingCommand;
3637
import com.cloud.agent.api.PingRoutingCommand;
3738
import com.cloud.agent.api.ReadyAnswer;
@@ -129,7 +130,8 @@ public StartupCommand[] initialize() {
129130
@Override
130131
public PingCommand getCurrentStatus(long id) {
131132
//TODO: check server
132-
return new PingRoutingCommand(getType(), id, new HashMap<String, State>());
133+
return new PingRoutingCommand(getType(), id, new HashMap<String, State>(),
134+
new HashMap<String, HostVmStateReportEntry>());
133135
}
134136

135137
protected ReadyAnswer execute(ReadyCommand cmd) {

plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import com.cloud.agent.api.Answer;
3333
import com.cloud.agent.api.Command;
34+
import com.cloud.agent.api.HostVmStateReportEntry;
3435
import com.cloud.agent.api.PingCommand;
3536
import com.cloud.agent.api.PingRoutingCommand;
3637
import com.cloud.agent.api.routing.DhcpEntryCommand;
@@ -105,7 +106,8 @@ public PingCommand getCurrentStatus(long id) {
105106
return null;
106107
} else {
107108
SSHCmdHelper.releaseSshConnection(sshConnection);
108-
return new PingRoutingCommand(getType(), id, new HashMap<String, State>());
109+
return new PingRoutingCommand(getType(), id, new HashMap<String, State>(),
110+
new HashMap<String, HostVmStateReportEntry>());
109111
}
110112
}
111113

plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import com.cloud.agent.api.Answer;
3434
import com.cloud.agent.api.Command;
35+
import com.cloud.agent.api.HostVmStateReportEntry;
3536
import com.cloud.agent.api.PingCommand;
3637
import com.cloud.agent.api.PingRoutingCommand;
3738
import com.cloud.agent.api.routing.DhcpEntryCommand;
@@ -98,7 +99,8 @@ public PingCommand getCurrentStatus(long id) {
9899
return null;
99100
} else {
100101
SSHCmdHelper.releaseSshConnection(sshConnection);
101-
return new PingRoutingCommand(getType(), id, new HashMap<String, State>());
102+
return new PingRoutingCommand(getType(), id, new HashMap<String, State>(),
103+
new HashMap<String, HostVmStateReportEntry>());
102104
}
103105
}
104106

0 commit comments

Comments
 (0)