Skip to content

Commit 7ada9b2

Browse files
author
Anthony Xu
committed
clean up xenserver resource code
1 parent 1e4a253 commit 7ada9b2

9 files changed

Lines changed: 45 additions & 117 deletions

File tree

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
148148
EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId()));
149149
host = hostDao.findById(ep.getId());
150150
hostDao.loadDetails(host);
151-
String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XSHasHotFix62ESP1004);
152-
if (snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase("true")) {
151+
String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XS620HotFix);
152+
if (snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)) {
153153
return new Pair<Boolean, Long>(Boolean.TRUE, new Long(ep.getId()));
154154
}
155155
}

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public void processConnect(com.cloud.host.Host agent, StartupCommand cmd, boolea
588588
} else if (prodBrand.equals("XenServer") && prodVersion.equals("6.1.0")) {
589589
resource = XenServer610Resource.class.getName();
590590
} else if (prodBrand.equals("XenServer") && prodVersion.equals("6.2.0")) {
591-
String hotfix = details.get("XS620HotFix");
591+
String hotfix = details.get(XenserverConfigs.XS620HotFix);
592592
if (hotfix != null && hotfix.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)) {
593593
resource = Xenserver625Resource.class.getName();
594594
} else if (hotfix != null && hotfix.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1)){

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
package com.cloud.hypervisor.xen.resource;
1818

19-
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
2019
import com.cloud.agent.IAgentControl;
2120
import com.cloud.agent.api.Answer;
2221
import com.cloud.agent.api.AttachIsoCommand;
@@ -183,8 +182,6 @@
183182
import com.xensource.xenapi.Host;
184183
import com.xensource.xenapi.HostCpu;
185184
import com.xensource.xenapi.HostMetrics;
186-
import com.xensource.xenapi.HostPatch;
187-
import com.xensource.xenapi.PoolPatch;
188185
import com.xensource.xenapi.Network;
189186
import com.xensource.xenapi.PBD;
190187
import com.xensource.xenapi.PIF;
@@ -5533,24 +5530,6 @@ public Connection getConnection() {
55335530
}
55345531

55355532

5536-
protected boolean hostHasHotFix(Connection conn, String hotFixUuid) {
5537-
try {
5538-
Host host = Host.getByUuid(conn, _host.uuid);
5539-
Host.Record re = host.getRecord(conn);
5540-
Set<HostPatch> patches = re.patches;
5541-
PoolPatch poolPatch = PoolPatch.getByUuid(conn, hotFixUuid);
5542-
for(HostPatch patch : patches) {
5543-
PoolPatch pp = patch.getPoolPatch(conn);
5544-
if (pp.equals(poolPatch) && patch.getApplied(conn)) {
5545-
return true;
5546-
}
5547-
}
5548-
} catch (Exception e) {
5549-
s_logger.debug("can't get patches information for hotFix: " + hotFixUuid);
5550-
}
5551-
return false;
5552-
}
5553-
55545533
protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
55555534
final StringBuilder caps = new StringBuilder();
55565535
try {
@@ -5569,9 +5548,6 @@ protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
55695548
}
55705549
details.put("product_brand", productBrand);
55715550
details.put("product_version", _host.productVersion);
5572-
Boolean hotFix62ESP1004 = hostHasHotFix(conn, XenserverConfigs.XSHotFix62ESP1004);
5573-
details.put(XenserverConfigs.XSHasHotFix62ESP1004, hotFix62ESP1004.toString());
5574-
55755551
if (hr.softwareVersion.get("product_version_text_short") != null) {
55765552
details.put("product_version_text_short", hr.softwareVersion.get("product_version_text_short"));
55775553
cmd.setHypervisorVersion(hr.softwareVersion.get("product_version_text_short"));

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer602Resource.java‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,9 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717
package com.cloud.hypervisor.xen.resource;
18-
19-
import java.io.File;
20-
import java.util.ArrayList;
21-
import java.util.List;
22-
2318
import javax.ejb.Local;
24-
2519
import org.apache.log4j.Logger;
26-
2720
import com.cloud.resource.ServerResource;
28-
import com.cloud.utils.exception.CloudRuntimeException;
29-
import com.cloud.utils.script.Script;
3021

3122
@Local(value = ServerResource.class)
3223
public class XenServer602Resource extends XenServer56FP1Resource {
@@ -41,19 +32,6 @@ protected String getGuestOsType(String stdType, boolean bootFromCD) {
4132
return CitrixHelper.getXenServer602GuestOsType(stdType, bootFromCD);
4233
}
4334

44-
@Override
45-
protected List<File> getPatchFiles() {
46-
List<File> files = new ArrayList<File>();
47-
String patch = "scripts/vm/hypervisor/xenserver/xenserver60/patch";
48-
String patchfilePath = Script.findScript("", patch);
49-
if (patchfilePath == null) {
50-
throw new CloudRuntimeException("Unable to find patch file " + patch);
51-
}
52-
File file = new File(patchfilePath);
53-
files.add(file);
54-
return files;
55-
}
56-
5735
@Override
5836
public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
5937
long recommendedValue = CitrixHelper.getXenServer602StaticMax(os, b);

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
package com.cloud.hypervisor.xen.resource;
1818

19-
import java.io.File;
2019
import java.util.ArrayList;
2120
import java.util.HashMap;
2221
import java.util.List;
@@ -62,7 +61,6 @@
6261
import com.cloud.network.Networks.TrafficType;
6362
import com.cloud.resource.ServerResource;
6463
import com.cloud.utils.exception.CloudRuntimeException;
65-
import com.cloud.utils.script.Script;
6664
import com.cloud.vm.VirtualMachine.State;
6765

6866
@Local(value = ServerResource.class)
@@ -78,19 +76,6 @@ protected String getGuestOsType(String stdType, boolean bootFromCD) {
7876
return CitrixHelper.getXenServer610GuestOsType(stdType, bootFromCD);
7977
}
8078

81-
@Override
82-
protected List<File> getPatchFiles() {
83-
List<File> files = new ArrayList<File>();
84-
String patch = "scripts/vm/hypervisor/xenserver/xenserver60/patch";
85-
String patchfilePath = Script.findScript("", patch);
86-
if (patchfilePath == null) {
87-
throw new CloudRuntimeException("Unable to find patch file " + patch);
88-
}
89-
File file = new File(patchfilePath);
90-
files.add(file);
91-
return files;
92-
}
93-
9479
@Override
9580
public Answer executeRequest(Command cmd) {
9681
if (cmd instanceof MigrateWithStorageCommand) {

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620Resource.java‎

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717
package com.cloud.hypervisor.xen.resource;
18-
19-
import java.io.File;
20-
import java.util.ArrayList;
21-
import java.util.List;
18+
import com.xensource.xenapi.Connection;
19+
import com.xensource.xenapi.Host;
20+
import com.xensource.xenapi.HostPatch;
21+
import com.xensource.xenapi.PoolPatch;
22+
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
23+
import java.util.Map;
24+
import java.util.Set;
2225

2326
import javax.ejb.Local;
2427

2528
import org.apache.log4j.Logger;
2629

30+
import com.cloud.agent.api.StartupRoutingCommand;
2731
import com.cloud.resource.ServerResource;
28-
import com.cloud.utils.exception.CloudRuntimeException;
29-
import com.cloud.utils.script.Script;
3032

3133
@Local(value = ServerResource.class)
3234
public class XenServer620Resource extends XenServer610Resource {
@@ -41,19 +43,6 @@ protected String getGuestOsType(String stdType, boolean bootFromCD) {
4143
return CitrixHelper.getXenServer620GuestOsType(stdType, bootFromCD);
4244
}
4345

44-
@Override
45-
protected List<File> getPatchFiles() {
46-
List<File> files = new ArrayList<File>();
47-
String patch = "scripts/vm/hypervisor/xenserver/xenserver60/patch";
48-
String patchfilePath = Script.findScript("", patch);
49-
if (patchfilePath == null) {
50-
throw new CloudRuntimeException("Unable to find patch file " + patch);
51-
}
52-
File file = new File(patchfilePath);
53-
files.add(file);
54-
return files;
55-
}
56-
5746
@Override
5847
public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) {
5948
long recommendedValue = CitrixHelper.getXenServer620StaticMax(os, b);
@@ -83,4 +72,37 @@ public long getStaticMin(String os, boolean b, long dynamicMinRam, long dynamicM
8372
}
8473
return dynamicMinRam;
8574
}
75+
76+
protected boolean hostHasHotFix(Connection conn, String hotFixUuid) {
77+
try {
78+
Host host = Host.getByUuid(conn, _host.uuid);
79+
Host.Record re = host.getRecord(conn);
80+
Set<HostPatch> patches = re.patches;
81+
PoolPatch poolPatch = PoolPatch.getByUuid(conn, hotFixUuid);
82+
for(HostPatch patch : patches) {
83+
PoolPatch pp = patch.getPoolPatch(conn);
84+
if (pp.equals(poolPatch) && patch.getApplied(conn)) {
85+
return true;
86+
}
87+
}
88+
} catch (Exception e) {
89+
s_logger.debug("can't get patches information for hotFix: " + hotFixUuid);
90+
}
91+
return false;
92+
}
93+
94+
protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
95+
super.fillHostInfo(conn, cmd);
96+
Map<String, String> details = cmd.getHostDetails();
97+
Boolean hotFix62ESP1004 = hostHasHotFix(conn, XenserverConfigs.XSHotFix62ESP1004);
98+
if( hotFix62ESP1004 != null && hotFix62ESP1004 ) {
99+
details.put(XenserverConfigs.XS620HotFix , XenserverConfigs.XSHotFix62ESP1004);
100+
} else {
101+
Boolean hotFix62ESP1 = hostHasHotFix(conn, XenserverConfigs.XSHotFix62ESP1);
102+
if( hotFix62ESP1 != null && hotFix62ESP1 ) {
103+
details.put(XenserverConfigs.XS620HotFix , XenserverConfigs.XSHotFix62ESP1);
104+
}
105+
}
106+
cmd.setHostDetails(details);
107+
}
86108
}

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620SP1Resource.java‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@
1818
*/
1919
package com.cloud.hypervisor.xen.resource;
2020

21-
import java.io.File;
22-
import java.util.ArrayList;
2321
import java.util.HashMap;
2422
import java.util.Iterator;
25-
import java.util.List;
2623
import java.util.Map;
2724
import java.util.Set;
2825

2926
import javax.ejb.Local;
3027

31-
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
3228
import org.apache.log4j.Logger;
3329
import org.apache.xmlrpc.XmlRpcException;
3430

@@ -40,8 +36,6 @@
4036
import com.cloud.agent.api.StartupRoutingCommand;
4137
import com.cloud.agent.api.to.GPUDeviceTO;
4238
import com.cloud.resource.ServerResource;
43-
import com.cloud.utils.exception.CloudRuntimeException;
44-
import com.cloud.utils.script.Script;
4539
import com.xensource.xenapi.Connection;
4640
import com.xensource.xenapi.GPUGroup;
4741
import com.xensource.xenapi.Host;
@@ -84,9 +78,6 @@ protected GetGPUStatsAnswer execute(GetGPUStatsCommand cmd) {
8478
@Override
8579
protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
8680
super.fillHostInfo(conn, cmd);
87-
Map<String, String> details = cmd.getHostDetails();
88-
details.put("XS620HotFix", XenserverConfigs.XSHotFix62ESP1);
89-
cmd.setHostDetails(details);
9081
try {
9182
HashMap<String, HashMap<String, Long>> groupDetails = getGPUGroupDetails(conn);
9283
cmd.setGpuGroupDetails(groupDetails);
@@ -163,19 +154,6 @@ protected String getGuestOsType(String stdType, boolean bootFromCD) {
163154
return CitrixHelper.getXenServer620SP1GuestOsType(stdType, bootFromCD);
164155
}
165156

166-
@Override
167-
protected List<File> getPatchFiles() {
168-
List<File> files = new ArrayList<File>();
169-
String patch = "scripts/vm/hypervisor/xenserver/xenserver60/patch";
170-
String patchfilePath = Script.findScript("", patch);
171-
if (patchfilePath == null) {
172-
throw new CloudRuntimeException("Unable to find patch file " + patch);
173-
}
174-
File file = new File(patchfilePath);
175-
files.add(file);
176-
return files;
177-
}
178-
179157
@Override
180158
public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam){
181159
long recommendedValue = CitrixHelper.getXenServer620SP1StaticMax(os, b);

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/Xenserver625Resource.java‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.File;
2222
import java.util.ArrayList;
2323
import java.util.List;
24-
import java.util.Map;
2524

2625
import javax.ejb.Local;
2726

@@ -33,9 +32,7 @@
3332
import com.xensource.xenapi.VM;
3433

3534
import org.apache.cloudstack.hypervisor.xenserver.XenServerResourceNewBase;
36-
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
3735

38-
import com.cloud.agent.api.StartupRoutingCommand;
3936
import com.cloud.resource.ServerResource;
4037
import com.cloud.storage.resource.StorageSubsystemCommandHandler;
4138
import com.cloud.storage.resource.StorageSubsystemCommandHandlerBase;
@@ -69,14 +66,6 @@ protected List<File> getPatchFiles() {
6966
return files;
7067
}
7168

72-
@Override
73-
protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) {
74-
super.fillHostInfo(conn, cmd);
75-
Map<String, String> details = cmd.getHostDetails();
76-
details.put("XS620HotFix", XenserverConfigs.XSHotFix62ESP1004);
77-
cmd.setHostDetails(details);
78-
}
79-
8069
@Override
8170
public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam){
8271
long recommendedValue = CitrixHelper.getXenServer625StaticMax(os, b);

‎plugins/hypervisors/xen/src/org/apache/cloudstack/hypervisor/xenserver/XenserverConfigs.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package org.apache.cloudstack.hypervisor.xenserver;
2020

2121
public final class XenserverConfigs {
22-
public static final String XSHasHotFix62ESP1004 = "xs_has_hot_fix_esp1004";
22+
public static final String XS620HotFix = "xs620hotfix";
2323
public static final String XSHotFix62ESP1 = "0850b186-4d47-11e3-a720-001b2151a503";
2424
public static final String XSHotFix62ESP1004 = "996dd2e7-ad95-49cc-a0be-2c9adc4dfb0b";
2525
}

0 commit comments

Comments
 (0)