clean up xenserver resource code
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/15c14232 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/15c14232 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/15c14232 Branch: refs/heads/marvin Commit: 15c142326fdc5f0d4b66188ac0e54c7034152b14 Parents: b94a982 Author: Anthony Xu <[email protected]> Authored: Fri Apr 4 14:08:01 2014 -0700 Committer: Anthony Xu <[email protected]> Committed: Fri Apr 4 14:14:22 2014 -0700 ---------------------------------------------------------------------- .../src/com/cloud/hypervisor/XenServerGuru.java | 4 +- .../xen/discoverer/XcpServerDiscoverer.java | 2 +- .../xen/resource/CitrixResourceBase.java | 24 -------- .../xen/resource/XenServer602Resource.java | 22 ------- .../xen/resource/XenServer610Resource.java | 15 ----- .../xen/resource/XenServer620Resource.java | 60 +++++++++++++------- .../xen/resource/XenServer620SP1Resource.java | 22 ------- .../xen/resource/Xenserver625Resource.java | 11 ---- .../hypervisor/xenserver/XenserverConfigs.java | 2 +- 9 files changed, 45 insertions(+), 117 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15c14232/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java index 62a90a6..89e4ab5 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java @@ -148,8 +148,8 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId())); host = hostDao.findById(ep.getId()); hostDao.loadDetails(host); - String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XSHasHotFix62ESP1004); - if (snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase("true")) { + String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XS620HotFix); + if (snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)) { return new Pair<Boolean, Long>(Boolean.TRUE, new Long(ep.getId())); } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15c14232/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java index 2c49709..2cb6f77 100755 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java @@ -588,7 +588,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L } else if (prodBrand.equals("XenServer") && prodVersion.equals("6.1.0")) { resource = XenServer610Resource.class.getName(); } else if (prodBrand.equals("XenServer") && prodVersion.equals("6.2.0")) { - String hotfix = details.get("XS620HotFix"); + String hotfix = details.get(XenserverConfigs.XS620HotFix); if (hotfix != null && hotfix.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)) { resource = Xenserver625Resource.class.getName(); } else if (hotfix != null && hotfix.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1)){ http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15c14232/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index b509efe..0cdd335 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -16,7 +16,6 @@ // under the License. package com.cloud.hypervisor.xen.resource; -import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; import com.cloud.agent.api.AttachIsoCommand; @@ -183,8 +182,6 @@ import com.xensource.xenapi.Console; import com.xensource.xenapi.Host; import com.xensource.xenapi.HostCpu; import com.xensource.xenapi.HostMetrics; -import com.xensource.xenapi.HostPatch; -import com.xensource.xenapi.PoolPatch; import com.xensource.xenapi.Network; import com.xensource.xenapi.PBD; import com.xensource.xenapi.PIF; @@ -5533,24 +5530,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } - protected boolean hostHasHotFix(Connection conn, String hotFixUuid) { - try { - Host host = Host.getByUuid(conn, _host.uuid); - Host.Record re = host.getRecord(conn); - Set<HostPatch> patches = re.patches; - PoolPatch poolPatch = PoolPatch.getByUuid(conn, hotFixUuid); - for(HostPatch patch : patches) { - PoolPatch pp = patch.getPoolPatch(conn); - if (pp.equals(poolPatch) && patch.getApplied(conn)) { - return true; - } - } - } catch (Exception e) { - s_logger.debug("can't get patches information for hotFix: " + hotFixUuid); - } - return false; - } - protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) { final StringBuilder caps = new StringBuilder(); try { @@ -5569,9 +5548,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } details.put("product_brand", productBrand); details.put("product_version", _host.productVersion); - Boolean hotFix62ESP1004 = hostHasHotFix(conn, XenserverConfigs.XSHotFix62ESP1004); - details.put(XenserverConfigs.XSHasHotFix62ESP1004, hotFix62ESP1004.toString()); - if (hr.softwareVersion.get("product_version_text_short") != null) { details.put("product_version_text_short", hr.softwareVersion.get("product_version_text_short")); cmd.setHypervisorVersion(hr.softwareVersion.get("product_version_text_short")); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15c14232/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer602Resource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer602Resource.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer602Resource.java index a57c53b..edf54d5 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer602Resource.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer602Resource.java @@ -15,18 +15,9 @@ // specific language governing permissions and limitations // under the License. package com.cloud.hypervisor.xen.resource; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - import javax.ejb.Local; - import org.apache.log4j.Logger; - import com.cloud.resource.ServerResource; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.script.Script; @Local(value = ServerResource.class) public class XenServer602Resource extends XenServer56FP1Resource { @@ -42,19 +33,6 @@ public class XenServer602Resource extends XenServer56FP1Resource { } @Override - protected List<File> getPatchFiles() { - List<File> files = new ArrayList<File>(); - String patch = "scripts/vm/hypervisor/xenserver/xenserver60/patch"; - String patchfilePath = Script.findScript("", patch); - if (patchfilePath == null) { - throw new CloudRuntimeException("Unable to find patch file " + patch); - } - File file = new File(patchfilePath); - files.add(file); - return files; - } - - @Override public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) { long recommendedValue = CitrixHelper.getXenServer602StaticMax(os, b); if (recommendedValue == 0) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15c14232/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java index ffedaff..fa44d14 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java @@ -16,7 +16,6 @@ // under the License. package com.cloud.hypervisor.xen.resource; -import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -62,7 +61,6 @@ import com.cloud.agent.api.to.VolumeTO; import com.cloud.network.Networks.TrafficType; import com.cloud.resource.ServerResource; import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.script.Script; import com.cloud.vm.VirtualMachine.State; @Local(value = ServerResource.class) @@ -79,19 +77,6 @@ public class XenServer610Resource extends XenServer56FP1Resource { } @Override - protected List<File> getPatchFiles() { - List<File> files = new ArrayList<File>(); - String patch = "scripts/vm/hypervisor/xenserver/xenserver60/patch"; - String patchfilePath = Script.findScript("", patch); - if (patchfilePath == null) { - throw new CloudRuntimeException("Unable to find patch file " + patch); - } - File file = new File(patchfilePath); - files.add(file); - return files; - } - - @Override public Answer executeRequest(Command cmd) { if (cmd instanceof MigrateWithStorageCommand) { return execute((MigrateWithStorageCommand)cmd); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15c14232/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620Resource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620Resource.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620Resource.java index 4c0ca8d..f8b9919 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620Resource.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620Resource.java @@ -15,18 +15,20 @@ // specific language governing permissions and limitations // under the License. package com.cloud.hypervisor.xen.resource; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Host; +import com.xensource.xenapi.HostPatch; +import com.xensource.xenapi.PoolPatch; +import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs; +import java.util.Map; +import java.util.Set; import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.resource.ServerResource; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.script.Script; @Local(value = ServerResource.class) public class XenServer620Resource extends XenServer610Resource { @@ -42,19 +44,6 @@ public class XenServer620Resource extends XenServer610Resource { } @Override - protected List<File> getPatchFiles() { - List<File> files = new ArrayList<File>(); - String patch = "scripts/vm/hypervisor/xenserver/xenserver60/patch"; - String patchfilePath = Script.findScript("", patch); - if (patchfilePath == null) { - throw new CloudRuntimeException("Unable to find patch file " + patch); - } - File file = new File(patchfilePath); - files.add(file); - return files; - } - - @Override public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) { long recommendedValue = CitrixHelper.getXenServer620StaticMax(os, b); if (recommendedValue == 0) { @@ -83,4 +72,37 @@ public class XenServer620Resource extends XenServer610Resource { } return dynamicMinRam; } + + protected boolean hostHasHotFix(Connection conn, String hotFixUuid) { + try { + Host host = Host.getByUuid(conn, _host.uuid); + Host.Record re = host.getRecord(conn); + Set<HostPatch> patches = re.patches; + PoolPatch poolPatch = PoolPatch.getByUuid(conn, hotFixUuid); + for(HostPatch patch : patches) { + PoolPatch pp = patch.getPoolPatch(conn); + if (pp.equals(poolPatch) && patch.getApplied(conn)) { + return true; + } + } + } catch (Exception e) { + s_logger.debug("can't get patches information for hotFix: " + hotFixUuid); + } + return false; + } + + protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) { + super.fillHostInfo(conn, cmd); + Map<String, String> details = cmd.getHostDetails(); + Boolean hotFix62ESP1004 = hostHasHotFix(conn, XenserverConfigs.XSHotFix62ESP1004); + if( hotFix62ESP1004 != null && hotFix62ESP1004 ) { + details.put(XenserverConfigs.XS620HotFix , XenserverConfigs.XSHotFix62ESP1004); + } else { + Boolean hotFix62ESP1 = hostHasHotFix(conn, XenserverConfigs.XSHotFix62ESP1); + if( hotFix62ESP1 != null && hotFix62ESP1 ) { + details.put(XenserverConfigs.XS620HotFix , XenserverConfigs.XSHotFix62ESP1); + } + } + cmd.setHostDetails(details); + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15c14232/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620SP1Resource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620SP1Resource.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620SP1Resource.java index 82a4df0..877d0cb 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620SP1Resource.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer620SP1Resource.java @@ -18,17 +18,13 @@ */ package com.cloud.hypervisor.xen.resource; -import java.io.File; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Set; import javax.ejb.Local; -import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs; import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; @@ -40,8 +36,6 @@ import com.cloud.agent.api.StartCommand; import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.agent.api.to.GPUDeviceTO; import com.cloud.resource.ServerResource; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.script.Script; import com.xensource.xenapi.Connection; import com.xensource.xenapi.GPUGroup; import com.xensource.xenapi.Host; @@ -84,9 +78,6 @@ public class XenServer620SP1Resource extends XenServer620Resource { @Override protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) { super.fillHostInfo(conn, cmd); - Map<String, String> details = cmd.getHostDetails(); - details.put("XS620HotFix", XenserverConfigs.XSHotFix62ESP1); - cmd.setHostDetails(details); try { HashMap<String, HashMap<String, Long>> groupDetails = getGPUGroupDetails(conn); cmd.setGpuGroupDetails(groupDetails); @@ -164,19 +155,6 @@ public class XenServer620SP1Resource extends XenServer620Resource { } @Override - protected List<File> getPatchFiles() { - List<File> files = new ArrayList<File>(); - String patch = "scripts/vm/hypervisor/xenserver/xenserver60/patch"; - String patchfilePath = Script.findScript("", patch); - if (patchfilePath == null) { - throw new CloudRuntimeException("Unable to find patch file " + patch); - } - File file = new File(patchfilePath); - files.add(file); - return files; - } - - @Override public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam){ long recommendedValue = CitrixHelper.getXenServer620SP1StaticMax(os, b); if(recommendedValue == 0){ http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15c14232/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/Xenserver625Resource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/Xenserver625Resource.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/Xenserver625Resource.java index 388e3cf..b1442de 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/Xenserver625Resource.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/Xenserver625Resource.java @@ -21,7 +21,6 @@ package com.cloud.hypervisor.xen.resource; import java.io.File; import java.util.ArrayList; import java.util.List; -import java.util.Map; import javax.ejb.Local; @@ -33,9 +32,7 @@ import com.xensource.xenapi.Types; import com.xensource.xenapi.VM; import org.apache.cloudstack.hypervisor.xenserver.XenServerResourceNewBase; -import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs; -import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.resource.ServerResource; import com.cloud.storage.resource.StorageSubsystemCommandHandler; import com.cloud.storage.resource.StorageSubsystemCommandHandlerBase; @@ -70,14 +67,6 @@ public class Xenserver625Resource extends XenServerResourceNewBase { } @Override - protected void fillHostInfo(Connection conn, StartupRoutingCommand cmd) { - super.fillHostInfo(conn, cmd); - Map<String, String> details = cmd.getHostDetails(); - details.put("XS620HotFix", XenserverConfigs.XSHotFix62ESP1004); - cmd.setHostDetails(details); - } - - @Override public long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam){ long recommendedValue = CitrixHelper.getXenServer625StaticMax(os, b); if(recommendedValue == 0){ http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15c14232/plugins/hypervisors/xen/src/org/apache/cloudstack/hypervisor/xenserver/XenserverConfigs.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/org/apache/cloudstack/hypervisor/xenserver/XenserverConfigs.java b/plugins/hypervisors/xen/src/org/apache/cloudstack/hypervisor/xenserver/XenserverConfigs.java index 50388a7..bec4740 100644 --- a/plugins/hypervisors/xen/src/org/apache/cloudstack/hypervisor/xenserver/XenserverConfigs.java +++ b/plugins/hypervisors/xen/src/org/apache/cloudstack/hypervisor/xenserver/XenserverConfigs.java @@ -19,7 +19,7 @@ package org.apache.cloudstack.hypervisor.xenserver; public final class XenserverConfigs { - public static final String XSHasHotFix62ESP1004 = "xs_has_hot_fix_esp1004"; + public static final String XS620HotFix = "xs620hotfix"; public static final String XSHotFix62ESP1 = "0850b186-4d47-11e3-a720-001b2151a503"; public static final String XSHotFix62ESP1004 = "996dd2e7-ad95-49cc-a0be-2c9adc4dfb0b"; }
