Skip to content

Commit ab1d3af

Browse files
author
Anthony Xu
committed
Use seperate path to sync VM metadata for XS
VM status sync only does VM status sync
1 parent d1c0b81 commit ab1d3af

16 files changed

Lines changed: 271 additions & 149 deletions

File tree

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ public class HostVmStateReportEntry {
3232
// host name or host uuid
3333
String host;
3434

35-
// XS needs Xen Tools version info
36-
String hostToolsVersion;
37-
3835
public HostVmStateReportEntry() {
3936
}
4037

41-
public HostVmStateReportEntry(PowerState state, String host, String hostToolsVersion) {
38+
public HostVmStateReportEntry(PowerState state, String host) {
4239
this.state = state;
4340
this.host = host;
44-
this.hostToolsVersion = hostToolsVersion;
4541
}
4642

4743
public PowerState getState() {
@@ -51,8 +47,4 @@ public PowerState getState() {
5147
public String getHost() {
5248
return host;
5349
}
54-
55-
public String getHostToolsVersion() {
56-
return hostToolsVersion;
57-
}
5850
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@
1818

1919
import java.util.HashMap;
2020

21-
import com.cloud.utils.Ternary;
21+
import com.cloud.utils.Pair;
2222
import com.cloud.vm.VirtualMachine.State;
2323

2424
public class ClusterSyncAnswer extends Answer {
2525
private long _clusterId;
26-
private HashMap<String, Ternary<String, State, String>> _newStates;
26+
private HashMap<String, Pair<String, State>> _newStates;
2727
private boolean _isExecuted = false;
2828

2929
// this is here because a cron command answer is being sent twice
3030
// AgentAttache.processAnswers
3131
// AgentManagerImpl.notifyAnswersToMonitors
32-
public boolean isExceuted() {
32+
public boolean isExecuted() {
3333
return _isExecuted;
3434
}
3535

3636
public void setExecuted() {
3737
_isExecuted = true;
3838
}
3939

40-
public ClusterSyncAnswer(long clusterId, HashMap<String, Ternary<String, State, String>> newStates) {
40+
public ClusterSyncAnswer(long clusterId, HashMap<String, Pair<String, State>> newStates) {
4141
_clusterId = clusterId;
4242
_newStates = newStates;
4343
result = true;
@@ -47,7 +47,7 @@ public long getClusterId() {
4747
return _clusterId;
4848
}
4949

50-
public HashMap<String, Ternary<String, State, String>> getNewStates() {
50+
public HashMap<String, Pair<String, State>> getNewStates() {
5151
return _newStates;
5252
}
5353

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.agent.api;
18+
19+
import java.util.HashMap;
20+
21+
public class ClusterVMMetaDataSyncAnswer extends Answer {
22+
private long _clusterId;
23+
private HashMap<String, String> _vmMetaDatum;
24+
private boolean _isExecuted=false;
25+
26+
// this is here because a cron command answer is being sent twice
27+
// AgentAttache.processAnswers
28+
// AgentManagerImpl.notifyAnswersToMonitors
29+
public boolean isExecuted(){
30+
return _isExecuted;
31+
}
32+
33+
public void setExecuted(){
34+
_isExecuted = true;
35+
}
36+
37+
38+
public ClusterVMMetaDataSyncAnswer(long clusterId, HashMap<String, String> vmMetaDatum){
39+
_clusterId = clusterId;
40+
_vmMetaDatum = vmMetaDatum;
41+
result = true;
42+
}
43+
44+
public long getClusterId() {
45+
return _clusterId;
46+
}
47+
48+
public HashMap<String, String> getVMMetaDatum() {
49+
return _vmMetaDatum;
50+
}
51+
52+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.agent.api;
18+
19+
20+
public class ClusterVMMetaDataSyncCommand extends Command implements CronCommand {
21+
int _interval;
22+
23+
long _clusterId;
24+
25+
public ClusterVMMetaDataSyncCommand() {
26+
}
27+
28+
public ClusterVMMetaDataSyncCommand(int interval, long clusterId){
29+
_interval = interval;
30+
_clusterId = clusterId;
31+
}
32+
33+
@Override
34+
public int getInterval() {
35+
return _interval;
36+
}
37+
38+
public long getClusterId() {
39+
return _clusterId;
40+
}
41+
42+
@Override
43+
public boolean executeInSequence() {
44+
return false;
45+
}
46+
47+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.cloud.host.Host;
2323
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2424
import com.cloud.network.Networks.RouterPrivateIpStrategy;
25-
import com.cloud.utils.Ternary;
25+
import com.cloud.utils.Pair;
2626
import com.cloud.vm.VirtualMachine.State;
2727

2828
public class StartupRoutingCommand extends StartupCommand {
@@ -63,7 +63,7 @@ public String getHost() {
6363
// TODO vmsync
6464
// deprecated, will delete after full replacement
6565
Map<String, VmState> vms;
66-
HashMap<String, Ternary<String, State, String>> _clusterVMStates;
66+
HashMap<String, Pair<String, State>> _clusterVMStates;
6767

6868
String caps;
6969
String pool;
@@ -137,7 +137,7 @@ public void setStateChanges(Map<String, State> vms) {
137137
}
138138
}
139139

140-
public void setClusterVMStateChanges(HashMap<String, Ternary<String, State, String>> allStates) {
140+
public void setClusterVMStateChanges(HashMap<String, Pair<String, State>> allStates) {
141141
_clusterVMStates = allStates;
142142
}
143143

@@ -169,7 +169,7 @@ public Map<String, VmState> getVmStates() {
169169
return vms;
170170
}
171171

172-
public HashMap<String, Ternary<String, State, String>> getClusterVMStateChanges() {
172+
public HashMap<String, Pair<String, State>> getClusterVMStateChanges() {
173173
return _clusterVMStates;
174174
}
175175

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

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
import com.cloud.agent.api.CheckVirtualMachineCommand;
8181
import com.cloud.agent.api.ClusterSyncAnswer;
8282
import com.cloud.agent.api.ClusterSyncCommand;
83+
import com.cloud.agent.api.ClusterVMMetaDataSyncCommand;
84+
import com.cloud.agent.api.ClusterVMMetaDataSyncAnswer;
8385
import com.cloud.agent.api.Command;
8486
import com.cloud.agent.api.MigrateAnswer;
8587
import com.cloud.agent.api.MigrateCommand;
@@ -340,6 +342,8 @@ public void setHostAllocators(List<HostAllocator> hostAllocators) {
340342
static final ConfigKey<Integer> ClusterDeltaSyncInterval = new ConfigKey<Integer>("Advanced", Integer.class, "sync.interval", "60",
341343
"Cluster Delta sync interval in seconds",
342344
false);
345+
static final ConfigKey<Integer> ClusterVMMetaDataSyncInterval = new ConfigKey<Integer>("Advanced", Integer.class, "vmmetadata.sync.interval", "180", "Cluster VM metadata sync interval in seconds",
346+
false);
343347

344348
static final ConfigKey<Boolean> VmJobEnabled = new ConfigKey<Boolean>("Advanced",
345349
Boolean.class, "vm.job.enabled", "true",
@@ -2521,7 +2525,35 @@ public Commands deltaHostSync(long hostId, Map<String, State> newStates) {
25212525
return commands;
25222526
}
25232527

2524-
public void deltaSync(Map<String, Ternary<String, State, String>> newStates) {
2528+
// this is XenServer specific
2529+
public void syncVMMetaData(Map<String, String> vmMetadatum) {
2530+
if (vmMetadatum == null || vmMetadatum.isEmpty()) {
2531+
return;
2532+
}
2533+
for (Map.Entry<String, String> entry : vmMetadatum.entrySet()) {
2534+
String name = entry.getKey();
2535+
String platform = entry.getValue();
2536+
if (platform == null || platform.isEmpty()) {
2537+
continue;
2538+
}
2539+
VMInstanceVO vm = _vmDao.findVMByInstanceName(name);
2540+
if (vm != null && vm.getType() == VirtualMachine.Type.User) {
2541+
// track platform info
2542+
UserVmVO userVm = _userVmDao.findById(vm.getId());
2543+
_userVmDao.loadDetails(userVm);
2544+
userVm.setDetail("platform", platform);
2545+
String pvdriver = "xenserver56";
2546+
if ( platform.contains("device_id")) {
2547+
pvdriver = "xenserver61";
2548+
}
2549+
userVm.setDetail("hypervisortoolsversion", pvdriver);
2550+
_userVmDao.saveDetails(userVm);
2551+
}
2552+
}
2553+
}
2554+
2555+
2556+
public void deltaSync(Map<String, Pair<String, State>> newStates) {
25252557
Map<Long, AgentVmInfo> states = convertToInfos(newStates);
25262558

25272559
for (Map.Entry<Long, AgentVmInfo> entry : states.entrySet()) {
@@ -2556,7 +2588,7 @@ public void deltaSync(Map<String, Ternary<String, State, String>> newStates) {
25562588
}
25572589
}
25582590

2559-
public void fullSync(final long clusterId, Map<String, Ternary<String, State, String>> newStates) {
2591+
public void fullSync(final long clusterId, Map<String, Pair<String, State>> newStates) {
25602592
if (newStates == null)
25612593
return;
25622594
Map<Long, AgentVmInfo> infos = convertToInfos(newStates);
@@ -2686,24 +2718,24 @@ public void fullSync(final long clusterId, Map<String, Ternary<String, State, St
26862718

26872719
}
26882720

2689-
protected Map<Long, AgentVmInfo> convertToInfos(final Map<String, Ternary<String, State, String>> newStates) {
2721+
protected Map<Long, AgentVmInfo> convertToInfos(final Map<String, Pair<String, State>> newStates) {
26902722
final HashMap<Long, AgentVmInfo> map = new HashMap<Long, AgentVmInfo>();
26912723
if (newStates == null) {
26922724
return map;
26932725
}
26942726
boolean is_alien_vm = true;
26952727
long alien_vm_count = -1;
2696-
for (Map.Entry<String, Ternary<String, State, String>> entry : newStates.entrySet()) {
2728+
for (Map.Entry<String, Pair<String, State>> entry : newStates.entrySet()) {
26972729
is_alien_vm = true;
26982730
String name = entry.getKey();
26992731
VMInstanceVO vm = _vmDao.findVMByInstanceName(name);
27002732
if (vm != null) {
2701-
map.put(vm.getId(), new AgentVmInfo(entry.getKey(), vm, entry.getValue().second(), entry.getValue().first(), entry.getValue().third()));
2733+
map.put(vm.getId(), new AgentVmInfo(entry.getKey(), vm, entry.getValue().second(), entry.getValue().first()));
27022734
is_alien_vm = false;
27032735
}
27042736
// alien VMs
27052737
if (is_alien_vm) {
2706-
map.put(alien_vm_count--, new AgentVmInfo(entry.getKey(), null, entry.getValue().second(), entry.getValue().first(), entry.getValue().third()));
2738+
map.put(alien_vm_count--, new AgentVmInfo(entry.getKey(), null, entry.getValue().second(), entry.getValue().first()));
27072739
s_logger.warn("Found an alien VM " + entry.getKey());
27082740
}
27092741
}
@@ -2784,15 +2816,6 @@ protected Command compareState(long hostId, VMInstanceVO vm, final AgentVmInfo i
27842816
") stopped on host " + hostDesc + " due to storage failure", "Virtual Machine " + vm.getInstanceName() + " (id: " + vm.getId() + ") running on host [" +
27852817
vm.getHostId() + "] stopped due to storage failure.");
27862818
}
2787-
// track platform info
2788-
if (info.platform != null && !info.platform.isEmpty()) {
2789-
if (vm.getType() == VirtualMachine.Type.User) {
2790-
UserVmVO userVm = _userVmDao.findById(vm.getId());
2791-
_userVmDao.loadDetails(userVm);
2792-
userVm.setDetail("platform", info.platform);
2793-
_userVmDao.saveDetails(userVm);
2794-
}
2795-
}
27962819

27972820
if (trackExternalChange) {
27982821
if (serverState == State.Starting) {
@@ -3013,6 +3036,12 @@ public boolean processAnswers(long agentId, long seq, Answer[] answers) {
30133036
hs.setExecuted();
30143037
}
30153038
}
3039+
} else if ( answer instanceof ClusterVMMetaDataSyncAnswer) {
3040+
ClusterVMMetaDataSyncAnswer cvms = (ClusterVMMetaDataSyncAnswer)answer;
3041+
if (!cvms.isExecuted()) {
3042+
syncVMMetaData(cvms.getVMMetaDatum());
3043+
cvms.setExecuted();
3044+
}
30163045
}
30173046
}
30183047
return true;
@@ -3046,7 +3075,6 @@ public boolean processCommands(long agentId, long seq, Command[] cmds) {
30463075
}
30473076
}
30483077
}
3049-
30503078
if(VmJobEnabled.value()) {
30513079
if (ping.getHostVmStateReport() != null) {
30523080
_syncMgr.processHostVmStatePingReport(agentId, ping.getHostVmStateReport());
@@ -3105,7 +3133,6 @@ public void processConnect(Host agent, StartupCommand cmd, boolean forRebalance)
31053133
if (allStates != null) {
31063134
fullSync(clusterId, allStates);
31073135
}
3108-
31093136
// initiate the cron job
31103137
ClusterSyncCommand syncCmd = new ClusterSyncCommand(ClusterDeltaSyncInterval.value(), clusterId);
31113138
try {
@@ -3115,6 +3142,14 @@ public void processConnect(Host agent, StartupCommand cmd, boolean forRebalance)
31153142
s_logger.fatal("The Cluster VM sync process failed for cluster id " + clusterId + " with ", e);
31163143
}
31173144
}
3145+
// initiate the cron job
3146+
ClusterVMMetaDataSyncCommand syncVMMetaDataCmd = new ClusterVMMetaDataSyncCommand(ClusterVMMetaDataSyncInterval.value(), clusterId);
3147+
try {
3148+
long seq_no = _agentMgr.send(agentId, new Commands(syncVMMetaDataCmd), this);
3149+
s_logger.debug("Cluster VM metadata sync started with jobid " + seq_no);
3150+
} catch (AgentUnavailableException e) {
3151+
s_logger.fatal("The Cluster VM metadata sync process failed for cluster id " + clusterId + " with ", e);
3152+
}
31183153
} else { // for others KVM and VMWare
31193154
if (!VmJobEnabled.value()) {
31203155
StartupRoutingCommand startup = (StartupRoutingCommand)cmd;
@@ -3185,33 +3220,22 @@ protected class AgentVmInfo {
31853220
public State state;
31863221
public String hostUuid;
31873222
public VMInstanceVO vm;
3188-
public String platform;
31893223

31903224
@SuppressWarnings("unchecked")
3191-
public AgentVmInfo(String name, VMInstanceVO vm, State state, String host, String platform) {
3225+
public AgentVmInfo(String name, VMInstanceVO vm, State state, String host) {
31923226
this.name = name;
31933227
this.state = state;
31943228
this.vm = vm;
31953229
hostUuid = host;
3196-
this.platform = platform;
3197-
3198-
}
3199-
3200-
public AgentVmInfo(String name, VMInstanceVO vm, State state, String host) {
3201-
this(name, vm, state, host, null);
32023230
}
32033231

32043232
public AgentVmInfo(String name, VMInstanceVO vm, State state) {
3205-
this(name, vm, state, null, null);
3233+
this(name, vm, state, null);
32063234
}
32073235

32083236
public String getHostUuid() {
32093237
return hostUuid;
32103238
}
3211-
3212-
public String getPlatform() {
3213-
return platform;
3214-
}
32153239
}
32163240

32173241
@Override

0 commit comments

Comments
 (0)