Skip to content

Commit d0a7ca0

Browse files
committed
Decouple hypervisor resource from VM state sync
1 parent e31e33c commit d0a7ca0

33 files changed

Lines changed: 455 additions & 518 deletions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import com.cloud.agent.api.CheckNetworkAnswer;
3030
import com.cloud.agent.api.CheckNetworkCommand;
3131
import com.cloud.agent.api.Command;
32+
import com.cloud.agent.api.HostVmStateReportEntry;
3233
import com.cloud.agent.api.PingCommand;
3334
import com.cloud.agent.api.StartupCommand;
3435
import com.cloud.agent.api.StartupRoutingCommand;
3536
import com.cloud.agent.api.StartupStorageCommand;
3637
import com.cloud.agent.api.StoragePoolInfo;
37-
import com.cloud.agent.api.StartupRoutingCommand.VmState;
3838
import com.cloud.host.Host;
3939
import com.cloud.host.Host.Type;
4040
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -162,7 +162,7 @@ protected StoragePoolInfo initializeLocalStorage() {
162162

163163
@Override
164164
public StartupCommand[] initialize() {
165-
Map<String, VmState> changes = null;
165+
Map<String, HostVmStateReportEntry> changes = null;
166166

167167
final List<Object> info = getHostInfo();
168168

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@
1616
// under the License.
1717
package com.cloud.agent.api;
1818

19-
import com.cloud.vm.VirtualMachine.State;
19+
import com.cloud.vm.VirtualMachine.PowerState;
2020

2121
public class CheckVirtualMachineAnswer extends Answer {
2222

2323
Integer vncPort;
24-
State state;
24+
PowerState state;
2525

2626

2727
protected CheckVirtualMachineAnswer() {
2828
}
2929

30-
public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, State state, Integer vncPort, String detail) {
30+
public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, PowerState state, Integer vncPort, String detail) {
3131
super(cmd, true, detail);
3232
this.state = state;
3333
this.vncPort = vncPort;
3434
}
3535

36-
public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, State state, Integer vncPort) {
36+
public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, PowerState state, Integer vncPort) {
3737
this(cmd, state, vncPort, null);
3838
}
3939

@@ -46,7 +46,7 @@ public Integer getVncPort() {
4646
return vncPort;
4747
}
4848

49-
public State getState() {
49+
public PowerState getState() {
5050
return state;
5151
}
5252
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
import java.util.HashMap;
2020

2121
import com.cloud.utils.Pair;
22-
import com.cloud.vm.VirtualMachine.State;
22+
import com.cloud.vm.VirtualMachine.PowerState;
2323

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

2929
// this is here because a cron command answer is being sent twice
@@ -38,7 +38,7 @@ public void setExecuted(){
3838
}
3939

4040

41-
public ClusterSyncAnswer(long clusterId, HashMap<String, Pair<String, State>> newStates){
41+
public ClusterSyncAnswer(long clusterId, HashMap<String, Pair<String, PowerState>> newStates){
4242
_clusterId = clusterId;
4343
_newStates = newStates;
4444
result = true;
@@ -48,7 +48,7 @@ public long getClusterId() {
4848
return _clusterId;
4949
}
5050

51-
public HashMap<String, Pair<String, State>> getNewStates() {
51+
public HashMap<String, Pair<String, PowerState>> getNewStates() {
5252
return _newStates;
5353
}
5454

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 com.cloud.vm.VirtualMachine;
20+
import com.cloud.vm.VirtualMachine.PowerState;
21+
22+
public class HostVmStateReportEntry {
23+
VirtualMachine.PowerState state;
24+
String host;
25+
26+
public HostVmStateReportEntry() {
27+
}
28+
29+
public HostVmStateReportEntry(PowerState state, String host) {
30+
this.state = state;
31+
this.host = host;
32+
}
33+
34+
public PowerState getState() {
35+
return state;
36+
}
37+
38+
public String getHost() {
39+
return host;
40+
}
41+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
import java.util.Map;
2020

2121
import com.cloud.host.Host;
22-
import com.cloud.vm.VirtualMachine.State;
22+
import com.cloud.vm.VirtualMachine.PowerState;
2323

2424
public class PingRoutingCommand extends PingCommand {
25-
Map<String, State> newStates;
25+
Map<String, PowerState> newStates;
2626
boolean _gatewayAccessible = true;
2727
boolean _vnetAccessible = true;
2828

2929
protected PingRoutingCommand() {
3030
}
3131

32-
public PingRoutingCommand(Host.Type type, long id, Map<String, State> states) {
32+
public PingRoutingCommand(Host.Type type, long id, Map<String, PowerState> states) {
3333
super(type, id);
3434
this.newStates = states;
3535
}
3636

37-
public Map<String, State> getNewStates() {
37+
public Map<String, PowerState> getNewStates() {
3838
return newStates;
3939
}
4040

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import com.cloud.host.Host;
2323
import com.cloud.utils.Pair;
24-
import com.cloud.vm.VirtualMachine.State;
24+
import com.cloud.vm.VirtualMachine.PowerState;
2525

2626

2727
public class PingRoutingWithNwGroupsCommand extends PingRoutingCommand {
@@ -31,7 +31,7 @@ protected PingRoutingWithNwGroupsCommand() {
3131
super();
3232
}
3333

34-
public PingRoutingWithNwGroupsCommand(Host.Type type, long id, Map<String, State> states, HashMap<String, Pair<Long, Long>> nwGrpStates) {
34+
public PingRoutingWithNwGroupsCommand(Host.Type type, long id, Map<String, PowerState> states, HashMap<String, Pair<Long, Long>> nwGrpStates) {
3535
super(type, id, states);
3636
newGroupStates = nwGrpStates;
3737
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import com.cloud.host.Host;
2323
import com.cloud.utils.Pair;
24-
import com.cloud.vm.VirtualMachine.State;
24+
import com.cloud.vm.VirtualMachine.PowerState;
2525

2626
public class PingRoutingWithOvsCommand extends PingRoutingCommand {
2727
List<Pair<String, Long>> states;
@@ -31,7 +31,7 @@ protected PingRoutingWithOvsCommand() {
3131
}
3232

3333
public PingRoutingWithOvsCommand(Host.Type type, long id,
34-
Map<String, State> states, List<Pair<String, Long>> ovsStates) {
34+
Map<String, PowerState> states, List<Pair<String, Long>> ovsStates) {
3535
super(type, id, states);
3636
this.states = ovsStates;
3737
}

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

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,16 @@
2323
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2424
import com.cloud.network.Networks.RouterPrivateIpStrategy;
2525
import com.cloud.utils.Pair;
26-
import com.cloud.vm.VirtualMachine.State;
26+
import com.cloud.vm.VirtualMachine.PowerState;
2727

2828
public class StartupRoutingCommand extends StartupCommand {
29-
public static class VmState {
30-
State state;
31-
String host;
32-
public VmState() {
33-
}
34-
public VmState(State state, String host) {
35-
this.state = state;
36-
this.host = host;
37-
}
38-
public State getState() {
39-
return state;
40-
}
41-
public String getHost() {
42-
return host;
43-
}
44-
}
4529
int cpus;
4630
long speed;
4731
long memory;
4832
long dom0MinMemory;
4933
boolean poolSync;
50-
Map<String, VmState> vms;
51-
HashMap<String, Pair<String, State>> _clusterVMStates;
34+
Map<String, HostVmStateReportEntry> vms;
35+
HashMap<String, Pair<String, PowerState>> _clusterVMStates;
5236
String caps;
5337
String pool;
5438
HypervisorType hypervisorType;
@@ -59,7 +43,6 @@ public StartupRoutingCommand() {
5943
super(Host.Type.Routing);
6044
hostDetails = new HashMap<String, String>();
6145
getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), RouterPrivateIpStrategy.DcGlobal.toString());
62-
6346
}
6447

6548
public StartupRoutingCommand(int cpus,
@@ -69,8 +52,9 @@ public StartupRoutingCommand(int cpus,
6952
String caps,
7053
HypervisorType hypervisorType,
7154
RouterPrivateIpStrategy privIpStrategy,
72-
Map<String, VmState> vms) {
73-
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, vms);
55+
Map<String, HostVmStateReportEntry> vms) {
56+
57+
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, vms);
7458
getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStrategy.toString());
7559
}
7660

@@ -81,9 +65,10 @@ public StartupRoutingCommand(int cpus,
8165
String caps,
8266
HypervisorType hypervisorType,
8367
RouterPrivateIpStrategy privIpStrategy) {
84-
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, new HashMap<String,String>(), new HashMap<String, VmState>());
85-
getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStrategy.toString());
86-
}
68+
69+
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, new HashMap<String,String>(), new HashMap<String, HostVmStateReportEntry>());
70+
getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStrategy.toString());
71+
}
8772

8873
public StartupRoutingCommand(int cpus,
8974
long speed,
@@ -92,7 +77,7 @@ public StartupRoutingCommand(int cpus,
9277
final String caps,
9378
final HypervisorType hypervisorType,
9479
final Map<String, String> hostDetails,
95-
Map<String, VmState> vms) {
80+
Map<String, HostVmStateReportEntry> vms) {
9681
super(Host.Type.Routing);
9782
this.cpus = cpus;
9883
this.speed = speed;
@@ -107,29 +92,29 @@ public StartupRoutingCommand(int cpus,
10792

10893
public StartupRoutingCommand(int cpus2, long speed2, long memory2,
10994
long dom0MinMemory2, String caps2, HypervisorType hypervisorType2,
110-
Map<String, VmState> vms2) {
95+
Map<String, HostVmStateReportEntry> vms2) {
11196
this(cpus2, speed2, memory2, dom0MinMemory2, caps2, hypervisorType2, new HashMap<String,String>(), vms2);
11297
}
11398

114-
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) {
99+
public StartupRoutingCommand(int cpus, long speed, long memory, long dom0MinMemory, final String caps, final HypervisorType hypervisorType, final Map<String, String> hostDetails, Map<String, HostVmStateReportEntry> vms, String hypervisorVersion) {
115100
this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, hostDetails, vms);
116101
this.hypervisorVersion = hypervisorVersion;
117102
}
118103

119-
public void setChanges(Map<String, VmState> vms) {
104+
public void setChanges(Map<String, HostVmStateReportEntry> vms) {
120105
this.vms = vms;
121106
}
122107

123-
public void setStateChanges(Map<String, State> vms) {
108+
public void setStateChanges(Map<String, PowerState> vms) {
124109
for( String vm_name : vms.keySet() ) {
125110
if( this.vms == null ) {
126-
this.vms = new HashMap<String, VmState>();
111+
this.vms = new HashMap<String, HostVmStateReportEntry>();
127112
}
128-
this.vms.put(vm_name, new VmState(vms.get(vm_name), null));
113+
this.vms.put(vm_name, new HostVmStateReportEntry(vms.get(vm_name), null));
129114
}
130115
}
131116

132-
public void setClusterVMStateChanges(HashMap<String, Pair<String, State>> allStates){
117+
public void setClusterVMStateChanges(HashMap<String, Pair<String, PowerState>> allStates){
133118
_clusterVMStates = allStates;
134119
}
135120

@@ -153,11 +138,11 @@ public long getDom0MinMemory() {
153138
return dom0MinMemory;
154139
}
155140

156-
public Map<String, VmState> getVmStates() {
141+
public Map<String, HostVmStateReportEntry> getVmStates() {
157142
return vms;
158143
}
159144

160-
public HashMap<String, Pair<String, State>> getClusterVMStateChanges() {
145+
public HashMap<String, Pair<String, PowerState>> getClusterVMStateChanges() {
161146
return _clusterVMStates;
162147
}
163148

core/src/com/cloud/hypervisor/hyperv/resource/HypervResource.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
import com.cloud.utils.Pair;
110110
import com.cloud.utils.exception.CloudRuntimeException;
111111
import com.cloud.vm.DiskProfile;
112+
import com.cloud.vm.VirtualMachine.PowerState;
112113
import com.cloud.vm.VirtualMachine.State;
113114
import com.google.gson.Gson;
114115

@@ -900,8 +901,8 @@ private List <String> getHostsInCluster(String clusterName)
900901
return hypervHosts;
901902
}
902903

903-
protected HashMap<String, State> sync() {
904-
HashMap<String, State> changes = new HashMap<String, State>();
904+
protected HashMap<String, PowerState> sync() {
905+
HashMap<String, PowerState> changes = new HashMap<String, PowerState>();
905906

906907
try {
907908
synchronized (_vms) {
@@ -916,9 +917,9 @@ protected HashMap<String, State> sync() {
916917

917918
@Override
918919
public PingCommand getCurrentStatus(long id) {
919-
HashMap<String, State> newStates = sync();
920+
HashMap<String, PowerState> newStates = sync();
920921
if (newStates == null) {
921-
newStates = new HashMap<String, State>();
922+
newStates = new HashMap<String, PowerState>();
922923
}
923924
PingRoutingCommand cmd = new PingRoutingCommand(com.cloud.host.Host.Type.Routing, id, newStates);
924925
return cmd;

0 commit comments

Comments
 (0)