Skip to content

Commit 30e72e4

Browse files
Refactoring the whole XsHost thing
Refactor the ReadyCommand Fixing the old test Adding basic tests for ReadyCommandWrapper
1 parent c3ae8c7 commit 30e72e4

File tree

16 files changed

+1558
-1306
lines changed

16 files changed

+1558
-1306
lines changed

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixHelper.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,22 @@
1616
// under the License.
1717
package com.cloud.hypervisor.xenserver.resource;
1818

19-
import java.util.ArrayList;
2019
import java.util.HashMap;
2120

22-
import org.apache.log4j.Logger;
23-
2421
import com.xensource.xenapi.Host;
2522

2623
/**
2724
* Reduce bloat inside CitrixResourceBase
2825
*
2926
*/
3027
public class CitrixHelper {
31-
private static final Logger s_logger = Logger.getLogger(CitrixHelper.class);
32-
33-
3428
private static final HashMap<String, MemoryValues> XenServerGuestOsMemoryMap = new HashMap<String, MemoryValues>(70);
35-
private static final ArrayList<String> GuestOsList = new ArrayList<String>(70);
36-
3729

3830
public static class MemoryValues {
3931
long max;
4032
long min;
4133

42-
public MemoryValues(long min, long max) {
34+
public MemoryValues(final long min, final long max) {
4335
this.min = min * 1024 * 1024;
4436
this.max = max * 1024 * 1024;
4537
}
@@ -53,8 +45,6 @@ public long getMin() {
5345
}
5446
}
5547

56-
57-
5848
static {
5949
XenServerGuestOsMemoryMap.put("CentOS 4.5 (32-bit)", new MemoryValues(256l, 16 * 1024l));
6050
XenServerGuestOsMemoryMap.put("CentOS 4.6 (32-bit)", new MemoryValues(256l, 16 * 1024l));
@@ -207,37 +197,37 @@ public long getMin() {
207197
XenServerGuestOsMemoryMap.put("Windows XP SP3 (32-bit)", new MemoryValues(256l, 4 * 1024l));
208198
XenServerGuestOsMemoryMap.put("Ubuntu 10.04 (32-bit)", new MemoryValues(128l, 512l));
209199
XenServerGuestOsMemoryMap.put("Ubuntu 10.04 (64-bit)", new MemoryValues(128l, 32 * 1024l));
210-
XenServerGuestOsMemoryMap.put("Ubuntu 10.10 (32-bit)", new MemoryValues(512l, 16*1024l));
211-
XenServerGuestOsMemoryMap.put("Ubuntu 10.10 (64-bit)", new MemoryValues(512l, 16*1024l));
200+
XenServerGuestOsMemoryMap.put("Ubuntu 10.10 (32-bit)", new MemoryValues(512l, 16 * 1024l));
201+
XenServerGuestOsMemoryMap.put("Ubuntu 10.10 (64-bit)", new MemoryValues(512l, 16 * 1024l));
212202
XenServerGuestOsMemoryMap.put("Ubuntu 12.04 (32-bit)", new MemoryValues(512l, 32 * 1024l));
213203
XenServerGuestOsMemoryMap.put("Ubuntu 12.04 (64-bit)", new MemoryValues(512l, 128 * 1024l));
214204
XenServerGuestOsMemoryMap.put("Ubuntu 14.04 (32-bit)", new MemoryValues(512l, 32 * 1024l));
215205
XenServerGuestOsMemoryMap.put("Ubuntu 14.04 (64-bit)", new MemoryValues(512l, 128 * 1024l));
216206
}
217207

218-
public static long getXenServerStaticMax(String stdType, boolean bootFromCD) {
219-
MemoryValues recommendedMaxMinMemory = XenServerGuestOsMemoryMap.get(stdType);
208+
public static long getXenServerStaticMax(final String stdType, final boolean bootFromCD) {
209+
final MemoryValues recommendedMaxMinMemory = XenServerGuestOsMemoryMap.get(stdType);
220210
if (recommendedMaxMinMemory == null) {
221211
return 0l;
222212
}
223213
return recommendedMaxMinMemory.getMax();
224214
}
225215

226-
public static long getXenServerStaticMin(String stdType, boolean bootFromCD) {
227-
MemoryValues recommendedMaxMinMemory = XenServerGuestOsMemoryMap.get(stdType);
216+
public static long getXenServerStaticMin(final String stdType, final boolean bootFromCD) {
217+
final MemoryValues recommendedMaxMinMemory = XenServerGuestOsMemoryMap.get(stdType);
228218
if (recommendedMaxMinMemory == null) {
229219
return 0l;
230220
}
231221
return recommendedMaxMinMemory.getMin();
232222
}
233223

234-
public static String getProductVersion(Host.Record record) {
224+
public static String getProductVersion(final Host.Record record) {
235225
String prodVersion = record.softwareVersion.get("product_version");
236226
if (prodVersion == null) {
237227
prodVersion = record.softwareVersion.get("platform_version").trim();
238228
} else {
239229
prodVersion = prodVersion.trim();
240-
String[] items = prodVersion.split("\\.");
230+
final String[] items = prodVersion.split("\\.");
241231
if (Integer.parseInt(items[0]) > 6) {
242232
prodVersion = "6.5.0";
243233
} else if (Integer.parseInt(items[0]) == 6 && Integer.parseInt(items[1]) >= 4) {

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java

Lines changed: 220 additions & 252 deletions
Large diffs are not rendered by default.

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpOssResource.java

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@
2727
import org.apache.log4j.Logger;
2828
import org.apache.xmlrpc.XmlRpcException;
2929

30-
import com.xensource.xenapi.Connection;
31-
import com.xensource.xenapi.Host;
32-
import com.xensource.xenapi.SR;
33-
import com.xensource.xenapi.Types;
34-
import com.xensource.xenapi.Types.XenAPIException;
35-
import com.xensource.xenapi.VBD;
36-
import com.xensource.xenapi.VDI;
37-
import com.xensource.xenapi.VM;
38-
3930
import com.cloud.agent.api.Answer;
4031
import com.cloud.agent.api.Command;
4132
import com.cloud.agent.api.NetworkUsageAnswer;
@@ -49,6 +40,14 @@
4940
import com.cloud.storage.Storage;
5041
import com.cloud.utils.exception.CloudRuntimeException;
5142
import com.cloud.utils.script.Script;
43+
import com.xensource.xenapi.Connection;
44+
import com.xensource.xenapi.Host;
45+
import com.xensource.xenapi.SR;
46+
import com.xensource.xenapi.Types;
47+
import com.xensource.xenapi.Types.XenAPIException;
48+
import com.xensource.xenapi.VBD;
49+
import com.xensource.xenapi.VDI;
50+
import com.xensource.xenapi.VM;
5251

5352
@Local(value = ServerResource.class)
5453
public class XcpOssResource extends CitrixResourceBase {
@@ -57,63 +56,63 @@ public class XcpOssResource extends CitrixResourceBase {
5756

5857
@Override
5958
protected List<File> getPatchFiles() {
60-
List<File> files = new ArrayList<File>();
61-
String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch";
62-
String patchfilePath = Script.findScript("", patch);
59+
final List<File> files = new ArrayList<File>();
60+
final String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch";
61+
final String patchfilePath = Script.findScript("", patch);
6362
if (patchfilePath == null) {
6463
throw new CloudRuntimeException("Unable to find patch file " + patch);
6564
}
66-
File file = new File(patchfilePath);
65+
final File file = new File(patchfilePath);
6766
files.add(file);
6867
return files;
6968
}
7069

7170
@Override
72-
protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
71+
protected void fillHostInfo(final Connection conn, final StartupRoutingCommand cmd) {
7372
super.fillHostInfo(conn, cmd);
7473
cmd.setCaps(cmd.getCapabilities() + " , hvm");
7574
}
7675

7776
@Override
78-
protected boolean launchHeartBeat(Connection conn) {
77+
protected boolean launchHeartBeat(final Connection conn) {
7978
return true;
8079
}
8180

8281
@Override
83-
protected StartupStorageCommand initializeLocalSR(Connection conn) {
84-
SR extsr = getLocalEXTSR(conn);
82+
protected StartupStorageCommand initializeLocalSR(final Connection conn) {
83+
final SR extsr = getLocalEXTSR(conn);
8584
if (extsr != null) {
8685
try {
87-
String extuuid = extsr.getUuid(conn);
88-
_host.localSRuuid = extuuid;
89-
long cap = extsr.getPhysicalSize(conn);
86+
final String extuuid = extsr.getUuid(conn);
87+
_host.setLocalSRuuid(extuuid);
88+
final long cap = extsr.getPhysicalSize(conn);
9089
if (cap > 0) {
91-
long avail = cap - extsr.getPhysicalUtilisation(conn);
92-
String name = "Cloud Stack Local EXT Storage Pool for " + _host.uuid;
90+
final long avail = cap - extsr.getPhysicalUtilisation(conn);
91+
final String name = "Cloud Stack Local EXT Storage Pool for " + _host.getUuid();
9392
extsr.setNameDescription(conn, name);
94-
Host host = Host.getByUuid(conn, _host.uuid);
95-
String address = host.getAddress(conn);
96-
StoragePoolInfo pInfo = new StoragePoolInfo(extsr.getNameLabel(conn), address, SRType.EXT.toString(), SRType.EXT.toString(), Storage.StoragePoolType.EXT, cap, avail);
97-
StartupStorageCommand cmd = new StartupStorageCommand();
93+
final Host host = Host.getByUuid(conn, _host.getUuid());
94+
final String address = host.getAddress(conn);
95+
final StoragePoolInfo pInfo = new StoragePoolInfo(extsr.getNameLabel(conn), address, SRType.EXT.toString(), SRType.EXT.toString(), Storage.StoragePoolType.EXT, cap, avail);
96+
final StartupStorageCommand cmd = new StartupStorageCommand();
9897
cmd.setPoolInfo(pInfo);
99-
cmd.setGuid(_host.uuid);
98+
cmd.setGuid(_host.getUuid());
10099
cmd.setDataCenter(Long.toString(_dcId));
101100
cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
102101
return cmd;
103102
}
104-
} catch (XenAPIException e) {
105-
String msg = "build local EXT info err in host:" + _host.uuid + e.toString();
103+
} catch (final XenAPIException e) {
104+
final String msg = "build local EXT info err in host:" + _host.getUuid() + e.toString();
106105
s_logger.warn(msg);
107-
} catch (XmlRpcException e) {
108-
String msg = "build local EXT info err in host:" + _host.uuid + e.getMessage();
106+
} catch (final XmlRpcException e) {
107+
final String msg = "build local EXT info err in host:" + _host.getUuid() + e.getMessage();
109108
s_logger.warn(msg);
110109
}
111110
}
112111
return null;
113112
}
114113

115114
@Override
116-
protected String getGuestOsType(String stdType, String platformEmulator, boolean bootFromCD) {
115+
protected String getGuestOsType(final String stdType, final String platformEmulator, final boolean bootFromCD) {
117116
if (stdType.equalsIgnoreCase("Debian GNU/Linux 6(64-bit)")) {
118117
return "Debian Squeeze 6.0 (64-bit)";
119118
} else if (stdType.equalsIgnoreCase("CentOS 5.6 (64-bit)")) {
@@ -124,54 +123,54 @@ protected String getGuestOsType(String stdType, String platformEmulator, boolean
124123
}
125124

126125
@Override
127-
protected synchronized VBD createPatchVbd(Connection conn, String vmName, VM vm) throws XmlRpcException, XenAPIException {
128-
if (_host.localSRuuid != null) {
126+
protected synchronized VBD createPatchVbd(final Connection conn, final String vmName, final VM vm) throws XmlRpcException, XenAPIException {
127+
if (_host.getLocalSRuuid() != null) {
129128
//create an iso vdi on it
130-
String result = callHostPlugin(conn, "vmops", "createISOVHD", "uuid", _host.localSRuuid);
129+
final String result = callHostPlugin(conn, "vmops", "createISOVHD", "uuid", _host.getLocalSRuuid());
131130
if (result == null || result.equalsIgnoreCase("Failed")) {
132131
throw new CloudRuntimeException("can not create systemvm vdi");
133132
}
134133

135-
Set<VDI> vdis = VDI.getByNameLabel(conn, "systemvm-vdi");
134+
final Set<VDI> vdis = VDI.getByNameLabel(conn, "systemvm-vdi");
136135
if (vdis.size() != 1) {
137136
throw new CloudRuntimeException("can not find systemvmiso");
138137
}
139-
VDI systemvmVDI = vdis.iterator().next();
138+
final VDI systemvmVDI = vdis.iterator().next();
140139

141-
VBD.Record cdromVBDR = new VBD.Record();
140+
final VBD.Record cdromVBDR = new VBD.Record();
142141
cdromVBDR.VM = vm;
143142
cdromVBDR.empty = false;
144143
cdromVBDR.bootable = false;
145144
cdromVBDR.userdevice = "3";
146145
cdromVBDR.mode = Types.VbdMode.RO;
147146
cdromVBDR.type = Types.VbdType.DISK;
148147
cdromVBDR.VDI = systemvmVDI;
149-
VBD cdromVBD = VBD.create(conn, cdromVBDR);
148+
final VBD cdromVBD = VBD.create(conn, cdromVBDR);
150149
return cdromVBD;
151150
} else {
152151
throw new CloudRuntimeException("can not find local sr");
153152
}
154153
}
155154

156-
protected NetworkUsageAnswer execute(NetworkUsageCommand cmd) {
155+
protected NetworkUsageAnswer execute(final NetworkUsageCommand cmd) {
157156
try {
158-
Connection conn = getConnection();
157+
final Connection conn = getConnection();
159158
if (cmd.getOption() != null && cmd.getOption().equals("create")) {
160-
String result = networkUsage(conn, cmd.getPrivateIP(), "create", null);
161-
NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
159+
final String result = networkUsage(conn, cmd.getPrivateIP(), "create", null);
160+
final NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
162161
return answer;
163162
}
164-
long[] stats = getNetworkStats(conn, cmd.getPrivateIP());
165-
NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
163+
final long[] stats = getNetworkStats(conn, cmd.getPrivateIP());
164+
final NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
166165
return answer;
167-
} catch (Exception ex) {
166+
} catch (final Exception ex) {
168167
s_logger.warn("Failed to get network usage stats due to ", ex);
169168
return new NetworkUsageAnswer(cmd, ex);
170169
}
171170
}
172171

173172
@Override
174-
public Answer executeRequest(Command cmd) {
173+
public Answer executeRequest(final Command cmd) {
175174
if (cmd instanceof NetworkUsageCommand) {
176175
return execute((NetworkUsageCommand) cmd);
177176
} else {
@@ -180,18 +179,18 @@ public Answer executeRequest(Command cmd) {
180179
}
181180

182181
@Override
183-
public StopAnswer execute(StopCommand cmd) {
184-
StopAnswer answer = super.execute(cmd);
185-
String vmName = cmd.getVmName();
182+
public StopAnswer execute(final StopCommand cmd) {
183+
final StopAnswer answer = super.execute(cmd);
184+
final String vmName = cmd.getVmName();
186185
if (vmName.startsWith("v-")) {
187-
Connection conn = getConnection();
186+
final Connection conn = getConnection();
188187
callHostPlugin(conn, "vmops", "setDNATRule", "add", "false");
189188
}
190189
return answer;
191190
}
192191

193192
@Override
194-
protected void setMemory(Connection conn, VM vm, long minMemsize, long maxMemsize) throws XmlRpcException, XenAPIException {
193+
protected void setMemory(final Connection conn, final VM vm, final long minMemsize, final long maxMemsize) throws XmlRpcException, XenAPIException {
195194
vm.setMemoryLimits(conn, mem_32m, maxMemsize, minMemsize, maxMemsize);
196195
}
197196
}

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected void disableVlanNetwork(final Connection conn, final Network network)
8989
final String bridge = networkr.bridge.trim();
9090
for (final PIF pif : networkr.PIFs) {
9191
final PIF.Record pifr = pif.getRecord(conn);
92-
if (!pifr.host.getUuid(conn).equalsIgnoreCase(_host.uuid)) {
92+
if (!pifr.host.getUuid(conn).equalsIgnoreCase(_host.getUuid())) {
9393
continue;
9494
}
9595

@@ -102,13 +102,13 @@ protected void disableVlanNetwork(final Connection conn, final Network network)
102102
}
103103
try {
104104
vlan.destroy(conn);
105-
final Host host = Host.getByUuid(conn, _host.uuid);
105+
final Host host = Host.getByUuid(conn, _host.getUuid());
106106
host.forgetDataSourceArchives(conn, "pif_" + bridge + "_tx");
107107
host.forgetDataSourceArchives(conn, "pif_" + bridge + "_rx");
108108
host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_tx");
109109
host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_rx");
110110
} catch (final XenAPIException e) {
111-
s_logger.trace("Catch " + e.getClass().getName() + ": failed to destory VLAN " + device + " on host " + _host.uuid + " due to " + e.toString());
111+
s_logger.trace("Catch " + e.getClass().getName() + ": failed to destory VLAN " + device + " on host " + _host.getUuid() + " due to " + e.toString());
112112
}
113113
}
114114
return;
@@ -210,7 +210,7 @@ protected NetworkUsageAnswer execute(final NetworkUsageCommand cmd) {
210210
}
211211

212212
protected Boolean check_heartbeat(final String hostuuid) {
213-
final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.ip, 22);
213+
final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22);
214214
try {
215215
sshConnection.connect(null, 60000, 60000);
216216
if (!sshConnection.authenticateWithPassword(_username, _password.peek())) {

0 commit comments

Comments
 (0)