Skip to content

Commit 50c4836

Browse files
rafaelweingartnerwilderrodrigues
authored andcommitted
Cleaned class “com.cloud.hypervisor.xenserver.resource.XcpOssResource” that seemed to be forgotten during the evolution of the ACS. It was removed a few methods that were already coded properly in its parent class “com.cloud.hypervisor.xenserver.resource.CitrixResourceBase”. It was also removed some methods that seemed to cause weird behaviors. The methods removed/fixed are detailed as follows: • com.cloud.hypervisor.xenserver.resource.XcpOssResource.fillHostInfo(Connection, StartupRoutingCommand) – it was removed, because it always added the string “, hvm” to the host capabilities. Therefore, if one uses XCP hypervisor it could cause a lot of trouble when deploying HVM virtual machines in an environment that has PV and HVM clusters. The method is already properly coded in parent class. • com.cloud.hypervisor.xenserver.resource.XcpOssResource.launchHeartBeat(Connection) – It was removed. It was not performing anything and always returns a true value. The method of parent class is properly coded and works for XCP environments. The heartbeat plugin exists in XCP environment. • com.cloud.hypervisor.xenserver.resource.XcpOssResource.initializeLocalSR(Connection) – it was removed. The method of the parent class works properly for XCP environments. • com.cloud.hypervisor.xenserver.resource.XcpOssResource.createPatchVbd(Connection, String, VM) – It was removed. This method causes a bug in XCP environments, because of its half-implementation, it was not possible to migrate system VMs. The parent class implementation works properly for XCP. • com.cloud.hypervisor.xenserver.resource.XcpOssResource.execute(NetworkUsageCommand) – removed, hence it was already coded into parent class and its respective wrappers (“com.cloud.hypervisor.xenserver.resource.wrapper.xcp.XcpServerNetworkUsageCommandWrapper”). BTW: I noticed that the class XcpServerNetworkUsageCommandWrapper and XenServer56NetworkUsageCommandWrapper are almost the same, with the exception that XenServer56NetworkUsageCommandWrapper deals with VPC. I believe that those wrappers could be converted into one, and moved to parent. I am not doing that here because I do not have a XCP environment with advanced networking to test it. • com.cloud.hypervisor.xenserver.resource.XcpOssResource.executeRequest(Command) – removed, hence it is not needed anymor. • com.cloud.hypervisor.xenserver.resource.XcpOssResource.execute(StopCommand) – I did not understand that method. It seemed weird and its removal did not change any behavior of the environment I tested it with.
Signed-off-by: wilderrodrigues <wrodrigues@schubergphilis.com>
1 parent 97ed8c3 commit 50c4836

File tree

1 file changed

+34
-160
lines changed

1 file changed

+34
-160
lines changed

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

Lines changed: 34 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -20,179 +20,53 @@
2020
import java.io.File;
2121
import java.util.ArrayList;
2222
import java.util.List;
23-
import java.util.Set;
2423

2524
import javax.ejb.Local;
2625

27-
import org.apache.log4j.Logger;
2826
import org.apache.xmlrpc.XmlRpcException;
2927

30-
import com.cloud.agent.api.Answer;
31-
import com.cloud.agent.api.Command;
32-
import com.cloud.agent.api.NetworkUsageAnswer;
33-
import com.cloud.agent.api.NetworkUsageCommand;
34-
import com.cloud.agent.api.StartupRoutingCommand;
35-
import com.cloud.agent.api.StartupStorageCommand;
36-
import com.cloud.agent.api.StopAnswer;
37-
import com.cloud.agent.api.StopCommand;
38-
import com.cloud.agent.api.StoragePoolInfo;
3928
import com.cloud.resource.ServerResource;
40-
import com.cloud.storage.Storage;
4129
import com.cloud.utils.exception.CloudRuntimeException;
4230
import com.cloud.utils.script.Script;
4331
import com.xensource.xenapi.Connection;
44-
import com.xensource.xenapi.Host;
45-
import com.xensource.xenapi.SR;
46-
import com.xensource.xenapi.Types;
4732
import com.xensource.xenapi.Types.XenAPIException;
48-
import com.xensource.xenapi.VBD;
49-
import com.xensource.xenapi.VDI;
5033
import com.xensource.xenapi.VM;
5134

5235
@Local(value = ServerResource.class)
5336
public class XcpOssResource extends CitrixResourceBase {
5437

55-
private final static Logger s_logger = Logger.getLogger(XcpOssResource.class);
56-
57-
private static final long mem_32m = 33554432L;
58-
59-
@Override
60-
protected List<File> getPatchFiles() {
61-
final List<File> files = new ArrayList<File>();
62-
final String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch";
63-
final String patchfilePath = Script.findScript("", patch);
64-
if (patchfilePath == null) {
65-
throw new CloudRuntimeException("Unable to find patch file " + patch);
66-
}
67-
final File file = new File(patchfilePath);
68-
files.add(file);
69-
return files;
70-
}
71-
72-
@Override
73-
protected void fillHostInfo(final Connection conn, final StartupRoutingCommand cmd) {
74-
super.fillHostInfo(conn, cmd);
75-
cmd.setCaps(cmd.getCapabilities() + " , hvm");
76-
}
77-
78-
@Override
79-
public boolean launchHeartBeat(final Connection conn) {
80-
return true;
81-
}
82-
83-
@Override
84-
protected StartupStorageCommand initializeLocalSR(final Connection conn) {
85-
final SR extsr = getLocalEXTSR(conn);
86-
if (extsr != null) {
87-
try {
88-
final String extuuid = extsr.getUuid(conn);
89-
_host.setLocalSRuuid(extuuid);
90-
final long cap = extsr.getPhysicalSize(conn);
91-
if (cap > 0) {
92-
final long avail = cap - extsr.getPhysicalUtilisation(conn);
93-
final String name = "Cloud Stack Local EXT Storage Pool for " + _host.getUuid();
94-
extsr.setNameDescription(conn, name);
95-
final Host host = Host.getByUuid(conn, _host.getUuid());
96-
final String address = host.getAddress(conn);
97-
final StoragePoolInfo pInfo = new StoragePoolInfo(extsr.getNameLabel(conn), address, SRType.EXT.toString(), SRType.EXT.toString(), Storage.StoragePoolType.EXT, cap, avail);
98-
final StartupStorageCommand cmd = new StartupStorageCommand();
99-
cmd.setPoolInfo(pInfo);
100-
cmd.setGuid(_host.getUuid());
101-
cmd.setDataCenter(Long.toString(_dcId));
102-
cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
103-
return cmd;
104-
}
105-
} catch (final XenAPIException e) {
106-
final String msg = "build local EXT info err in host:" + _host.getUuid() + e.toString();
107-
s_logger.warn(msg);
108-
} catch (final XmlRpcException e) {
109-
final String msg = "build local EXT info err in host:" + _host.getUuid() + e.getMessage();
110-
s_logger.warn(msg);
111-
}
112-
}
113-
return null;
114-
}
115-
116-
@Override
117-
protected String getGuestOsType(final String stdType, final String platformEmulator, final boolean bootFromCD) {
118-
if (stdType.equalsIgnoreCase("Debian GNU/Linux 6(64-bit)")) {
119-
return "Debian Squeeze 6.0 (64-bit)";
120-
} else if (stdType.equalsIgnoreCase("CentOS 5.6 (64-bit)")) {
121-
return "CentOS 5 (64-bit)";
122-
} else {
123-
return super.getGuestOsType(stdType, platformEmulator, bootFromCD);
124-
}
125-
}
126-
127-
@Override
128-
public synchronized VBD createPatchVbd(final Connection conn, final String vmName, final VM vm) throws XmlRpcException, XenAPIException {
129-
if (_host.getLocalSRuuid() != null) {
130-
//create an iso vdi on it
131-
final String result = callHostPlugin(conn, "vmops", "createISOVHD", "uuid", _host.getLocalSRuuid());
132-
if (result == null || result.equalsIgnoreCase("Failed")) {
133-
throw new CloudRuntimeException("can not create systemvm vdi");
134-
}
135-
136-
final Set<VDI> vdis = VDI.getByNameLabel(conn, "systemvm-vdi");
137-
if (vdis.size() != 1) {
138-
throw new CloudRuntimeException("can not find systemvmiso");
139-
}
140-
final VDI systemvmVDI = vdis.iterator().next();
141-
142-
final VBD.Record cdromVBDR = new VBD.Record();
143-
cdromVBDR.VM = vm;
144-
cdromVBDR.empty = false;
145-
cdromVBDR.bootable = false;
146-
cdromVBDR.userdevice = "3";
147-
cdromVBDR.mode = Types.VbdMode.RO;
148-
cdromVBDR.type = Types.VbdType.DISK;
149-
cdromVBDR.VDI = systemvmVDI;
150-
final VBD cdromVBD = VBD.create(conn, cdromVBDR);
151-
return cdromVBD;
152-
} else {
153-
throw new CloudRuntimeException("can not find local sr");
154-
}
155-
}
156-
157-
protected NetworkUsageAnswer execute(final NetworkUsageCommand cmd) {
158-
try {
159-
final Connection conn = getConnection();
160-
if (cmd.getOption() != null && cmd.getOption().equals("create")) {
161-
final String result = networkUsage(conn, cmd.getPrivateIP(), "create", null);
162-
final NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
163-
return answer;
164-
}
165-
final long[] stats = getNetworkStats(conn, cmd.getPrivateIP());
166-
final NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, "", stats[0], stats[1]);
167-
return answer;
168-
} catch (final Exception ex) {
169-
s_logger.warn("Failed to get network usage stats due to ", ex);
170-
return new NetworkUsageAnswer(cmd, ex);
171-
}
172-
}
173-
174-
@Override
175-
public Answer executeRequest(final Command cmd) {
176-
if (cmd instanceof NetworkUsageCommand) {
177-
return execute((NetworkUsageCommand) cmd);
178-
} else {
179-
return super.executeRequest(cmd);
180-
}
181-
}
182-
183-
@Override
184-
public StopAnswer execute(final StopCommand cmd) {
185-
final StopAnswer answer = super.execute(cmd);
186-
final String vmName = cmd.getVmName();
187-
if (vmName.startsWith("v-")) {
188-
final Connection conn = getConnection();
189-
callHostPlugin(conn, "vmops", "setDNATRule", "add", "false");
190-
}
191-
return answer;
192-
}
193-
194-
@Override
195-
protected void setMemory(final Connection conn, final VM vm, final long minMemsize, final long maxMemsize) throws XmlRpcException, XenAPIException {
196-
vm.setMemoryLimits(conn, mem_32m, maxMemsize, minMemsize, maxMemsize);
197-
}
38+
private static final long mem_32m = 33554432L;
39+
40+
@Override
41+
protected List<File> getPatchFiles() {
42+
final List<File> files = new ArrayList<File>();
43+
final String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch";
44+
final String patchfilePath = Script.findScript("", patch);
45+
if (patchfilePath == null) {
46+
throw new CloudRuntimeException("Unable to find patch file "
47+
+ patch);
48+
}
49+
final File file = new File(patchfilePath);
50+
files.add(file);
51+
return files;
52+
}
53+
54+
@Override
55+
protected String getGuestOsType(final String stdType,
56+
final String platformEmulator, final boolean bootFromCD) {
57+
if (stdType.equalsIgnoreCase("Debian GNU/Linux 6(64-bit)")) {
58+
return "Debian Squeeze 6.0 (64-bit)";
59+
} else if (stdType.equalsIgnoreCase("CentOS 5.6 (64-bit)")) {
60+
return "CentOS 5 (64-bit)";
61+
} else {
62+
return super.getGuestOsType(stdType, platformEmulator, bootFromCD);
63+
}
64+
}
65+
66+
@Override
67+
protected void setMemory(final Connection conn, final VM vm,
68+
final long minMemsize, final long maxMemsize)
69+
throws XmlRpcException, XenAPIException {
70+
vm.setMemoryLimits(conn, mem_32m, maxMemsize, minMemsize, maxMemsize);
71+
}
19872
}

0 commit comments

Comments
 (0)