cleanup XenServer code

This commit is contained in:
anthony 2011-01-28 18:47:14 -08:00
parent 24e4c885e2
commit 76ad02d2fa
8 changed files with 116 additions and 407 deletions

View File

@ -1,48 +0,0 @@
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 XenServer56FP1PremiumResource extends XenServer56Resource {
private final static Logger s_logger = Logger.getLogger(XenServer56FP1PremiumResource.class);
public XenServer56FP1PremiumResource() {
super();
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer56FP1GuestOsType(stdType);
}
@Override
protected List<File> getPatchFiles() {
List<File> files = new ArrayList<File>();
String patch = "scripts/vm/hypervisor/xenserver/xenserver56fp1/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);
patch = "premium-scripts/vm/hypervisor/xenserver/xenserver56fp1/patch";
patchfilePath = Script.findScript("" , patch);
if (patchfilePath == null) {
throw new CloudRuntimeException("Unable to find patch file " + patch);
}
file = new File(patchfilePath);
files.add(file);
return files;
}
}

View File

@ -35,7 +35,7 @@ import com.xensource.xenapi.Types.XenAPIException;
@Local(value=ServerResource.class)
public class XenServer56FP1Resource extends CitrixResourceBase {
public class XenServer56FP1Resource extends XenServer56Resource {
private static final Logger s_logger = Logger.getLogger(XenServer56FP1Resource.class);
public XenServer56FP1Resource() {
@ -46,12 +46,7 @@ public class XenServer56FP1Resource extends CitrixResourceBase {
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServer56FP1GuestOsType(stdType);
}
@Override
protected void setMemory(Connection conn, VM vm, long memsize) throws XmlRpcException, XenAPIException {
vm.setMemoryLimits(conn, memsize, memsize, memsize, memsize);
}
@Override
protected List<File> getPatchFiles() {
List<File> files = new ArrayList<File>();

View File

@ -72,7 +72,7 @@ import com.xensource.xenapi.VLAN;
import com.xensource.xenapi.VM;
@Local(value = ServerResource.class)
public class XenServer56Resource extends XenServerResource {
public class XenServer56Resource extends CitrixResourceBase {
private final static Logger s_logger = Logger.getLogger(XenServer56Resource.class);
protected int _heartbeatInterval = 60;
@ -88,6 +88,12 @@ public class XenServer56Resource extends XenServerResource {
return super.executeRequest(cmd);
}
}
@Override
protected void setMemory(Connection conn, VM vm, long memsize) throws XmlRpcException, XenAPIException {
vm.setMemoryLimits(conn, memsize, memsize, memsize, memsize);
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {

View File

@ -1,73 +0,0 @@
/**
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
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 org.apache.xmlrpc.XmlRpcException;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.SecurityIngressRuleAnswer;
import com.cloud.agent.api.SecurityIngressRulesCmd;
import com.cloud.hypervisor.xen.resource.CitrixResourceBase;
import com.xensource.xenapi.VM;
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.Types.XenAPIException;
@Local(value=ServerResource.class)
public class XenServerResource extends CitrixResourceBase {
private static final Logger s_logger = Logger.getLogger(XenServerResource.class);
public XenServerResource() {
super();
}
@Override
protected String getGuestOsType(String stdType, boolean bootFromCD) {
return CitrixHelper.getXenServerGuestOsType(stdType);
}
@Override
protected void setMemory(Connection conn, VM vm, long memsize) throws XmlRpcException, XenAPIException {
vm.setMemoryLimits(conn, memsize, memsize, memsize, memsize);
}
@Override
protected List<File> getPatchFiles() {
List<File> files = new ArrayList<File>();
String patch = "scripts/vm/hypervisor/xenserver/xenserver56/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;
}
}

View File

@ -39,12 +39,16 @@ import com.cloud.agent.api.AgentControlCommand;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.alert.AlertManager;
import com.cloud.configuration.Config;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConnectionException;
import com.cloud.exception.DiscoveryException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.HostEnvironment;
import com.cloud.host.HostInfo;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
@ -54,8 +58,8 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.xen.resource.CitrixResourceBase;
import com.cloud.hypervisor.xen.resource.XcpServerResource;
import com.cloud.hypervisor.xen.resource.XenServer56FP1Resource;
import com.cloud.hypervisor.xen.resource.XenServer56Resource;
import com.cloud.hypervisor.xen.resource.XenServerConnectionPool;
import com.cloud.hypervisor.xen.resource.XenServerResource;
import com.cloud.resource.Discoverer;
import com.cloud.resource.DiscovererBase;
import com.cloud.resource.ServerResource;
@ -74,6 +78,8 @@ import com.xensource.xenapi.Pool;
import com.xensource.xenapi.Session;
import com.xensource.xenapi.Types.SessionAuthenticationFailed;
import com.xensource.xenapi.Types.XenAPIException;
import com.cloud.agent.api.SetupCommand;
import com.cloud.agent.api.SetupAnswer;
@Local(value=Discoverer.class)
public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, Listener {
@ -86,6 +92,15 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
protected XenServerConnectionPool _connPool;
protected boolean _checkHvm;
protected String _guestNic;
protected boolean _setupMultipath;
private String _minProductVersion;
private String _minXapiVersion;
private String _minXenVersion;
private String _maxProductVersion;
private String _maxXapiVersion;
private String _maxXenVersion;
@Inject protected AlertManager _alertMgr;
@Inject protected AgentManager _agentMgr;
@ -366,7 +381,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
return new XcpServerResource();
if(prodBrand.equals("XenServer") && prodVersion.equals("5.6.0"))
return new XenServerResource();
return new XenServer56Resource();
if(prodBrand.equals("XenServer") && prodVersion.equals("5.6.100"))
return new XenServer56FP1Resource();
@ -378,7 +393,27 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
}
protected void serverConfig() {
_minXenVersion = _params.get(Config.XenMinVersion.key());
if (_minXenVersion == null) {
_minXenVersion = "3.3.1";
}
_minProductVersion = _params.get(Config.XenProductMinVersion.key());
if (_minProductVersion == null) {
_minProductVersion = "5.5.0";
}
_minXapiVersion = _params.get(Config.XenXapiMinVersion.key());
if (_minXapiVersion == null) {
_minXapiVersion = "1.3";
}
_maxXenVersion = _params.get(Config.XenMaxVersion.key());
_maxProductVersion = _params.get(Config.XenProductMaxVersion.key());
_maxXapiVersion = _params.get(Config.XenXapiMaxVersion.key());
String value = _params.get(Config.XenSetupMultipath.key());
_setupMultipath = Boolean.parseBoolean(value);
}
@Override
@ -468,6 +503,50 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
@Override
public void processConnect(HostVO agent, StartupCommand cmd) throws ConnectionException {
if (!(cmd instanceof StartupRoutingCommand )) {
return;
}
long agentId = agent.getId();
StartupRoutingCommand startup = (StartupRoutingCommand)cmd;
if (startup.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Not XenServer so moving on.");
return;
}
HostVO host = _hostDao.findById(agentId);
if (host.isSetup()) {
return;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up host " + agentId);
}
HostEnvironment env = new HostEnvironment();
SetupCommand setup = new SetupCommand(env);
if (_setupMultipath) {
setup.setMultipathOn();
}
try {
SetupAnswer answer = (SetupAnswer)_agentMgr.send(agentId, setup);
if (answer != null && answer.getResult()) {
host.setSetup(true);
host.setLastPinged((System.currentTimeMillis()>>10) - 5 * 60 );
_hostDao.update(host.getId(), host);
if ( answer.needReconnect() ) {
throw new ConnectionException(false, "Reinitialize agent after setup.");
}
return;
} else {
s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null)?answer.getDetails():"return null"));
}
} catch (AgentUnavailableException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
} catch (OperationTimedoutException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
}
throw new ConnectionException(true, "Reinitialize agent after setup.");
}
@Override

View File

@ -1,276 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.hypervisor.xen.discoverer;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import com.cloud.agent.api.SetupAnswer;
import com.cloud.agent.api.SetupCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.alert.AlertManager;
import com.cloud.configuration.Config;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConnectionException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.HostEnvironment;
import com.cloud.host.HostVO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.xen.resource.CitrixResourceBase;
import com.cloud.hypervisor.xen.resource.XenServer56FP1PremiumResource;
import com.cloud.hypervisor.xen.resource.XenServer56Resource;
import com.cloud.maint.Version;
import com.cloud.resource.Discoverer;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Host;
import com.xensource.xenapi.HostPatch;
import com.xensource.xenapi.PoolPatch;
import com.xensource.xenapi.Types.XenAPIException;
@Local(value=Discoverer.class)
public class XenServerDiscoverer extends XcpServerDiscoverer {
private static final Logger s_logger = Logger.getLogger(XenServerDiscoverer.class);
private String _minProductVersion;
private String _minXapiVersion;
private String _minXenVersion;
private String _maxProductVersion;
private String _maxXapiVersion;
private String _maxXenVersion;
private List<Pair<String, String>> _requiredPatches;
private boolean _setupMultipath;
protected XenServerDiscoverer() {
}
@Override
protected CitrixResourceBase createServerResource(long dcId, Long podId, Host.Record record) {
String prodBrand = record.softwareVersion.get("product_brand").trim();
String prodVersion = record.softwareVersion.get("product_version").trim();
if(prodBrand.equals("XenServer")){
if(prodVersion.equals("5.6.0")) {
return new XenServer56Resource();
} else if(prodVersion.equals("5.6.100")) {
return new XenServer56FP1PremiumResource();
}
}
String msg = "Only support XenServer 5.6 and XenServer 5.6 FP1, but this one is " + prodBrand + " " + prodVersion;
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
throw new RuntimeException(msg);
}
protected boolean checkServer(Connection conn, long dcId, Long podId, Host host, Host.Record record) {
String prodVersion = record.softwareVersion.get("product_version");
String xapiVersion = record.softwareVersion.get("xapi");
String xenVersion = record.softwareVersion.get("xen");
String prodBrand = record.softwareVersion.get("product_brand");
if(!prodBrand.equals("XenServer")) {
String msg = "Do not support product brand " + prodBrand;
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
throw new RuntimeException(msg);
}
if (Version.compare(_minProductVersion, prodVersion) > 0) {
String msg = "Unable to add host " + record.address + " because the product version " + prodVersion + " is lower than the minimum " + _minProductVersion;
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
return false;
}
if (_maxProductVersion != null && Version.compare(prodVersion, _maxProductVersion) > 0) {
String msg = "Unable to add host " + record.address + " because the product version " + prodVersion + " is higher than the maximum " + _maxProductVersion;
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
return false;
}
if (Version.compare(_minXenVersion, xenVersion) > 0) {
String msg = "Unable to add host " + record.address + " because the xen version " + xenVersion + " is lower than the minimum " + _minXenVersion;
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
return false;
}
if (_maxXenVersion != null && Version.compare(xenVersion, _maxXenVersion) > 0) {
String msg = "Unable to add host " + record.address + " because the xen version " + xenVersion + " is higher than the maximum " + _maxXenVersion;
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
return false;
}
if (Version.compare(_minXapiVersion, xapiVersion) > 0) {
String msg = "Unable to add host " + record.address + " because the xapi version " + xapiVersion + " is lower than the minimum " + _minXapiVersion;
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
return false;
}
if (_maxXapiVersion != null && Version.compare(xapiVersion, _maxXapiVersion) > 0) {
String msg = "Unable to add host " + record.address + " because the xapi version " + xapiVersion + " is higher than the maximum " + _maxXapiVersion;
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
return false;
}
if(Version.compare(prodVersion, _minProductVersion) >= 0)
return true;
Set<Ternary<String, String, Boolean>> required = new HashSet<Ternary<String, String, Boolean>>(_requiredPatches.size());
for (Pair<String, String> req : _requiredPatches) {
required.add(new Ternary<String, String, Boolean>(req.first(), req.second(), false));
}
try {
Set<HostPatch> patches = host.getPatches(conn);
if (patches != null) {
for (HostPatch patch : patches) {
HostPatch.Record hpr = patch.getRecord(conn);
PoolPatch.Record ppr = hpr.poolPatch.getRecord(conn);
for (Ternary<String, String, Boolean> req: required) {
if (hpr.nameLabel != null && hpr.nameLabel.contains(req.first()) &&
hpr.version != null && hpr.version.contains(req.second())) {
req.third(true);
break;
}
if (ppr.nameLabel != null && ppr.nameLabel.contains(req.first()) &&
ppr.version != null && ppr.version.contains(req.second())) {
req.third(true);
break;
}
}
}
}
for (Ternary<String, String, Boolean> req : required) {
if (!req.third()) {
String msg = "Unable to add host " + record.address + " because unable to find the following patch: " + req.first() + " version " + req.second();
s_logger.warn(msg);
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
return false;
}
}
} catch (XenAPIException e) {
s_logger.warn("Unable to add " + record.address, e);
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + record.address , "Error is " + e.getMessage());
return false;
} catch (XmlRpcException e) {
s_logger.warn("Unable to add " + record.address, e);
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + record.address, "Error is " + e.getMessage());
return false;
}
return true;
}
@Override
protected void serverConfig() {
_minXenVersion = _params.get(Config.XenMinVersion.key());
if (_minXenVersion == null) {
_minXenVersion = "3.3.1";
}
_minProductVersion = _params.get(Config.XenProductMinVersion.key());
if (_minProductVersion == null) {
_minProductVersion = "5.5.0";
}
_minXapiVersion = _params.get(Config.XenXapiMinVersion.key());
if (_minXapiVersion == null) {
_minXapiVersion = "1.3";
}
_maxXenVersion = _params.get(Config.XenMaxVersion.key());
_maxProductVersion = _params.get(Config.XenProductMaxVersion.key());
_maxXapiVersion = _params.get(Config.XenXapiMaxVersion.key());
String value = _params.get(Config.XenSetupMultipath.key());
_setupMultipath = Boolean.parseBoolean(value);
}
@Override
public void processConnect(HostVO agent, StartupCommand cmd) throws ConnectionException {
super.processConnect(agent, cmd);
if (!(cmd instanceof StartupRoutingCommand )) {
return;
}
long agentId = agent.getId();
StartupRoutingCommand startup = (StartupRoutingCommand)cmd;
if (startup.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Not XenServer so moving on.");
return;
}
HostVO host = _hostDao.findById(agentId);
if (host.isSetup()) {
return;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up host " + agentId);
}
HostEnvironment env = new HostEnvironment();
SetupCommand setup = new SetupCommand(env);
if (_setupMultipath) {
setup.setMultipathOn();
}
try {
SetupAnswer answer = (SetupAnswer)_agentMgr.send(agentId, setup);
if (answer != null && answer.getResult()) {
host.setSetup(true);
host.setLastPinged((System.currentTimeMillis()>>10) - 5 * 60 );
_hostDao.update(host.getId(), host);
if ( answer.needReconnect() ) {
throw new ConnectionException(false, "Reinitialize agent after setup.");
}
return;
} else {
s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null)?answer.getDetails():"return null"));
}
} catch (AgentUnavailableException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
} catch (OperationTimedoutException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
}
throw new ConnectionException(true, "Reinitialize agent after setup.");
}
}

7
thirdparty/.classpath vendored Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>^

19
thirdparty/.project vendored Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>thirdparty</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>