execute only emergency command with slaveconn. othersiwe api call hands

This commit is contained in:
anthony 2010-09-14 19:22:24 -07:00
parent c3144e0d76
commit 05499fa5f6
4 changed files with 679 additions and 453 deletions

View File

@ -153,7 +153,6 @@ import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.network.Network.BroadcastDomainType;
import com.cloud.network.Network.TrafficType;
import com.cloud.hypervisor.xen.resource.XenServerConnectionPool.XenServerConnection;
import com.cloud.resource.ServerResource;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.ImageFormat;
@ -282,7 +281,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
s_logger.debug("Logging out of " + _host.uuid);
if (_host.pool != null) {
_connPool.disconnect(_host.uuid, _host.pool);
_host.pool = null;
}
}
@ -446,15 +444,26 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
}
protected boolean pingxenserver() {
String status;
status = callHostPlugin("vmops", "pingxenserver");
if (status == null || status.isEmpty()) {
Session slaveSession = null;
Connection slaveConn = null;
try {
URL slaveUrl = null;
slaveUrl = new URL("http://" + _host.ip);
slaveConn = new Connection(slaveUrl, 100);
slaveSession = Session.slaveLocalLoginWithPassword(slaveConn, _username, _password);
return true;
} catch (Exception e) {
return false;
} finally {
if( slaveSession != null ){
try{
Session.localLogout(slaveConn);
} catch (Exception e) {
}
slaveConn.dispose();
}
}
return true;
}
protected String logX(XenAPIObject obj, String msg) {
@ -2536,42 +2545,45 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
public boolean joinPool(String address, String username, String password) {
Connection conn = getConnection();
public boolean joinPool(String masterIp, String username, String password) {
Connection slaveConn = null;
Connection poolConn = null;
Session slaveSession = null;
URL slaveUrl = null;
try {
// set the _host.poolUuid to the old pool uuid in case it's not set.
_host.pool = getPoolUuid();
// Connect and find out about the new connection to the new pool.
poolConn = _connPool.connect(address, username, password, _wait);
Map<Pool, Pool.Record> pools = Pool.getAllRecords(poolConn);
Pool.Record pr = pools.values().iterator().next();
// Now join it.
String masterAddr = pr.master.getAddress(poolConn);
Pool.join(conn, masterAddr, username, password);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Joined the pool at " + masterAddr);
poolConn = _connPool.masterConnect(masterIp, username, password);
//check if this host is already in pool
Set<Host> hosts = Host.getAll(poolConn);
for( Host host : hosts ) {
if(host.getAddress(poolConn).equals(_host.ip)) {
return true;
}
}
disconnected(); // Logout of our own session.
slaveUrl = new URL("http://" + _host.ip);
slaveConn = new Connection(slaveUrl, 100);
slaveSession = Session.slaveLocalLoginWithPassword(slaveConn, _username, _password);
// Now join it.
Pool.join(slaveConn, masterIp, username, password);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Joined the pool at " + masterIp);
}
try {
// slave will restart xapi in 10 sec
Thread.sleep(10000);
} catch (InterruptedException e) {
}
// Set the pool uuid now to the newest pool.
_host.pool = pr.uuid;
URL url;
try {
url = new URL("http://" + _host.ip);
} catch (MalformedURLException e1) {
throw new CloudRuntimeException("Problem with url " + _host.ip);
}
Connection c = null;
// check if the master of this host is set correctly.
Connection c = new Connection(slaveUrl, 100);
for (int i = 0; i < 15; i++) {
c = new Connection(url, _wait);
try {
Session.loginWithPassword(c, _username, _password, APIVersion.latest().toString());
s_logger.debug("Still waiting for the conversion to the master");
@ -2597,18 +2609,33 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
} catch (InterruptedException e) {
}
}
return true;
} catch (MalformedURLException e) {
throw new CloudRuntimeException("Problem with url " + _host.ip);
} catch (XenAPIException e) {
String msg = "Unable to allow host " + _host.uuid + " to join pool " + address + " due to " + e.toString();
String msg = "Unable to allow host " + _host.uuid
+ " to join pool " + masterIp + " due to " + e.toString();
s_logger.warn(msg, e);
throw new RuntimeException(msg);
} catch (XmlRpcException e) {
String msg = "Unable to allow host " + _host.uuid + " to join pool " + address + " due to " + e.getMessage();
String msg = "Unable to allow host " + _host.uuid
+ " to join pool " + masterIp + " due to " + e.getMessage();
s_logger.warn(msg, e);
throw new RuntimeException(msg);
} finally {
if (poolConn != null) {
XenServerConnectionPool.logout(poolConn);
try {
Session.logout(poolConn);
} catch (Exception e) {
}
poolConn.dispose();
}
if(slaveSession != null) {
try {
Session.localLogout(slaveConn);
} catch (Exception e) {
}
}
}
}
@ -3414,6 +3441,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
return false;
return true;
}
protected String callHostPlugin(String plugin, String cmd, String... params) {
//default time out is 300 s
return callHostPluginWithTimeOut(plugin, cmd, 300, params);
@ -3421,23 +3449,10 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
protected String callHostPluginWithTimeOut(String plugin, String cmd, int timeout, String... params) {
Map<String, String> args = new HashMap<String, String>();
Session slaveSession = null;
Connection slaveConn = null;
try {
URL slaveUrl = null;
try {
slaveUrl = new URL("http://" + _host.ip);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
slaveConn = new Connection(slaveUrl, timeout);
slaveSession = Session.slaveLocalLoginWithPassword(slaveConn, _username, _password);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Slave logon successful. session= " + slaveSession);
}
Host host = Host.getByUuid(slaveConn, _host.uuid);
try {
Connection conn = getConnection();
for (int i = 0; i < params.length; i += 2) {
args.put(params[i], params[i + 1]);
}
@ -3445,8 +3460,10 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
if (s_logger.isTraceEnabled()) {
s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args));
}
String result = host.callPlugin(slaveConn, plugin, cmd, args);
if( _host.host == null ) {
_host.host = Host.getByUuid(conn, _host.uuid);
}
String result = _host.host.callPlugin(conn, plugin, cmd, args);
if (s_logger.isTraceEnabled()) {
s_logger.trace("callHostPlugin Result: " + result);
}
@ -3455,13 +3472,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString());
} catch (XmlRpcException e) {
s_logger.debug("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage());
} finally {
if( slaveSession != null) {
try {
Session.localLogout(slaveConn);
} catch (Exception e) {
}
}
}
return null;
}
@ -3941,7 +3951,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
try {
Host myself = Host.getByUuid(conn, _host.uuid);
_host.pool = getPoolUuid();
boolean findsystemvmiso = false;
Set<SR> srs = SR.getByNameLabel(conn, "XenServer Tools");
@ -4198,9 +4207,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
cmd.setCluster(_cluster);
StartupStorageCommand sscmd = initializeLocalSR();
_host.pool = getPoolUuid();
if (sscmd != null) {
/* report pv driver iso */
getPVISO(sscmd);
@ -4503,7 +4509,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
}
public Connection getConnection() {
return _connPool.connect(_host.uuid, _host.ip, _username, _password, _wait);
return _connPool.connect(_host.uuid, _host.pool, _host.ip, _username, _password, _wait);
}
protected void fillHostInfo(StartupRoutingCommand cmd) {
@ -4635,8 +4641,10 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
} catch (NumberFormatException e) {
throw new ConfigurationException("Unable to get the zone " + params.get("zone"));
}
_host.host = null;
_name = _host.uuid;
_host.ip = (String) params.get("url");
_host.pool = (String) params.get("pool");
_username = (String) params.get("username");
_password = (String) params.get("password");
_pod = (String) params.get("pod");
@ -4681,8 +4689,6 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
throw new ConfigurationException("Unable to get the uuid");
}
params.put("domr.scripts.dir", "scripts/network/domr");
String patchPath = getPatchPath();
_patchPath = Script.findScript(patchPath, "patch");
@ -6405,6 +6411,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
public String systemvmisouuid;
public String uuid;
public String ip;
public Host host;
public String publicNetwork;
public String privateNetwork;
public String linkLocalNetwork;

View File

@ -690,11 +690,12 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
long seq = _hostDao.getNextSequence(hostId);
Request req = new Request(seq, hostId, _nodeId, new Command[] { new CheckHealthCommand() }, true, true);
Answer[] answers = agent.send(req, 50 * 1000);
if (answers[0].getResult()) {
if (answers != null && answers[0] != null ) {
Status status = answers[0].getResult() ? Status.Up : Status.Down;
if (s_logger.isDebugEnabled()) {
s_logger.debug("agent (" + hostId + ") responded to checkHeathCommand, reporting that agent is up");
s_logger.debug("agent (" + hostId + ") responded to checkHeathCommand, reporting that agent is " + status);
}
return answers[0].getResult() ? Status.Up : Status.Down;
return status;
}
} catch (AgentUnavailableException e) {
s_logger.debug("Agent is unavailable so we move on.");

View File

@ -102,6 +102,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password) throws DiscoveryException {
Map<CitrixResourceBase, Map<String, String>> resources = new HashMap<CitrixResourceBase, Map<String, String>>();
Connection conn = null;
Connection slaveConn = null;
if (!url.getScheme().equals("http")) {
String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
s_logger.debug(msg);
@ -113,7 +114,8 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
InetAddress ia = InetAddress.getByName(hostname);
String addr = ia.getHostAddress();
conn = _connPool.connect(addr, username, password, _wait);
conn = _connPool.masterConnect(addr, username, password);
if (conn == null) {
String msg = "Unable to get a connection to " + url;
s_logger.debug(msg);
@ -133,33 +135,33 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
if (clusterId != null) {
cluster = Long.toString(clusterId);
}
Set<Pool> pools = Pool.getAll(conn);
Pool pool = pools.iterator().next();
String poolUuid = pool.getUuid(conn);
Map<Host, Host.Record> hosts = Host.getAllRecords(conn);
if (_checkHvm) {
for (Map.Entry<Host, Host.Record> entry : hosts.entrySet()) {
Host.Record record = entry.getValue();
boolean support_hvm = false;
for ( String capability : record.capabilities ) {
if(capability.contains("hvm")) {
support_hvm = true;
break;
for (Map.Entry<Host, Host.Record> entry : hosts.entrySet()) {
Host.Record record = entry.getValue();
boolean support_hvm = false;
for ( String capability : record.capabilities ) {
if(capability.contains("hvm")) {
support_hvm = true;
break;
}
}
if( !support_hvm ) {
String msg = "Unable to add host " + record.address + " because it doesn't support hvm";
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
throw new RuntimeException(msg);
}
}
if( !support_hvm ) {
String msg = "Unable to add host " + record.address + " because it doesn't support hvm";
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
throw new RuntimeException(msg);
}
}
}
for (Map.Entry<Host, Host.Record> entry : hosts.entrySet()) {
Host.Record record = entry.getValue();
Host host = entry.getKey();
Host.Record record = entry.getValue();
String hostAddr = record.address;
String prodVersion = record.softwareVersion.get("product_version");
@ -180,6 +182,8 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
Map<String, Object> params = new HashMap<String, Object>();
details.put("url", hostAddr);
params.put("url", hostAddr);
details.put("pool", poolUuid);
params.put("pool", poolUuid);
details.put("username", username);
params.put("username", username);
details.put("password", password);
@ -253,10 +257,13 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
return null;
} finally {
if (conn != null) {
XenServerConnectionPool.logout(conn);
try{
Session.logout(conn);
} catch (Exception e ) {
}
conn.dispose();
}
}
return resources;
}
@ -333,20 +340,30 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
username = host.getDetail("username");
password = host.getDetail("password");
address = host.getDetail("url");
Connection hostConn = _connPool.connect(address, username, password, _wait);
Connection hostConn = _connPool.slaveConnect(address, username, password);
if (hostConn == null) {
continue;
}
try {
if (hostConn == null) {
continue;
}
Set<Pool> pools = Pool.getAll(hostConn);
Pool pool = pools.iterator().next();
poolUuid1 = pool.getUuid(hostConn);
poolMaster = pool.getMaster(hostConn).getAddress(hostConn);
Session.logout(hostConn);
} finally {
hostConn.dispose();
break;
} catch (Exception e ) {
s_logger.warn("Can not get master ip address from host " + address);
}
finally {
try{
Session.localLogout(hostConn);
} catch (Exception e ) {
}
hostConn.dispose();
hostConn = null;
poolMaster = null;
poolUuid1 = null;
}
break;
}
if (poolMaster == null) {